Mercurial > repos > dfornika > pick_plasmids_containing_genes
comparison pick_plasmids_containing_genes.py @ 4:109b9d1e2e99 draft default tip
"planemo upload for repository https://github.com/public-health-bioinformatics/galaxy_tools/tree/master/tools/pick_plasmids_containing_genes commit 0f3fff91eb329adf437224eb8f7449853083b01e-dirty"
| author | dfornika |
|---|---|
| date | Thu, 19 Dec 2019 21:06:14 +0000 |
| parents | 2dd1a0ed7cce |
| children |
comparison
equal
deleted
inserted
replaced
| 3:50640b06fca5 | 4:109b9d1e2e99 |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 from __future__ import print_function | 3 from __future__ import print_function |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import csv | |
| 6 import errno | 7 import errno |
| 7 import csv | |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import shutil | 10 import shutil |
| 11 import sys | |
| 12 | 11 |
| 13 from pprint import pprint | |
| 14 | 12 |
| 15 def parse_screen_file(screen_file): | 13 def parse_screen_file(screen_file): |
| 16 screen = [] | 14 screen = [] |
| 17 with open(screen_file) as f: | 15 with open(screen_file) as f: |
| 18 reader = csv.DictReader(f, delimiter="\t", quotechar='"') | 16 reader = csv.DictReader(f, delimiter="\t", quotechar='"') |
| 19 for row in reader: | 17 for row in reader: |
| 20 screen.append(row) | 18 screen.append(row) |
| 21 return screen | 19 return screen |
| 20 | |
| 22 | 21 |
| 23 def main(args): | 22 def main(args): |
| 24 # create output directory | 23 # create output directory |
| 25 try: | 24 try: |
| 26 os.mkdir(args.outdir) | 25 os.mkdir(args.outdir) |
| 45 if re.search(gene['regex'], abricate_report_row['GENE']): | 44 if re.search(gene['regex'], abricate_report_row['GENE']): |
| 46 contigs_with_genes_of_interest.append(abricate_report_row['SEQUENCE']) | 45 contigs_with_genes_of_interest.append(abricate_report_row['SEQUENCE']) |
| 47 f.seek(0) | 46 f.seek(0) |
| 48 next(abricate_report_reader) | 47 next(abricate_report_reader) |
| 49 | 48 |
| 50 # copy the corresponding plasmid fasta files into outdir | 49 # copy the corresponding plasmid fasta files into outdir |
| 51 for contig in contigs_with_genes_of_interest: | 50 for contig in contigs_with_genes_of_interest: |
| 52 for plasmid in args.plasmids: | 51 for plasmid in args.plasmids: |
| 53 copy_plasmid = False | 52 copy_plasmid = False |
| 54 with open(plasmid, 'r') as f: | 53 with open(plasmid, 'r') as f: |
| 55 for line in f: | 54 for line in f: |
| 57 copy_plasmid = True | 56 copy_plasmid = True |
| 58 if copy_plasmid: | 57 if copy_plasmid: |
| 59 print("\t".join([plasmid, "True"])) | 58 print("\t".join([plasmid, "True"])) |
| 60 shutil.copy2(plasmid, args.outdir) | 59 shutil.copy2(plasmid, args.outdir) |
| 61 | 60 |
| 61 | |
| 62 if __name__ == '__main__': | 62 if __name__ == '__main__': |
| 63 parser = argparse.ArgumentParser() | 63 parser = argparse.ArgumentParser() |
| 64 parser.add_argument("--plasmids", nargs='+', help="plasmid assemblies (fasta)") | 64 parser.add_argument("--plasmids", nargs='+', help="plasmid assemblies (fasta)") |
| 65 parser.add_argument("--concatenated_abricate_reports", help="abricate reports (tsv)") | 65 parser.add_argument("--concatenated_abricate_reports", help="abricate reports (tsv)") |
| 66 parser.add_argument("--abricate_report_screening_file", help="") | 66 parser.add_argument("--abricate_report_screening_file", help="") |
