Set fastq option straight

This commit is contained in:
Chris Wright 2021-03-19 11:21:32 +00:00
parent 4a72aee687
commit e8e584d451
3 changed files with 44 additions and 4 deletions

View File

@ -99,7 +99,7 @@ OUTPUT=output
nextflow run epi2me-labs/wf-template \
-w ${OUTPUT}/workspace \
-profile standard \
--fastq test_data/reads.fq.gz \
--fastq test_data \
--out_dir ${OUTPUT}
```

View File

@ -23,12 +23,17 @@ def main():
"""Run entry point."""
parser = argparse.ArgumentParser()
parser.add_argument(
"directory", help="Directory containing .fastq(.gz) files")
"fastq", help="Directory containing .fastq(.gz) files, or single fastq")
parser.add_argument(
"output", help="Output file")
args = parser.parse_args()
fastqs = glob.glob(os.path.join(args.directory, "*.fastq*"))
if os.path.isfile(args.fastq):
fastqs = [args.fastq]
elif os.path.isdir(args.fastq):
fastqs = glob.glob(os.path.join(args.directory, "*.fastq*"))
else:
raise IOError("fastq argument should be directory of file.")
reads = itertools.chain.from_iterable(
pysam.FastxFile(fname) for fname in fastqs)

37
main.nf
View File

@ -27,6 +27,40 @@ Script Options:
}
process concatFastq {
// concatenate fastq and fastq.gz in a dir
label "pysam"
cpus 1
input:
file "input"
output:
file "reads.fastq.gz"
shell:
'''
#!/usr/bin/env python
from glob import glob
import gzip
import itertools
import os
import pysam
# we use pysam just because it will read both fastq and fastq.gz
# and we don't have to worry about having a combination or not
with gzip.open("reads.fastq.gz", "wt") as fh:
files = itertools.chain(
glob("input/*.fastq"), glob("input/*.fastq.gz"))
records = itertools.chain.from_iterable(
pysam.FastxFile(fn) for fn in files)
for rec in records:
annot = " {}".format(rec.comment) if rec.comment else ""
qual = rec.quality if rec.quality else "+"*len(rec.sequence)
fh.write("@{}{}\\n{}\\n+\\n{}\\n".format(rec.name, annot, rec.sequence, qual))
'''
}
process readSeqs {
// Just write a file with sequence lengths
label "pysam"
@ -75,6 +109,7 @@ workflow pipeline {
take:
reads
main:
reads = concatFastq(reads)
summary = readSeqs(reads)
report = makeReport(summary)
emit:
@ -99,7 +134,7 @@ workflow {
reads = file("$params.fastq/*.fastq*", type: 'file', maxdepth: 1)
if (reads) {
reads = Channel.fromPath(params.fastq, type: 'dir', maxDepth: 1)
reads = Channel.fromPath(params.fastq, type: 'dir', checkIfExists: true)
results = pipeline(reads)
output(results)
} else {