3 \title{Read DNA Sequences in a File}
5 read.dna(file, format = "interleaved", skip = 0,
6 nlines = 0, comment.char = "#", seq.names = NULL,
10 \item{file}{a file name specified by either a variable of mode character,
11 or a double-quoted string.}
12 \item{format}{a character string specifying the format of the DNA
13 sequences. Four choices are possible: \code{"interleaved"},
14 \code{"sequential"}, \code{"clustal"}, or \code{"fasta"}, or any
15 unambiguous abbreviation of these.}
16 \item{skip}{the number of lines of the input file to skip before
17 beginning to read data.}
18 \item{nlines}{the number of lines to be read (by default the file is
19 read untill its end).}
20 \item{comment.char}{a single character, the remaining of the line
21 after this character is ignored.}
22 \item{seq.names}{the names to give to each sequence; by default the
23 names read in the file are used.}
24 \item{as.character}{a logical controlling whether to return the
25 sequences as an object of class \code{"DNAbin"} (the default).}
28 This function reads DNA sequences in a file, and returns a matrix or a
29 list of DNA sequences with the names of the taxa read in the file as
30 rownames or names, respectively. By default, the sequences are stored
31 in binary format, otherwise (if \code{as.character = "TRUE"}) in lower
35 This function follows the interleaved and sequential formats defined
36 in PHYLIP (Felsenstein, 1993) but with the original feature than there
37 is no restriction on the lengths of the taxa names. For these two
38 formats, the first line of the file must contain the dimensions of the
39 data (the numbers of taxa and the numbers of nucleotides); the
40 sequences are considered as aligned and thus must be of the same
41 lengths for all taxa. For the FASTA format, the conventions defined in
42 the URL below (see References) are followed; the sequences are taken as
43 non-aligned. For all formats, the nucleotides can be arranged in any
44 way with blanks and line-breaks inside (with the restriction that the
45 first ten nucleotides must be contiguous for the interleaved and
46 sequential formats, see below). The names of the sequences are read in
47 the file unless the `seq.names' option is used. Particularities for
48 each format are detailed below.
50 \item{Interleaved:}{the function starts to read the sequences when it
51 finds 10 contiguous characters belonging to the ambiguity code of
52 the IUPAC (namely A, C, G, T, U, M, R, W, S, Y, K, V, H, D, B, and
53 N, upper- or lowercase, so you might run into trouble if you have a
54 taxa name with 10 contiguous letters among these!) All characters
55 before the sequences are taken as the taxa names after removing the
56 leading and trailing spaces (so spaces in a taxa name are
57 allowed). It is assumed that the taxa names are not repeated in the
58 subsequent blocks of nucleotides.}
60 \item{Sequential:}{the same criterion than for the interleaved format
61 is used to start reading the sequences and the taxa names; the
62 sequences are then read until the number of nucleotides specified in
63 the first line of the file is reached. This is repeated for each taxa.}
65 \item{Clustal:}{this is the format output by the Clustal programs
66 (.aln). It is somehow similar to the interleaved format: the
67 differences being that the dimensions of the data are not indicated
68 in the file, and the names of the sequences are repeated in each block.}
70 \item{FASTA:}{This looks like the sequential format but the taxa names
71 (or rather a description of the sequence) are on separate lines
72 beginning with a `greater than' character ``>'' (there may be
73 leading spaces before this character). These lines are taken as taxa
74 names after removing the ``>'' and the possible leading and trailing
75 spaces. All the data in the file before the first sequence is ignored.}
78 a matrix or a list (if \code{format = "fasta"}) of DNA sequences
79 stored in binary format, or of mode character (if \code{as.character =
83 Anonymous. FASTA format description.
84 \url{http://www.ncbi.nlm.nih.gov/BLAST/fasta.html}
86 Anonymous. IUPAC ambiguity codes.
87 \url{http://www.ncbi.nlm.nih.gov/SNP/iupac.html}
89 Felsenstein, J. (1993) Phylip (Phylogeny Inference Package) version
90 3.5c. Department of Genetics, University of Washington.
91 \url{http://evolution.genetics.washington.edu/phylip/phylip.html}
94 \code{\link{read.GenBank}}, \code{\link{write.dna}},
95 \code{\link{DNAbin}}, \code{\link{dist.dna}}, \code{\link{woodmouse}}
97 \author{Emmanuel Paradis \email{Emmanuel.Paradis@mpl.ird.fr}}
99 ### a small extract from `data(woddmouse)'
101 "No305 NTTCGAAAAACACACCCACTACTAAAANTTATCAGTCACT",
102 "No304 ATTCGAAAAACACACCCACTACTAAAAATTATCAACCACT",
103 "No306 ATTCGAAAAACACACCCACTACTAAAAATTATCAATCACT",
104 file = "exdna.txt", sep = "\n")
105 ex.dna <- read.dna("exdna.txt", format = "sequential")
108 ### the same data in interleaved format...
110 "No305 NTTCGAAAAA CACACCCACT",
111 "No304 ATTCGAAAAA CACACCCACT",
112 "No306 ATTCGAAAAA CACACCCACT",
113 " ACTAAAANTT ATCAGTCACT",
114 " ACTAAAAATT ATCAACCACT",
115 " ACTAAAAATT ATCAATCACT",
116 file = "exdna.txt", sep = "\n")
117 ex.dna2 <- read.dna("exdna.txt")
118 ### ... in clustal format...
119 cat("CLUSTAL (ape) multiple sequence alignment", "",
120 "No305 NTTCGAAAAACACACCCACTACTAAAANTTATCAGTCACT",
121 "No304 ATTCGAAAAACACACCCACTACTAAAAATTATCAACCACT",
122 "No306 ATTCGAAAAACACACCCACTACTAAAAATTATCAATCACT",
123 " ************************** ****** ****",
124 file = "exdna.txt", sep = "\n")
125 ex.dna3 <- read.dna("exdna.txt", format = "clustal")
126 ### ... and in FASTA format
128 "NTTCGAAAAACACACCCACTACTAAAANTTATCAGTCACT",
130 "ATTCGAAAAACACACCCACTACTAAAAATTATCAACCACT",
132 "ATTCGAAAAACACACCCACTACTAAAAATTATCAATCACT",
133 file = "exdna.txt", sep = "\n")
134 ex.dna4 <- read.dna("exdna.txt", format = "fasta")
135 ### The first three are the same!
136 identical(ex.dna, ex.dna2)
137 identical(ex.dna, ex.dna3)
138 identical(ex.dna, ex.dna4)
139 unlink("exdna.txt") # clean-up