2626from gimmemotifs .config import MotifConfig
2727from gimmemotifs .c_metrics import pfmscan , score
2828from gimmemotifs .motif import parse_motifs , read_motifs
29- from gimmemotifs .utils import pfmfile_location , make_equal_length
29+ from gimmemotifs .utils import pfmfile_location , make_equal_length , ppm_pseudocount
3030
3131# pool import is at the bottom
3232
@@ -204,6 +204,7 @@ def chisq(p1, p2):
204204 -------
205205 score : float
206206 """
207+
207208 return chi2_contingency ([p1 , p2 ])[1 ]
208209
209210
@@ -440,8 +441,13 @@ def compare_motifs(
440441 combine ,
441442 self .max_partial (m1 .pwm , m2 .pwm , metric , combine ),
442443 )
443- elif metric in ["pcc" , "ed" , "distance" , "wic" , "chisq" , "ssd" ]:
444- return self .max_partial (m1 .pwm , m2 .pwm , metric , combine )
444+ elif metric in ["pcc" , "ed" , "distance" , "wic" , "chisq" , "ssd" , "akl" ]:
445+ return self .max_partial (
446+ ppm_pseudocount (m1 .pwm ),
447+ ppm_pseudocount (m2 .pwm ),
448+ metric ,
449+ combine ,
450+ )
445451 else :
446452 return self .max_partial (m1 .pfm , m2 .pfm , metric , combine )
447453
@@ -455,19 +461,33 @@ def compare_motifs(
455461 combine ,
456462 self .max_total (m1 .pwm , m2 .pwm , metric , combine ),
457463 )
458- elif metric in ["pcc" , "akl" ]:
459- # Slightly randomize the weight matrix
464+ elif metric in [
465+ "ed" ,
466+ "distance" ,
467+ "wic" ,
468+ "chisq" ,
469+ "pcc" ,
470+ "ssd" ,
471+ "akl" ,
472+ "pcc" ,
473+ ]:
460474 return self .max_total (
461- m1 .wiggle_pwm (), m2 .wiggle_pwm (), metric , combine
475+ ppm_pseudocount (m1 .pwm ),
476+ ppm_pseudocount (m2 .pwm ),
477+ metric ,
478+ combine ,
462479 )
463- elif metric in ["ed" , "distance" , "wic" , "chisq" , "pcc" , "ssd" ]:
464- return self .max_total (m1 .pwm , m2 .pwm , metric , combine )
465480 else :
466481 return self .max_total (m1 .pfm , m2 .pfm , metric , combine )
467482
468483 elif match == "subtotal" :
469484 if metric in ["pcc" , "ed" , "distance" , "wic" , "chisq" , "ssd" ]:
470- return self .max_subtotal (m1 .pwm , m2 .pwm , metric , combine )
485+ return self .max_subtotal (
486+ ppm_pseudocount (m1 .pwm ),
487+ ppm_pseudocount (m2 .pwm ),
488+ metric ,
489+ combine ,
490+ )
471491 else :
472492 return self .max_subtotal (m1 .pfm , m2 .pfm , metric , combine )
473493 else :
0 commit comments