INNER CODE UNIT · Python
filter_reads
Gabaldonlab/redundans · redundans.py:304
def filter_reads(outdir, fq1, fq2, minlen, maxlen, limit, minqual=10):
"""Filter FastQ files and return output fnames."""
fastq = (fq1, fq2)
# generate output files
fn1 = os.path.join(outdir, "_reads.%s" % (os.path.basename(fq1.name.rstrip(".gz"))))
fn2 = os.path.join(outdir, "_reads.%s" % (os.path.basename(fq2.name.rstrip(".gz"))))
# skip if fq files already generated
if os.path.isfile(fn1) and os.path.isfile(fn2):
# notify about empty trimmed libs
if not os.path.getsize(fn1) or not os.path.getsize(fn2):
return fn1, fn2, 0
return fn1, fn2, 1
# open output files
out1 = open(fn1, "w")
out2 = open(fn2, "w")
outfiles = (out1, out2, 0, 0)
# run filtering
i, filtered, orphans = filter_paired(