annotate delete_organism.py @ 17:8dc690130172 draft default tip

planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 12282c16658b37858f49944796fd95515ef0fc0b
author gga
date Wed, 11 Jan 2023 11:48:41 +0000
parents bc2b80fc7e30
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
1 #!/usr/bin/env python
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
2 from __future__ import print_function
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
3
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
4 import argparse
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
5 import logging
10
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
6 import os
0
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
7
10
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
8 from apollo import accessible_organisms
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
9 from apollo.util import GuessOrg, OrgOrGuess
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
10
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
11 from arrow.apollo import get_apollo_instance
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
12
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
13 from webapollo import UserObj, handle_credentials
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
14
0
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
15 logging.basicConfig(level=logging.INFO)
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
16 log = logging.getLogger(__name__)
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
17
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
18
10
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
19 def IsRemote():
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
20 return 'GALAXY_SHARED_DIR' not in os.environ or len(os.environ['GALAXY_SHARED_DIR'].lower().strip()) == 0
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
21
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
22
0
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
23 if __name__ == '__main__':
10
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
24 parser = argparse.ArgumentParser(description='Script to completely delete an organism')
0
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
25 parser.add_argument('email', help='User Email')
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
26 OrgOrGuess(parser)
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
27
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
28 args = parser.parse_args()
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
29
10
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
30 wa = get_apollo_instance()
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
31
0
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
32 # User must have an account
10
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
33 gx_user = UserObj(**wa.users._assert_or_create_user(args.email))
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
34 handle_credentials(gx_user)
0
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
35
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
36 # Get organism
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
37 org_cn = GuessOrg(args, wa)
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
38 if isinstance(org_cn, list):
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
39 org_cn = org_cn[0]
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
40
10
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
41 all_orgs = wa.organisms.get_organisms()
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
42 if 'error' in all_orgs:
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
43 all_orgs = []
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
44 all_orgs = [org['commonName'] for org in all_orgs]
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
45 if org_cn not in all_orgs:
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
46 raise Exception("Could not find organism %s" % org_cn)
0
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
47
10
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
48 orgs = accessible_organisms(gx_user, [org_cn], 'WRITE')
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
49 if not orgs:
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
50 raise Exception("You do not have write permission on this organism")
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
51 org = wa.organisms.show_organism(org_cn)
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
52
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
53 wa.organisms.delete_features(org['id'])
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
54
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
55 if IsRemote():
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
56 print(wa.remote.delete_organism(org['commonName']))
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
57 else:
bc2b80fc7e30 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents: 5
diff changeset
58 print(wa.organisms.delete_organism(org['id']))