Skip to content

Commit

Permalink
fix: issue when picard does not create output files (#496)
Browse files Browse the repository at this point in the history
* Added touch to possibly missing files

* Fixed typos

* Bumped version

* Remove append

Co-authored-by: Johannes Köster <johannes.koester@uni-due.de>
  • Loading branch information
fgvieira and johanneskoester committed Jun 30, 2022
1 parent 6419dbf commit aceab7e
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 49 deletions.
2 changes: 1 addition & 1 deletion bio/picard/addorreplacereadgroups/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/bedtointervallist/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/collectalignmentsummarymetrics/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/collectgcbiasmetrics/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
3 changes: 2 additions & 1 deletion bio/picard/collecthsmetrics/environment.yaml
@@ -1,6 +1,7 @@
channels:
- bioconda
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/collectinsertsizemetrics/environment.yaml
Expand Up @@ -3,6 +3,6 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- r-base ==3.6.2
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/collectmultiplemetrics/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
45 changes: 21 additions & 24 deletions bio/picard/collectmultiplemetrics/meta.yaml
@@ -1,54 +1,52 @@
name: picard CollectMultipleMetrics
description: >
A ``picard`` meta-metrics tool that collects multiple classes of metrics.
For usage information about CollectMultipleMetrics, please see ``picard``'s `documentation <https://broadinstitute.github.io/picard/command-line-overview.html#CollectMultipleMetrics>`_.
For more information about ``picard``, also see the `source code <https://github.com/broadinstitute/picard>`_.
You can select which tool(s) to run by adding the respective extension(s) (see table below) to the requested output of the wrapper invocation (see example Snakemake rule below).
+-----------------------------------+-----------------------------------------+
| Tool | Extension(s) for the output files |
+===================================+=========================================+
| CollectAlignmentSummaryMetrics | ".alignment_summary_metrics" |
| CollectAlignmentSummaryMetrics | `.alignment_summary_metrics` |
+-----------------------------------+-----------------------------------------+
| CollectInsertSizeMetrics | ".insert_size_metrics", |
| CollectInsertSizeMetrics | `.insert_size_metrics`, |
| | |
| | ".insert_size_histogram.pdf" |
| | `.insert_size_histogram.pdf` |
+-----------------------------------+-----------------------------------------+
| QualityScoreDistribution | ".quality_distribution_metrics", |
| QualityScoreDistribution | `.quality_distribution_metrics`, |
| | |
| | ".quality_distribution.pdf" |
| | `.quality_distribution.pdf` |
+-----------------------------------+-----------------------------------------+
| MeanQualityByCycle | ".quality_by_cycle_metrics", |
| MeanQualityByCycle | `.quality_by_cycle_metrics`, |
| | |
| | ".quality_by_cycle.pdf" |
| | `.quality_by_cycle.pdf` |
+-----------------------------------+-----------------------------------------+
| CollectBaseDistributionByCycle | ".base_distribution_by_cycle_metrics", |
| CollectBaseDistributionByCycle | `.base_distribution_by_cycle_metrics`, |
| | |
| | ".base_distribution_by_cycle.pdf" |
| | `.base_distribution_by_cycle.pdf` |
+-----------------------------------+-----------------------------------------+
| CollectGcBiasMetrics | ".gc_bias.detail_metrics", |
| CollectGcBiasMetrics | `.gc_bias.detail_metrics`, |
| | |
| | ".gc_bias.summary_metrics", |
| | `.gc_bias.summary_metrics`, |
| | |
| | ".gc_bias.pdf" |
| | `.gc_bias.pdf` |
+-----------------------------------+-----------------------------------------+
| RnaSeqMetrics | ".rna_metrics" |
| RnaSeqMetrics | `.rna_metrics` |
+-----------------------------------+-----------------------------------------+
| CollectSequencingArtifactMetrics | ".bait_bias_detail_metrics", |
| CollectSequencingArtifactMetrics | `.bait_bias_detail_metrics`, |
| | |
| | ".bait_bias_summary_metrics", |
| | `.bait_bias_summary_metrics`, |
| | |
| | ".error_summary_metrics", |
| | `.error_summary_metrics`, |
| | |
| | ".pre_adapter_detail_metrics", |
| | `.pre_adapter_detail_metrics`, |
| | |
| | ".pre_adapter_summary_metrics" |
| | `.pre_adapter_summary_metrics` |
+-----------------------------------+-----------------------------------------+
| CollectQualityYieldMetrics | ".quality_yield_metrics" |
| CollectQualityYieldMetrics | `.quality_yield_metrics` |
+-----------------------------------+-----------------------------------------+
url: https://broadinstitute.github.io/picard/command-line-overview.html#CollectMultipleMetrics
authors:
- David Laehnemann
- Antonie Vietor
Expand All @@ -61,7 +59,6 @@ output:
- multiple metrics pdf files (.pdf)
- the appropriate extensions for the output files must be used depending on the desired tools
notes: |
* The `java_opts` param allows for additional arguments to be passed to the java compiler, e.g. "-XX:ParallelGCThreads=10" (not for `-XmX` or `-Djava.io.tmpdir`, since they are handled automatically).
* The `java_opts` param allows for additional arguments to be passed to the java compiler, e.g. `-XX:ParallelGCThreads=10` (not for `-XmX` or `-Djava.io.tmpdir`, since they are handled automatically).
* The `extra` param allows for additional program arguments.
* `--TMP_DIR` is automatically set by `resources.tmpdir`
* For more information see, https://broadinstitute.github.io/picard/command-line-overview.html#CollectMultipleMetrics
25 changes: 19 additions & 6 deletions bio/picard/collectmultiplemetrics/wrapper.py
Expand Up @@ -3,12 +3,12 @@
__email__ = "antonie.v@gmx.de"
__license__ = "MIT"

import sys
import tempfile
from pathlib import Path
from snakemake.shell import shell
from snakemake_wrapper_utils.java import get_java_opts

log = snakemake.log_fmt_shell(stdout=False, stderr=True)
log = snakemake.log_fmt_shell(stdout=True, stderr=True)

extra = snakemake.params.get("extra", "")
java_opts = get_java_opts(snakemake)
Expand All @@ -34,28 +34,32 @@
".pre_adapter_summary_metrics": "CollectSequencingArtifactMetrics",
".quality_yield_metrics": "CollectQualityYieldMetrics",
}
progs = set()


# Select programs to run from output files
progs = set()
for file in snakemake.output:
matched = False
for ext in exts_to_prog:
if file.endswith(ext):
progs.add(exts_to_prog[ext])
matched = True
if not matched:
sys.exit(
raise ValueError(
"Unknown type of metrics file requested, for possible metrics files, see https://snakemake-wrappers.readthedocs.io/en/stable/wrappers/picard/collectmultiplemetrics.html"
)

programs = " --PROGRAM null --PROGRAM " + " --PROGRAM ".join(progs)
programs = "--PROGRAM null --PROGRAM " + " --PROGRAM ".join(progs)


out = str(snakemake.wildcards.sample) # as default
# Infer common output prefix
output_file = str(snakemake.output[0])
for ext in exts_to_prog:
if output_file.endswith(ext):
out = output_file[: -len(ext)]
break


with tempfile.TemporaryDirectory() as tmpdir:
shell(
"picard CollectMultipleMetrics"
Expand All @@ -67,3 +71,12 @@
" {programs}"
" {log}"
)


# Under some circumstances, some picard programs might not produce an output (https://github.com/snakemake/snakemake-wrappers/issues/357). To avoid snakemake errors, the output files of those programs are created empty (if they do not exist).
for ext in [
ext for ext, prog in exts_to_prog.items() if prog in ["CollectInsertSizeMetrics"]
]:
for file in snakemake.output:
if file.endswith(ext) and not Path(file).is_file():
Path(file).touch()
2 changes: 1 addition & 1 deletion bio/picard/collectrnaseqmetrics/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/collecttargetedpcrmetrics/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/createsequencedictionary/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
4 changes: 2 additions & 2 deletions bio/picard/markduplicates/environment.yaml
Expand Up @@ -3,6 +3,6 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- samtools =1.15.1
- picard =2.27
- samtools =1.15
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/markduplicateswithmatecigar/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/markduplicateswithmatecigar/wrapper.py
Expand Up @@ -8,7 +8,7 @@
from snakemake.shell import shell
from snakemake_wrapper_utils.java import get_java_opts

log = snakemake.log_fmt_shell(stdout=True, stderr=True, append=True)
log = snakemake.log_fmt_shell(stdout=True, stderr=True)

extra = snakemake.params.get("extra", "")
java_opts = get_java_opts(snakemake)
Expand Down
2 changes: 1 addition & 1 deletion bio/picard/mergesamfiles/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/mergevcfs/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/revertsam/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/samtofastq/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3
2 changes: 1 addition & 1 deletion bio/picard/sortsam/environment.yaml
Expand Up @@ -3,5 +3,5 @@ channels:
- conda-forge
- defaults
dependencies:
- picard =2.26
- picard =2.27
- snakemake-wrapper-utils ==0.1.3

0 comments on commit aceab7e

Please sign in to comment.