as.dna-methods: Coerces an object to a 'Dna' object

Description Usage Arguments Details Value Methods Examples

Description

Coerces an object that contains DNA sequences to an object of Class Dna.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## S4 method for signature 'matrix'
as.dna(x)
## S4 method for signature 'data.frame'
as.dna(x)
## S4 method for signature 'list'
as.dna(x)
## S4 method for signature 'character'
as.dna(x)
## S4 method for signature 'Haplotype'
as.dna(x)
## S4 method for signature 'DNAbin'
as.dna(x)
## S4 method for signature 'phyDat'
as.dna(x)

Arguments

x

a matrix, a data.frame, a list, a character, an object of class Haplotype, DNAbin {ape} or phyDat {phangorn} object containing the DNA sequences.

Details

Elements of the list must be vectors. Each element of the list contains a single DNA sequence. If the sequence lengths differ, the longest sequence is taken into account and gaps are introduced to the shorter sequences at the end of the matrix in the slot sequence. Sequence length information is stored in the slot seqlengths.

Valid characters for the slot sequence are "A","C","G","T","a","c","g","t","-","?". During the conversion of the object to the class Dna, integers 0,1,2,3,4,5 or characters "0","1","2","3","4","5" are converted to "?","A","C","G","T","-", respectively. Invalid characters are replaced with "?" with a warning message.

Value

an object of class Dna.

Methods

signature(x = "matrix")

coerces matrix to a Dna object.

signature(x = "data.frame")

coerces data.frame to a Dna object.

signature(x = "list")

coerces list to a Dna object.

signature(x = "character")

coerces characters to a Dna object.

signature(x = "Haplotype")

coerces a Haplotype object to a Dna object.

signature(x = "DNAbin")

coerces a DNAbin object to a Dna object.

signature(x = "phyDat")

coerces a phyDat object to a Dna object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
## 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

## Not run: 
# 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


## End(Not run)

haplotypes documentation built on Feb. 28, 2020, 5:08 p.m.