annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
1 #!/usr/bin/env python
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
2
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
3 from __future__ import print_function
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
4
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
5 import argparse
1
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
6 import csv
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
7 import re
1
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
8
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
9
3
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
10 class Range(object):
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
11 """
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
12 Used to limit the min_coverage and min_identity args to range 0.0 - 100.0
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
13 """
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
14 def __init__(self, start, end):
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
15 self.start = start
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
16 self.end = end
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
17
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
18 def __eq__(self, other):
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
19 return self.start <= other <= self.end
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
20
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
21 def __contains__(self, item):
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
22 return self.__eq__(item)
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
23
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
24 def __iter__(self):
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
25 yield self
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
26
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
27 def __repr__(self):
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
28 return str(self.start) + " - " + str(self.end)
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
29
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
30
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
31 def parse_screen_file(screen_file):
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
32 screen = []
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
33 with open(screen_file) as f:
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
34 reader = csv.DictReader(f, delimiter="\t", quotechar='"')
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
35 for row in reader:
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
36 screen.append(row)
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
37 return screen
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
38
1
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
39
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
40 def get_fieldnames(input_file):
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
41 with open(input_file) as f:
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
42 reader = csv.DictReader(f, delimiter="\t", quotechar='"')
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
43 row = next(reader)
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
44 fieldnames = row.keys()
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
45 return fieldnames
1
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
46
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
47
3
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
48 def detect_gene(abricate_report_row, regex, min_coverage, min_identity):
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
49 gene_of_interest = bool(re.search(regex, abricate_report_row['GENE']))
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
50 sufficient_coverage = float(abricate_report_row['%COVERAGE']) >= min_coverage
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
51 sufficient_identity = float(abricate_report_row['%IDENTITY']) >= min_identity
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
52 if gene_of_interest and sufficient_coverage and sufficient_identity:
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
53 return True
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
54 else:
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
55 return False
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
56
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
57
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
58 def main(args):
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
59 screen = parse_screen_file(args.screening_file)
4
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
60 gene_detection_status_fieldnames = ['gene_name', 'detected', 'alleles']
1
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
61 with open(args.abricate_report, 'r') as f1, \
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
62 open(args.screened_report, 'w') as f2, \
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
63 open(args.gene_detection_status, 'w') as f3:
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
64 abricate_report_reader = csv.DictReader(f1, delimiter="\t", quotechar='"')
1
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
65 screened_report_writer = csv.DictWriter(f2, delimiter="\t", quotechar='"',
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
66 fieldnames=abricate_report_reader.fieldnames)
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
67 gene_detection_status_writer = csv.DictWriter(f3, delimiter="\t", quotechar='"',
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
68 fieldnames=gene_detection_status_fieldnames)
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
69 screened_report_writer.writeheader()
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
70 gene_detection_status_writer.writeheader()
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
71
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
72 for gene in screen:
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
73 gene_detection_status = {
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
74 'gene_name': gene['gene_name'],
4
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
75 'detected': False,
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
76 'alleles': None,
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
77 }
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
78 for abricate_report_row in abricate_report_reader:
3
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
79 if detect_gene(abricate_report_row, gene['regex'], args.min_coverage, args.min_identity):
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
80 gene_detection_status['detected'] = True
4
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
81 if not gene_detection_status['alleles']:
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
82 gene_detection_status['alleles'] = abricate_report_row['GENE']
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
83 else:
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
84 gene_detection_status['alleles'] = ",".join([
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
85 gene_detection_status['alleles'],
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
86 abricate_report_row['GENE'],
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
87 ])
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
88 screened_report_writer.writerow(abricate_report_row)
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
89 gene_detection_status_writer.writerow(gene_detection_status)
1
4f963b583186 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit c27095ceaf23aa2c910e0ea866db9ec8d3e7816b"
public-health-bioinformatics
parents: 0
diff changeset
90 f1.seek(0) # return file pointer to start of abricate report
3
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
91 next(abricate_report_reader)
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
92
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
93
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
94 if __name__ == '__main__':
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
95 parser = argparse.ArgumentParser()
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
96 parser.add_argument("abricate_report", help="Input: Abricate report to screen (tsv)")
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
97 parser.add_argument("--screening_file", help="Input: List of genes to screen for (tsv)")
3
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
98 parser.add_argument("--screened_report",
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
99 help=("Output: Screened abricate report, including only genes of interest (tsv)"))
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
100 parser.add_argument("--gene_detection_status",
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
101 help=("Output: detection status for all genes listed in the screening file (tsv)"))
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
102 parser.add_argument("--min_coverage", type=float, default=90.0,
4
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
103 choices=Range(0.0, 100.0),
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
104 help=("Minimum percent coverage (default 90.0)"))
3
2262e531c50b "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 50a464c3e6f87ca8d2c874842cbcee370d8aa9c4"
public-health-bioinformatics
parents: 1
diff changeset
105 parser.add_argument("--min_identity", type=float, default=90.0,
4
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
106 choices=Range(0.0, 100.0),
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
107 help=("Minimum percent identity (default 90.0)"))
22247b1a59d5 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit ae10b1f55b2356bea735a994619288f7575430cb"
public-health-bioinformatics
parents: 3
diff changeset
108 parser.add_argument("-v", "--version", action='version', version='%(prog)s 0.4.0')
0
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
109 args = parser.parse_args()
b2d56a44a872 "planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/blob/master/tools/screen_abricate_report commit 1d569fc27b052d1982d82ca19455caaff6386f46"
public-health-bioinformatics
parents:
diff changeset
110 main(args)