Skip to content

Commit

Permalink
Refactor get_map_alleles
Browse files Browse the repository at this point in the history
  • Loading branch information
szhan committed Aug 31, 2023
1 parent 3230897 commit 87a9d51
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions python/tests/test_beagle.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,25 +461,23 @@ def _compute_allele_probabilities(a):
return p


def get_map_alleles(i_hap_probs):
def get_map_alleles(allele_probs):
"""
Compute the maximum a posteriori alleles at the imputed markers of a query haplotype.
Assuming all biallelic sites, it is a matrix of size (x, 2),
where x is the number of imputed markers.
This implementation is based on Equation 2 (the rearranged one) in BB2016.
:param numpy.ndarray i_hap_probs: Interpolated haplotype probability matrix.
:return: MAP alleles at imputed markers.
:param numpy.ndarray allele_probs: Interpolated allele probabilities.
:return: Imputed alleles in the query haplotype.
:rtype: numpy.ndarray
"""
x = len(i_hap_probs)
x = len(allele_probs)
imputed_alleles = np.zeros((x, 2))
# TODO: Vectorise over the imputed markers
for i in np.arange(x):
imputed_alleles[i, 0] = np.argmax(i_hap_probs[i, :])
imputed_alleles[i, 1] = np.argmax(i_hap_probs[i, :])
imputed_alleles[i, 0] = np.argmax(allele_probs[i, :])
imputed_alleles[i, 1] = np.argmax(allele_probs[i, :])
return imputed_alleles


Expand Down

0 comments on commit 87a9d51

Please sign in to comment.