comparison screen_abricate_report.py @ 4:22247b1a59d5 draft default tip

"planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
author public-health-bioinformatics
date Fri, 03 Jan 2020 14:30:22 -0500
parents 2262e531c50b
children
comparison
equal deleted inserted replaced
3:2262e531c50b 4:22247b1a59d5
55 return False 55 return False
56 56
57 57
58 def main(args): 58 def main(args):
59 screen = parse_screen_file(args.screening_file) 59 screen = parse_screen_file(args.screening_file)
60 gene_detection_status_fieldnames = ['gene_name', 'detected'] 60 gene_detection_status_fieldnames = ['gene_name', 'detected', 'alleles']
61 with open(args.abricate_report, 'r') as f1, \ 61 with open(args.abricate_report, 'r') as f1, \
62 open(args.screened_report, 'w') as f2, \ 62 open(args.screened_report, 'w') as f2, \
63 open(args.gene_detection_status, 'w') as f3: 63 open(args.gene_detection_status, 'w') as f3:
64 abricate_report_reader = csv.DictReader(f1, delimiter="\t", quotechar='"') 64 abricate_report_reader = csv.DictReader(f1, delimiter="\t", quotechar='"')
65 screened_report_writer = csv.DictWriter(f2, delimiter="\t", quotechar='"', 65 screened_report_writer = csv.DictWriter(f2, delimiter="\t", quotechar='"',
70 gene_detection_status_writer.writeheader() 70 gene_detection_status_writer.writeheader()
71 71
72 for gene in screen: 72 for gene in screen:
73 gene_detection_status = { 73 gene_detection_status = {
74 'gene_name': gene['gene_name'], 74 'gene_name': gene['gene_name'],
75 'detected': False 75 'detected': False,
76 'alleles': None,
76 } 77 }
77 for abricate_report_row in abricate_report_reader: 78 for abricate_report_row in abricate_report_reader:
78 if detect_gene(abricate_report_row, gene['regex'], args.min_coverage, args.min_identity): 79 if detect_gene(abricate_report_row, gene['regex'], args.min_coverage, args.min_identity):
79 gene_detection_status['detected'] = True 80 gene_detection_status['detected'] = True
81 if not gene_detection_status['alleles']:
82 gene_detection_status['alleles'] = abricate_report_row['GENE']
83 else:
84 gene_detection_status['alleles'] = ",".join([
85 gene_detection_status['alleles'],
86 abricate_report_row['GENE'],
87 ])
80 screened_report_writer.writerow(abricate_report_row) 88 screened_report_writer.writerow(abricate_report_row)
81 gene_detection_status_writer.writerow(gene_detection_status) 89 gene_detection_status_writer.writerow(gene_detection_status)
82 f1.seek(0) # return file pointer to start of abricate report 90 f1.seek(0) # return file pointer to start of abricate report
83 next(abricate_report_reader) 91 next(abricate_report_reader)
84 92
90 parser.add_argument("--screened_report", 98 parser.add_argument("--screened_report",
91 help=("Output: Screened abricate report, including only genes of interest (tsv)")) 99 help=("Output: Screened abricate report, including only genes of interest (tsv)"))
92 parser.add_argument("--gene_detection_status", 100 parser.add_argument("--gene_detection_status",
93 help=("Output: detection status for all genes listed in the screening file (tsv)")) 101 help=("Output: detection status for all genes listed in the screening file (tsv)"))
94 parser.add_argument("--min_coverage", type=float, default=90.0, 102 parser.add_argument("--min_coverage", type=float, default=90.0,
95 choices=Range(0.0, 100.0), help=("Minimum percent coverage")) 103 choices=Range(0.0, 100.0),
104 help=("Minimum percent coverage (default 90.0)"))
96 parser.add_argument("--min_identity", type=float, default=90.0, 105 parser.add_argument("--min_identity", type=float, default=90.0,
97 choices=Range(0.0, 100.0), help=("Minimum percent identity")) 106 choices=Range(0.0, 100.0),
107 help=("Minimum percent identity (default 90.0)"))
108 parser.add_argument("-v", "--version", action='version', version='%(prog)s 0.4.0')
98 args = parser.parse_args() 109 args = parser.parse_args()
99 main(args) 110 main(args)