Skip to content

Read Protein Sequences from FASTA Files ​

This function reads protein sequences from the specified FASTA file or all FASTA files within a directory. It specifically looks for metadata in the FASTA headers with key-value pairs separated by an equals sign =. For example, from the header '>protein1 [gene=scnD] [protein=ScnD]', it extracts 'gene' as the key and 'scnD' as its value, and similarly for other key-value pairs.

Usage ​

r
read_fasta(fasta_path, sequence = TRUE, keys = NULL, file_extension = "fasta")

Arguments ​

ArgumentDescription
fasta_pathPath to the FASTA file or directory containing FASTA files.
sequenceLogical; if TRUE, the protein sequences are included in the returned data frame.
keysAn optional vector of strings representing specific keys within the fasta header to retain in the final data frame. If NULL (the default), all keys within the specified feature are included.
file_extensionExtension of the FASTA files to be read from the directory (default is 'fasta').

Value ​

A data frame with columns for each piece of information extracted from the FASTA headers. With a location key, it also has start and end, the full span of the location, and strand: "complement" or "forward".

Details ​

The files are read with base R, so no Bioconductor packages are needed. Gzip-compressed files are read as well.

Examples ​

r
fasta_file <- system.file("extdata", "BGC0000108.fasta", package = "geneviewer")

# Read sequences from a single FASTA file
sequences_df <- read_fasta(fasta_file)

# Read all FASTA files in a directory, without the sequences
sequences_df <- read_fasta(dirname(fasta_file), sequence = FALSE)