def test_multiple_comparisons(self): """multiple_comparisons should match values from R""" self.assertFloatEqual(multiple_comparisons(1e-7, 10000), 1-0.9990005) self.assertFloatEqual(multiple_comparisons(0.05, 10), 0.4012631) self.assertFloatEqual(multiple_comparisons(1e-20, 1), 1e-20) self.assertFloatEqual(multiple_comparisons(1e-300, 1), 1e-300) self.assertFloatEqual(multiple_comparisons(0.95, 3),0.99987499999999996) self.assertFloatEqual(multiple_comparisons(0.75, 100),0.999999999999679) self.assertFloatEqual(multiple_comparisons(0.5, 1000),1) self.assertFloatEqual(multiple_comparisons(0.01, 1000),0.99995682875259) self.assertFloatEqual(multiple_comparisons(0.5, 5), 0.96875) self.assertFloatEqual(multiple_comparisons(1e-20, 10), 1e-19)
def test_multiple_comparisons(self): """multiple_comparisons should match values from R""" self.assertFloatEqual(multiple_comparisons(1e-7, 10000), 1 - 0.9990005) self.assertFloatEqual(multiple_comparisons(0.05, 10), 0.4012631) self.assertFloatEqual(multiple_comparisons(1e-20, 1), 1e-20) self.assertFloatEqual(multiple_comparisons(1e-300, 1), 1e-300) self.assertFloatEqual(multiple_comparisons(0.95, 3), 0.99987499999999996) self.assertFloatEqual(multiple_comparisons(0.75, 100), 0.999999999999679) self.assertFloatEqual(multiple_comparisons(0.5, 1000), 1) self.assertFloatEqual(multiple_comparisons(0.01, 1000), 0.99995682875259) self.assertFloatEqual(multiple_comparisons(0.5, 5), 0.96875) self.assertFloatEqual(multiple_comparisons(1e-20, 10), 1e-19)
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