write.nexus: Write a nexus file from a DNAStringSet object

View source: R/helper.functions.R

write.nexusR Documentation

Write a nexus file from a DNAStringSet object

Description

Takes a character vector or a DNAStringSet and write a nexus file to disk.

Usage

write.nexus(
  x,
  aln = FALSE,
  gapOpening = c(-18, -16),
  gapExtension = c(-2, -1),
  dir.out,
  fn,
  charset = FALSE,
  locusIDs,
  locusLength,
  verbose = FALSE
)

Arguments

x

Either a character vector or a DNAStringSet

aln

Logical. Whether x is an alignment

gapOpening

Integer (negative). Penalty for opening a gap in the alignment

gapExtension

Integer (negative). Penalty for extending a gap in the alignment

dir.out

The path where to save the output

fn

The output file name

charset

Whether a charset block should be added at the end of the nexus file

locusIDs

character vector with the names of the loci (if charset=TRUE) in the same order as they appear in the sequences

locusLength

Integer vector with the length of each locus (if charset=TRUE) in the same order as they appear in the sequences @param verbose Whether print info on progress

Details

If x is a character vector, it will convert it to a DNAStringSet. if aln=FALSE, write.nexus will align the sequences first and then write the nexus file. If aln=TRUE, it will assume that all sequences have the same length and are aligned.

If charset=TRUE, write.nexus will append a character block at the end of the file. This is sometimes used to partition the alignment when it is imported in software like BEAST2

Value

Writes a nexus file to disk

Examples

seqs <- c("AAATTTT", "GAATTCT")
        names(seqs) <- c("seq1", "seq2")
        x <- Biostrings::DNAStringSet(seqs)
        locusNames <- c("locus1", "locus2")
        locusLen <- c(3, 4)
        tmpDir <- tempdir(check = TRUE)
        write.nexus(x, aln=TRUE, dir.out=tmpDir, fn="aln.nex", charset=TRUE, 
                locusIDs=locusNames, locusLength=locusLen)

carlopacioni/amplicR documentation built on Aug. 19, 2023, 7:59 p.m.