Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hassanfa committed Jan 9, 2021
1 parent 0652324 commit e178fea
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 27 deletions.
3 changes: 2 additions & 1 deletion BALSAMIC/commands/run/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

# CLI commands and decorators
from BALSAMIC.utils.cli import (createDir, get_schedulerpy, get_snakefile,
SnakeMake, get_config, get_fastq_bind_path, job_id_dump_to_yaml)
SnakeMake, get_config, get_fastq_bind_path,
job_id_dump_to_yaml)
from BALSAMIC.utils.constants import ANALYSIS_TYPES, VCF_DICT, BALSAMIC_SCRIPTS

LOG = logging.getLogger(__name__)
Expand Down
14 changes: 7 additions & 7 deletions BALSAMIC/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,11 @@ def generate_h5(job_name: str, job_id: str, file_path: str) -> str:
h5_file_name = Path(file_path, job_name + ".h5")
sh5util_output = subprocess.check_output(
["sh5util", "-o",
h5_file_name.as_posix(), "-S", "-j", job_id], stderr=subprocess.STDOUT)

if "sh5util: No node-step files found for jobid" in sh5util_output.decode("utf-8"):
h5_file_name.as_posix(), "-S", "-j", job_id],
stderr=subprocess.STDOUT)

if "sh5util: No node-step files found for jobid" in sh5util_output.decode(
"utf-8"):
h5_file_name = None

return h5_file_name
Expand All @@ -598,8 +600,6 @@ def generate_h5(job_name: str, job_id: str, file_path: str) -> str:
def job_id_dump_to_yaml(job_id_dump: Path, job_id_yaml: Path, case_name: str):
"""Write an input job_id_sacct_file to yaml output"""
with open(job_id_dump, "r") as jobid_in, open(job_id_yaml,
"w") as jobid_out:
"w") as jobid_out:
jobid_list = jobid_in.read().splitlines()
yaml.dump({case_name: jobid_list},
jobid_out)

yaml.dump({case_name: jobid_list}, jobid_out)
9 changes: 7 additions & 2 deletions BALSAMIC/utils/workflowscripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ def plot_analysis(log_file: Path, h5_file: Path,
max_cpu_line.set_label("Max available")

mem_ax_color = 'g'
df.plot(y="VMSize", x="ElapsedTime", ax=mem_ax, color=mem_ax_color, style="--")
df.plot(y="VMSize",
x="ElapsedTime",
ax=mem_ax,
color=mem_ax_color,
style="--")
mem_ax.set_title("Memory statistics")
mem_ax.set_xlabel("Wall seconds")
mem_ax.set_ylabel("Memory usage GB (max {}GB)".format(
Expand Down Expand Up @@ -156,7 +160,8 @@ def plot_analysis(log_file: Path, h5_file: Path,
x="ElapsedTime",
ax=write_io_ax,
color=write_io_ax_color,
style="--", legend=False)
style="--",
legend=False)
write_io_ax.set_title("Disk I/O statistics")
write_io_ax.set_xlabel("Wall seconds")
write_io_ax.set_ylabel("Disk write (MB)")
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/report/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_status_tumor_normal_panel(invoke_cli, tumor_normal_config, helpers,


def test_status_analysis_finish(invoke_cli, tumor_normal_config, helpers,
sentieon_install_dir, sentieon_license):
sentieon_install_dir, sentieon_license):
# GIVEN a tumor-normal config file
helpers.read_config(tumor_normal_config)

Expand Down
4 changes: 2 additions & 2 deletions tests/commands/run/test_run_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def test_run_analysis_create_dir(invoke_cli, tumor_only_config):
with mock.patch.object(subprocess, 'run') as mocked:
mocked.return_value.stdout = 1
invoke_cli([
'run', 'analysis', '-s', tumor_only_config, '-r', '--benchmark', '--account',
'development'
'run', 'analysis', '-s', tumor_only_config, '-r', '--benchmark',
'--account', 'development'
])
# THEN it should abort with error
assert Path(re.sub('/$', '.1/', log_dir)).exists()
Expand Down
3 changes: 2 additions & 1 deletion tests/commands/run/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def test_scheduler_slurm_py(snakemake_job_script, tumor_normal_config, capsys):
"--sample-config", tumor_normal_config, "--profile",
scheduler_profile_slurm, "--qos", "low", "--account", "development",
"--log-dir", log_dir, "--script-dir", script_dir, "--result-dir",
sample_config['analysis']['result'], "--slurm-profiler", "task", "--slurm-profiler-interval", "10"
sample_config['analysis']['result'], "--slurm-profiler", "task",
"--slurm-profiler-interval", "10"
]
scheduler_cmd.extend(scheduler_args)

Expand Down
25 changes: 13 additions & 12 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
get_file_status_string, get_from_two_key, find_file_index, merge_json,
validate_fastq_pattern, get_panel_chrom, create_fastq_symlink,
get_fastq_bind_path, singularity, get_file_extension,
get_bioinfo_tools_version, convert_deliverables_tags, check_executable, job_id_dump_to_yaml, generate_h5)
get_bioinfo_tools_version, convert_deliverables_tags, check_executable,
job_id_dump_to_yaml, generate_h5)

from BALSAMIC.utils.rule import (get_chrom, get_vcf, get_sample_type,
get_picard_mrkdup, get_variant_callers,
Expand Down Expand Up @@ -791,7 +792,7 @@ def test_check_executable_not_existing():


def test_job_id_dump_to_yaml(tmp_path):

# GIVEN a file with one job id per line, a key (case name), and an output file name
dummy_dir = tmp_path / "job_id_dump_dir"
dummy_dir.mkdir()
Expand All @@ -801,43 +802,43 @@ def test_job_id_dump_to_yaml(tmp_path):
dummy_name = "angrybird"

dummy_yaml_out = dummy_dir / "jod_id.yaml"

# WHEN creating yaml from job id dump
job_id_dump_to_yaml(dummy_job_id_dump, dummy_yaml_out, dummy_name)

# THEN file should exist
assert dummy_yaml_out.exists()
assert dummy_yaml_out.exists()


def test_generate_h5(tmp_path):

# GIVEN a job name, a path, and a job id
dummy_path= tmp_path / "h5dir"
dummy_path = tmp_path / "h5dir"
dummy_path.mkdir()
dummy_job_name = "awesome_name"
dummy_job_id = "31415.123123"
correct_output = Path(dummy_path, dummy_job_name + ".h5")

# WHEN generating a h5 output
with mock.patch.object(subprocess, 'check_output') as mocked:
with mock.patch.object(subprocess, 'check_output') as mocked:
actual_output = generate_h5(dummy_job_name, dummy_job_id, dummy_path)

assert actual_output == correct_output


def test_generate_h5_capture_no_output(tmp_path):

# GIVEN a job name, a path, and a job id
dummy_path= tmp_path / "h5dir"
dummy_path = tmp_path / "h5dir"
dummy_path.mkdir()
dummy_job_name = "awesome_name"
dummy_job_id = "31415.123123"
mocked_output = "sh5util: No node-step files found for jobid"
correct_output = Path(dummy_path, dummy_job_name + ".h5")

# WHEN generating a h5 output
with mock.patch.object(subprocess, 'check_output') as mocked:
with mock.patch.object(subprocess, 'check_output') as mocked:
mocked.return_value = mocked_output.encode("utf-8")
actual_output = generate_h5(dummy_job_name, dummy_job_id, dummy_path)

assert actual_output == None
2 changes: 1 addition & 1 deletion tests/utils/test_workflowscripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ def test_plot_analysis_bad_h5(tmp_path_factory):
# WHEN calling plot_analysis
actual_pdf_file = plot_analysis(dummy_log_file, dummy_h5, dummy_pdf_name)

assert actual_pdf_file is None
assert actual_pdf_file is None

0 comments on commit e178fea

Please sign in to comment.