annotate create_features_from_gff3.py @ 8:df7a90763b3c draft default tip

planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 37aa8fa02c144220da9a3899644025b8c19697c9
author eric-rasche
date Tue, 27 Jun 2017 04:13:27 -0400
parents f9a6e151b3b4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
1 #!/usr/bin/env python
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
2 from builtins import str
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
3 import sys
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
4 import time
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
5 import argparse
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
6 from webapollo import WebApolloInstance, featuresToFeatureSchema
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
7 from webapollo import WAAuth, OrgOrGuess, GuessOrg, AssertUser, retry
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
8 from BCBio import GFF
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
9 import logging
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
10 logging.basicConfig(level=logging.INFO)
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
11 log = logging.getLogger(__name__)
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
12
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
13
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
14 if __name__ == '__main__':
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
15 parser = argparse.ArgumentParser(description='Sample script to add an attribute to a feature via web services')
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
16 WAAuth(parser)
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
17 parser.add_argument('email', help='User Email')
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
18 parser.add_argument('--source', help='URL where the input dataset can be found.')
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
19 OrgOrGuess(parser)
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
20
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
21 parser.add_argument('gff3', type=argparse.FileType('r'), help='GFF3 file')
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
22 args = parser.parse_args()
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
23
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
24 wa = WebApolloInstance(args.apollo, args.username, args.password)
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
25 # User must have an account
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
26 gx_user = AssertUser(wa.users.loadUsers(email=args.email))
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
27
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
28 # Get organism
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
29 org_cn = GuessOrg(args, wa)
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
30 if isinstance(org_cn, list):
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
31 org_cn = org_cn[0]
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
32
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
33 # TODO: Check user perms on org.
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
34 org = wa.organisms.findOrganismByCn(org_cn)
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
35
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
36 bad_quals = ['date_creation', 'source', 'owner', 'date_last_modified', 'Name', 'ID']
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
37
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
38 sys.stdout.write('# ')
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
39 sys.stdout.write('\t'.join(['Feature ID', 'Apollo ID', 'Success', 'Messages']))
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
40 sys.stdout.write('\n')
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
41 # print(wa.annotations.getFeatures())
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
42 for rec in GFF.parse(args.gff3):
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
43 wa.annotations.setSequence(rec.id, org['id'])
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
44 for feature in rec.features:
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
45 # We can only handle genes right now
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
46 if feature.type not in ('gene', 'terminator'):
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
47 continue
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
48 # Convert the feature into a presentation that Apollo will accept
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
49 featureData = featuresToFeatureSchema([feature])
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
50 if 'children' in featureData[0] and any([child['type']['name'] == 'tRNA' for child in featureData[0]['children']]):
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
51 # We're experiencing a (transient?) problem where gene_001 to
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
52 # gene_025 will be rejected. Thus, hardcode to a known working
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
53 # gene name and update later.
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
54
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
55 featureData[0]['name'] = 'tRNA_000'
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
56 tRNA_sf = [child for child in feature.sub_features if child.type == 'tRNA'][0]
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
57 tRNA_type = 'tRNA-' + tRNA_sf.qualifiers.get('Codon', ["Unk"])[0]
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
58
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
59 if 'Name' in feature.qualifiers:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
60 if feature.qualifiers['Name'][0].startswith('tRNA-'):
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
61 tRNA_type = feature.qualifiers['Name'][0]
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
62
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
63 newfeature = wa.annotations.addFeature(featureData, trustme=True)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
64
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
65 def func0():
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
66 wa.annotations.setName(
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
67 newfeature['features'][0]['uniquename'],
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
68 tRNA_type,
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
69 )
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
70 retry(func0)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
71
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
72 if args.source:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
73 gene_id = newfeature['features'][0]['parent_id']
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
74
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
75 def setSource():
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
76 wa.annotations.addAttributes(gene_id, {'DatasetSource': [args.source]})
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
77 retry(setSource)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
78
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
79 sys.stdout.write('\t'.join([
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
80 feature.id,
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
81 newfeature['features'][0]['uniquename'],
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
82 'success',
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
83 ]))
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
84 elif featureData[0]['type']['name'] == 'terminator':
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
85 # We're experiencing a (transient?) problem where gene_001 to
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
86 # gene_025 will be rejected. Thus, hardcode to a known working
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
87 # gene name and update later.
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
88 featureData[0]['name'] = 'terminator_000'
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
89 newfeature = wa.annotations.addFeature(featureData, trustme=True)
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
90
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
91 def func0():
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
92 wa.annotations.setName(
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
93 newfeature['features'][0]['uniquename'],
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
94 'terminator'
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
95 )
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
96
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
97 retry(func0)
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
98
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
99 if args.source:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
100 gene_id = newfeature['features'][0]['parent_id']
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
101
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
102 def setSource():
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
103 wa.annotations.addAttributes(gene_id, {'DatasetSource': [args.source]})
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
104 retry(setSource)
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
105
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
106 sys.stdout.write('\t'.join([
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
107 feature.id,
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
108 newfeature['features'][0]['uniquename'],
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
109 'success',
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
110 ]))
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
111 else:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
112 try:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
113 # We're experiencing a (transient?) problem where gene_001 to
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
114 # gene_025 will be rejected. Thus, hardcode to a known working
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
115 # gene name and update later.
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
116 featureData[0]['name'] = 'gene_000'
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
117 # Extract CDS feature from the feature data, this will be used
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
118 # to set the CDS location correctly (apollo currently screwing
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
119 # this up (2.0.6))
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
120 CDS = featureData[0]['children'][0]['children']
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
121 CDS = [x for x in CDS if x['type']['name'] == 'CDS'][0]['location']
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
122 # Create the new feature
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
123 newfeature = wa.annotations.addFeature(featureData, trustme=True)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
124 # Extract the UUIDs that apollo returns to us
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
125 mrna_id = newfeature['features'][0]['uniquename']
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
126 gene_id = newfeature['features'][0]['parent_id']
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
127 # Sleep to give it time to actually persist the feature. Apollo
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
128 # is terrible about writing + immediately reading back written
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
129 # data.
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
130 time.sleep(1)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
131 # Correct the translation start, but with strand specific log
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
132 if CDS['strand'] == 1:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
133 wa.annotations.setTranslationStart(mrna_id, min(CDS['fmin'], CDS['fmax']))
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
134 else:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
135 wa.annotations.setTranslationStart(mrna_id, max(CDS['fmin'], CDS['fmax']) - 1)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
136
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
137 # Finally we set the name, this should be correct.
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
138 time.sleep(0.5)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
139 wa.annotations.setName(mrna_id, feature.qualifiers.get('product', feature.qualifiers.get('Name', ["Unknown"]))[0])
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
140 time.sleep(0.5)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
141
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
142 def func():
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
143 wa.annotations.setName(gene_id, feature.qualifiers.get('product', feature.qualifiers.get('Name', ["Unknown"]))[0])
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
144 retry(func)
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
145
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
146 if args.source:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
147 gene_id = newfeature['features'][0]['parent_id']
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
148
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
149 def setSource():
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
150 wa.annotations.addAttributes(gene_id, {'DatasetSource': [args.source]})
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
151 retry(setSource)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
152 extra_attr = {}
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
153 for (key, values) in feature.qualifiers.items():
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
154 if key in bad_quals:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
155 continue
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
156
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
157 if key == 'Note':
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
158 def func2():
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
159 wa.annotations.addComments(gene_id, values)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
160 retry(func2)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
161 else:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
162 extra_attr[key] = values
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
163
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
164 def func3():
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
165 wa.annotations.addAttributes(gene_id, extra_attr)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
166 retry(func3)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
167
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
168 sys.stdout.write('\t'.join([
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
169 feature.id,
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
170 gene_id,
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
171 'success',
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
172 ]))
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
173 except Exception as e:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
174 msg = str(e)
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
175 if '\n' in msg:
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
176 msg = msg[0:msg.index('\n')]
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
177 sys.stdout.write('\t'.join([
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
178 feature.id,
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
179 '',
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
180 'ERROR',
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
181 msg
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
182 ]))
5
7610987e0c48 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff changeset
183 sys.stdout.write('\n')
7
f9a6e151b3b4 planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents: 5
diff changeset
184 sys.stdout.flush()