Learn R Programming

SeqVarTools (version 1.10.0)

heterozygosity: Heterozygosity and Homozygosity

Description

Calculate heterozygosity and homozygosity by variant or by sample

Usage

"heterozygosity"(gdsobj, margin=c("by.variant", "by.sample"), use.names=FALSE) "homozygosity"(gdsobj, allele=c("any", "ref", "alt"), margin=c("by.variant", "by.sample"), use.names=FALSE)

Arguments

gdsobj
A SeqVarGDSClass object with VCF data.
margin
Possible values are "by.variant" or "by.sample," indicating whether the calculation should be done over all samples for each variant, or over all variants for each sample.
use.names
A logical indicating whether to assign variant or samples IDs as names of the output vector.
allele
Possible values are "any", "ref," or "alt," indicating which alleles to consider when calculating homozygosity.

Value

A numeric vector of heterozyogity or homozygosity rates. If margin="by.variant", the vector will have length equal to the number of variants in the GDS object. If margin="by.sample", the vector will have length equal to the number of samples.

Details

heterozyogosity calulates the fraction of heterozygous genotypes in a GDS object, either by variant or by sample.

homozygosity calculates the rate of homozygous genotypes in a GDS object, either by sample or by variant. If allele="any", all homozygous genotypes are considered (reference or any alternate allele). If allele="ref", only reference homozygotes are considered. If allele="alt", any alternate allele homozygote is considered. For example, "ref" will count "0/0" genotypes only, "alt" will count "1/1", "2/2", etc. (but not "0/0"), and "any" will count all of the above.

See Also

SeqVarGDSClass, applyMethod, alleleFrequency

Examples

Run this code
gds <- seqOpen(seqExampleFileName("gds"))
head(heterozygosity(gds, margin="by.variant"))
head(homozygosity(gds, allele="any", margin="by.variant"))
head(homozygosity(gds, allele="ref", margin="by.variant"))
head(homozygosity(gds, allele="alt", margin="by.variant"))

## Het/Hom Non-Ref by sample
hhnr <- heterozygosity(gds, margin="by.sample") /
        homozygosity(gds, allele="alt", margin="by.sample")
head(hhnr)

seqClose(gds)

Run the code above in your browser using DataLab