def getPValueLoose(self, module, alphabet_len=None): """Returns the Pvalue of a module. - pass alphabet_len if alphabet other than module.MolType was used to find modules (i.e. using a protein reduced alphabet) """ # Length of the module module_len = len(module.Template) # if moltype length has not been passed, get it from module.MolType # if not alphabet_len: alphabet_len = len(module.MolType.Alphabet) # Total length of the alignment aln_len = sum(map(len, self.Alignment.values())) # Number of sequences in the alignment num_seqs = len(self.Alignment) # get module_p module_p = 1 for char in module.Template: module_p *= self._degen_p(char, module.MolType) # Mean for passing to poisson_high using loose correction loose_mean = (aln_len + num_seqs * (1 - module_len)) * (module_p) # Loose P value from poisson_high loose_p_value = poisson_high(len(module) - 1, loose_mean) # Correct P value for multiple comparisons loose_p_corrected = multiple_comparisons(loose_p_value, alphabet_len ** module_len) return loose_p_corrected
def getPValueLoose(self, module, alphabet_len=None): """Returns the Pvalue of a module. - pass alphabet_len if alphabet other than module.MolType was used to find modules (i.e. using a protein reduced alphabet) """ #Length of the module module_len = len(module.Template) #if moltype length has not been passed, get it from module.MolType # if not alphabet_len: alphabet_len = len(module.MolType.Alphabet) #Total length of the alignment aln_len = sum(map(len, self.Alignment.values())) #Number of sequences in the alignment num_seqs = len(self.Alignment) #get module_p module_p = 1 for char in module.Template: module_p *= self._degen_p(char, module.MolType) #Mean for passing to poisson_high using loose correction loose_mean = \ (aln_len + num_seqs*(1-module_len))*(module_p) #Loose P value from poisson_high loose_p_value = poisson_high(len(module) - 1, loose_mean) #Correct P value for multiple comparisons loose_p_corrected = \ multiple_comparisons(loose_p_value,alphabet_len**module_len) return loose_p_corrected
def test_poisson_high(self): """Upper tail of poisson should match R for integer successes""" #WARNING: Results only guaranteed for integer successes: floating #point _should_ yield reasonable values, but R rounds to int. expected = { (0, 0): 0, (0, 0.75): 0.5276334, (0, 1): 0.6321206, (0, 5): 0.993262, (0, 113.7): 1, (2, 0): 0, (2, 3): 0.5768099, (2, 17.8): 0.9999967, (17, 29.6): 0.9912467, (180, 0): 0, (180, 137.4):0.0002159856, (180, 318):1, (180, 1024):1, } for (key, value) in expected.items(): self.assertFloatEqual(poisson_high(*key), value)