Mercurial > repos > gga > apollo_create_account
comparison export.py @ 16:0929c15c3d70 draft
"planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 1f9a5502a7423c78d862e81537b7646c9f4da5d9"
author | gga |
---|---|
date | Fri, 10 Dec 2021 09:54:02 +0000 |
parents | d6f1caebd5a4 |
children |
comparison
equal
deleted
inserted
replaced
15:115d5e5c88d4 | 16:0929c15c3d70 |
---|---|
14 | 14 |
15 if __name__ == '__main__': | 15 if __name__ == '__main__': |
16 parser = argparse.ArgumentParser(description='Script to export data from Apollo via web services') | 16 parser = argparse.ArgumentParser(description='Script to export data from Apollo via web services') |
17 CnOrGuess(parser) | 17 CnOrGuess(parser) |
18 parser.add_argument('--gff', type=argparse.FileType('w')) | 18 parser.add_argument('--gff', type=argparse.FileType('w')) |
19 parser.add_argument('--gff_with_fasta', action='store_true') | |
19 parser.add_argument('--fasta_pep', type=argparse.FileType('w')) | 20 parser.add_argument('--fasta_pep', type=argparse.FileType('w')) |
20 parser.add_argument('--fasta_cds', type=argparse.FileType('w')) | 21 parser.add_argument('--fasta_cds', type=argparse.FileType('w')) |
21 parser.add_argument('--fasta_cdna', type=argparse.FileType('w')) | 22 parser.add_argument('--fasta_cdna', type=argparse.FileType('w')) |
22 parser.add_argument('--vcf', type=argparse.FileType('w')) | 23 parser.add_argument('--vcf', type=argparse.FileType('w')) |
23 parser.add_argument('--json', type=argparse.FileType('w')) | 24 parser.add_argument('--json', type=argparse.FileType('w')) |
25 parser.add_argument('--die', action='store_true') | |
24 parser.add_argument('email', help='User Email') | 26 parser.add_argument('email', help='User Email') |
25 args = parser.parse_args() | 27 args = parser.parse_args() |
26 | 28 |
27 wa = get_apollo_instance() | 29 wa = get_apollo_instance() |
28 | 30 |
37 all_orgs = wa.organisms.get_organisms() | 39 all_orgs = wa.organisms.get_organisms() |
38 if 'error' in all_orgs: | 40 if 'error' in all_orgs: |
39 all_orgs = [] | 41 all_orgs = [] |
40 all_orgs = [org['commonName'] for org in all_orgs] | 42 all_orgs = [org['commonName'] for org in all_orgs] |
41 | 43 |
44 def error(message): | |
45 if args.die: | |
46 raise Exception(message) | |
47 else: | |
48 print(message) | |
49 | |
42 org_data = [] | 50 org_data = [] |
43 for org_cn in org_cns: | 51 for org_cn in org_cns: |
44 if org_cn not in all_orgs: | 52 if org_cn not in all_orgs: |
45 raise Exception("Could not find organism %s" % org_cn) | 53 raise Exception("Could not find organism %s" % org_cn) |
46 | 54 |
48 if not orgs: | 56 if not orgs: |
49 raise Exception("You do not have read permission on organism %s" % org_cn) | 57 raise Exception("You do not have read permission on organism %s" % org_cn) |
50 | 58 |
51 org = wa.organisms.show_organism(org_cn) | 59 org = wa.organisms.show_organism(org_cn) |
52 | 60 |
53 uuid_gff = wa.io.write_downloadable(org['commonName'], 'GFF3', export_gff3_fasta=True, sequences=seqs) | 61 # Fetch all the refseqs |
54 if 'error' in uuid_gff or 'uuid' not in uuid_gff: | 62 realSeqs = wa.organisms.get_sequences(org['id']) |
55 raise Exception("Apollo failed to prepare the GFF3 file for download: %s" % uuid_gff) | |
56 args.gff.write(wa.io.download(uuid_gff['uuid'], output_format="text")) | |
57 | 63 |
58 time.sleep(1) | 64 # We'll loop over them individually for decreased memory pressure |
65 for sequence in realSeqs['sequences']: | |
66 print("Downloading", sequence) | |
59 | 67 |
60 uuid_vcf = wa.io.write_downloadable(org['commonName'], 'VCF', sequences=seqs) | 68 try: |
61 if 'error' in uuid_vcf or 'uuid' not in uuid_vcf: | 69 uuid_gff = wa.io.write_downloadable(org['commonName'], 'GFF3', export_gff3_fasta=args.gff_with_fasta, sequences=[sequence['name']]) |
62 raise Exception("Apollo failed to prepare the VCF file for download: %s" % uuid_vcf) | 70 if 'error' in uuid_gff or 'uuid' not in uuid_gff: |
63 args.vcf.write(wa.io.download(uuid_vcf['uuid'], output_format="text")) | 71 error("Apollo failed to prepare the GFF3 file for download: %s" % uuid_gff) |
72 args.gff.write(wa.io.download(uuid_gff['uuid'], output_format="text")) | |
73 time.sleep(1) | |
74 except Exception as e: | |
75 error(e) | |
64 | 76 |
65 time.sleep(1) | 77 try: |
78 uuid_vcf = wa.io.write_downloadable(org['commonName'], 'VCF', sequences=[sequence['name']]) | |
79 if 'error' in uuid_vcf or 'uuid' not in uuid_vcf: | |
80 error("Apollo failed to prepare the VCF file for download: %s" % uuid_vcf) | |
81 args.vcf.write(wa.io.download(uuid_vcf['uuid'], output_format="text")) | |
82 time.sleep(1) | |
83 except Exception as e: | |
84 error(e) | |
66 | 85 |
67 uuid_fa = wa.io.write_downloadable(org['commonName'], 'FASTA', sequences=seqs, seq_type='cdna') | 86 try: |
68 if 'error' in uuid_fa or 'uuid' not in uuid_fa: | 87 uuid_fa = wa.io.write_downloadable(org['commonName'], 'FASTA', sequences=[sequence['name']], seq_type='cdna') |
69 raise Exception("Apollo failed to prepare the cdna FASTA file for download: %s" % uuid_fa) | 88 if 'error' in uuid_fa or 'uuid' not in uuid_fa: |
70 args.fasta_cdna.write(wa.io.download(uuid_fa['uuid'], output_format="text")) | 89 error("Apollo failed to prepare the cdna FASTA file for download: %s" % uuid_fa) |
90 args.fasta_cdna.write(wa.io.download(uuid_fa['uuid'], output_format="text")) | |
91 time.sleep(1) | |
92 except Exception as e: | |
93 error(e) | |
71 | 94 |
72 time.sleep(1) | 95 try: |
96 uuid_fa = wa.io.write_downloadable(org['commonName'], 'FASTA', sequences=[sequence['name']], seq_type='cds') | |
97 if 'error' in uuid_fa or 'uuid' not in uuid_fa: | |
98 error("Apollo failed to prepare the cds FASTA file for download: %s" % uuid_fa) | |
99 args.fasta_cds.write(wa.io.download(uuid_fa['uuid'], output_format="text")) | |
100 time.sleep(1) | |
101 except Exception as e: | |
102 error(e) | |
73 | 103 |
74 uuid_fa = wa.io.write_downloadable(org['commonName'], 'FASTA', sequences=seqs, seq_type='cds') | 104 try: |
75 if 'error' in uuid_fa or 'uuid' not in uuid_fa: | 105 uuid_fa = wa.io.write_downloadable(org['commonName'], 'FASTA', sequences=[sequence['name']], seq_type='peptide') |
76 raise Exception("Apollo failed to prepare the cds FASTA file for download: %s" % uuid_fa) | 106 if 'error' in uuid_fa or 'uuid' not in uuid_fa: |
77 args.fasta_cds.write(wa.io.download(uuid_fa['uuid'], output_format="text")) | 107 error("Apollo failed to prepare the file for download: %s" % uuid_fa) |
108 args.fasta_pep.write(wa.io.download(uuid_fa['uuid'], output_format="text")) | |
109 time.sleep(1) | |
110 except Exception as e: | |
111 error(e) | |
78 | 112 |
79 time.sleep(1) | 113 org_data.append(org) |
80 | |
81 uuid_fa = wa.io.write_downloadable(org['commonName'], 'FASTA', sequences=seqs, seq_type='peptide') | |
82 if 'error' in uuid_fa or 'uuid' not in uuid_fa: | |
83 raise Exception("Apollo failed to prepare the file for download: %s" % uuid_fa) | |
84 args.fasta_pep.write(wa.io.download(uuid_fa['uuid'], output_format="text")) | |
85 | |
86 org_data.append(org) | |
87 | 114 |
88 args.json.write(json.dumps(org_data, indent=2)) | 115 args.json.write(json.dumps(org_data, indent=2)) |