gl.read.fasta: Reads FASTA files and converts them to genlight object

View source: R/gl.read.fasta.r

gl.read.fastaR Documentation

Reads FASTA files and converts them to genlight object

Description

The following IUPAC Ambiguity Codes are taken as heterozygotes:

  • M is heterozygote for AC and CA

  • R is heterozygote for AG and GA

  • W is heterozygote for AT and TA

  • S is heterozygote for CG and GC

  • Y is heterozygote for CT and TC

  • K is heterozygote for GT and TG

The following IUPAC Ambiguity Codes are taken as missing data:

  • V

  • H

  • D

  • B

  • N

The function can deal with missing data in individuals, e.g. when FASTA files have different number of individuals due to missing data. The allele with the highest frequency is taken as the reference allele. SNPs with more than two alleles are skipped.

Usage

gl.read.fasta(
  fasta.files,
  parallel = FALSE,
  n.cores = NULL,
  fbm = FALSE,
  verbose = NULL
)

Arguments

fasta.files

Fasta files to read [required].

parallel

A logical indicating whether multiple cores -if available- should be used for the computations (TRUE), or not (FALSE); requires the package parallel to be installed [default FALSE].

n.cores

If parallel is TRUE, the number of cores to be used in the computations; if NULL, then the maximum number of cores available on the computer is used [default NULL].

fbm

Logical. If TRUE, the returned genlight object will contain a file-backed matrix (fbm) in its @genome slot. This is useful for very large datasets that do not fit into RAM. Note that using fbm objects requires the package bigsnpr to be installed. [default FALSE]. to back convert use gl.fbm2gen().

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default 2, unless specified using gl.set.verbosity].

Details

Ambiguity characters are often used to code heterozygotes. However, using heterozygotes as ambiguity characters may bias many estimates. See more information in the link below: https://evodify.com/heterozygotes-ambiguity-characters/

Each record in a FASTA file must occupy exactly two lines: a '>' header line followed by the full sequence on a single line. Line-wrapped (multi-line) FASTA is not supported and is rejected with an error.

Value

A genlight object.

Author(s)

Author(s): Luis Mijangos. Custodian: Luis Mijangos – Post to https://groups.google.com/d/forum/dartr

See Also

Other io: gl.load(), gl.read.PLINK(), gl.read.csv(), gl.read.dart(), gl.read.silicodart(), gl.save(), gl.write.csv(), utils.read.dart()

Examples

# Folder where the fasta files are located. 
folder_samples <- system.file('extdata', package ='dartR.data')
# listing the FASTA files, including their path. Files have an extension
# that contains "fas".
file_names <- list.files(path = folder_samples, pattern = "*.fas", 
full.names = TRUE)
# reading fasta files
obj <- gl.read.fasta(file_names)
  

dartR.base documentation built on Nov. 18, 2026, 9:06 a.m.