Skip to content

Commit

Permalink
fixed the cli to export validated variants and created its test
Browse files Browse the repository at this point in the history
  • Loading branch information
northwestwitch committed Mar 26, 2019
1 parent f1687a6 commit 76c59f5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
12 changes: 10 additions & 2 deletions scout/commands/export/variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from scout.export.variant import export_variants, export_verified_variants
from .utils import json_option

from scout.constants import CALLERS
from scout.constants.variants_export import VCF_HEADER, VERIFIED_VARIANTS_HEADER
from scout.server.extensions import store

Expand Down Expand Up @@ -52,7 +52,12 @@ def verified(collaborator, test, outpath=None):
LOG.warning('There are no verified variants for institute {} in database!'.format(collaborator))
return None

document_lines = export_verified_variants(verified_vars)
unique_callers = set()
for var_type, var_callers in CALLERS.items():
for caller in var_callers:
unique_callers.add(caller.get('id'))

document_lines = export_verified_variants(verified_vars, unique_callers)

today = datetime.datetime.now().strftime('%Y-%m-%d')
document_name = '.'.join(['verified_variants', collaborator, today]) + '.xlsx'
Expand All @@ -62,6 +67,9 @@ def verified(collaborator, test, outpath=None):
written_files +=1
LOG.info('Success. Verified variants file contains {} lines'.format(len(document_lines)))
return written_files
elif test:
LOG.info('Could not create document lines. Verified variants not found for customer {}'.format(collaborator))
return

# create workbook and new sheet
# set up outfolder
Expand Down
56 changes: 55 additions & 1 deletion tests/commands/export/test_export_variant_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_export_variants(mock_app, case_obj):
])
assert store.variant_collection.find().count() > 0

# update case registering a causatove variant
# update case registering a causative variant
variant_obj = store.variant_collection.find_one()
store.case_collection.find_one_and_update(
{'_id' : case_obj['_id'] },
Expand Down Expand Up @@ -84,3 +84,57 @@ def test_export_variants(mock_app, case_obj):
# variant should be returned
assert str(variant_obj['position']) in result.output
assert '"position": {}'.format(variant_obj['position']) in result.output


def test_export_verified(mock_app, case_obj, user_obj, institute_obj):
"""Test the CLI command that exports verified variants into excel files"""

runner = mock_app.test_cli_runner()
assert runner

# Load snv variants using the cli
result = runner.invoke(app_cli, ['load', 'variants', case_obj['_id'],
'--snv',
])
assert store.variant_collection.find().count() > 0

# Test the cli without verified variants available
result = runner.invoke(app_cli, ['export', 'verified'])
assert result.exit_code == 0
assert 'There are no verified variants for institute cust000 in database!' in result.output

# Set a variant as verified
variant_obj = store.variant_collection.find_one()

# Validate the above variant:
store.validate(institute=institute_obj, case=case_obj, user=user_obj,
link='link_to_var', variant=variant_obj, validate_type='True positive')
assert store.variant_collection.find({'validation':'True positive'}).count() == 1
assert store.event_collection.find({'verb':'validate'}).count() == 1


# Test the cli without parameters
result = runner.invoke(app_cli, ['export', 'verified', '--test'])
assert result.exit_code == 0
# Variant should be found now
assert 'Success. Verified variants file contains' in result.output


# Test the cli with with a wrong collaborator param
result = runner.invoke(app_cli, ['export', 'verified',
'--test',
'-c', 'cust666'
])
assert result.exit_code == 0
# Variant should not be found now
assert 'There are no verified variants for institute cust666 in database!' in result.output


# Test the cli with the right collaborator param
result = runner.invoke(app_cli, ['export', 'verified',
'--test',
'-c', case_obj['owner']
])
assert result.exit_code == 0
# Variant should be found again
assert 'Success. Verified variants file contains' in result.output

0 comments on commit 76c59f5

Please sign in to comment.