Mercurial > repos > gga > apollo_delete_features
comparison create_or_update_organism.py @ 7:7d885dfe3966 draft
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit b9143221aee2cd09e1334ee56ff9651550b1797a
author | gga |
---|---|
date | Fri, 15 Mar 2019 06:05:55 -0400 |
parents | f7e9c792047b |
children | 3f0f2af50989 |
comparison
equal
deleted
inserted
replaced
6:c753a0ef794e | 7:7d885dfe3966 |
---|---|
2 from __future__ import print_function | 2 from __future__ import print_function |
3 | 3 |
4 import argparse | 4 import argparse |
5 import json | 5 import json |
6 import logging | 6 import logging |
7 import os | |
7 import shutil | 8 import shutil |
9 import subprocess | |
8 import sys | 10 import sys |
11 import tempfile | |
9 import time | 12 import time |
13 | |
10 | 14 |
11 from webapollo import GuessOrg, OrgOrGuess, PermissionCheck, WAAuth, WebApolloInstance | 15 from webapollo import GuessOrg, OrgOrGuess, PermissionCheck, WAAuth, WebApolloInstance |
12 logging.basicConfig(level=logging.INFO) | 16 logging.basicConfig(level=logging.INFO) |
13 log = logging.getLogger(__name__) | 17 log = logging.getLogger(__name__) |
14 | 18 |
19 | |
20 def IsBlatEnabled(): | |
21 if 'BLAT_ENABLED' not in os.environ: | |
22 return False | |
23 value = os.environ['BLAT_ENABLED'] | |
24 if value.lower() in ('true', 't', '1'): | |
25 return True | |
26 else: | |
27 return False | |
28 | |
29 | |
15 if __name__ == '__main__': | 30 if __name__ == '__main__': |
16 parser = argparse.ArgumentParser(description='Create or update an organism in an Apollo instance') | 31 parser = argparse.ArgumentParser(description='Create or update an organism in an Apollo instance') |
17 WAAuth(parser) | 32 WAAuth(parser) |
18 | 33 parser.add_argument('jbrowse_src', help='Old JBrowse Data Directory') |
19 parser.add_argument('jbrowse', help='JBrowse Data Directory') | 34 parser.add_argument('jbrowse', help='JBrowse Data Directory') |
20 parser.add_argument('email', help='User Email') | 35 parser.add_argument('email', help='User Email') |
21 OrgOrGuess(parser) | 36 OrgOrGuess(parser) |
22 parser.add_argument('--genus', help='Organism Genus') | 37 parser.add_argument('--genus', help='Organism Genus') |
23 parser.add_argument('--species', help='Organism Species') | 38 parser.add_argument('--species', help='Organism Species') |
24 parser.add_argument('--public', action='store_true', help='Make organism public') | 39 parser.add_argument('--public', action='store_true', help='Make organism public') |
25 parser.add_argument('--group', help='Give access to a user group') | 40 parser.add_argument('--group', help='Give access to a user group') |
26 parser.add_argument('--remove_old_directory', action='store_true', help='Remove old directory') | 41 parser.add_argument('--remove_old_directory', action='store_true', help='Remove old directory') |
42 args = parser.parse_args() | |
43 CHUNK_SIZE = 2**20 | |
44 blat_db = None | |
27 | 45 |
28 args = parser.parse_args() | 46 # Cleanup if existing |
47 if(os.path.exists(args.jbrowse)): | |
48 shutil.rmtree(args.jbrowse) | |
49 # Copy files | |
50 shutil.copytree(args.jbrowse_src, args.jbrowse) | |
51 | |
52 path_fasta = args.jbrowse + '/seq/genome.fasta' | |
53 path_2bit = args.jbrowse + '/seq/genome.2bit' | |
54 | |
55 # Convert fasta if existing | |
56 if(IsBlatEnabled() and os.path.exists(path_fasta)): | |
57 arg = ['faToTwoBit', path_fasta, path_2bit] | |
58 tmp_stderr = tempfile.NamedTemporaryFile(prefix="tmp-twobit-converter-stderr") | |
59 proc = subprocess.Popen(args=arg, shell=False, cwd=args.jbrowse, stderr=tmp_stderr.fileno()) | |
60 return_code = proc.wait() | |
61 if return_code: | |
62 tmp_stderr.flush() | |
63 tmp_stderr.seek(0) | |
64 print("Error building index:", file=sys.stderr) | |
65 while True: | |
66 chunk = tmp_stderr.read(CHUNK_SIZE) | |
67 if not chunk: | |
68 break | |
69 sys.stderr.write(chunk) | |
70 sys.exit(return_code) | |
71 blat_db = path_2bit | |
72 tmp_stderr.close() | |
73 | |
29 wa = WebApolloInstance(args.apollo, args.username, args.password) | 74 wa = WebApolloInstance(args.apollo, args.username, args.password) |
30 | 75 |
31 org_cn = GuessOrg(args, wa) | 76 org_cn = GuessOrg(args, wa) |
32 if isinstance(org_cn, list): | 77 if isinstance(org_cn, list): |
33 org_cn = org_cn[0] | 78 org_cn = org_cn[0] |
54 org_cn, | 99 org_cn, |
55 args.jbrowse, | 100 args.jbrowse, |
56 # mandatory | 101 # mandatory |
57 genus=args.genus, | 102 genus=args.genus, |
58 species=args.species, | 103 species=args.species, |
59 public=args.public | 104 public=args.public, |
105 blatdb=blat_db | |
60 ) | 106 ) |
61 time.sleep(2) | 107 time.sleep(2) |
62 if args.remove_old_directory and args.jbrowse != old_directory: | 108 if args.remove_old_directory and args.jbrowse != old_directory: |
63 shutil.rmtree(old_directory) | 109 shutil.rmtree(old_directory) |
64 | 110 |
70 data = wa.organisms.addOrganism( | 116 data = wa.organisms.addOrganism( |
71 org_cn, | 117 org_cn, |
72 args.jbrowse, | 118 args.jbrowse, |
73 genus=args.genus, | 119 genus=args.genus, |
74 species=args.species, | 120 species=args.species, |
75 public=args.public | 121 public=args.public, |
122 blatdb=blat_db | |
76 ) | 123 ) |
77 | 124 |
78 # Must sleep before we're ready to handle | 125 # Must sleep before we're ready to handle |
79 time.sleep(2) | 126 time.sleep(2) |
80 log.info("Updating permissions for %s on %s", gx_user, org_cn) | 127 log.info("Updating permissions for %s on %s", gx_user, org_cn) |