smoothPolarizedGenotypes: Smooths Polarized Genotype States

View source: R/smoothPolarizedGenotypes.r

smoothPolarizedGenotypesR Documentation

Smooths Polarized Genotype States

Description

This function smooths polarized genotype states using a Laplace kernel density estimation. It calculates a smoothed version of the genotype states over specified windows.

Usage

smoothPolarizedGenotypes(
  genotypes,
  includedSites,
  ChosenSites = "all",
  windows = NULL,
  windowSize = NULL,
  ...
)

Arguments

genotypes

A character matrix comprising of _012 encodings.

includedSites

A character path to a file with columns CHROM and POS.

ChosenSites

A logical vector indicating which sites are to be included in the analysis.

windows

A two-column numeric matrix with indices of start and end positions for windows for all markers indicated by ChosenSites.

windowSize

A numeric window size for metric conversion in base-pairs.

...

Additional parameters to be passed to rank2map if windows = NULL.

Details

Ensure that ChosenSites is the same as was used to import polarized genotypes.

The function uses a Laplace kernel to weight the genotype states within a window around each marker position, based on physical positions of the markers. The smoothing process accounts for chromosome-level scales.

The Laplace kernel density is calculated as:

\frac{1}{2b} \exp\left(\frac{-|x - \mu|}{b}\right)

where x is the position, \mu is the center of the kernel, and b is the scale parameter. The scale parameter is b = 10^{-4} n, where n is the position of the last marker on the chromosome.

Examples

 ## Not run: 
 # Run this example in a working directory with write permissions
 myo <- system.file("extdata", "myotis.vcf", package = "diemr")
 vcf2diem(myo, "myo")
 fit <- diem("myo-001.txt", ChosenInds = 1:14)
 gen <- importPolarized("myo-001.txt", changePolarity = fit$markerPolarity, ChosenInds = 1:14)
 h <- apply(gen, 1, \(x) pHetErrOnStateCount(sStateCount(x)))[1, ]
 gen2 <- smoothPolarizedGenotypes(genotypes = gen, 
    includedSites = "myo-includedSites.txt", windowSize = 50)
 plotPolarized(gen, h)
 plotPolarized(gen2, h)
 
## End(Not run)

diemr documentation built on Sept. 23, 2024, 5:10 p.m.