poolfstat_DT2pooldata: Convert a data table of read counts into a pooldata object

View source: R/poolfstat_DT2pooldata.R

poolfstat_DT2pooldataR Documentation

Convert a data table of read counts into a pooldata object

Description

Used to takes a data table of pool-seq read counts and creates an object of class "pooldata", as per the poolfstat package (Hivert et al. 2018).

Usage

poolfstat_DT2pooldata(dat, flip = FALSE, poolInfo)

Arguments

dat

Data table: A long-format data table of read counts for pool-seq samples of biallelic SNP loci to be converted into a pooldata object. Must contain all the following columns:

  1. $CHROM The chromosome (contig) ID.

  2. $POS The variant position on the chromosome.

  3. $REF The reference allele.

  4. $ALT The alternate allele.

  5. $LOCUS The locus ID.

  6. $POOL The pool ID.

  7. $AO The number of reads supporting the alternate allele.

  8. $RO The number of reads supporting the reference allele.

Alternatively, a pooldata object to be converted into a data table. See param flip with respect to specifying the direction of the conversion.

flip

Logical: Should the function be reversed? Default is FALSE. When flip==FALSE, a data table is converted into a pooldata object. When flip==TRUE, a pooldata object is converted into a data table.

poolInfo

Data table: Contains the sample sample sizes (number of diploids) for for each unique pool listed in dat$POOL. Requires two columns:

  1. $POOL The pools listed in dat$POOL.

  2. $INDS The number of diploid individuals for the pools.

You only need to specify poolInfo when flip==FALSE, that is, transforming a data table itno a pooldata object.

Value

When flip==FALSE, returns a pooldata object as per the poolfstat package. Alternatively, when flip==TRUE, returns a data table.

References

Hivert et al. (2018) Genetics. DOI: 10.1534/genetics.118.300900

Examples

library(genomalicious)

# Load in the pool metadata and reads
data(data_PoolInfo)
data(data_PoolFreqs)

# Pool info
data_PoolInfo

# Pool reads in $DP, $AO, and $RO
data_PoolFreqs[, c('POOL','DP','AO','RO')]

# Make pooldata object
pooldataObj <-poolfstat_DT2pooldata(
   data_PoolFreqs,
   flip=FALSE,
   poolInfo=data_PoolInfo
)

class(pooldataObj)

pooldataObj

# And go back to data table
pooldataTab <- poolfstat_DT2pooldata(pooldataObj, flip=TRUE)

head(pooldataTab)


j-a-thia/genomalicious documentation built on Oct. 19, 2024, 7:51 p.m.