Skip to content

Commit

Permalink
Add check that filter_reads worked after running
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulthran committed Jun 16, 2023
1 parent f88d99e commit a49f1be
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion workflow/scripts/filter_reads.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit a49f1be

Please sign in to comment.