Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

write.fasta

Write sequence(s) into a file in fasta format


Description

Writes one or more sequences into a file in FASTA format.

Usage

write.fasta(sequences, names, file.out, open = "w", nbchar = 60, as.string = FALSE)

Arguments

sequences

A DNA or protein sequence (in the form of a vector of single characters by default) or a list of such sequences.

as.string

FALSE. When set to TRUE sequences are in the form of strings instead of vectors of single characters.

names

The name(s) of the sequences.

nbchar

The number of characters per line (default: 60)

file.out

The name of the output file.

open

Mode to open the output file, use "w" to write into a new file, use "a" to append at the end of an already existing file.

Value

none.

Author(s)

A. Necşulea

References

citation("seqinr")

See Also

Examples

## Read 3 sequences from a FASTA file:
ortho <- read.fasta(file = system.file("sequences/ortho.fasta", package =
"seqinr"))

## Select only third codon positions:
ortho3 <- lapply(ortho, function(x) x[seq(from = 3, to = length(x), by = 3)])

## Write the 3 modified sequences to a file:
fname <- tempfile(pattern = "ortho3", tmpdir = tempdir(), fileext = "fasta")
#write.fasta(sequences = ortho3, names = names(ortho3), nbchar = 80, file.out = "ortho3.fasta")
write.fasta(sequences = ortho3, names = names(ortho3), nbchar = 80, file.out = fname)

## Read them again from the same file and check that sequences are preserved:
ortho3bis <- read.fasta(fname, set.attributes = FALSE)
stopifnot(identical(ortho3bis, ortho3))

seqinr

Biological Sequences Retrieval and Analysis

v4.2-16
GPL (>= 2)
Authors
Delphine Charif [aut], Olivier Clerc [ctb], Carolin Frank [ctb], Jean R. Lobry [aut, cph], Anamaria Necşulea [ctb], Leonor Palmeira [ctb], Simon Penel [cre], Guy Perrière [ctb]
Initial release
2022-05-19

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.