annotate create_features_from_gff3.py @ 13:06254eb0cb13 draft

"planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 7bf18c69becc57152efdadedf7ebd0bcfa382a15"
author gga
date Mon, 29 Jun 2020 09:16:00 -0400
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 import argparse
13
06254eb0cb13 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 7bf18c69becc57152efdadedf7ebd0bcfa382a15"
gga
parents: 10
diff changeset
3 import json
0
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 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
5
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 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
7 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
8
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
9 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
10
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 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
12 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
13 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
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
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
16 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
17 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
18 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
19 parser.add_argument('--source', help='URL where the input dataset can be found.')
13
06254eb0cb13 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 7bf18c69becc57152efdadedf7ebd0bcfa382a15"
gga
parents: 10
diff changeset
20 parser.add_argument('--use_name', action='store_true', help='Use the given name instead of generating one.')
06254eb0cb13 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 7bf18c69becc57152efdadedf7ebd0bcfa382a15"
gga
parents: 10
diff changeset
21 parser.add_argument('--disable_cds_recalculation', action='store_true', help='Disable CDS recalculation and instead use the one provided.')
0
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
22 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
23
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
24 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
25 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
26
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
27 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
28 # 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
29 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
30 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
31
1f2e360f7554 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit f745b23c84a615bf434d717c8c0e553a012f0268
gga
parents:
diff changeset
32 # 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
33 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
34 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
35 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
36
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
37 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
38 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
39 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
40 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
41 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
42 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
43
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
44 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
45 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
46 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
47
13
06254eb0cb13 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 7bf18c69becc57152efdadedf7ebd0bcfa382a15"
gga
parents: 10
diff changeset
48 load_result = wa.annotations.load_gff3(org_cn, args.gff3, args.source, use_name=args.use_name, disable_cds_recalculation=args.disable_cds_recalculation)
06254eb0cb13 "planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 7bf18c69becc57152efdadedf7ebd0bcfa382a15"
gga
parents: 10
diff changeset
49 print(json.dumps(load_result, indent=2))