| readFasta {microseq} | R Documentation |
Reads and writes biological sequences (DNA, RNA, protein) in the FASTA format.
readFasta(in.file) writeFasta(fdta, out.file, width = 80)
in.file |
url/directory/name of FASTA file to read. |
fdta |
A |
out.file |
Name of FASTA file to create. |
width |
Number of characters per line, or 0 for no linebreaks. |
These functions handle input/output of sequences in the commonly used FASTA format. For every sequence it is presumed there is one Header-line starting with a ‘>’.
The sequences are stored in a tibble, opening up all the possibilities in R for
fast and easy manipulations. The content of the file is stored as two columns, Header
and Sequence. If other columns are added, these will be ignored by writeFasta.
Setting width = 0 in writeFasta results in no linebreaks in the sequences
(one sequence per line).
readFasta returns a tibble with the contents of the FASTA
file stored in two columns of text. The first, named Header, contains
the headerlines and the second, named Sequence, contains the sequences.
writeFasta produces a FASTA file.
Lars Snipen and Kristian Hovde Liland.
## Not run:
# We need a FASTA-file to read, here is one example file:
fa.file <- file.path(file.path(path.package("microseq"),"extdata"),"small.ffn")
# Read and write
fdta <- readFasta(fa.file)
ok <- writeFasta(fdta[4:5,], out.file = "delete_me.fasta")
# Make use of dplyr to copy parts of the file to another file
readFasta(fa.file) %>%
filter(str_detect(Sequence, "TGA$")) %>%
writeFasta(out.file = "TGAstop.fasta", width = 0) -> ok
## End(Not run)