Skip to content

Commit

Permalink
Rename motif search max_genes argument, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kimrutherford committed Jul 23, 2024
1 parent efd5ec1 commit e560a50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions motifsearch/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def read_data(self):
seq = regex.sub(r"\*$", "", seq)
self.peptides.update({peptide_id: seq})

def motif(self, scope, search_text, max_genes = 500, context = 25):
def motif(self, scope, search_text, max_gene_details = 500, context = 25):
"""Search all peptides of the regular expression 'search_text'
returning an array like:
[
Expand Down Expand Up @@ -144,7 +144,7 @@ def add_match(peptide_id, peptide_matches, seq):
pep_res = []
pep_res_count = 0
for m in patt.finditer(seq, timeout=2):
if len(peptide_matches) >= max_genes:
if len(peptide_matches) >= max_gene_details:
pep_matches = {
'peptide_id': peptide_id
}
Expand Down
14 changes: 14 additions & 0 deletions motifsearch/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,17 @@ def test_one_gene(self):
self.assertEqual(len(result[0]['matches']), 1)
self.assertEqual(result[0]['matches'][0]['end'], 14)
self.assertEqual(result[0]['matches'][0]['before'], 'MASTFSQS')

def test_max_genes(self):
result = self._search.motif('all', 'F', max_gene_details = 999)
count = 0
for res in result:
if 'matches' in res:
count += 1
self.assertEqual(count, 5)
result = self._search.motif('all', 'F', max_gene_details = 2)
count = 0
for res in result:
if 'matches' in res:
count += 1
self.assertEqual(count, 2)

0 comments on commit e560a50

Please sign in to comment.