Mercurial > repos > sanbi-uwc > build_ctb_gene
annotate build_ctb_gene.py @ 15:e6d850bb9fb6 draft
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit c78b1532031ee875ff51cb2a4c73f4577bd07839
author | sanbi-uwc |
---|---|
date | Wed, 18 May 2016 08:28:36 -0400 |
parents | 4caf3e2d10e8 |
children | eb925a043a43 |
rev | line source |
---|---|
4
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
2 from __future__ import print_function |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
3 import argparse |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
4 import os |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
5 import sys |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
6 import glob |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
7 import shlex |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
8 import shutil |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
9 import datetime |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
10 from subprocess import check_call, CalledProcessError |
4
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
11 |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
12 import logging |
7
d89a58d00a92
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 74c1cc58782b9960175753e731dfdd120f234b4c
sanbi-uwc
parents:
6
diff
changeset
|
13 |
d89a58d00a92
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 74c1cc58782b9960175753e731dfdd120f234b4c
sanbi-uwc
parents:
6
diff
changeset
|
14 log = logging.getLogger(__name__) |
4
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
15 |
7
d89a58d00a92
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 74c1cc58782b9960175753e731dfdd120f234b4c
sanbi-uwc
parents:
6
diff
changeset
|
16 |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
17 class BuildCtbRunner(object): |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
18 def __init__(self, args=None): |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
19 ''' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
20 Initializes an object to run CtbRunner in Galaxy. |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
21 ''' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
22 # Check whether the options are specified and saves them into the object |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
23 # assert args != None |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
24 self.args = args |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
25 |
12
7d49ea27d9f6
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9ba2424793e47546990c750ac5f1129bd1e3a77c
sanbi-uwc
parents:
11
diff
changeset
|
26 def build_ctb_gene(self): |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
27 # cmdline_str = "build_ctb_gene goterms ${}".format(input_file) |
13
3ef417806df9
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3dd4b95732efe95365fc09bfcdfb917c25b2796e
sanbi-uwc
parents:
12
diff
changeset
|
28 cmdline_str = "touch /tmp/foo.bar" |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
29 cmdline_str = self.newSplit(cmdline_str) |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
30 build_ctb_run = True |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
31 try: |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
32 check_call(cmdline_str) |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
33 build_ctb_run = False |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
34 except CalledProcessError: |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
35 print("Error running the build_ctb_gene goterms", file=sys.stderr) |
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
36 if build_ctb_run: |
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
37 self.copy_output_file_to_dataset() |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
38 |
11
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
39 def newSplit(self, value): |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
40 lex = shlex.shlex(value) |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
41 lex.quotes = '"' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
42 lex.whitespace_split = True |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
43 lex.commenters = '' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
44 return list(lex) |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
45 |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
46 def copy_output_file_to_dataset(self): |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
47 ''' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
48 Retrieves the output files from the output directory and copies them to the Galaxy output files |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
49 ''' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
50 # retrieve neo4j files to the working gx directory |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
51 result_file = glob.glob(self.args.mount_point + '/*') |
11
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
52 for file_name in result_file: |
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
53 shutil.copy(file_name, self.args.outputdir) |
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
54 |
4
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
55 |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
56 def main(): |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
57 parser = argparse.ArgumentParser(description="Tool used to extract data about genes using locus_tags") |
15
e6d850bb9fb6
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit c78b1532031ee875ff51cb2a4c73f4577bd07839
sanbi-uwc
parents:
14
diff
changeset
|
58 parser.add_argument('--outputfile') |
8
56555326a056
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 333add5fa185ac676c1a09b9b62e4d6c07b3bafa
sanbi-uwc
parents:
7
diff
changeset
|
59 parser.add_argument('--outputdir') |
4
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
60 parser.add_argument('--input_file') |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
61 parser.add_argument('--mount_point') |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
62 parser.add_argument('--username') |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
63 parser.add_argument('--password') |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
64 parser.add_argument('--url') |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
65 parser.add_argument('--port') |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
66 args = parser.parse_args() |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
67 |
5
6098213127d7
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 225901c2aced445746de69c7e8733cfa59681869
sanbi-uwc
parents:
4
diff
changeset
|
68 export_cmd = "export NEO4J_REST_URL=http://${args.username}:${args.password}@${args.url}:${args.port}/db/data/" |
4
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
69 try: |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
70 os.system(export_cmd) |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
71 except (OSError, ValueError), e: |
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
72 print("Error exporting the NEO4J db environmental values", e) |
4
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
73 |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
74 # make the output directory |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
75 if not os.path.exists(args.outputdir): |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
76 os.makedirs(args.outputdir) |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
77 |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
78 ctb_gene_runner = BuildCtbRunner(args) |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
79 if ctb_gene_runner.build_ctb_gene(): |
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
80 print("Building a new DB, current time: %s" % str(datetime.date.today())) |
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
81 print("Noe4j Database Name: http://%s:%s@%s:%s/db/data/" % (args.username, args.password, args.url, args.port)) |
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
82 print("GFF File - Input: %s" % str(args.input_file)) |
7
d89a58d00a92
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 74c1cc58782b9960175753e731dfdd120f234b4c
sanbi-uwc
parents:
6
diff
changeset
|
83 |
11
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
84 |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
85 if __name__ == "__main__": main() |