-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Clinical-Genomics/extract
Separate 'extract' and 'import' functionalities in CLI
- Loading branch information
Showing
8 changed files
with
153 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import click | ||
import logging | ||
from shutil import rmtree | ||
from pathlib import Path | ||
import yaml | ||
import sys | ||
import os | ||
|
||
from mutacc_auto.utils.tmp_dir import TemporaryDirectory | ||
from mutacc_auto.recipes.input_recipe import get_inputs | ||
from mutacc_auto.recipes.extract_recipe import run_mutacc_extract | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
@click.command('extract') | ||
@click.option('-c','--case-id', type=str) | ||
@click.option('-d','--days-ago', type=int) | ||
@click.option('-e','--environment', type=str) | ||
@click.option('-C','--config-file', type=click.Path(exists=True)) | ||
@click.option('-L', '--log-directory', type=click.Path(exists=True)) | ||
@click.option('-E', '--email', type=str) | ||
@click.option('-p','--padding', type=int) | ||
@click.option('-D','--dry', is_flag=True) | ||
@click.option('-V','--verbose', is_flag=True) | ||
@click.option('-k', '--conda', is_flag=True) | ||
@click.pass_context | ||
def extract_command(ctx, | ||
case_id, | ||
days_ago, | ||
environment, | ||
config_file, | ||
log_directory, | ||
email, | ||
padding, | ||
dry, | ||
verbose, | ||
conda): | ||
|
||
#Open and read config fore mutacc | ||
with open(Path(config_file)) as yaml_handle: | ||
|
||
mutacc_conf = yaml.load(yaml_handle) | ||
|
||
#Find directory where cases ready for import are stored | ||
case_dir = Path(mutacc_conf['case_dir']) | ||
|
||
#Create a temporary dir to store created vcf, yaml, and script files | ||
with TemporaryDirectory() as tmp_dir: | ||
|
||
LOG.info("All files are placed in {}".format(tmp_dir)) | ||
|
||
#Prepare input for case with case_id or days since updated | ||
inputs = get_inputs(tmp_dir, case_id=case_id, days_ago=days_ago, padding = padding) | ||
|
||
for case_input in inputs: | ||
#Extract reads for every case | ||
sbatch_script = run_mutacc_extract( | ||
tmp_dir, | ||
config_file, | ||
case_input['input_file'], | ||
case_input['padding'], | ||
environment, | ||
log_directory, | ||
email=email, | ||
conda=conda, | ||
dry=dry | ||
) | ||
|
||
if verbose: | ||
|
||
with open(sbatch_script) as sbatch_handle: | ||
|
||
LOG.info("\n{}".format(sbatch_handle.read())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import pytest | ||
from mock import patch | ||
import yaml | ||
from pathlib import Path | ||
|
||
from click.testing import CliRunner | ||
|
||
from mutacc_auto.cli.root import cli | ||
|
||
INPUTS_LIST = [{'input_file': 'path_to_file', 'padding':600}]*2 | ||
SBATCH_TEMPLATE = "tests/fixtures/sbatch_template.txt" | ||
|
||
@patch('mutacc_auto.cli.extract_command.get_inputs') | ||
@patch('mutacc_auto.cli.extract_command.run_mutacc_extract') | ||
def test_extract_command( | ||
mock_extract, | ||
mock_inputs, | ||
tmpdir | ||
): | ||
|
||
tmp_dir = Path(tmpdir.mkdir('test_export_command')) | ||
mock_inputs.return_value = INPUTS_LIST | ||
mock_extract.return_value = SBATCH_TEMPLATE | ||
|
||
with open(tmp_dir.joinpath('tmp_conf.yaml'), 'w') as conf_handle: | ||
|
||
conf_dict = {'case_dir': str(tmp_dir)} | ||
yaml.dump(conf_dict, conf_handle) | ||
conf_path = conf_handle.name | ||
|
||
with open(tmp_dir.joinpath('tmp_test.mutacc'), 'w') as handle: | ||
handle.write('\n') | ||
|
||
runner = CliRunner() | ||
result = runner.invoke(cli, [ | ||
'extract', | ||
'--case-id', 'test_id', | ||
'--environment', 'env', | ||
'--config-file', conf_path, | ||
'--log-directory', str(tmp_dir), | ||
'--email', 'email@email.com', | ||
'--dry', | ||
'--verbose' | ||
] | ||
) | ||
|
||
assert result.exit_code == 0 | ||
|
||
result = runner.invoke(cli, [ | ||
'extract', | ||
'--days-ago', '300', | ||
'--environment', 'env', | ||
'--config-file', conf_path, | ||
'--log-directory', tmp_dir | ||
] | ||
) | ||
|
||
assert result.exit_code == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters