Skip to content

Commit

Permalink
add fail message when no data is left after trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
cimendes committed Jul 2, 2019
1 parent 66bd5d2 commit 3230027
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 3 additions & 1 deletion DEN-IM.nf
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ file ".versions"
for seqfile in *.fq;
do if [ ! -s \$seqfile ]
then
echo \$seqfile is empty && exit 120
echo \$seqfile is empty
echo 'No data left after polymorphic sequence filtering' > .fail
exit 120
fi
done
Expand Down
2 changes: 1 addition & 1 deletion templates/integrity_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def main(sample_id, fastq_pair, gsize, minimum_coverage, opts):
status_fh.write("pass")
# Estimated coverage does not pass minimum threshold
else:
fail_msg = "Sample with low coverage ({}), below the {} " \
fail_msg = "Sample with low coverage ({}), below the {}x " \
"threshold".format(exp_coverage, minimum_coverage)
logger.error(fail_msg)
fail_fh.write(fail_msg)
Expand Down
26 changes: 21 additions & 5 deletions templates/trimmomatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import json
import fileinput
import subprocess
import gzip

from subprocess import PIPE
from collections import OrderedDict
Expand Down Expand Up @@ -219,6 +220,14 @@ def write_report(storage_dic, output_file, sample_id):
}],
"badReads": vals["bad_reads"]
}

# in cases where all reads where trimmed
if vals["clean_len"] == 0:
json_dic["fail"] = [{
"sample": sample_id,
"table": "qc",
"value": ["No data left after trimming."]
}]
json_rep.write(json.dumps(json_dic, separators=(",", ":")))


Expand Down Expand Up @@ -399,11 +408,18 @@ def main(sample_id, fastq_pair, trim_range, trim_opts, phred, adapters_file,
# Check if trimmomatic ran successfully. If not, write the error message
# to the status channel and exit.
with open(".status", "w") as status_fh:
if p.returncode != 0:
status_fh.write("fail")
return
else:
status_fh.write("pass")
with open(".fail", "w") as fail_fh:
if p.returncode != 0:
status_fh.write("fail")
return
else:
# check if read file is empty
with gzip.open("{}_1_trim.fastq.gz".format(SAMPLE_ID), "r") as read1:
if read1.peek(1).decode("utf-8") == '':
status_fh.write("fail")
fail_fh.write("No data left after trimming.")
return
status_fh.write("pass")


if __name__ == '__main__':
Expand Down

0 comments on commit 3230027

Please sign in to comment.