Mercurial > repos > estrain > microrunqc
comparison run_fastq_scan.py @ 0:4e629e82c5b1 draft default tip
planemo upload commit a820b38dea9a409c11e220ba904da232fdbc4c05
| author | estrain |
|---|---|
| date | Fri, 13 Mar 2026 12:51:10 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4e629e82c5b1 |
|---|---|
| 1 #!/usr/bin/env | |
| 2 | |
| 3 ## Run fastq-scan to get mean read length and mean quality score | |
| 4 ## author: errol strain, estrain@gmail.com | |
| 5 | |
| 6 from argparse import (ArgumentParser, FileType) | |
| 7 import sys | |
| 8 import glob | |
| 9 import subprocess | |
| 10 import json | |
| 11 | |
| 12 def parse_args(): | |
| 13 "Parse the input arguments, use '-h' for help." | |
| 14 | |
| 15 parser = ArgumentParser(description='Run fastq-scan on a pair of gzipped FASTQ files') | |
| 16 | |
| 17 # Read inputs | |
| 18 parser.add_argument('--fastq', type=str, required=True, nargs=2, help='FASTQ files') | |
| 19 parser.add_argument('--output', type=str, required=True, nargs=1, help='Output File') | |
| 20 parser.add_argument('--type', type=str, required=True, nargs=1, help='File Type (text or gz)') | |
| 21 | |
| 22 return parser.parse_args() | |
| 23 | |
| 24 args =parse_args() | |
| 25 | |
| 26 # FASTA file | |
| 27 r1 = args.fastq[0] | |
| 28 r2 = args.fastq[1] | |
| 29 | |
| 30 # Read 1 | |
| 31 if str(args.type[0]) == "gz" : | |
| 32 cmd1 = ["zcat", r1] | |
| 33 else : | |
| 34 cmd1 = ["cat", r1] | |
| 35 cmd2 = ["fastq-scan"] | |
| 36 pcmd1= subprocess.Popen(cmd1,stdout= subprocess.PIPE,shell=False) | |
| 37 r1json = json.loads(subprocess.Popen(cmd2, stdin=pcmd1.stdout,stdout=subprocess.PIPE,shell=False).communicate()[0]) | |
| 38 r1q = round(r1json["qc_stats"]["qual_mean"],1) | |
| 39 r1l = round(r1json["qc_stats"]["read_mean"],1) | |
| 40 | |
| 41 # Read 2 | |
| 42 if str(args.type[0]) == "gz" : | |
| 43 cmd1 = ["zcat", r2] | |
| 44 else : | |
| 45 cmd1 = ["cat", r2] | |
| 46 cmd2 = ["fastq-scan"] | |
| 47 pcmd1= subprocess.Popen(cmd1,stdout= subprocess.PIPE,shell=False) | |
| 48 r2json = json.loads(subprocess.Popen(cmd2, stdin=pcmd1.stdout,stdout=subprocess.PIPE,shell=False).communicate()[0]) | |
| 49 r2q = round(r2json["qc_stats"]["qual_mean"],1) | |
| 50 r2l = round(r2json["qc_stats"]["read_mean"],1) | |
| 51 | |
| 52 # Write output to be used by sum_mlst.py | |
| 53 output = open(args.output[0],"w") | |
| 54 output.write(str(r1l) + "\t" + str(r2l) + "\t" + str(r1q) + "\t" + str(r2q)) |
