## Coercing a matrix to a 'Dna' object.
# all valid characters
x<-matrix(c("?","A","C","g","t","-","0","1","2","3","4","5"),4,6)
rownames(x)<-c("seq1","seq2","seq3","seq4")
dna.obj<-as.dna(x)
dna.obj
# the sequence matrix
dna.obj@sequence
if (FALSE) {
# includes invalid characters
x<-matrix(c("X","y","*","?","t","-","0","1","2","3","4","5"),4,6)
rownames(x)<-c("seq1","seq2","seq3","seq4")
dna.obj<-as.dna(x)
dna.obj
dna.obj@sequence
# all valid integers
x<-matrix(c(0,1,2,3,4,5,0,1,2,3,4,5),4,6)
rownames(x)<-c("seq1","seq2","seq3","seq4")
dna.obj<-as.dna(x)
dna.obj
dna.obj@sequence
## Coercing a data.frame to a 'Dna' object.
x<-data.frame(matrix(c("?","A","C","g","t","-","0","1","2","3","4","5"),4,6))
rownames(x)<-c("seq1","seq2","seq3","seq4")
dna.obj<-as.dna(x)
dna.obj
dna.obj@sequence
## Coercing a list to a 'Dna' object.
seq1<-c("?","A","C","g","t","-","0","1")
seq2<-c("?","A","C","g","t","-","0","1","2")
seq3<-c("?","A","C","g","t","-","0","1","2","3")
x<-list(seq1=seq1,seq2=seq2,seq3=seq3)
dna.obj<-as.dna(x)
# sequence lengths differ
dna.obj@seqlengths
dna.obj@sequence
## Coercing a character vector to a Dna object.
seq<-c("?","A","C","g","t","-","0","1")
x<-as.dna(seq)
x
## Coercing a Haplotype object to a Dna object.
data("dna.obj")
x<-dna.obj
h<-haplotype(x)
# DNA Sequences of unique haplotypes
dna.obj<-as.dna(h)
dna.obj
d<-distance(x)
# if 'Haplotype' object does not contain 'DNA' Sequences
h<-haplotype(d)
# returns an error
as.dna(h)
## Coercing a DNAbin object to a Dna object.
require(ape)
data(woodmouse)
x<-as.dna(woodmouse)
x
}
Run the code above in your browser using DataLab