3 \title{Read DNA Sequences in a File}
5 read.dna(file, format = "interleaved", skip = 0,
6 nlines = 0, comment.char = "#", seq.names = NULL,
7 as.character = FALSE, as.matrix = 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).}
26 \item{as.matrix}{(used if \code{format = "fasta"}) one of the three
27 followings: (i) \code{NULL}: returns the sequences in a matrix if
28 they are of the same length, otherwise in a list; (ii) \code{TRUE}:
29 returns the sequences in a matrix, or stops with an error if they
30 are of different lengths; (iii) \code{FALSE}: always returns the
34 This function reads DNA sequences in a file, and returns a matrix or a
35 list of DNA sequences with the names of the taxa read in the file as
36 rownames or names, respectively. By default, the sequences are stored
37 in binary format, otherwise (if \code{as.character = "TRUE"}) in lower
41 This function follows the interleaved and sequential formats defined
42 in PHYLIP (Felsenstein, 1993) but with the original feature than there
43 is no restriction on the lengths of the taxa names. For these two
44 formats, the first line of the file must contain the dimensions of the
45 data (the numbers of taxa and the numbers of nucleotides); the
46 sequences are considered as aligned and thus must be of the same
47 lengths for all taxa. For the FASTA format, the conventions defined in
48 the URL below (see References) are followed; the sequences are taken as
49 non-aligned. For all formats, the nucleotides can be arranged in any
50 way with blanks and line-breaks inside (with the restriction that the
51 first ten nucleotides must be contiguous for the interleaved and
52 sequential formats, see below). The names of the sequences are read in
53 the file unless the `seq.names' option is used. Particularities for
54 each format are detailed below.
57 \item{Interleaved:}{the function starts to read the sequences when it
58 finds 10 contiguous characters belonging to the ambiguity code of
59 the IUPAC (namely A, C, G, T, U, M, R, W, S, Y, K, V, H, D, B, and
60 N, upper- or lowercase, so you might run into trouble if you have a
61 taxa name with 10 contiguous letters among these!) All characters
62 before the sequences are taken as the taxa names after removing the
63 leading and trailing spaces (so spaces in a taxa name are
64 allowed). It is assumed that the taxa names are not repeated in the
65 subsequent blocks of nucleotides.}
67 \item{Sequential:}{the same criterion than for the interleaved format
68 is used to start reading the sequences and the taxa names; the
69 sequences are then read until the number of nucleotides specified in
70 the first line of the file is reached. This is repeated for each taxa.}
72 \item{Clustal:}{this is the format output by the Clustal programs
73 (.aln). It is somehow similar to the interleaved format: the
74 differences being that the dimensions of the data are not indicated
75 in the file, and the names of the sequences are repeated in each block.}
77 \item{FASTA:}{This looks like the sequential format but the taxa names
78 (or rather a description of the sequence) are on separate lines
79 beginning with a `greater than' character ``>'' (there may be
80 leading spaces before this character). These lines are taken as taxa
81 names after removing the ``>'' and the possible leading and trailing
82 spaces. All the data in the file before the first sequence is ignored.}
85 a matrix or a list (if \code{format = "fasta"}) of DNA sequences
86 stored in binary format, or of mode character (if \code{as.character =
90 Anonymous. FASTA format description.
91 \url{http://www.ncbi.nlm.nih.gov/BLAST/fasta.html}
93 Anonymous. IUPAC ambiguity codes.
94 \url{http://www.ncbi.nlm.nih.gov/SNP/iupac.html}
96 Felsenstein, J. (1993) Phylip (Phylogeny Inference Package) version
97 3.5c. Department of Genetics, University of Washington.
98 \url{http://evolution.genetics.washington.edu/phylip/phylip.html}
101 \code{\link{read.GenBank}}, \code{\link{write.dna}},
102 \code{\link{DNAbin}}, \code{\link{dist.dna}}, \code{\link{woodmouse}}
104 \author{Emmanuel Paradis}
106 ### a small extract from `data(woddmouse)'
108 "No305 NTTCGAAAAACACACCCACTACTAAAANTTATCAGTCACT",
109 "No304 ATTCGAAAAACACACCCACTACTAAAAATTATCAACCACT",
110 "No306 ATTCGAAAAACACACCCACTACTAAAAATTATCAATCACT",
111 file = "exdna.txt", sep = "\n")
112 ex.dna <- read.dna("exdna.txt", format = "sequential")
115 ### the same data in interleaved format...
117 "No305 NTTCGAAAAA CACACCCACT",
118 "No304 ATTCGAAAAA CACACCCACT",
119 "No306 ATTCGAAAAA CACACCCACT",
120 " ACTAAAANTT ATCAGTCACT",
121 " ACTAAAAATT ATCAACCACT",
122 " ACTAAAAATT ATCAATCACT",
123 file = "exdna.txt", sep = "\n")
124 ex.dna2 <- read.dna("exdna.txt")
125 ### ... in clustal format...
126 cat("CLUSTAL (ape) multiple sequence alignment", "",
127 "No305 NTTCGAAAAACACACCCACTACTAAAANTTATCAGTCACT",
128 "No304 ATTCGAAAAACACACCCACTACTAAAAATTATCAACCACT",
129 "No306 ATTCGAAAAACACACCCACTACTAAAAATTATCAATCACT",
130 " ************************** ****** ****",
131 file = "exdna.txt", sep = "\n")
132 ex.dna3 <- read.dna("exdna.txt", format = "clustal")
133 ### ... and in FASTA format
135 "NTTCGAAAAACACACCCACTACTAAAANTTATCAGTCACT",
137 "ATTCGAAAAACACACCCACTACTAAAAATTATCAACCACT",
139 "ATTCGAAAAACACACCCACTACTAAAAATTATCAATCACT",
140 file = "exdna.txt", sep = "\n")
141 ex.dna4 <- read.dna("exdna.txt", format = "fasta")
142 ### The first three are the same!
143 identical(ex.dna, ex.dna2)
144 identical(ex.dna, ex.dna3)
145 identical(ex.dna, ex.dna4)
146 unlink("exdna.txt") # clean-up