annotate build_ctb_gene.py @ 38:65df0b64db15 draft

planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit d7d335bdd8e18529d643b7ce55a311db71f957bc
author sanbi-uwc
date Wed, 01 Jun 2016 07:37:28 -0400
parents 8f16164019bd
children 2a9a2575c8a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
38
65df0b64db15 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit d7d335bdd8e18529d643b7ce55a311db71f957bc
sanbi-uwc
parents: 37
diff changeset
41 self.outputdir = args.outputdir
27
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
42 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
43 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
44
12
7d49ea27d9f6 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9ba2424793e47546990c750ac5f1129bd1e3a77c
sanbi-uwc
parents: 11
diff changeset
45 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
46 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
47 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
48 try:
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
49 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
50 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
51 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
52 return None
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
53 else:
38
65df0b64db15 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit d7d335bdd8e18529d643b7ce55a311db71f957bc
sanbi-uwc
parents: 37
diff changeset
54 # self.copy_output_file_to_dataset()
35
06813449f44f planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents: 34
diff changeset
55 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
56 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
57 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
58
11
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
59 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
60 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
61 lex.quotes = '"'
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
62 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
63 lex.commenters = ''
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
64 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
65
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
66 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
67 """
06813449f44f planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents: 34
diff changeset
68 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
69 """
10
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
70 # 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
71 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
72 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
73 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
74 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
75 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
76 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
77 # 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
78 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
79 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
80
27
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
81 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
82 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
83 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
84 try:
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
85 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
86 except CalledProcessError:
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
87 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
88 return None
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
89 else:
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
90 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
91
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
92 def docker_run(self):
38
65df0b64db15 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit d7d335bdd8e18529d643b7ce55a311db71f957bc
sanbi-uwc
parents: 37
diff changeset
93 self.mount_point = "{}".format(self.outputdir)
37
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
94 try:
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
95 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
96 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
97 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
98
36
25caec56f66b planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 76a68ce6fedc94f5541c925dfb7f8e5fe1f4e0b6
sanbi-uwc
parents: 35
diff changeset
99 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
100 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
101 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
102 try:
b8ecf55d8987 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents: 28
diff changeset
103 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
104 except CalledProcessError:
b8ecf55d8987 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents: 28
diff changeset
105 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
106
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
107
4
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
108 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
109 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
110 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
111 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
112 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
113
26
51a48982f643 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a8d49944fccca430c0d79782f01e8e8758161cb8
sanbi-uwc
parents: 25
diff changeset
114 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
115
51a48982f643 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a8d49944fccca430c0d79782f01e8e8758161cb8
sanbi-uwc
parents: 25
diff changeset
116 # 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
117 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
118
29
b8ecf55d8987 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents: 28
diff changeset
119 # 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
120 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
121
35
06813449f44f planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents: 34
diff changeset
122 # 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
123 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
124 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
125 exit(1)
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
126 else:
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
127 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
128 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
129 try:
32
9e33d452ad8c planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit cca5de2166bbc2fbbab368415853e085d474b6b2
sanbi-uwc
parents: 31
diff changeset
130 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
131 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
132 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
133
10
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
134 # 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
135 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
136 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
137
37
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
138 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
139 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
140 (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
141 else:
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
142 (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
143 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
144 connected = False
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
145 #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
146 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
147 try:
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
148 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
149 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
150 timeout -= 1
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
151 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
152 else:
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
153 connected = True
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
154 break
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
155 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
156 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
157
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
158 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
159 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
160 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
161
11
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
162
14
4caf3e2d10e8 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents: 13
diff changeset
163 if __name__ == "__main__": main()