From a49f1be847463f8c5e4598e0c98378acf6a489aa Mon Sep 17 00:00:00 2001 From: ctbus Date: Fri, 16 Jun 2023 13:37:14 -0400 Subject: [PATCH] Add check that filter_reads worked after running --- workflow/scripts/filter_reads.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/workflow/scripts/filter_reads.py b/workflow/scripts/filter_reads.py index 094ed42a..7a687c83 100755 --- a/workflow/scripts/filter_reads.py +++ b/workflow/scripts/filter_reads.py @@ -5,7 +5,8 @@ import sys from collections import OrderedDict from io import TextIOWrapper -from sunbeamlib.parse import parse_fastq, write_many_fastq, write_fastq +from pathlib import Path +from sunbeamlib.parse import parse_fastq, write_fastq def count_host_reads(fp: str, hostdict: dict, net_hostlist: set): @@ -57,6 +58,13 @@ def write_log(f: TextIOWrapper, hostdict: OrderedDict, host: int, nonhost: int): if not header_str.split(" ")[0] in ids and not header_str.replace("/1", "").replace("/2", "") in ids: write_fastq([header_str, seq_str, plus_str, quality_str], f_out) + # Check that the output file is about the right size given the number of ids removed + if Path(snakemake.input.reads).stat().st_size == Path(snakemake.output.reads).stat().st_size and Path(snakemake.input.hostreads).stat().st_size != 0: + s = f"ERROR: {snakemake.input.hostreads} is not empty but {snakemake.input.reads} and {snakemake.output.reads} are the same size. Something went wrong in the filtering." + l.write(s) + sys.stderr.write(s) + sys.exit(1) + with open(snakemake.output.log, "w") as log: write_log(log, hostdict, host, nonhost)