varona.maf
Minor allele frequency (MAF) calculation.
This module provides a few competing strategies for obtaining MAF data from a VFC file.
- class MafMethod(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
CiStrEnum
Enum for the MAF calculation method.
Values:
Value
Description
FR
Use the FR field in the info section of the variant to calculate the MAF.
BCFTOOLS
Only available if non-pysam bcftools is installed. Use the MAF
field in the info section of the variant to calculate the MAF, which
is added by
bcftools +fill-tags
.SAMPLES
Description of SAMPLES method
Note: The BCFTOOLS value is conditionally available based on the presence of non-pysam bcftools.
- maf_from_samples(variant: VariantRecord) float [source]
Compute the MAF from the sample genotypes in a variant.
This function assumes that the genotypes are in the “GT” key of the samples section of the variant.
- Parameters:
variant – A
pysam.VariantRecord
object.- Returns:
The MAF value.
- Raises:
KeyError if the “GT” key is not found in the samples section.
- maf_from_fr(variant: VariantRecord) float [source]
Compute the MAF from the “FR” info value in a variant.
- Parameters:
variant – A
pysam.VariantRecord
object.- Returns:
The MAF value derived from the “FR” info value.
- Raises:
KeyError
if the “FR” key is not found in the info section.
- maf_from_bcftools(variant: VariantRecord) float [source]
Extract the “MAF” value from the info section in a variant.
This function assumes the presence of an “MAF” key in the info section. bcftools, if installed, may be used to add this key to the VCF file using a command like
bcftools +fill-tags
.- Parameters:
variant – A
pysam.VariantRecord
object.- Returns:
The MAF value.
- Raises:
KeyError if the “MAF” key is not found in the info section.
- maf_from_method(variant: VariantRecord, method: MafMethod) float [source]
A dispatcher for
maf_from_fr()
,maf_from_bcftools()
, andmaf_from_samples()
.- Parameters:
variant – A
pysam.VariantRecord
object.method – The MAF calculation method.
- Returns:
The MAF value.
- Raises:
KeyError if the method is not recognized.