I want to use a binary matrix to build a phylogenetic tree using the R package [phangorn][1] as done in this paper:[Tracking the Genomic Evolution of Esophageal Adenocarcinoma through Neoadjuvant Chemotherapy][1]

In the methods they say:

> Trees were built using binary presence/absence matrices built from the regional distribution of variants within the tumor. The R Bioconductor package phangorn (1.99-7; ref. 36) was utilized to perform the parsimony ratchet method (18), generating unrooted trees. Branch lengths were determined using the `acctran` function.

I have the binary presence/absence matrix, however the phangorn package uses phyDat objects, which are derived from sequence alignments according to the [phangorn vignettes][3].

My question is:

**How can I use a binary table to build a phylogenetic tree with the R phangorn package?**

If there is a way to read the binary matrix as a phyDat object, that would solve the problem, but I don't see how that could be done.

 [1]: https://github.com/KlausVigo/phangorn
 [2]: http://cancerdiscovery.aacrjournals.org/content/5/8/821.long
 [3]: https://cran.r-project.org/web/packages/phangorn/vignettes/Trees.pdf
Hello Alejandro, 

There are generic functions `as.phyDat()` in phangorn to transform matrices and data.frames into phyDat objects.

For example you can read in your data with `read.table()` or `read.csv()`, but you might need to transpose your data. For matrices `as.phyDat()` assumes that the entries each row belongs to one individual (taxa), but for data.frame each column. For binary data you can transform these with a command like (depending how you coded them):

    as.phyDat(data, type="USER", levels = c(0, 1))
    as.phyDat(data, type="USER", levels = c(TRUE, FALSE))

Regards,  
Klaus