annotate build_ctb_gene.py @ 49:74ad74a4be56 draft default tip

planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 11bbdc95f9fe5a9f85c3e71c35acfd874c0ab9be
author sanbi-uwc
date Thu, 07 Jul 2016 09:34:47 -0400
parents 515fdc4654a5
children
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
46
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
12 from subprocess import check_call, check_output, CalledProcessError, Popen, STDOUT, PIPE
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))
46
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
44 self.neo4j_proc = None
10
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
45
12
7d49ea27d9f6 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9ba2424793e47546990c750ac5f1129bd1e3a77c
sanbi-uwc
parents: 11
diff changeset
46 def build_ctb_gene(self):
47
515fdc4654a5 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 98d4308400f203c124e041692846267e1b22387e
sanbi-uwc
parents: 46
diff changeset
47 cmdline_str = "goget goterms {} {}".format(self.args.input_file, self.args.human_interactions)
10
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
48 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
49 try:
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
50 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
51 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
52 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
53 return None
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
54 else:
38
65df0b64db15 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit d7d335bdd8e18529d643b7ce55a311db71f957bc
sanbi-uwc
parents: 37
diff changeset
55 # 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
56 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
57 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
58 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
59
11
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
60 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
61 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
62 lex.quotes = '"'
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
63 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
64 lex.commenters = ''
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
65 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
66
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
67 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
68 """
06813449f44f planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents: 34
diff changeset
69 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
70 """
10
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
71 # 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
72 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
73 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
74 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
75 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
76 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
77 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
78 # 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
79 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
80 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
81
27
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
82 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
83 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
84 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
85 try:
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
86 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
87 except CalledProcessError:
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
88 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
89 return None
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
90 else:
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
91 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
92
46
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
93 def get_docker_output(self):
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
94 if self.neo4j_proc is not None:
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
95 return_code = self.neo4j_proc.wait()
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
96 (output, _) = self.neo4j_proc.communicate()
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
97 return 'Return code: {rc}\n{output}'.format(rc=return_code, output=output)
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
98
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
99 def shutdown_docker(self):
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
100 if self.neo4j_proc is not None:
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
101 self.neo4j_proc.terminate()
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
102
27
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
103 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
104 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
105 try:
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
106 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
107 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
108 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
109
46
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
110 cmd_str = "docker run --rm -P -v {mount_point}:/data -e NEO4J_UID={uid} -e NEO4J_GID={gid} -e NEO4J_AUTH=none -e NEO4J_MONITOR_TRAFFIC=false --name {name} thoba/neo4j_galaxy_ie:latest".format(
41
4cc08d9558cc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 7215a100b21673bd9ad3f1c2bca454984d4a5e54
sanbi-uwc
parents: 40
diff changeset
111 mount_point=self.mount_point,
4cc08d9558cc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 7215a100b21673bd9ad3f1c2bca454984d4a5e54
sanbi-uwc
parents: 40
diff changeset
112 name=self.docker_instance_name,
4cc08d9558cc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 7215a100b21673bd9ad3f1c2bca454984d4a5e54
sanbi-uwc
parents: 40
diff changeset
113 uid=os.getuid(),
4cc08d9558cc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 7215a100b21673bd9ad3f1c2bca454984d4a5e54
sanbi-uwc
parents: 40
diff changeset
114 gid=os.getgid(),
4cc08d9558cc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 7215a100b21673bd9ad3f1c2bca454984d4a5e54
sanbi-uwc
parents: 40
diff changeset
115 )
27
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
116 cmd = self.newSplit(cmd_str)
46
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
117 self.neo4j_proc = Popen(cmd, stdout=PIPE, stderr=STDOUT)
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
118 time.sleep(30) # give the container time to wake up
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
119 if self.neo4j_proc.poll() is not None:
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
120 raise CalledProcessError("Error running docker run by build_ctb_gene:\n", self.get_docker_output)
27
3995dfb6b497 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
sanbi-uwc
parents: 26
diff changeset
121
4
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
122 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
123 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
124 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
125 parser.add_argument('--input_file')
47
515fdc4654a5 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 98d4308400f203c124e041692846267e1b22387e
sanbi-uwc
parents: 46
diff changeset
126 parser.add_argument('--human_interactions')
4
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
127 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
128
26
51a48982f643 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a8d49944fccca430c0d79782f01e8e8758161cb8
sanbi-uwc
parents: 25
diff changeset
129 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
130
51a48982f643 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a8d49944fccca430c0d79782f01e8e8758161cb8
sanbi-uwc
parents: 25
diff changeset
131 # 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
132 ctb_gene_runner.docker_run()
46
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
133
29
b8ecf55d8987 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit a97b08e4a7c05855b6409588ff50d3716071dd80
sanbi-uwc
parents: 28
diff changeset
134 # 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
135 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
136
35
06813449f44f planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit e4eb20dee5f8e8627d90c80fb68b3a61ea29cdfe
sanbi-uwc
parents: 34
diff changeset
137 # 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
138 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
139 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
140 exit(1)
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 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
143 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
144 try:
32
9e33d452ad8c planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit cca5de2166bbc2fbbab368415853e085d474b6b2
sanbi-uwc
parents: 31
diff changeset
145 os.environ["NEO4J_REST_URL"] = neo4j_url
46
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
146 except (OSError, ValueError) as e:
32
9e33d452ad8c planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit cca5de2166bbc2fbbab368415853e085d474b6b2
sanbi-uwc
parents: 31
diff changeset
147 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
148
10
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
149 # 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
150 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
151 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
152
37
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
153 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
154 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
155 (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
156 else:
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
157 (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
158 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
159 connected = False
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
160 #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
161 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
162 try:
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
163 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
164 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
165 timeout -= 1
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
166 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
167 else:
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
168 connected = True
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
169 break
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
170 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
171 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
172
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
173 status = ctb_gene_runner.build_ctb_gene()
46
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
174 ctb_gene_runner.shutdown_docker()
c41519f46131 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit ffaef23431949a00c0944029af7365e8e57cb609
sanbi-uwc
parents: 44
diff changeset
175
37
8f16164019bd planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3cb86dfb85e313a464efbce8529442c8fc4630a5
sanbi-uwc
parents: 36
diff changeset
176 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
177 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
178
11
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
179
14
4caf3e2d10e8 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 63871d62b7acd851ff2d50dc08520c17bdf834f6
sanbi-uwc
parents: 13
diff changeset
180 if __name__ == "__main__": main()