comparison delete_organism.py @ 10:c3b5bc8b4080 draft

"planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
author gga
date Mon, 02 Dec 2019 05:43:20 -0500
parents 950fb2bf116d
children
comparison
equal deleted inserted replaced
9:f45ad96c9e08 10:c3b5bc8b4080
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 from __future__ import print_function 2 from __future__ import print_function
3 3
4 import argparse 4 import argparse
5 import logging 5 import logging
6 import os
6 7
7 from webapollo import GuessOrg, OrgOrGuess, PermissionCheck, WAAuth, WebApolloInstance 8 from apollo import accessible_organisms
9 from apollo.util import GuessOrg, OrgOrGuess
10
11 from arrow.apollo import get_apollo_instance
12
13 from webapollo import UserObj, handle_credentials
14
8 logging.basicConfig(level=logging.INFO) 15 logging.basicConfig(level=logging.INFO)
9 log = logging.getLogger(__name__) 16 log = logging.getLogger(__name__)
10 17
11 18
19 def IsRemote():
20 return 'GALAXY_SHARED_DIR' not in os.environ or len(os.environ['GALAXY_SHARED_DIR'].lower().strip()) == 0
21
22
12 if __name__ == '__main__': 23 if __name__ == '__main__':
13 parser = argparse.ArgumentParser(description='Sample script to completely delete an organism') 24 parser = argparse.ArgumentParser(description='Script to completely delete an organism')
14 WAAuth(parser)
15 parser.add_argument('email', help='User Email') 25 parser.add_argument('email', help='User Email')
16 OrgOrGuess(parser) 26 OrgOrGuess(parser)
17 27
18 args = parser.parse_args() 28 args = parser.parse_args()
19 29
20 wa = WebApolloInstance(args.apollo, args.username, args.password) 30 wa = get_apollo_instance()
31
21 # User must have an account 32 # User must have an account
22 gx_user = wa.users.assertOrCreateUser(args.email) 33 gx_user = UserObj(**wa.users._assert_or_create_user(args.email))
34 handle_credentials(gx_user)
23 35
24 # Get organism 36 # Get organism
25 org_cn = GuessOrg(args, wa) 37 org_cn = GuessOrg(args, wa)
26 if isinstance(org_cn, list): 38 if isinstance(org_cn, list):
27 org_cn = org_cn[0] 39 org_cn = org_cn[0]
28 40
29 if not PermissionCheck(gx_user, org_cn, "WRITE"): 41 all_orgs = wa.organisms.get_organisms()
42 if 'error' in all_orgs:
43 all_orgs = []
44 all_orgs = [org['commonName'] for org in all_orgs]
45 if org_cn not in all_orgs:
46 raise Exception("Could not find organism %s" % org_cn)
47
48 orgs = accessible_organisms(gx_user, [org_cn], 'WRITE')
49 if not orgs:
30 raise Exception("You do not have write permission on this organism") 50 raise Exception("You do not have write permission on this organism")
31 org = wa.organisms.findOrganismByCn(org_cn) 51 org = wa.organisms.show_organism(org_cn)
32 52
33 # Call setSequence to tell apollo which organism we're working with 53 wa.organisms.delete_features(org['id'])
34 wa.annotations.setSequence(org['commonName'], org['id']) 54
35 # Then get a list of features. 55 if IsRemote():
36 features = wa.annotations.getFeatures() 56 print(wa.remote.delete_organism(org['commonName']))
37 # For each feature in the features 57 else:
38 # If it exists 58 print(wa.organisms.delete_organism(org['id']))
39 if 'features' in features:
40 for feature in features['features']:
41 # We see that deleteFeatures wants a uniqueName, and so we pass
42 # is the uniquename field in the feature.
43 print(wa.annotations.deleteFeatures([feature['uniquename']]))