Mercurial > repos > sanbi-uwc > build_ctb_gene
annotate build_ctb_gene.py @ 37:8f16164019bd draft
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
author | sanbi-uwc |
---|---|
date | Tue, 31 May 2016 03:04:08 -0400 |
parents | 25caec56f66b |
children | 65df0b64db15 |
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 |
27
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
10 import time |
29
b8ecf55d8987
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents:
28
diff
changeset
|
11 import random |
27
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
12 from subprocess import check_call, check_output, CalledProcessError |
37
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
13 import socket |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
14 try: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
15 from urllib.parse import urlparse |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
16 except ImportError: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
17 from urlparse import urlparse |
4
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
18 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
|
19 |
d89a58d00a92
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 74c1cc58782b9960175753e731dfdd120f234b4c
sanbi-uwc
parents:
6
diff
changeset
|
20 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
|
21 |
7
d89a58d00a92
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 74c1cc58782b9960175753e731dfdd120f234b4c
sanbi-uwc
parents:
6
diff
changeset
|
22 |
30
60aedbda386d
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9dc41c2c903e6c9a26e70114f56680903671a669
sanbi-uwc
parents:
29
diff
changeset
|
23 def inspect_docker(cmd_str): |
60aedbda386d
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9dc41c2c903e6c9a26e70114f56680903671a669
sanbi-uwc
parents:
29
diff
changeset
|
24 output = None |
60aedbda386d
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9dc41c2c903e6c9a26e70114f56680903671a669
sanbi-uwc
parents:
29
diff
changeset
|
25 try: |
60aedbda386d
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9dc41c2c903e6c9a26e70114f56680903671a669
sanbi-uwc
parents:
29
diff
changeset
|
26 output = check_output(cmd_str, shell=True) |
60aedbda386d
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9dc41c2c903e6c9a26e70114f56680903671a669
sanbi-uwc
parents:
29
diff
changeset
|
27 except CalledProcessError: |
60aedbda386d
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9dc41c2c903e6c9a26e70114f56680903671a669
sanbi-uwc
parents:
29
diff
changeset
|
28 print("Error running get_docker_port by build_ctb_gene", file=sys.stderr) |
37
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
29 return None |
30
60aedbda386d
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9dc41c2c903e6c9a26e70114f56680903671a669
sanbi-uwc
parents:
29
diff
changeset
|
30 return output |
60aedbda386d
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9dc41c2c903e6c9a26e70114f56680903671a669
sanbi-uwc
parents:
29
diff
changeset
|
31 |
60aedbda386d
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9dc41c2c903e6c9a26e70114f56680903671a669
sanbi-uwc
parents:
29
diff
changeset
|
32 |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
33 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
|
34 def __init__(self, args=None): |
35
06813449f44f
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents:
34
diff
changeset
|
35 """ |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
36 Initializes an object to run CtbRunner in Galaxy. |
35
06813449f44f
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents:
34
diff
changeset
|
37 """ |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
38 # 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
|
39 # 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
|
40 self.args = args |
27
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
41 self.mount_point = None |
29
b8ecf55d8987
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents:
28
diff
changeset
|
42 self.docker_instance_name = "build_ctb_gene_" + str(random.randrange(0, 1000, 2)) |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
43 |
12
7d49ea27d9f6
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9ba2424793e47546990c750ac5f1129bd1e3a77c
sanbi-uwc
parents:
11
diff
changeset
|
44 def build_ctb_gene(self): |
33
f9ad7d3cd333
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit db69b9573268732d814981b56d187fcbab235b4c
sanbi-uwc
parents:
32
diff
changeset
|
45 cmdline_str = "build_ctb_gene test {}".format(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
|
46 cmdline_str = self.newSplit(cmdline_str) |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
47 try: |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
48 check_call(cmdline_str) |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
49 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
|
50 print("Error running the build_ctb_gene goterms", file=sys.stderr) |
37
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
51 return None |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
52 else: |
35
06813449f44f
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents:
34
diff
changeset
|
53 self.copy_output_file_to_dataset() |
06813449f44f
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents:
34
diff
changeset
|
54 print("Building a new DB, current time: %s" % str(datetime.date.today())) |
06813449f44f
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents:
34
diff
changeset
|
55 print("GFF File - Input: %s" % str(self.args.input_file)) |
37
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
56 return True |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
57 |
11
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
58 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
|
59 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
|
60 lex.quotes = '"' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
61 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
|
62 lex.commenters = '' |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
63 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
|
64 |
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
65 def copy_output_file_to_dataset(self): |
35
06813449f44f
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents:
34
diff
changeset
|
66 """ |
06813449f44f
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents:
34
diff
changeset
|
67 Retrieves the output files from the gx working directory and copy them to the Galaxy output directory |
06813449f44f
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents:
34
diff
changeset
|
68 """ |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
69 # retrieve neo4j files to the working gx directory |
27
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
70 mp = self.mount_point + "/graph.db" |
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
71 result_file = glob.glob(mp + '/*') |
11
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
72 for file_name in result_file: |
23
9e9f1a97f97b
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 504dc929afd0bd35a5a5b90a2bcfb30ee007c481
sanbi-uwc
parents:
22
diff
changeset
|
73 if os.path.isfile(file_name): |
9e9f1a97f97b
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 504dc929afd0bd35a5a5b90a2bcfb30ee007c481
sanbi-uwc
parents:
22
diff
changeset
|
74 shutil.copy2(file_name, self.args.outputdir) |
9e9f1a97f97b
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 504dc929afd0bd35a5a5b90a2bcfb30ee007c481
sanbi-uwc
parents:
22
diff
changeset
|
75 elif os.path.isdir(file_name): |
24
dfc610c206af
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 54182d587632d9bf0577fbf89b3c90d3fdab863e
sanbi-uwc
parents:
23
diff
changeset
|
76 # create the parent dir before copytree |
dfc610c206af
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 54182d587632d9bf0577fbf89b3c90d3fdab863e
sanbi-uwc
parents:
23
diff
changeset
|
77 os.chdir(self.args.outputdir) |
dfc610c206af
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 54182d587632d9bf0577fbf89b3c90d3fdab863e
sanbi-uwc
parents:
23
diff
changeset
|
78 shutil.copytree(file_name, file_name.rsplit('/', 1)[-1]) |
11
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
79 |
27
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
80 def docker_stop(self): |
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
81 stop_cmd = 'docker stop build_ctb_gene' |
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
82 stop_cmd_str = self.newSplit(stop_cmd) |
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
83 try: |
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
84 check_call(stop_cmd_str) |
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
85 except CalledProcessError: |
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
86 print("Error running docker stop build_ctb_gene", file=sys.stderr) |
37
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
87 return None |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
88 else: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
89 return True |
27
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
90 |
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
91 def docker_run(self): |
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
92 self.mount_point = "{}/neo4j/data".format(os.getcwd()) |
37
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
93 try: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
94 os.makedirs(self.mount_point) |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
95 except os.error as e: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
96 print("Error creating mount point {mount_point}: {error}".format(mount_point=self.mount_point, error=e.strerror)) |
29
b8ecf55d8987
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents:
28
diff
changeset
|
97 |
36
25caec56f66b
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 76a68ce6fedc94f5541c925dfb7f8e5fe1f4e0b6
sanbi-uwc
parents:
35
diff
changeset
|
98 cmd_str = "docker run -d -P -v {}:/data -e NEO4J_AUTH=none --name {} thoba/neo4j_galaxy_ie".format( |
29
b8ecf55d8987
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents:
28
diff
changeset
|
99 self.mount_point, self.docker_instance_name) |
27
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
100 cmd = self.newSplit(cmd_str) |
29
b8ecf55d8987
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents:
28
diff
changeset
|
101 try: |
b8ecf55d8987
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents:
28
diff
changeset
|
102 check_call(cmd) |
b8ecf55d8987
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents:
28
diff
changeset
|
103 except CalledProcessError: |
b8ecf55d8987
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents:
28
diff
changeset
|
104 print("Error running docker run by build_ctb_gene", file=sys.stderr) |
27
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
105 |
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
106 |
4
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
107 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
|
108 parser = argparse.ArgumentParser(description="Tool used to extract data about genes using locus_tags") |
8
56555326a056
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 333add5fa185ac676c1a09b9b62e4d6c07b3bafa
sanbi-uwc
parents:
7
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 |
26
51a48982f643
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a8d49944fccca430c0d79782f01e8e8758161cb8
sanbi-uwc
parents:
25
diff
changeset
|
113 ctb_gene_runner = BuildCtbRunner(args) |
51a48982f643
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a8d49944fccca430c0d79782f01e8e8758161cb8
sanbi-uwc
parents:
25
diff
changeset
|
114 |
51a48982f643
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a8d49944fccca430c0d79782f01e8e8758161cb8
sanbi-uwc
parents:
25
diff
changeset
|
115 # boot up a neo4j docker container |
27
3995dfb6b497
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents:
26
diff
changeset
|
116 ctb_gene_runner.docker_run() |
26
51a48982f643
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a8d49944fccca430c0d79782f01e8e8758161cb8
sanbi-uwc
parents:
25
diff
changeset
|
117 |
29
b8ecf55d8987
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents:
28
diff
changeset
|
118 # get the port of the docker container |
31
bcf4f741b94f
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ea7a94d6a0aa64dfc8f3a11ac977c39d57bba3e3
sanbi-uwc
parents:
30
diff
changeset
|
119 cmd_str = "docker inspect --format='{{(index (index .NetworkSettings.Ports \"7474/tcp\") 0).HostPort}}' %s" % ctb_gene_runner.docker_instance_name |
29
b8ecf55d8987
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents:
28
diff
changeset
|
120 |
35
06813449f44f
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents:
34
diff
changeset
|
121 # TODO: randomise the ports/names/mount_point and use the auto kill image |
37
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
122 neo4j_container_info = inspect_docker(cmd_str) |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
123 if neo4j_container_info is None: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
124 exit(1) |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
125 else: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
126 neo4j_port = neo4j_container_info[:-1] |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
127 neo4j_url = 'http://localhost:{}/db/data/'.format(neo4j_port) |
4
714cbeae0b96
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff
changeset
|
128 try: |
32
9e33d452ad8c
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit cca5de2166bbc2fbbab368415853e085d474b6b2
sanbi-uwc
parents:
31
diff
changeset
|
129 os.environ["NEO4J_REST_URL"] = neo4j_url |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
130 except (OSError, ValueError), e: |
32
9e33d452ad8c
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit cca5de2166bbc2fbbab368415853e085d474b6b2
sanbi-uwc
parents:
31
diff
changeset
|
131 print("Error setting 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
|
132 |
10
cb322069c7bc
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents:
9
diff
changeset
|
133 # 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
|
134 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
|
135 os.makedirs(args.outputdir) |
35
06813449f44f
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents:
34
diff
changeset
|
136 |
37
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
137 url = urlparse(neo4j_url) |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
138 if '@' in url.netloc: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
139 (host, port) = url.netloc.split('@')[1].split(':') |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
140 else: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
141 (host, port) = url.netloc.split(':') |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
142 timeout = int(os.environ.get('NEO4J_WAIT_TIMEOUT', 30)) # time to wait till neo4j |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
143 connected = False |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
144 #print('host, port', host, port) |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
145 while timeout > 0: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
146 try: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
147 socket.create_connection((host, port), 1) |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
148 except socket.error: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
149 timeout -= 1 |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
150 time.sleep(1) |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
151 else: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
152 connected = True |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
153 break |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
154 if not connected: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
155 sys.exit('timed out trying to connect to {}'.format(neo4j_url)) |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
156 |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
157 status = ctb_gene_runner.build_ctb_gene() |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
158 if status is None: |
8f16164019bd
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents:
36
diff
changeset
|
159 exit(1) |
7
d89a58d00a92
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 74c1cc58782b9960175753e731dfdd120f234b4c
sanbi-uwc
parents:
6
diff
changeset
|
160 |
11
517691812452
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents:
10
diff
changeset
|
161 |
14
4caf3e2d10e8
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents:
13
diff
changeset
|
162 if __name__ == "__main__": main() |