Skip to content

Commit

Permalink
Close #438 by searching for default pipelines by name.
Browse files Browse the repository at this point in the history
  • Loading branch information
donkirkby committed Apr 17, 2018
1 parent 3abcd47 commit 7d6b121
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
29 changes: 29 additions & 0 deletions micall/monitor/kive_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def __init__(self,
self.folder_watchers = {} # {base_calls_folder: FolderWatcher}
self.pipelines = {} # {pipeline_id: pipeline}
self.external_directory_path = self.external_directory_name = None
self.find_default_pipelines()
self.input_pipeline_ids = config and dict(
quality_csv=config.micall_filter_quality_pipeline_id,
bad_cycles_csv=config.micall_main_pipeline_id,
Expand All @@ -181,6 +182,34 @@ def __init__(self,
# Active runs started by other users.
self.other_runs = None # {(pipeline_id, dataset_id, dataset_id, ...): run}

def find_default_pipelines(self):
default_family_names = ['filter quality',
'main',
'resistance']
family_data = None
for family_name in default_family_names:
attribute_name = (
'micall_' + family_name.replace(' ', '_') + '_pipeline_id')
if getattr(self.config, attribute_name) is not None:
continue
if family_data is None:
self.check_session()
filter_text = 'filters[0][key]=smart&filters[0][val]=micall'
family_data = self.session.get(
'@api_pipeline_families',
context={'filters': filter_text}).json()

search_text = 'micall ' + family_name
for family in family_data:
if search_text in family['name'].lower():
for member in family['members']:
setattr(self.config, attribute_name, member['id'])
break
break
else:
raise RuntimeError(f'Argument {attribute_name} not set, and '
f'no pipeline found named {search_text!r}.')

def is_full(self):
active_count = sum(len(folder_watcher.active_samples)
for folder_watcher in self.folder_watchers.values())
Expand Down
60 changes: 60 additions & 0 deletions micall/tests/test_kive_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,66 @@ def create_raw_data_with_two_runs(tmpdir):
return raw_data


def test_find_default_pipelines(mock_open_kive):
mock_session = mock_open_kive.return_value
mock_session.get.side_effect = [
Mock(name='get external file directories',
**{'json.return_value': []}),
Mock(name='get pipeline families',
**{'json.return_value': [
dict(id=42,
name='Other MiCall',
members=[dict(id=420)]),
dict(id=43,
name='MiCall Filter Quality',
members=[dict(id=435),
dict(id=432)]),
dict(id=44,
name='MiCall Main',
members=[dict(id=440)]),
dict(id=45,
name='MiCall Resistance',
members=[dict(id=450)])]})]
expected_filter_quality_pipeline_id = 435
expected_main_pipeline_id = 440
expected_resistance_pipeline_id = 450
args = parse_args([]) # No parameters: all defaults.

kive_watcher = KiveWatcher(args)

assert expected_filter_quality_pipeline_id == \
kive_watcher.config.micall_filter_quality_pipeline_id
assert expected_main_pipeline_id == \
kive_watcher.config.micall_main_pipeline_id
assert expected_resistance_pipeline_id == \
kive_watcher.config.micall_resistance_pipeline_id


def test_default_pipeline_not_found(mock_open_kive):
mock_session = mock_open_kive.return_value
mock_session.get.side_effect = [
Mock(name='get external file directories',
**{'json.return_value': []}),
Mock(name='get pipeline families',
**{'json.return_value': [
dict(id=43,
name='MiCall Filter Quality',
members=[dict(id=435)]),
dict(id=44,
name='MiCrawl Main', # <== Typo
members=[dict(id=440)]),
dict(id=45,
name='MiCall Resistance',
members=[dict(id=450)])]})]
args = parse_args([]) # No parameters: all defaults.

with pytest.raises(
RuntimeError,
match=r"Argument micall_main_pipeline_id not set, and no "
r"pipeline found named 'micall main'\."):
KiveWatcher(args)


def test_hcv_pair(raw_data_with_hcv_pair):
sample_queue = DummyQueueSink()
sample_queue.expect_put(
Expand Down
3 changes: 0 additions & 3 deletions micall_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ def parse_args(argv=None):
args.kive_password = os.environ.get('MICALL_KIVE_PASSWORD', 'kive')
if not hasattr(args, 'qai_password'):
args.qai_password = os.environ.get('MICALL_QAI_PASSWORD', 'testing')
if args.micall_filter_quality_pipeline_id is None:
parser.error('Missing micall_filter_quality_pipeline_id. Set the '
'argument or environment variable.')
return args


Expand Down

0 comments on commit 7d6b121

Please sign in to comment.