Skip to content

Commit

Permalink
Merge pull request #88 from MaozGelbart/pssmmotif_from_sequences
Browse files Browse the repository at this point in the history
MAINT: adapt MotifPssmPattern to modern biopython
  • Loading branch information
veghp authored Oct 30, 2024
2 parents aef8733 + 6e0950c commit e368695
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions dnachisel/SequencePattern/MotifPssmPattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MotifPssmPattern(SequencePattern):
----------
pssm
A Bio.Align.AlignInfo.PSSM object.
A `Bio.motifs.Motif` object.
threshold
locations of the sequence with a PSSM score above this value will be
Expand All @@ -32,6 +32,10 @@ class MotifPssmPattern(SequencePattern):
def __init__(
self, pssm, threshold=None, relative_threshold=None,
):
if not isinstance(pssm, Bio.motifs.Motif):
raise ValueError(
f"Expected PSSM type of `Bio.motifs.Motif`, but {type(pssm)} was passed"
)
self.name = pssm.name
self.pssm = pssm.pssm
if relative_threshold is not None:
Expand Down Expand Up @@ -108,8 +112,8 @@ def from_sequences(
sequences = [Seq(s) for s in sequences]
motif = motifs.create(sequences)
cls.apply_pseudocounts(motif, pseudocounts)
pssm = PSSM(motif.pssm)
pssm.name = name
motif.name = name
pssm = motif
return MotifPssmPattern(
pssm=pssm, threshold=threshold, relative_threshold=relative_threshold,
)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ def test_pssm_pattern_from_file(
)
assert len(multiple_patterns) == 2
assert all([isinstance(p, MotifPssmPattern) for p in multiple_patterns])


def test_pssm_from_sequences():
seqs = ['ACGT', 'ACCT', 'AAGT']
motif_name = "test motif"
pat = MotifPssmPattern.from_sequences(seqs, name=motif_name, relative_threshold=0.9)
assert isinstance(pat, MotifPssmPattern)
assert len(pat.find_matches_in_string("ACATACGTACAC")) == 1
assert len(pat.find_matches_in_string("ACATAATTACAC")) == 0

0 comments on commit e368695

Please sign in to comment.