Hi Josh,

Try doing this when you read in the data:

> ex.dna<-read.dna("exdna.txt",format="sequential",as.character=T)

This will return an object of class matrix instead of a DNAbin object. The elements in the matrix should just be the letters from your input file.

There may be a better way to do this, but if you already have the object in memory, you can write it to file and then read it back in using read.dna(...,as.character=T), as above.

- Liam

--
Liam J. Revell
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://phytools.blogspot.com

On 4/7/2011 11:16 AM, Josh B wrote:
Dear Listserve,

I have a seemingly simple problem that I cannot figure out. I would like to
convert an element of class DNAbin to a matrix.

Consider the example from the read.dna help file:

cat("3 40",
"No305     NTTCGAAAAACACACCCACTACTAAAANTTATCAGTCACT",
"No304     ATTCGAAAAACACACCCACTACTAAAAATTATCAACCACT",
"No306     ATTCGAAAAACACACCCACTACTAAAAATTATCAATCACT",
file = "exdna.txt", sep = "\n")
ex.dna<- read.dna("exdna.txt", format = "sequential")

This is where I am stuck: how do I create a matrix from ex.dna, where the
rownames are "No305", "No304", and "No306", and the columns are the aligned
single-nucleotide sites. For example, Column 1 should have the value of "N" for
row "No305", the value of "A" for row "No304", and the value of "A" for row
"No306," corresponding to the values of the first site in the sequence.

Thank you very much for your help!
-----------------------------------
Josh Banta, Ph.D
Center for Genomics and Systems Biology
New York University
100 Washington Square East
New York, NY 10003
Tel: (212) 998-8465
http://plantevolutionaryecology.org

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

Reply via email to