Skip to contents

These functions read a sequence alignment file and return a named list of sequences. Currently supported formats are `fasta` and `nexus`. Interleaved formats, where sequences are defined in a repeating blocks, are not supported.

Usage

read_sequences(file, format = NULL)

read_fasta(file)

read_nexus(file)

Arguments

file

with alignment

format

requested format

Value

named list of sequences

Details

The function `[read_sequences]` tries to guess the correct format from the file extension. Alternatively, the correct format can be specified. Currently supported formats are fasta and nexus.

Functions `[read_fasta]` and `[read_nexus]` are then used to read the sequence alignment file.

Examples

seq1 = c("A" = "AAA", "B" = "BBB", "C" = "CCC")
fasta = tempfile(fileext = ".fasta")
writeLines(paste0(">", names(seq1), "\n", seq1), fasta)

seq2 = read_sequences(fasta)
seq3 = read_fasta(fasta)
identical(seq1, seq2)
#> [1] TRUE
identical(seq1, seq3)
#> [1] TRUE