write.fasta: Write Sequences to a FASTA Text File

View source: R/write.fasta.R

write.fastaR Documentation

Write Sequences to a FASTA Text File

Description

A function to write a vector of strings representing nucleotide sequences into a text file, with optional line breaks

Usage

write.fasta(x, file, linebreak = NULL, sep = "\n")

Arguments

x

A character vector storing the nucleotide sequences.

file

A character string describing the connection (see the description of argument description in function file help page).

linebreak

Interval for line breaking to improve file readability (default: NULL, meaning no line breaking).

sep

Character used for line breaking (default: "\n").

Value

NULL (invisibly).

Author(s)

Guillaume Guénard [aut, cre] (<https://orcid.org/0000-0003-0761-3072>), Pierre Legendre [ctb] (<https://orcid.org/0000-0002-3838-3305>)

Examples

## Define a raw vector for storing nuceotide values:
c(Sequence_1 = "ATCG-TTTCG--CCCCA--TTA--TTAA-GTAA-GTAATCTTTCA",
  Sequence_2 = "TTGGCTTCC--TC--CAT-TTC--TTCA-GT-ACG-ATTCTTTTA",
  Sequence_3 = "TTCG-TACC-T-T---A-ATAA--T-AA-GTCTTGTAATCGTTCA") %>%
  sapply(charToRaw) %>%
  t -> sqn

## Display the raw sequence:
sqn

## Transforming the sequence to character strings
tmp <- concatenate(sqn)
tmp

## Transforming the sequence to character strings without the gaps:
concatenate(sqn, discard="-")

## Write the sequences into a text file:
write.fasta(tmp, file="Sequences.fst", linebreak=15)

## Clean-up:
file.remove("Sequences.fst")
rm(sqn, tmp)


guenardg/MPSEM documentation built on April 14, 2025, 3:53 p.m.