Mercurial > repos > eric-rasche > apollo
comparison delete_features.py @ 7:f9a6e151b3b4 draft
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
author | eric-rasche |
---|---|
date | Tue, 27 Jun 2017 04:05:17 -0400 |
parents | 7610987e0c48 |
children |
comparison
equal
deleted
inserted
replaced
6:8f76685cdfc8 | 7:f9a6e151b3b4 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 from __future__ import print_function | |
2 import argparse | 3 import argparse |
4 import random | |
3 from webapollo import WebApolloInstance | 5 from webapollo import WebApolloInstance |
4 from webapollo import WAAuth, OrgOrGuess, GuessOrg, AssertUser | 6 from webapollo import WAAuth, OrgOrGuess, GuessOrg, AssertUser, retry |
5 import logging | 7 import logging |
6 logging.basicConfig(level=logging.INFO) | 8 logging.basicConfig(level=logging.INFO) |
7 log = logging.getLogger(__name__) | 9 log = logging.getLogger(__name__) |
8 | 10 |
9 | 11 |
10 if __name__ == '__main__': | 12 if __name__ == '__main__': |
11 parser = argparse.ArgumentParser(description='Sample script to delete all features from an organism') | 13 parser = argparse.ArgumentParser(description='Sample script to delete all features from an organism') |
12 WAAuth(parser) | 14 WAAuth(parser) |
13 parser.add_argument('email', help='User Email') | 15 parser.add_argument('email', help='User Email') |
16 parser.add_argument('--type', help='Feature type filter') | |
14 OrgOrGuess(parser) | 17 OrgOrGuess(parser) |
15 | 18 |
16 args = parser.parse_args() | 19 args = parser.parse_args() |
17 | 20 |
18 wa = WebApolloInstance(args.apollo, args.username, args.password) | 21 wa = WebApolloInstance(args.apollo, args.username, args.password) |
25 org_cn = org_cn[0] | 28 org_cn = org_cn[0] |
26 | 29 |
27 # TODO: Check user perms on org. | 30 # TODO: Check user perms on org. |
28 org = wa.organisms.findOrganismByCn(org_cn) | 31 org = wa.organisms.findOrganismByCn(org_cn) |
29 | 32 |
30 # Call setSequence to tell apollo which organism we're working with | 33 sequences = wa.organisms.getSequencesForOrganism(org['id']) |
31 wa.annotations.setSequence(org['commonName'], org['id']) | 34 for sequence in sequences['sequences']: |
32 # Then get a list of features. | 35 log.info("Processing %s %s", org['commonName'], sequence['name']) |
33 features = wa.annotations.getFeatures() | 36 # Call setSequence to tell apollo which organism we're working with |
34 # For each feature in the features | 37 wa.annotations.setSequence(sequence['name'], org['id']) |
35 for feature in features['features']: | 38 # Then get a list of features. |
36 # We see that deleteFeatures wants a uniqueName, and so we pass | 39 features = wa.annotations.getFeatures() |
37 # is the uniquename field in the feature. | 40 # For each feature in the features |
38 print(wa.annotations.deleteFeatures([feature['uniquename']])) | 41 for feature in sorted(features['features'], key=lambda x: random.random()): |
42 if args.type: | |
43 if args.type == 'tRNA': | |
44 if feature['type']['name'] != 'tRNA': | |
45 continue | |
39 | 46 |
47 elif args.type == 'terminator': | |
48 if feature['type']['name'] != 'terminator': | |
49 continue | |
50 | |
51 elif args.type == 'mRNA': | |
52 if feature['type']['name'] != 'mRNA': | |
53 continue | |
54 | |
55 else: | |
56 raise Exception("Unknown type") | |
57 | |
58 # We see that deleteFeatures wants a uniqueName, and so we pass | |
59 # is the uniquename field in the feature. | |
60 def fn(): | |
61 wa.annotations.deleteFeatures([feature['uniquename']]) | |
62 print('Deleted %s [type=%s]' % (feature['uniquename'], feature['type']['name'])) | |
63 | |
64 if not retry(fn, limit=3): | |
65 print('Error %s' % feature['uniquename']) |