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