df2gtypes: Convert a data.frame to gtypes

View source: R/df2gtypes.R

df2gtypesR Documentation

Convert a data.frame to gtypes

Description

Load allelic data from a data.frame or matrix into a gtypes object.

Usage

df2gtypes(
  x,
  ploidy,
  id.col = 1,
  strata.col = 2,
  loc.col = 3,
  sequences = NULL,
  schemes = NULL,
  description = NULL,
  other = NULL
)

Arguments

x

a matrix or data.frame of genetic data.

ploidy

number of number of columns in x storing alleles at each locus.

id.col

column name or number where individual sample ids are stored. If NULL then rownames are used. If there are no rownames, then samples are labelled with consecutive numbers.

strata.col

column name or number where stratification is stored. If NULL then all samples are in one (default) stratum.

loc.col

column number of first allele of first locus.

sequences

a list, matrix, DNAbin, or multidna object containing sequences.

schemes

an optional data.frame of stratification schemes.

description

a label for the object (optional).

other

a list to carry other related information (optional).

Details

The genetic data in x starting at loc.col should be formatted such that every consecutive ploidy columns represent alleles of one locus. Locus names are taken from the column names in x and should be formatted with the same root locus name, with unique suffixes representing allels (e.g., for Locus1234: Locus1234.1 and Locus1234.2, or Locus1234_A and Locus1234_B).
If sequences are provided in sequences, then they should be named and match haplotype labels in loc.col of x. If multiple genes are given as a multidna, then they should have the same names as column names in x from loc.col to the end.

Value

a gtypes object.

Author(s)

Eric Archer eric.archer@noaa.gov

See Also

gtypes.initialize, sequence2gtypes, as.data.frame.gtypes, gtypes2genind, gtypes2loci, gtypes2phyDat

Examples

#--- create a diploid (microsatellite) gtypes object
data(dolph.msats)
ms.g <- df2gtypes(dolph.msats, ploidy = 2, strata.col = NULL, loc.col = 2)
ms.g

#' #--- create a haploid sequence (mtDNA) gtypes object
data(dolph.strata)
data(dolph.haps)

seq.df <- dolph.strata[ c("id", "broad", "dLoop")]
dl.g <- df2gtypes(seq.df, ploidy = 1, sequences = dolph.haps)
dl.g


EricArcher/strataG documentation built on Feb. 12, 2023, 4:11 a.m.