Mercurial > repos > eric-rasche > apollo
annotate delete_features.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 |
| 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 __future__ import print_function |
|
5
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
3 import argparse |
|
7
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
4 import random |
|
5
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
5 from webapollo import WebApolloInstance |
|
7
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
6 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
|
7 import logging |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
8 logging.basicConfig(level=logging.INFO) |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
9 log = logging.getLogger(__name__) |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
10 |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
11 |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
12 if __name__ == '__main__': |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
13 parser = argparse.ArgumentParser(description='Sample script to delete all features from an organism') |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
14 WAAuth(parser) |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
15 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
|
16 parser.add_argument('--type', help='Feature type filter') |
|
5
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
17 OrgOrGuess(parser) |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
18 |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
19 args = parser.parse_args() |
|
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 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
|
22 # User must have an account |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
23 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
|
24 |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
25 # Get organism |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
26 org_cn = GuessOrg(args, wa) |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
27 if isinstance(org_cn, list): |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
28 org_cn = org_cn[0] |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
29 |
|
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
30 # 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
|
31 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
|
32 |
|
7
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
33 sequences = wa.organisms.getSequencesForOrganism(org['id']) |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
34 for sequence in sequences['sequences']: |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
35 log.info("Processing %s %s", org['commonName'], sequence['name']) |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
36 # Call setSequence to tell apollo which organism we're working with |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
37 wa.annotations.setSequence(sequence['name'], org['id']) |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
38 # Then get a list of features. |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
39 features = wa.annotations.getFeatures() |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
40 # For each feature in the features |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
41 for feature in sorted(features['features'], key=lambda x: random.random()): |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
42 if args.type: |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
43 if args.type == 'tRNA': |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
44 if feature['type']['name'] != 'tRNA': |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
45 continue |
|
5
7610987e0c48
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 29795b77c0d5c7894219b018a92c5ee7818096c3
eric-rasche
parents:
diff
changeset
|
46 |
|
7
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
47 elif args.type == 'terminator': |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
48 if feature['type']['name'] != 'terminator': |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
49 continue |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
50 |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
51 elif args.type == 'mRNA': |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
52 if feature['type']['name'] != 'mRNA': |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
53 continue |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
54 |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
55 else: |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
56 raise Exception("Unknown type") |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
57 |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
58 # We see that deleteFeatures wants a uniqueName, and so we pass |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
59 # is the uniquename field in the feature. |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
60 def fn(): |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
61 wa.annotations.deleteFeatures([feature['uniquename']]) |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
62 print('Deleted %s [type=%s]' % (feature['uniquename'], feature['type']['name'])) |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
63 |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
64 if not retry(fn, limit=3): |
|
f9a6e151b3b4
planemo upload for repository https://github.com/TAMU-CPT/galaxy-webapollo commit 52b9e5bf6a6efb09a5cb845ee48703651c644174
eric-rasche
parents:
5
diff
changeset
|
65 print('Error %s' % feature['uniquename']) |
