From 027ffab99613f9a95da14cff7c29c64a6f46b299 Mon Sep 17 00:00:00 2001 From: RosCraddock <109593931+RosCraddock@users.noreply.github.com> Date: Tue, 2 Jun 2026 13:50:35 +0100 Subject: [PATCH] Extending MAF limits per issue #276 --- docs/source/changelog.rst | 3 +- docs/source/usage.rst | 9 +++--- src/tinypeel/Peeling/PeelingUpdates.py | 28 +++++++++---------- src/tinypeel/tinypeel.py | 8 +++--- ...lele_prob-est_alt_allele_prob_multiple.txt | 10 +++---- ...st_alt_allele_prob_multiple_individual.txt | 9 +++--- ...allele_prob-est_alt_allele_prob_single.txt | 10 +++---- ..._allele_prob-extra_metafounder_in_file.txt | 10 +++---- ...llele_prob-missing_metafounder_in_file.txt | 10 +++---- 9 files changed, 50 insertions(+), 47 deletions(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index a466d91..e717321 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -25,7 +25,8 @@ Bug fixes Maintenance ----------- - +* Update the alternative allele probability limits from [0.01, 0.99] to [0.001, 0.999] + (:issue:`185`, :issue:`276`, :pr:`227`, :user:`RosCraddock`, :user:`XingerTang`, :user:`gregorgorjanc`). * Renaming of command line arguments, changing of input format, and corresponding documentation and test updates (:issue:`221`, :pr:`219` ,:pr:`222`, :user:`RosCraddock`, :user:`gregorgorjanc`, :user:`XingerTang`). diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 5a35332..d03c3d7 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -326,10 +326,6 @@ Alternative allele probabilities are estimated (using ``-est_alt_allele_prob``) as half of the mean of estimated :ref:`allele dosage ` in the base population(s) (metafounders). -.. - The estimates are constrained to be between 0.01 and 0.99 - to avoid TODO: discuss with Evie how to word this. - This estimation can be warm-started with a sample estimate from inputted genomic data (using ``-est_start_alt_allele_prob``). Note that this sample estimate is not taking the pedigree structure into account, @@ -353,6 +349,11 @@ there are three options to obtain metafounder-specific alternative allele probab In all three cases, ``-est_alt_allele_prob`` is optional. +The estimates (using ``-est_start_alt_allele_prob`` or ``-est_alt_allele_prob``) or +inputs (using ``-alt_allele_prob_file``) of the alternative allele probabilities +are constrained to be between 0.001 and 0.999 to ensure valid probabilities and +avoid getting trapped in boundary values, 0 or 1. + Error probabilities (using ``-est_geno_error_prob`` and ``-est_seq_error_prob``) are estimated as the proportion of mismatches between observed and inferred states. diff --git a/src/tinypeel/Peeling/PeelingUpdates.py b/src/tinypeel/Peeling/PeelingUpdates.py index 8a0fa9a..383a3de 100644 --- a/src/tinypeel/Peeling/PeelingUpdates.py +++ b/src/tinypeel/Peeling/PeelingUpdates.py @@ -59,7 +59,7 @@ def updateMaf(pedigree, peelingInfo): def newtonMafUpdates(peelingInfo, AAP, index): """Iterative approximation for the prior alternative allele frequency. - Currently limits all AAP to be between 0.01 and 0.99. + Currently limits all AAP to be between 0.001 and 0.999. :param peelingInfo: Peeling information container. :type peelingInfo: class:`PeelingInfo.jit_peelingInformation` @@ -71,10 +71,10 @@ def newtonMafUpdates(peelingInfo, AAP, index): :rtype: float """ - if AAP[index] < 0.01: - maf = 0.01 - elif AAP[index] > 0.99: - maf = 0.99 + if AAP[index] < 0.001: + maf = 0.001 + elif AAP[index] > 0.999: + maf = 0.999 else: maf = AAP[index] @@ -84,10 +84,10 @@ def newtonMafUpdates(peelingInfo, AAP, index): maf_old = maf delta = getNewtonUpdate(maf_old, peelingInfo, index) maf = maf_old + delta - if maf < 0.01: - maf = 0.01 - if maf > 0.99: - maf = 0.99 + if maf < 0.001: + maf = 0.001 + if maf > 0.999: + maf = 0.999 if abs(maf - maf_old) < 0.0001: converged = True iters -= 1 @@ -166,7 +166,7 @@ def addIndividualToUpdate(d, p, LLp, LLpp): def updateMafAfterPeeling(pedigree, peelingInfo): """Updates the alternative allele frequency for each unknown parent group based on the mean genotype probabilities of the founders. - Currently limits all AAP to be between 0.01 and 0.99. + Currently limits all AAP to be between 0.001 and 0.999. :param pedigree: pedigree information container :type pedigree: class:`tinyhouse.Pedigree.Pedigree()` @@ -194,10 +194,10 @@ def updateMafAfterPeeling(pedigree, peelingInfo): for mfx in MF: for i in range(peelingInfo.nLoci): AAP[mfx][i] = AAP[mfx][i] / indMF[mfx] - if AAP[mfx][i] < 0.01: - AAP[mfx][i] = 0.01 - elif AAP[mfx][i] > 0.99: - AAP[mfx][i] = 0.99 + if AAP[mfx][i] < 0.001: + AAP[mfx][i] = 0.001 + elif AAP[mfx][i] > 0.999: + AAP[mfx][i] = 0.999 pedigree.AAP[mfx] = AAP[mfx].astype(np.float32) for ind in pedigree: diff --git a/src/tinypeel/tinypeel.py b/src/tinypeel/tinypeel.py index baf3a8e..17283a9 100644 --- a/src/tinypeel/tinypeel.py +++ b/src/tinypeel/tinypeel.py @@ -67,10 +67,10 @@ def runPeelingCycles(pedigree, peelingInfo, args, singleLocusMode=False): f"ERROR: Invalid value {pedigree.AAP[mfx][i]} for alternative allele probability for metafounder {mfx} at locus {i}. \nValues must be between 0 and 1. Set to 0.5 (default) if unknown. \nExiting..." ) sys.exit(2) - elif pedigree.AAP[mfx][i] < 0.01: - pedigree.AAP[mfx][i] = 0.01 - elif pedigree.AAP[mfx][i] > 0.99: - pedigree.AAP[mfx][i] = 0.99 + elif pedigree.AAP[mfx][i] < 0.001: + pedigree.AAP[mfx][i] = 0.001 + elif pedigree.AAP[mfx][i] > 0.999: + pedigree.AAP[mfx][i] = 0.999 AAP[mfx] = pedigree.AAP[mfx] if len(ind.MetaFounder) == 2: mafGeno = ProbMath.getGenotypesFromMultiMaf(AAP) diff --git a/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_multiple.txt b/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_multiple.txt index 77e61b5..eae1bcd 100644 --- a/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_multiple.txt +++ b/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_multiple.txt @@ -1,6 +1,6 @@ MF_1 MF_2 -9.999999776482582092e-03 9.900000095367431641e-01 -9.999999776482582092e-03 9.900000095367431641e-01 -9.999999776482582092e-03 9.900000095367431641e-01 -9.999999776482582092e-03 9.900000095367431641e-01 -9.999999776482582092e-03 9.900000095367431641e-01 +1.000000047497451305e-03 9.990000128746032715e-01 +1.000000047497451305e-03 9.990000128746032715e-01 +1.000000047497451305e-03 9.990000128746032715e-01 +1.000000047497451305e-03 9.990000128746032715e-01 +1.000000047497451305e-03 9.990000128746032715e-01 diff --git a/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_multiple_individual.txt b/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_multiple_individual.txt index b12ae58..0aa9405 100644 --- a/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_multiple_individual.txt +++ b/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_multiple_individual.txt @@ -1,6 +1,7 @@ MF_1 MF_2 -9.999999776482582092e-03 9.900000095367431641e-01 -9.999999776482582092e-03 9.900000095367431641e-01 +1.000000047497451305e-03 9.990000128746032715e-01 +1.000000047497451305e-03 9.990000128746032715e-01 5.000083446502685547e-01 4.999749958515167236e-01 -9.999999776482582092e-03 9.900000095367431641e-01 -9.999999776482582092e-03 9.900000095367431641e-01 +1.000000047497451305e-03 9.990000128746032715e-01 +1.000000047497451305e-03 9.990000128746032715e-01 + diff --git a/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_single.txt b/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_single.txt index 136a95f..b778060 100644 --- a/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_single.txt +++ b/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-est_alt_allele_prob_single.txt @@ -1,6 +1,6 @@ MF_1 -9.999999776482582092e-03 -9.999999776482582092e-03 -9.999999776482582092e-03 -9.999999776482582092e-03 -9.999999776482582092e-03 +1.000000047497451305e-03 +1.000000047497451305e-03 +1.000000047497451305e-03 +1.000000047497451305e-03 +1.000000047497451305e-03 diff --git a/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-extra_metafounder_in_file.txt b/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-extra_metafounder_in_file.txt index 05ce067..60be20e 100644 --- a/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-extra_metafounder_in_file.txt +++ b/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-extra_metafounder_in_file.txt @@ -1,6 +1,6 @@ MF_1 MF_2 -9.999999776482582092e-03 9.900000095367431641e-01 -9.999999776482582092e-03 9.900000095367431641e-01 -9.999999776482582092e-03 9.900000095367431641e-01 -9.999999776482582092e-03 9.900000095367431641e-01 -9.999999776482582092e-03 9.900000095367431641e-01 \ No newline at end of file +1.000000047497451305e-03 9.990000128746032715e-01 +1.000000047497451305e-03 9.990000128746032715e-01 +1.000000047497451305e-03 9.990000128746032715e-01 +1.000000047497451305e-03 9.990000128746032715e-01 +1.000000047497451305e-03 9.990000128746032715e-01 \ No newline at end of file diff --git a/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-missing_metafounder_in_file.txt b/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-missing_metafounder_in_file.txt index 586e562..bd47a19 100644 --- a/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-missing_metafounder_in_file.txt +++ b/tests/functional_tests/test_alt_allele_prob/true-alt_allele_prob-missing_metafounder_in_file.txt @@ -1,6 +1,6 @@ MF_1 MF_2 -9.999999776482582092e-03 5.000000000000000000e-01 -9.999999776482582092e-03 5.000000000000000000e-01 -9.999999776482582092e-03 5.000000000000000000e-01 -9.999999776482582092e-03 5.000000000000000000e-01 -9.999999776482582092e-03 5.000000000000000000e-01 \ No newline at end of file +1.000000047497451305e-03 5.000000000000000000e-01 +1.000000047497451305e-03 5.000000000000000000e-01 +1.000000047497451305e-03 5.000000000000000000e-01 +1.000000047497451305e-03 5.000000000000000000e-01 +1.000000047497451305e-03 5.000000000000000000e-01 \ No newline at end of file