diff --git a/Pedigree.py b/Pedigree.py index d60faa3..c08da05 100644 --- a/Pedigree.py +++ b/Pedigree.py @@ -95,7 +95,7 @@ def __init__(self, idx, idn, MetaFounder=None) : self.genotypedFounderStatus = None #? - self.MetaFounder = MetaFounder + self.MetaFounder = [MetaFounder] if MetaFounder is not None else None self.phenotype = None @@ -536,7 +536,7 @@ def readInPedigreeFromList(self, pedList): # check if the individual is a metafounder if idx is not None and idx[:3] == "MF_": - print(f"ERROR: Invalid metafounder input format.\nExiting...") + print(f"ERROR: Individual {idx} uses the prefix 'MF_' which is reserved for metafounders and cannot be used for an individual's id. \nExiting...") sys.exit(2) # All individuals (and dummy individuals) in the pedigree are assigned the default metafounder. @@ -574,14 +574,11 @@ def readInPedigreeFromList(self, pedList): # check if the metafounders match if sireID == damID: # Overwrite the default metafounder. - ind.MetaFounder = sireID + ind.MetaFounder = [sireID] else: - # expect more infomative error message - print(f"ERROR: Invalid metafounder input format.\nExiting...") - sys.exit(2) + ind.MetaFounder = [sireID, damID] else: - # expect more infomative error message - print(f"ERROR: Invalid metafounder input format.\nExiting...") + print(f"ERROR: Both parents must be metafounders if one is a metafounder. For individual {idx} the parents were {sireID} and {damID}.\nConsider using a dummy individual for the metafounder.\nExiting...") sys.exit(2) else: if sireID is None: @@ -1010,7 +1007,7 @@ def readInAAP(self, fileName): mfx, data = value nLoci = self.nLoci if len(data) != nLoci: - print("ERROR: Incorrect alternative allele probability input format. \nExiting...") + print(f"ERROR: For {mfx}, not all loci have an alternative allele frequency in the `-alt_allele_prob_file` input. \nExiting...") sys.exit(2) if mfx[:3] == "MF_": if mfx == MainMetaFounder: @@ -1019,11 +1016,11 @@ def readInAAP(self, fileName): try: current_aap[:] = data except ValueError: - print("ERROR: Incorrect alternative allele probability input format. \nExiting...") + print(f"ERROR: For {mfx}, the alternative allele frequency data gave a ValueError. Please check the `-alt_allele_prob_file` input. \nExiting...") sys.exit(2) self.AAP[mfx] = current_aap else: - print("ERROR: Incorrect alternative allele probability input format. \nExiting...") + print(f"ERROR: All metafounders must have the prefix 'MF_'. {mfx} does not but is present in the `-alt_allele_prob_file`. Please remove or rename {mfx}. \nExiting...") sys.exit(2) if default_aap: diff --git a/ProbMath.py b/ProbMath.py index b2a6ca4..a0a5917 100644 --- a/ProbMath.py +++ b/ProbMath.py @@ -13,6 +13,21 @@ def getGenotypesFromMaf(maf) : return mafGenotypes +def getGenotypesFromMultiMaf(mafDict) : + nLoci = len(mafDict[list(mafDict.keys())[0]]) + mafGenotypes = np.full((4, nLoci), .25, dtype = np.float32) + # Assumes two maf inputs. + # maf1 from the sire, maf2 from the dam. + maf1 = mafDict[list(mafDict.keys())[0]] + maf2 = mafDict[list(mafDict.keys())[1]] + + mafGenotypes[0,:] = (1-maf1)*(1-maf2) + mafGenotypes[1,:] = (1-maf1)*(maf2) + mafGenotypes[2,:] = (maf1)*(1-maf2) + mafGenotypes[3,:] = maf1*maf2 + + return mafGenotypes + def getGenotypeProbabilities_ind(ind, args = None, log = False): if args is None: error = 0.01