Mercurial > repos > gga > apollo_list_organism
annotate create_features_from_gff3.py @ 10:bc2b80fc7e30 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:49:03 -0500 |
parents | a3000d01c04c |
children | 06254eb0cb13 |
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 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
|
3 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
|
4 |
bc2b80fc7e30
"planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
gga
parents:
5
diff
changeset
|
5 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
|
6 from apollo.util import GuessOrg, OrgOrGuess |
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 arrow.apollo import get_apollo_instance |
0
1f2e360f7554
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff
changeset
|
9 |
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
|
10 from webapollo import UserObj, handle_credentials |
0
1f2e360f7554
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff
changeset
|
11 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
|
12 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
|
13 |
1f2e360f7554
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff
changeset
|
14 |
1f2e360f7554
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff
changeset
|
15 if __name__ == '__main__': |
1f2e360f7554
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff
changeset
|
16 parser = argparse.ArgumentParser(description='Sample script to add an attribute to a feature via web services') |
1f2e360f7554
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff
changeset
|
17 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
|
18 parser.add_argument('--source', help='URL where the input dataset can be found.') |
1f2e360f7554
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff
changeset
|
19 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
|
20 |
1f2e360f7554
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff
changeset
|
21 parser.add_argument('gff3', type=argparse.FileType('r'), help='GFF3 file') |
1f2e360f7554
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff
changeset
|
22 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
|
23 |
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 wa = get_apollo_instance() |
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 # 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
|
26 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
|
27 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
|
28 |
1f2e360f7554
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff
changeset
|
29 # 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
|
30 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
|
31 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
|
32 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
|
33 |
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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
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 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
|
42 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
|
43 raise Exception("You do not have write permission on this 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
|
44 |
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
|
45 wa.annotations.load_gff3(org_cn, args.gff3, args.source) |