Skip to content

Commit

Permalink
Allow MICALL_DD_SUBSEQ to be a regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Oct 11, 2023
1 parent 6ca68d5 commit 9732ccb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions micall/utils/aln2counts_simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections import defaultdict
import logging
import os
import re
from csv import DictReader
from typing import Union

Expand Down Expand Up @@ -44,6 +45,12 @@ def __init__(self,
self.get_result = getattr(self, 'check_' + test_name)
self.reads = read_aligned(self.filename)

expected_subsequence = os.environ.get(SUBSEQ_ENV_VARNAME, None)
if expected_subsequence is None:
raise RuntimeError(f"Expected ${SUBSEQ_ENV_VARNAME!r} environment variable to be set for the {'subseq'!r} test")

self.expected_subsequence_re = re.compile(expected_subsequence)

def _test(self, read_indexes):
read_count = len(read_indexes)
self.write_simple_aligned(self.simple, read_indexes)
Expand Down Expand Up @@ -93,8 +100,7 @@ def writer(filename):

return result

@staticmethod
def check_subseq(stitched_csv, read_count, exception):
def check_subseq(self, stitched_csv, read_count, exception):
if exception is not None:
return DD.UNRESOLVED

Expand All @@ -103,12 +109,8 @@ def check_subseq(stitched_csv, read_count, exception):
logger.debug('Result: %d stitched sequences from %d selected reads.',
simple_count, read_count)

expected_substring = os.environ.get(SUBSEQ_ENV_VARNAME, None)
if expected_substring is None:
raise RuntimeError(f"Expected ${SUBSEQ_ENV_VARNAME!r} environment variable to be set for the {'subseq'!r} test")

stitched_csv.seek(0)
success = any((expected_substring in line) for line in stitched_csv)
success = self.expected_subsequence_re.search(stitched_csv.read())

return DD.FAIL if success else DD.PASS

Expand Down

0 comments on commit 9732ccb

Please sign in to comment.