Mercurial > repos > sanbi-uwc > build_ctb_gene
annotate build_ctb_gene.py @ 20:06bd61e33a18 draft
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit eadb75a0a60406ee628a236da3e48456d330d840
author | sanbi-uwc |
---|---|
date | Thu, 19 May 2016 08:21:43 -0400 |
parents | d60316b849a1 |
children | 04f49a2f5ec9 |
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) |
18
71a3f4a25de3
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 79f3191bfc33e7bac3f31dc4ea519f99ffb09081
sanbi-uwc
parents:
17
diff
changeset
|
30 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
|
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) |
18
71a3f4a25de3
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 79f3191bfc33e7bac3f31dc4ea519f99ffb09081
sanbi-uwc
parents:
17
diff
changeset
|
33 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
|
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() |
19
d60316b849a1
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit c995ab52e8a43df67dc18c70aa70830f7568fc8b
sanbi-uwc
parents:
18
diff
changeset
|
38 print("Building a new DB, current time: %s" % str(datetime.date.today())) |
d60316b849a1
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit c995ab52e8a43df67dc18c70aa70830f7568fc8b
sanbi-uwc
parents:
18
diff
changeset
|
39 print("Noe4j Database Name: http://%s:%s@%s:%s/db/data/" % (self.args.username, self.args.password, self.args.url, self.args.port)) |
d60316b849a1
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit c995ab52e8a43df67dc18c70aa70830f7568fc8b
sanbi-uwc
parents:
18
diff
changeset
|
40 print("GFF File - Input: %s" % str(self.args.input_file)) |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
41 |
11
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
42 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
|
43 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
|
44 lex.quotes = '"' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
45 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
|
46 lex.commenters = '' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
47 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
|
48 |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
49 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
|
50 ''' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
51 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
|
52 ''' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
53 # 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
|
54 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
|
55 for file_name in result_file: |
20
06bd61e33a18
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit eadb75a0a60406ee628a236da3e48456d330d840
sanbi-uwc
parents:
19
diff
changeset
|
56 if os.path.isfile(file_name): |
06bd61e33a18
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit eadb75a0a60406ee628a236da3e48456d330d840
sanbi-uwc
parents:
19
diff
changeset
|
57 shutil.copy(file_name, self.args.outputdir) |
06bd61e33a18
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit eadb75a0a60406ee628a236da3e48456d330d840
sanbi-uwc
parents:
19
diff
changeset
|
58 else: |
06bd61e33a18
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit eadb75a0a60406ee628a236da3e48456d330d840
sanbi-uwc
parents:
19
diff
changeset
|
59 shutil.copytree(file_name, self.args.outputdir) |
11
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
60 |
4
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
61 |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 |
5
6098213127d7
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 225901c2aced445746de69c7e8733cfa59681869
sanbi-uwc
parents:
4
diff
changeset
|
74 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
|
75 try: |
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
80 # 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
|
81 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
|
82 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
|
83 |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
84 ctb_gene_runner = BuildCtbRunner(args) |
17
eb925a043a43
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9d6198aee2fff337b21dc42e8ec261069fa57c96
sanbi-uwc
parents:
15
diff
changeset
|
85 ctb_gene_runner.build_ctb_gene() |
7
d89a58d00a92
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 74c1cc58782b9960175753e731dfdd120f234b4c
sanbi-uwc
parents:
6
diff
changeset
|
86 |
11
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
87 |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
88 if __name__ == "__main__": main() |