From 04be1470a934176dc097e5443af5462058850d8d Mon Sep 17 00:00:00 2001 From: Dan Fornika Date: Tue, 2 Jul 2024 19:12:52 -0700 Subject: [PATCH] Handle case where segment is missing while plotting scaffold (#33) * Handle case where segment is missing while plotting scaffold * fill in docstring for make_plots * Update usage in README --- README.md | 6 ++++-- fluviewer/__init__.py | 2 +- fluviewer/plots.py | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4d82d17..432dcc0 100644 --- a/README.md +++ b/README.md @@ -106,8 +106,8 @@ pip3 install git+https://github.com/BCCDC-PHL/FluViewer.git ## Usage ``` -usage: fluviewer [-h] -f FORWARD_READS -r REVERSE_READS -d DATABASE [-o OUTDIR] -n OUTPUT_NAME [-i [0-100]] [-l [32-]] [-D [1-]] [-q [0-]] [-v [0-1]] [-V [0-1]] [-N [1-]] [-L [1-]] - [-t [1-]] [-M [1-]] [-g] [--log-level {info,debug}] +usage: fluviewer [-h] -f FORWARD_READS -r REVERSE_READS -d DB [-o OUTDIR] -n OUTPUT_NAME [-i [0-100]] [-l [32-]] [-D [1-]] [-q [0-]] [-v [0-1]] [-V [0-1]] [-N [1-]] [-L [1-]] [-t [1-]] [-M [1-]] [-g] [--force] + [--log-level {info,debug}] [--version] BCCDC-PHL/FluViewer: Influenza A virus consensus sequence generation and variant calling @@ -145,8 +145,10 @@ optional arguments: Gigabytes of memory allocated for normalizing reads (default=max) -g, --disable-garbage-collection Disable garbage collection and retain intermediate analysis files + --force Allow overwrite of existing files and directories. --log-level {info,debug} Log level (default=info) + --version show program's version number and exit ``` diff --git a/fluviewer/__init__.py b/fluviewer/__init__.py index 71998e8..cfe0fe0 100644 --- a/fluviewer/__init__.py +++ b/fluviewer/__init__.py @@ -1 +1 @@ -__version__ = '0.1.11-2' +__version__ = '0.1.11-3' diff --git a/fluviewer/plots.py b/fluviewer/plots.py index c721218..9669a9a 100644 --- a/fluviewer/plots.py +++ b/fluviewer/plots.py @@ -185,6 +185,18 @@ def make_scaffolding_plots(alignment: list[dict], scaffold: dict, output: Path) def make_plots(inputs, outdir, out_name): """ Generate plots for the analysis. + + :param inputs: The inputs dictionary. Expected keys are: + ['depth_of_cov_freebayes', 'alignment', 'depth_of_cov_freebayes', + 'low_coverage_positions', 'ambiguous_positions', 'variant_positions', + 'segment_contigs_alignments', 'scaffolds'] + :type inputs: dict + :param outdir: The output directory. + :type outdir: str + :param out_name: The output name. + :type out_name: str + :return: The analysis summary. Keys are ['timestamp_analysis_start', 'inputs', 'outputs', 'timestamp_analysis_complete'] + :rtype: dict """ timestamp_analysis_start = datetime.datetime.now().isoformat() analysis_summary = { @@ -222,6 +234,11 @@ def make_plots(inputs, outdir, out_name): ] outputs['scaffold_alignment_plots'] = {} for segment in segments: + + if segment not in inputs['segment_contigs_alignments']: + log.warning(f'No contig alignment file found for segment {segment}. Skipping...') + continue + contig_alignment_path = inputs['segment_contigs_alignments'][segment] if not os.path.exists(contig_alignment_path): log.warning(f'Contig alignment file {contig_alignment_path} does not exist. Skipping...')