Skip to content

Commit e368695

Browse files
authored
Merge pull request #88 from MaozGelbart/pssmmotif_from_sequences
MAINT: adapt MotifPssmPattern to modern biopython
2 parents aef8733 + 6e0950c commit e368695

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

dnachisel/SequencePattern/MotifPssmPattern.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MotifPssmPattern(SequencePattern):
1616
----------
1717
1818
pssm
19-
A Bio.Align.AlignInfo.PSSM object.
19+
A `Bio.motifs.Motif` object.
2020
2121
threshold
2222
locations of the sequence with a PSSM score above this value will be
@@ -32,6 +32,10 @@ class MotifPssmPattern(SequencePattern):
3232
def __init__(
3333
self, pssm, threshold=None, relative_threshold=None,
3434
):
35+
if not isinstance(pssm, Bio.motifs.Motif):
36+
raise ValueError(
37+
f"Expected PSSM type of `Bio.motifs.Motif`, but {type(pssm)} was passed"
38+
)
3539
self.name = pssm.name
3640
self.pssm = pssm.pssm
3741
if relative_threshold is not None:
@@ -108,8 +112,8 @@ def from_sequences(
108112
sequences = [Seq(s) for s in sequences]
109113
motif = motifs.create(sequences)
110114
cls.apply_pseudocounts(motif, pseudocounts)
111-
pssm = PSSM(motif.pssm)
112-
pssm.name = name
115+
motif.name = name
116+
pssm = motif
113117
return MotifPssmPattern(
114118
pssm=pssm, threshold=threshold, relative_threshold=relative_threshold,
115119
)

tests/test_patterns.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ def test_pssm_pattern_from_file(
3737
)
3838
assert len(multiple_patterns) == 2
3939
assert all([isinstance(p, MotifPssmPattern) for p in multiple_patterns])
40+
41+
42+
def test_pssm_from_sequences():
43+
seqs = ['ACGT', 'ACCT', 'AAGT']
44+
motif_name = "test motif"
45+
pat = MotifPssmPattern.from_sequences(seqs, name=motif_name, relative_threshold=0.9)
46+
assert isinstance(pat, MotifPssmPattern)
47+
assert len(pat.find_matches_in_string("ACATACGTACAC")) == 1
48+
assert len(pat.find_matches_in_string("ACATAATTACAC")) == 0

0 commit comments

Comments
 (0)