snakemake-wrappers
snakemake-wrappers copied to clipboard
picard CollectMultipleMetrics missing output files
Snakemake version Snakemake 5.31.1 Wrappers 0.74.0
Describe the bug After running the picard CollectMultipleMetrics wrapper, some output files might be missing if the input files were too small for picard to collect statistics. For example, CollectInsertSizeMetrics seems to need a certain amount of data to run, and if it is not enough, no output is produced by picard. This however leads to snakemake failing the rule due to missing output files.
A solution that works for me is to extend the wrapper by touching non-existing output files, so that at least an empty file is present that satisfies snakemake. Downstream, I use MultiQC on these files, which so far has not complained about those empty files. Still, there might be use cases where empty files lead to other issues downstream - but I do not see a better solution for this.
Here is the code that I added to a local copy of the wrapper script, and which I suggest could be added to the wrapper here:
import os
# Define a touch function.
def touch(fname, times=None):
with open(fname, 'a'):
os.utime(fname, times)
# Go through all files again, and simply touch the any non-existing ones.
# We only touch non-existing ones, to not mess with existing time stamps.
for file in snakemake.output:
if not os.path.isfile(file):
touch(file)
If there are better solutions, please let me know.
I guess you could also use pathlib
(https://docs.python.org/3/library/pathlib.html#pathlib.Path.touch) and touch all output files, no?