From e560a50300f66cbe33fef81b12b0ae673dde5cec Mon Sep 17 00:00:00 2001 From: Kim Rutherford Date: Tue, 23 Jul 2024 15:00:35 +1200 Subject: [PATCH] Rename motif search max_genes argument, add test --- motifsearch/search.py | 4 ++-- motifsearch/tests.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/motifsearch/search.py b/motifsearch/search.py index 3620bb0..c3291b4 100644 --- a/motifsearch/search.py +++ b/motifsearch/search.py @@ -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: [ @@ -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 } diff --git a/motifsearch/tests.py b/motifsearch/tests.py index a4da311..5751ac7 100644 --- a/motifsearch/tests.py +++ b/motifsearch/tests.py @@ -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)