ancIBD.emission

Class containing functions to calculate Emission Probabilities. Contains Sub-Classes for various types of data, as well as a factory Method to return the correct subclass @ Author: Harald Ringbauer, September 2020

Module Contents

Classes

Emissions

Class for emission probabilities

HaplotypeSharingEmissions

Class for emission probabilities of diploid haplotypes who

HaplotypeSharingEmissions2

Class for emission probabilities of diploid haplotypes who

HaplotypeSharingEmissions3

Basically the same as HaplotypeSharingEmissions2, but with two additional states to account for IBD2 region

HaplotypeSharing_twoHaploid

Class for emission probabilities of two haploid genomes (e.g, two male X chromosome)

HaplotypeSharing_hapVSdiploid

Class for emission probabilities of one haploid and one diploid genomes (e.g, between a male and a female chromosome)

Functions

load_emission_model([e_model])

Factory method to return the right Emission Model

class ancIBD.emission.Emissions

Bases: object

Class for emission probabilities Has methods to return emission probabilities

abstract give_emission_matrix(**kwargs)

Return Emission Matrix - for every possible set of states

give_emission_log(**kwargs)

Return the full emission Probability directly in Log Space. By default just log the emissiom matrix. Can be overwritten for nicer computational properties

set_params(**kwargs)

Set the Parameters. Takes keyworded arguments

class ancIBD.emission.HaplotypeSharingEmissions

Bases: Emissions

Class for emission probabilities of diploid haplotypes who possibly share one haplotype

hw_prob_haplo_pp(ht_p, p)

Calculate HW Probabilitiy of haplotype gt ht_p: [l] Array of haplotype prob for ancestral, l locis, p: [l] Array of (derived) allele frequencies returns [l] vector of HW prob of gt

hw_prob_haplo_share_pp(ht_p1, ht_p2, p)

Calculate probability of sharing haplotypes ht_p1, ht_p2: Array of haplotype likelihood for ancestral, l locis p: [l] Array of (derived) allele frequencies returns [l] vector of prob that shared haplotype

hw_prob_haplos_pp(hts_p, p)

Calculate HW Probabilitiy of haplotype gt gt: [k,l] Array of haplotype prob for ancestral p: [l] Array of (derived) allele frequencies returns [l] vector of HW prob of gt

hw_probs_shared(hts_p, p, shared=(0, 2), dtype='float')

Give emission probabilities for shared state. hts_p: [4,l] Array of four ancestral haplotype probabilities p: [l] array of derived genotype probability. shared: tuple of length 2 giving the indices of the shared haplotypes

give_emission_matrix(hts_p, p, dtype='float')

Give emission Matrix for 5-state HMM. 0th state: HW 1st-4th State: Haplotype Copying Input: p: [l] Array of (derived) allele frequencies hts_p: [4,l] Array of four ancestral haplotype probabilities. Return: emission matrix [5,l].

class ancIBD.emission.HaplotypeSharingEmissions2

Bases: Emissions

Class for emission probabilities of diploid haplotypes who possibly share one haplotype. Update to new emissions based on that output of Glimpse are posterior probabilities

hw_prob_haplo_share_pp(ht_p1, ht_p2, p, min_p=0.001)

Calculate probability of sharing haplotypes ht_p1, ht_p2: Array of haplotype likelihood for ancestral, l locis p: [l] Array of (derived) allele frequencies returns [l] vector of prob that shared haplotype

hw_probs_shared(hts_p, p, shared=(0, 2), dtype='float')

Give emission probabilities for shared state. hts_p: [4,l] Array of four ancestral haplotype probabilities p: [l] array of derived genotype probability. shared: tuple of length 2 giving the indices of the shared haplotypes

give_emission_matrix(hts_p, p, dtype='float')

Give emission Matrix for 5-state HMM. 0th state: HW 1st-4th State: Haplotype Copying Input: p: [l] Array of (derived) allele frequencies hts_p: [4,l] Array of four ancestral haplotype probabilities. Return: emission matrix [5,l].

class ancIBD.emission.HaplotypeSharingEmissions3

Bases: HaplotypeSharingEmissions2

Basically the same as HaplotypeSharingEmissions2, but with two additional states to account for IBD2 region

give_emission_matrix(hts_p, p, p_min=0.001, dtype='float')

Give emission matrix for 7-state HMM. 0th state: non-IBD state 1st-4th state: IBD1 state 5-7th state: IBD2 state

class ancIBD.emission.HaplotypeSharing_twoHaploid

Bases: HaplotypeSharingEmissions2

Class for emission probabilities of two haploid genomes (e.g, two male X chromosome) who possibly share one haplotype

give_emission_matrix(hts_p, p, dtype='float')

Give emission Matrix for 2-state HMM. 0th state: HW 1st State: Haplotype Copying Input: p: [l] Array of (derived) allele frequencies hts_p: [4,l] Array of two ancestral haplotype probabilities.

Note that for haploid samples, hts_p[1,:] and hts_p[4,:] are not used and the values there are meaningless. I keep these two rows only for consistency with the diploid case.

Return: emission matrix [2,l].

class ancIBD.emission.HaplotypeSharing_hapVSdiploid

Bases: HaplotypeSharingEmissions2

Class for emission probabilities of one haploid and one diploid genomes (e.g, between a male and a female chromosome) who possibly share one haplotype

give_emission_matrix(hts_p, p, dtype='float')

Give emission Matrix for 3-state HMM. Note that the code assumes that the first sample is haploid and the second sample is diploid. 0th state: HW 1st-2nd State: Haplotype Copying Input: p: [l] Array of (derived) allele frequencies hts_p: [4,l] Array of two ancestral haplotype probabilities.

Note that for hts_p[1,:] is not used and the values there are meaningless. I keep these it only for consistency with the diploid case.

Return: emission matrix [3,l].

ancIBD.emission.load_emission_model(e_model='haploid_gl')

Factory method to return the right Emission Model