dae.variants package

Submodules

dae.variants.attributes module

class dae.variants.attributes.GeneticModel(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

X = 4
X_broken = 5
autosomal = 1
autosomal_broken = 2
pseudo_autosomal = 3
class dae.variants.attributes.Inheritance(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumerator for variant inheritance type.

denovo = 4
static from_name(name: str) Inheritance[source]
static from_value(value: int) Inheritance[source]
mendelian = 2
missing = 128
omission = 16
other = 64
possible_denovo = 8
possible_omission = 32
reference = 1
unknown = 256
class dae.variants.attributes.Role(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumerator for a person’s role in a pedigree.

child = 512
dad = 32
property display_name: str
static from_name(name: str | int | None) Role[source]

Construct and return a Role from it’s string representation.

static from_value(val: int) Role[source]
half_sibling = 4096
maternal_aunt = 65536
maternal_cousin = 1048576
maternal_grandfather = 2
maternal_grandmother = 1
maternal_half_sibling = 1024
maternal_uncle = 131072
mom = 16
static not_role(value: int) int[source]
parent = 64
paternal_aunt = 262144
paternal_cousin = 2097152
paternal_grandfather = 8
paternal_grandmother = 4
paternal_half_sibling = 2048
paternal_uncle = 524288
prb = 128
sib = 256
spouse = 16777216
step_dad = 8388608
step_mom = 4194304
static to_name(value: int) str[source]
static to_value(name: str | int | None) int[source]
unknown = 33554432
class dae.variants.attributes.Sex(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumerator for a person’s sex.

F = 2
M = 1
U = 4
static aliases() dict[str, str][source]
female = 2
static from_name(name: int | str | None) Sex[source]

Construct and return person Sex from string.

static from_value(val: int) Sex[source]
male = 1
short() str[source]
static to_name(value: int) str[source]
static to_value(name: int | str | None) int[source]
unspecified = 4
class dae.variants.attributes.Status(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumerator for a person’s status.

affected = 2
static from_name(name: int | str | None) Status[source]

Construct and return person status from string.

static from_value(val: int) Status[source]
short() str[source]
static to_name(value: int) str[source]
static to_value(name: int | str | None) int[source]
unaffected = 1
unspecified = 4
class dae.variants.attributes.TransmissionType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

denovo = 2
transmitted = 1
unknown = 0
class dae.variants.attributes.Zygosity(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumerance for allele zygosity.

static from_name(name: str) Zygosity[source]
static from_value(value: int) Zygosity[source]
heterozygous = 2
homozygous = 1
undefined = 0
dae.variants.attributes.bitmask2inheritance(bitmask: int) set[Inheritance][source]

Convert a bitmask to set of inheritance.

dae.variants.core module

class dae.variants.core.Allele(chrom: str, pos: int, *, pos_end: int | None = None, ref: str | None = None, alt: str | None = None, allele_type: Type | None = None)[source]

Bases: object

Class representing alleles.

DISPLAY_NAME_TYPE: ClassVar[dict[str, str]] = {'cnv': 'cnv', 'cnv+': 'large_duplication', 'cnv-': 'large_deletion', 'comp': 'complex', 'complex': 'complex', 'del': 'small_deletion', 'ins': 'small_insertion', 'sub': 'substitution'}
TYPE_DISPLAY_NAME: ClassVar[dict[str, str]] = {'complex': 'comp', 'large_deletion': 'cnv-', 'large_duplication': 'cnv+', 'small_deletion': 'del', 'small_insertion': 'ins', 'substitution': 'sub'}
class Type(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumerator for allele type.

cnv = 48
complex = 8
indel = 14
classmethod is_cnv(vt: Type) bool[source]
classmethod is_tr(vt: Type) bool[source]
large_deletion = 16
large_duplication = 32
position = 0
small_deletion = 4
small_insertion = 2
substitution = 1
tandem_repeat = 64
tandem_repeat_del = 68
tandem_repeat_ins = 66
property allele_type: Type
property alternative: str | None
static build_cnv_allele(chrom: str, pos: int, pos_end: int, allele_type: Type) Allele[source]
static build_position_allele(chrom: str, pos: int) Allele[source]
static build_vcf_allele(chrom: str, pos: int, ref: str, alt: str) Allele[source]
property chrom: str
property chromosome: str
property end_position: int | None
get_annotatable() Annotatable[source]

Return an annotatable version of the allele.

property position: int
property reference: str | None

dae.variants.family_variant module

class dae.variants.family_variant.FamilyAllele(summary_allele: SummaryAllele, family: Family, *, family_id: str | None = None, member_ids: list[str] | None = None, genotype: ndarray | None, best_state: ndarray | None, genetic_model: GeneticModel | None = None, inheritance_in_members: list[Inheritance] | None = None)[source]

Bases: SummaryAllele

Class representing an allele in a family.

property allele_in_members: list[str | None]
property allele_in_roles: list[Role | None]
property allele_in_sexes: list[Sex | None]
property allele_in_statuses: list[Status | None]
property allele_index: int
property allele_type: Type
property alternative: str | None
property attributes: dict[str, Any]
property best_st: ndarray

Deprecated since version Replace: best_st with best_state

property best_state: ndarray

Return the best state of the variant.

classmethod calc_inheritance_trio(parent_1: ndarray, parent_2: ndarray, child: ndarray, allele_index: int) Inheritance[source]

Calculate the inheritance type of a trio family.

Parameters:
  • parent_1 – genotype of the first parent (pair of allele indexes).

  • parent_2 – genotype of the second parent.

  • child – genotype of the child.

Returns:

inheritance type as variants.attributes.Inheritance of the trio family.

static check_denovo_trio(parent_1: ndarray, parent_2: ndarray, child: ndarray, allele_index: int) bool[source]

Check if the inheritance type for a trio family is denovo.

Parameters:
  • parent_1 – genotype of the first parent (pair of allele indexes).

  • parent_2 – genotype of the second parent.

  • child – genotype of the child.

Returns:

True, when the inheritance is mendelian.

static check_mendelian_trio(parent_1: ndarray, parent_2: ndarray, child: ndarray, allele_index: int) bool[source]

Check if the inheritance type for a trio family is mendelian.

Parameters:
  • parent_1 – genotype of the first parent (pair of allele indexes).

  • parent_2 – genotype of the second parent.

  • child – genotype of the child.

Returns:

True, when the inheritance is mendelian.

static check_omission_trio(parent_1: ndarray, parent_2: ndarray, child: ndarray, allele_index: int) bool[source]

Check if the inheritance type for a trio family is omission.

Parameters:
  • parent_1 – genotype of the first parent (pair of allele indexes).

  • parent_2 – genotype of the second parent.

  • child – genotype of the child.

Returns:

True, when the inheritance is mendelian.

property chrom: str
property chromosome: str
property details: VariantDetails

Build and return CSHL allele details.

property effects: AlleleEffects | None

Build and return allele effect.

property end_position: int | None
property family_attributes: dict[str, Any]
property family_id: str

Return the family ID.

property family_index: int | None
property genetic_model: GeneticModel | None
property genotype: ndarray

Return the genotype of the family.

get_attribute(item: str, default_val: Any = None) Any[source]

Return list of values from additional attributes matching given key.

looks up values matching key item in additional attributes passed on creation of the variant.

gt_flatten() ndarray[source]

Return the family variant genotype flattened to a 1d array.

has_attribute(item: str) bool[source]

Check if the additional variant attributes contain a given key.

property inheritance_in_members: list[Inheritance]

Return list of family member inheritance.

property member_fpids: list[tuple[str, str]]

Return list of family members IDs.

property member_ids: list[str]

Return list of family members IDs.

property position: int
property reference: str | None
summary_allele: SummaryAllele

summary allele that corresponds to this allele in family variant

property summary_attributes: dict[str, Any]
property summary_index: int
property transmission_type: TransmissionType
update_attributes(atts: dict[str, Any]) None[source]

Update additional attributes of the variant.

property variant_in_member_fpids: list[tuple[str, str]]

Return list of person with the variant.

property variant_in_members: list[str | None]

Return set of affected by this variant family members’ IDs.

property variant_in_roles: list[Role | None]

Return list of roles that have affected by this variant members.

Returns None if none found.

property variant_in_sexes: list[Sex | None]

Return list of sexes that are affected by this variant in family.

property variant_in_statuses: list[Status | None]

Return list of statuses (or ‘None’) of the members with variant.

property zygosity_in_roles: int
property zygosity_in_sexes: int
property zygosity_in_status: int
class dae.variants.family_variant.FamilyVariant(summary_variant: SummaryVariant, family: Family, *, family_id: str | None = None, member_ids: list[str] | None = None, genotype: ndarray | None = None, best_state: ndarray | None = None, inheritance_in_members: dict[int, list[Inheritance]] | None = None)[source]

Bases: SummaryVariant

Class representing a variant in a family.

property allele_count: int
property allele_indexes: list[int]
property alleles: list[SummaryAllele]
property best_st: ndarray

Deprecated since version Replace: usage of best_st with best_state

property best_state: ndarray

Return best state of the variant.

static calc_alleles(gt: ndarray) list[int][source]

Return allele indexes that are relevant for the given genotype.

Parameters:

gt – genotype as np.array.

Returns:

list of all allele indexes present into genotype passed.

static calc_alt_alleles(gt: ndarray) list[int][source]

Return relevant for the given genotype alternative allele indexes.

Parameters:

gt – genotype as np.array.

Returns:

list of all alternative allele indexes present into genotype passed.

property chrom: str
property chromosome: str
property end_position: int | None
property family_allele_indexes: list[int]
property family_alleles: list[FamilyAllele]
property family_alt_alleles: list[FamilyAllele]
property family_best_state: ndarray
property family_genotype: list[list[int]]

Return family genotype using family variant indexes.

property family_id: str

Return the family ID.

property family_index: int | None
property fvuid: str

Construct and return the family variant unique identifier.

property genetic_model: GeneticModel
property genotype: list[list[int]]

Return genotype using summary variant allele indexes.

gt_flatten() ndarray[source]

Return genotype of the family variant flattened to a 1d array.

is_reference() bool[source]

Return True if all known alleles in the variant are reference.

is_unknown() bool[source]

Return True if all alleles in the variant are unknown.

property member_fpids: list[tuple[str, str]]

Return list of family members IDs.

property member_ids: list[str]

Return list of family members IDs.

property position: int
property reference: str | None
property summary_index: int
to_record() dict[str, Any][source]
property variant_in_members: set[str]

Return list of members with the variant.

property zygosity_in_roles: int

Calculate and cache zygosity based on alternative alleles.

property zygosity_in_sexes: int

Calculate and cache zygosity based on alternative alleles.

property zygosity_in_status: int

Calculate and cache zygosity based on alternative alleles.

dae.variants.family_variant.calculate_simple_best_state(genotype: ndarray, allele_count: int) ndarray[source]

Calculate and return the best state of a genotype.

dae.variants.variant module

Classes and helper function to represent variants.

class dae.variants.variant.SummaryAllele(chromosome: str, position: int, reference: str | None, alternative: str | None = None, *, end_position: int | None = None, summary_index: int = -1, allele_index: int = 0, transmission_type: TransmissionType = TransmissionType.transmitted, allele_type: Type | None = None, attributes: dict[str, Any] | None = None, effect: str | None = None)[source]

Bases: Allele

Class to represents a single allele for given position.

property allele_index: int
property attributes: dict[str, Any]
static create_reference_allele(allele: SummaryAllele) SummaryAllele[source]

Given an allele creates the corresponding reference allele.

property cshl_location: str

Return CSHL location (chrom:position) of an allele.

property cshl_position: int | None

Return CSHL position of an allele.

property cshl_variant: str | None
property cshl_variant_full: str
property details: VariantDetails

Build and return CSHL allele details.

property effect_gene_symbols: list[str]
property effect_genes: list[EffectGene]
property effect_types: list[str]
property effects: AlleleEffects | None

Build and return allele effect.

property frequency: float | None
get_attribute(item: str, default_val: Any = None) Any[source]

Return attribute value.

Looks up values matching key item in additional attributes passed on creation of the variant.

has_attribute(item: str) bool[source]

Check if an attribute item is available.

property is_reference_allele: bool
property summary_index: int
to_record() dict[str, Any][source]

Construct a record from an allele.

property transmission_type: TransmissionType
update_attributes(atts: dict[str, Any]) None[source]

Update allele attributes.

property variant_type: Type
property worst_effect: str | None
class dae.variants.variant.SummaryVariant(alleles: list[SummaryAllele])[source]

Bases: object

Represents summary variant.

property allele_count: int
property alleles: list[SummaryAllele]
property alt_alleles: list[SummaryAllele]

Return list of all alternative alleles of the variant.

property alternative: str | None
property attributes: list[dict[str, Any]]
property chrom: str
property chromosome: str
property cshl_location: list[str]
property cshl_variant: list[str | None]
property cshl_variant_full: list[str | None]
property details: list[VariantDetails]

Return list of ‘VariantDetails’ for each allele.

property effect_gene_symbols: list[str]
property effect_types: list[str]
property effects: list[AlleleEffects]

Return list of allele effects.

property end_position: int | None
property frequencies: list[float | None]

Return list of allele frequencies.

get_attribute(item: Any, default: Any | None = None) list[Any][source]
has_attribute(item: Any) bool[source]
property location: str

Return summary variant location.

property matched_alleles: list[SummaryAllele]
property matched_alleles_indexes: list[int]
property matched_gene_effects: set[EffectGene]
property position: int
property ref_allele: SummaryAllele

Return the reference allele of the variant.

property reference: str | None
set_matched_alleles(alleles_indexes: list[int]) None[source]
property summary_index: int
property svuid: str

Build and return summary variant ‘unique’ ID.

to_record() list[dict[str, Any]][source]
property transmission_type: TransmissionType
update_attributes(atts: dict[str, Any]) None[source]
property variant_types: set[Any]

Return set of allele types.

class dae.variants.variant.SummaryVariantFactory[source]

Bases: object

Factory for summary variants.

static summary_allele_from_record(record: dict[str, Any], transmission_type: TransmissionType | None = None, attr_filter: set[str] | None = None) SummaryAllele[source]

Build a summary allele from a dictionary (record).

static summary_variant_from_records(records: list[dict[str, Any]], transmission_type: TransmissionType | None = None, attr_filter: set[str] | None = None) SummaryVariant[source]

Build summary variant from a list of dictionaries (records).

static summary_variant_from_vcf(vcf_variant: VariantRecord, summary_index: int, transmission_type: TransmissionType) SummaryVariant[source]

Build sumamry variant from a pysam VCF record.

class dae.variants.variant.VariantDesc(variant_type: Type, position: int, *, end_position: int | None = None, ref: str | None = None, alt: str | None = None, length: int | None = None, tr_ref: int | None = None, tr_alt: int | None = None, tr_unit: str | None = None)[source]

Bases: object

Variant description.

static combine(variant_descs: list[VariantDesc]) list[str][source]

Combine multiple variant description into list of descriptions.

to_cshl_full() str[source]

Convert variant description into CSHL full type description.

Includes tandem repeats descriptions.

to_cshl_short() str[source]

Convert variant description into CSHL short type description.

class dae.variants.variant.VariantDetails(chrom: str, variant_desc: VariantDesc)[source]

Bases: object

Represents CSHL variant details.

static from_cnv(variant: SummaryAllele) VariantDetails[source]

Build variant details from a CNV variant.

static from_vcf(chrom: str, position: int, reference: str, alternative: str) VariantDetails[source]

Build variant details from a VCF variant.

dae.variants.variant.allele_type_from_cshl_variant(variant: str) Type[source]

Return allele type from a CSHL variant type.

dae.variants.variant.allele_type_from_name(name: str) Type[source]

Return allele type from an allele type name.

dae.variants.variant.cshl_format(pos: int, ref: str, alt: str, trimmer: ~collections.abc.Callable[[int, str, str], tuple[int, str, str]] = <function trim_str_left_right>) VariantDesc[source]

Build a description for an CSHL allele.

dae.variants.variant.tandem_repeat(ref: str, alt: str, min_mono_reference: int = 8) tuple[str | None, int | None, int | None][source]

Check if an allele is a tandem repeat and builds it.

dae.variants.variant.vcf2cshl(pos: int, ref: str, alt: str, trimmer: ~collections.abc.Callable[[int, str, str], tuple[int, str, str]] = <function trim_str_right_left>) VariantDesc[source]

Build a description for an VCF allele.

Module contents