]> git.donarmstrong.com Git - ape.git/blob - man/read.dna.Rd
3d4d33b9cc250f1872a18d91e34e4e9d673ad2d5
[ape.git] / man / read.dna.Rd
1 \name{read.dna}
2 \alias{read.dna}
3 \title{Read DNA Sequences in a File}
4 \usage{
5 read.dna(file, format = "interleaved", skip = 0,
6          nlines = 0, comment.char = "#", seq.names = NULL,
7          as.character = FALSE)
8 }
9 \arguments{
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 }
27 \description{
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
32   case.
33 }
34 \details{
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.
49
50 \itemize{
51   \item{Interleaved:}{the function starts to read the sequences when it
52     finds 10 contiguous characters belonging to the ambiguity code of
53     the IUPAC (namely A, C, G, T, U, M, R, W, S, Y, K, V, H, D, B, and
54     N, upper- or lowercase, so you might run into trouble if you have a
55     taxa name with 10 contiguous letters among these!) All characters
56     before the sequences are taken as the taxa names after removing the
57     leading and trailing spaces (so spaces in a taxa name are
58     allowed). It is assumed that the taxa names are not repeated in the
59     subsequent blocks of nucleotides.}
60
61   \item{Sequential:}{the same criterion than for the interleaved format
62     is used to start reading the sequences and the taxa names; the
63     sequences are then read until the number of nucleotides specified in
64     the first line of the file is reached. This is repeated for each taxa.}
65
66   \item{Clustal:}{this is the format output by the Clustal programs
67     (.aln). It is somehow similar to the interleaved format: the
68     differences being that the dimensions of the data are not indicated
69     in the file, and the names of the sequences are repeated in each block.}
70
71   \item{FASTA:}{This looks like the sequential format but the taxa names
72     (or rather a description of the sequence) are on separate lines
73     beginning with a `greater than' character ``>'' (there may be
74     leading spaces before this character). These lines are taken as taxa
75     names after removing the ``>'' and the possible leading and trailing
76     spaces. All the data in the file before the first sequence is ignored.}
77 }}
78 \value{
79   a matrix or a list (if \code{format = "fasta"}) of DNA sequences
80   stored in binary format, or of mode character (if \code{as.character =
81     "TRUE"}).
82 }
83 \references{
84   Anonymous. FASTA format description.
85   \url{http://www.ncbi.nlm.nih.gov/BLAST/fasta.html}
86
87   Anonymous. IUPAC ambiguity codes.
88   \url{http://www.ncbi.nlm.nih.gov/SNP/iupac.html}
89
90   Felsenstein, J. (1993) Phylip (Phylogeny Inference Package) version
91   3.5c. Department of Genetics, University of Washington.
92   \url{http://evolution.genetics.washington.edu/phylip/phylip.html}
93 }
94 \seealso{
95   \code{\link{read.GenBank}}, \code{\link{write.dna}},
96   \code{\link{DNAbin}}, \code{\link{dist.dna}}, \code{\link{woodmouse}}
97 }
98 \author{Emmanuel Paradis \email{Emmanuel.Paradis@mpl.ird.fr}}
99 \examples{
100 ### a small extract from `data(woddmouse)'
101 cat("3 40",
102 "No305     NTTCGAAAAACACACCCACTACTAAAANTTATCAGTCACT",
103 "No304     ATTCGAAAAACACACCCACTACTAAAAATTATCAACCACT",
104 "No306     ATTCGAAAAACACACCCACTACTAAAAATTATCAATCACT",
105 file = "exdna.txt", sep = "\n")
106 ex.dna <- read.dna("exdna.txt", format = "sequential")
107 str(ex.dna)
108 ex.dna
109 ### the same data in interleaved format...
110 cat("3 40",
111 "No305     NTTCGAAAAA CACACCCACT",
112 "No304     ATTCGAAAAA CACACCCACT",
113 "No306     ATTCGAAAAA CACACCCACT",
114 "          ACTAAAANTT ATCAGTCACT",
115 "          ACTAAAAATT ATCAACCACT",
116 "          ACTAAAAATT ATCAATCACT",
117 file = "exdna.txt", sep = "\n")
118 ex.dna2 <- read.dna("exdna.txt")
119 ### ... in clustal format...
120 cat("CLUSTAL (ape) multiple sequence alignment", "",
121 "No305     NTTCGAAAAACACACCCACTACTAAAANTTATCAGTCACT",
122 "No304     ATTCGAAAAACACACCCACTACTAAAAATTATCAACCACT",
123 "No306     ATTCGAAAAACACACCCACTACTAAAAATTATCAATCACT",
124 "           ************************** ******  ****",
125 file = "exdna.txt", sep = "\n")
126 ex.dna3 <- read.dna("exdna.txt", format = "clustal")
127 ### ... and in FASTA format
128 cat("> No305",
129 "NTTCGAAAAACACACCCACTACTAAAANTTATCAGTCACT",
130 "> No304",
131 "ATTCGAAAAACACACCCACTACTAAAAATTATCAACCACT",
132 "> No306",
133 "ATTCGAAAAACACACCCACTACTAAAAATTATCAATCACT",
134 file = "exdna.txt", sep = "\n")
135 ex.dna4 <- read.dna("exdna.txt", format = "fasta")
136 ### The first three are the same!
137 identical(ex.dna, ex.dna2)
138 identical(ex.dna, ex.dna3)
139 identical(ex.dna, ex.dna4)
140 unlink("exdna.txt") # clean-up
141 }
142 \keyword{IO}