Minimac4
|
Implements a Hidden Markov Model for genotype imputation. More...
#include <hidden_markov_model.hpp>
Public Member Functions | |
hidden_markov_model (float s3_prob_threshold, float s1_prob_threshold, float diff_threshold, float background_error, float decay) | |
Constructs a Hidden Markov Model with specified parameters. | |
void | traverse_forward (const std::deque< unique_haplotype_block > &ref_haps, const std::vector< target_variant > &tar_variant, std::size_t hap_idx) |
Performs a forward traversal over reference haplotypes for a given target haplotype. | |
void | traverse_backward (const std::deque< unique_haplotype_block > &ref_haps, const std::vector< target_variant > &tar_variant, std::size_t hap_idx, std::size_t out_idx, const std::vector< std::vector< std::vector< std::size_t > > > &reverse_maps, full_dosages_results &output, const reduced_haplotypes &full_reference_data) |
Performs a backward traversal over reference haplotypes to compute posterior probabilities. | |
Implements a Hidden Markov Model for genotype imputation.
This class performs multi-stage HMM-based imputation of genotype dosages for target haplotypes using reference haplotype blocks. It maintains forward and backward probability matrices, junction proportions, and intermediate haplotype states for S1, S2, and S3 probability transformations.
traverse_forward
) and backward traversal (traverse_backward
) along haplotype blocks. hidden_markov_model::hidden_markov_model | ( | float | s3_prob_threshold, |
float | s1_prob_threshold, | ||
float | diff_threshold, | ||
float | background_error, | ||
float | decay ) |
Constructs a Hidden Markov Model with specified parameters.
s3_prob_threshold | Threshold probability for S3 state. |
s1_prob_threshold | Threshold probability for S1 state. |
diff_threshold | Minimum difference required between probabilities to make a confident state call. |
background_error | Expected background error rate. |
decay | Decay factor controlling the influence of previous states. |
This constructor initializes the internal HMM parameters. These thresholds and the decay factor influence the model's sensitivity to differences in observed probabilities and determine how the hidden states are inferred.
void hidden_markov_model::traverse_backward | ( | const std::deque< unique_haplotype_block > & | ref_haps, |
const std::vector< target_variant > & | tar_variant, | ||
std::size_t | hap_idx, | ||
std::size_t | out_idx, | ||
const std::vector< std::vector< std::vector< std::size_t > > > & | reverse_maps, | ||
full_dosages_results & | output, | ||
const reduced_haplotypes & | full_reference_data ) |
Performs a backward traversal over reference haplotypes to compute posterior probabilities.
This function implements the backward algorithm of a Hidden Markov Model (HMM) for a given target haplotype. It computes probabilities by combining forward probabilities (from traverse_forward
) with backward likelihoods, handling recombination events, junction proportions, and leave-one-out considerations.
ref_haps | A deque of reference haplotype blocks (unique_haplotype_block ). Each block contains multiple haplotypes and variant positions. |
tar_variants | A vector of target variants (target_variant ) to traverse backward. |
hap_idx | Index of the target haplotype to traverse within tar_variants . |
out_idx | Output index used for storing results in full_dosages_results . |
reverse_maps | Maps from expanded to unique haplotypes for each block. |
output | Reference to a full_dosages_results structure where computed posterior dosages are stored. |
full_reference_data | Reduced haplotype reference data needed for imputation. |
The function performs the following steps:
backward
, backward_norecom
) and junction proportions for the last block.impute
to compute posterior dosages for each variant position.transpose
.traverse_forward
. void hidden_markov_model::traverse_forward | ( | const std::deque< unique_haplotype_block > & | ref_haps, |
const std::vector< target_variant > & | tar_variant, | ||
std::size_t | hap_idx ) |
Performs a forward traversal over reference haplotypes for a given target haplotype.
This function implements the forward algorithm of a Hidden Markov Model (HMM) to compute the probability of observing the target variants given the reference haplotypes. It accounts for recombination events and optional leave-one-out calculations.
ref_haps | A deque of reference haplotype blocks (unique_haplotype_block ). Each block contains multiple haplotypes and variant positions. |
tar_variants | A vector of target variants (target_variant ) for which the forward probabilities are computed. |
hap_idx | The index of the target haplotype to traverse within tar_variants . |
The function performs the following steps:
forward_probs_
, forward_norecom_probs_
) and junction probabilities (junction_prob_proportions_
).initialize_likelihoods
.precision_jumps_
by transposing probabilities to the next position.condition
.transpose
.observed < 0
) by skipping conditioning for those positions.