Learn R Programming

diemr (version 1.4.3)

smoothPolarizedGenotypes: Smooth 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 physical extent of genomic content around a site. At each genomic position, the function returns a weighted mode of the genomic state.

Usage

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

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. If windows = NULL, the function calculates the windows using rank2map.

windowSize

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

...

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

Details

Ensure that ChosenSites match those used to import polarized genotypes.

The function uses a truncated and scaled Laplace kernel to weight the genotype states within a window around each marker position, based on physical positions of the markers.

The Laplace kernel weights are calculated for physical positions of the sites centered at the site being smoothed as: $$\frac{10}{19} \exp\left(\frac{-x}{b}\right),$$ when \(x < 0\), meaning that the site \(x\) is upstream of the site being smoothed, and as: $$\frac{10}{19} \exp\left(\frac{x}{b}\right),$$ when \(x \geq 0\), meaning that the site is downstream. The value \(x\) is the position of a neighbouring site relative to the site being smoothed, and \(b\) is the scale parameter of the Laplace kernel. The scale parameter is equal to: $$b = \frac{\text{windowSize}}{2 \ln(20)}.$$

See Also

rank2map

Examples

Run this code
 if (FALSE) {
 # 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)
 }

Run the code above in your browser using DataLab