Skip to content

Commit

Permalink
Make sure lightmotif-py computes the right p-values
Browse files Browse the repository at this point in the history
  • Loading branch information
althonos committed Mar 8, 2024
1 parent ec8d85e commit 093889b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lightmotif-py/lightmotif/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ impl ScoringMatrix {
}
}

/// Compute the PSSM score for all positions of the given sequence.
/// Calculate the PSSM score for all positions of the given sequence.
///
/// Returns:
/// `~lightmotif.StripedScores`: The PSSM scores for every position
Expand Down
3 changes: 2 additions & 1 deletion lightmotif-py/lightmotif/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from . import test_pipeline, test_sequence
from . import test_pipeline, test_sequence, test_pvalue


def load_tests(loader, suite, pattern):
suite.addTests(loader.loadTestsFromModule(test_pipeline))
suite.addTests(loader.loadTestsFromModule(test_sequence))
suite.addTests(loader.loadTestsFromModule(test_pvalue))
return suite
21 changes: 21 additions & 0 deletions lightmotif-py/lightmotif/tests/test_pvalue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest
import lightmotif


class TestMA0045(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.ma0045 = lightmotif.CountMatrix("ACTG", {
"A": [3, 7, 9, 3, 11, 11, 11, 3, 4, 3, 8, 8, 9, 9, 11, 2],
"C": [5, 0, 1, 6, 0, 0, 0, 3, 1, 4, 5, 1, 0, 5, 0, 7],
"T": [2, 4, 3, 1, 0, 1, 1, 6, 1, 1, 0, 1, 3, 0, 0, 5],
"G": [4, 3, 1, 4, 3, 2, 2, 2, 8, 6, 1, 4, 2, 0, 3, 0],
"N": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
}).normalize(pseudocount=0.25).log_odds()

def test_pvalue(self):
self.assertAlmostEqual(self.ma0045.pvalue(8.7708), 0.00032910, places=5)

def test_score(self):
self.assertAlmostEqual(self.ma0045.score(0.00033), 8.756855, places=5)
2 changes: 2 additions & 0 deletions lightmotif/src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ impl<A: Alphabet> FrequencyMatrix<A> {

/// Convert to a scoring matrix using the given background frequencies.
///
/// This uses the base-2 logarithm.
///
/// # Note
/// By convention, columns with null background frequencies receive a
/// log-odds-ratio of [`f32::NEG_INFINITY`](https://doc.rust-lang.org/std/primitive.f32.html#associatedconstant.NEG_INFINITY).
Expand Down

0 comments on commit 093889b

Please sign in to comment.