# HG changeset patch
# User sanbi-uwc
# Date 1463945689 14400
# Node ID 3995dfb6b4974d6274ed600580735960b319b495
# Parent 51a48982f643f2c161acf623aa69f4b9ecc79675
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 03cbaf9b605624fc4f6fbad4ccfbbe984d54e990
diff -r 51a48982f643 -r 3995dfb6b497 build_ctb_gene.py
--- a/build_ctb_gene.py Fri May 20 06:25:15 2016 -0400
+++ b/build_ctb_gene.py Sun May 22 15:34:49 2016 -0400
@@ -7,7 +7,9 @@
import shlex
import shutil
import datetime
-from subprocess import check_call, CalledProcessError
+import time
+import random
+from subprocess import check_call, check_output, CalledProcessError
import logging
@@ -22,10 +24,11 @@
# Check whether the options are specified and saves them into the object
# assert args != None
self.args = args
+ self.mount_point = None
def build_ctb_gene(self):
- cmdline_str = "build_ctb_gene goterms ${}".format(input_file)
- #cmdline_str = "touch /tmp/foo.bar"
+ # cmdline_str = "build_ctb_gene goterms {}".format(self.args.input_file)
+ cmdline_str = "touch /tmp/foo.bar"
cmdline_str = self.newSplit(cmdline_str)
build_ctb_run = False
try:
@@ -36,8 +39,8 @@
if build_ctb_run:
self.copy_output_file_to_dataset()
print("Building a new DB, current time: %s" % str(datetime.date.today()))
- print("Noe4j Database Name: http://%s:%s@%s:%s/db/data/" % (
- self.args.username, self.args.password, self.args.url, self.args.port))
+ # print("Noe4j Database Name: http://%s:%s@%s:%s/db/data/" % (
+ # self.args.username, self.args.password, self.args.url, self.args.port))
print("GFF File - Input: %s" % str(self.args.input_file))
def newSplit(self, value):
@@ -52,7 +55,8 @@
Retrieves the output files from the output directory and copies them to the Galaxy output files
'''
# retrieve neo4j files to the working gx directory
- result_file = glob.glob(self.args.mount_point + '/*')
+ mp = self.mount_point + "/graph.db"
+ result_file = glob.glob(mp + '/*')
for file_name in result_file:
if os.path.isfile(file_name):
shutil.copy2(file_name, self.args.outputdir)
@@ -61,31 +65,60 @@
os.chdir(self.args.outputdir)
shutil.copytree(file_name, file_name.rsplit('/', 1)[-1])
- def docker_boot(self):
- cmd = 'docker run -d --name build_ctb_gene thoba/neo4j_galaxy_ie'
+ def docker_stop(self):
+ stop_cmd = 'docker stop build_ctb_gene'
+ stop_cmd_str = self.newSplit(stop_cmd)
+ try:
+ check_call(stop_cmd_str)
+ except CalledProcessError:
+ print("Error running docker stop build_ctb_gene", file=sys.stderr)
+
+ def docker_rm(self):
+ cmd_str = 'docker rm build_ctb_gene'
+ cmd = self.newSplit(cmd_str)
check_call(cmd)
+ def docker_run(self):
+ self.mount_point = "{}/neo4j/data".format(os.getcwd())
+ cmd_str = "docker run -d -p 7474:7474 -v {}:/data -e NEO4J_AUTH=none --name build_ctb_gene neo4j:2.3".format(
+ self.mount_point)
+ cmd = self.newSplit(cmd_str)
+ check_call(cmd)
+
+ def docker_container_check(self):
+ cmd_str = 'docker ps -a -f name=build_ctb_gene | grep build_ctb_gene'
+ output = False
+ try:
+ output = check_output(cmd_str, shell=True)
+ except CalledProcessError:
+ print("Error running docker container check", file=sys.stderr)
+ if output:
+ return True
+ return False
+
+
def main():
parser = argparse.ArgumentParser(description="Tool used to extract data about genes using locus_tags")
- parser.add_argument('--outputfile')
+ # parser.add_argument('--outputfile')
parser.add_argument('--outputdir')
parser.add_argument('--input_file')
- parser.add_argument('--mount_point')
- parser.add_argument('--username')
- parser.add_argument('--password')
- parser.add_argument('--url')
- parser.add_argument('--port')
+ # parser.add_argument('--mount_point')
+ # parser.add_argument('--username')
+ # parser.add_argument('--password')
+ # parser.add_argument('--url')
+ # parser.add_argument('--port')
args = parser.parse_args()
ctb_gene_runner = BuildCtbRunner(args)
- ctb_gene_runner.build_ctb_gene()
# boot up a neo4j docker container
- ctb_gene_runner.docker_boot()
+ if ctb_gene_runner.docker_container_check():
+ ctb_gene_runner.docker_stop()
+ ctb_gene_runner.docker_rm()
+ ctb_gene_runner.docker_run()
- # docker_cmd = 'docker run '
-
- export_cmd = "export NEO4J_REST_URL=http://${args.username}:${args.password}@${args.url}:${args.port}/db/data/"
+ # TODO: randomise the ports/names/mount_point and use the autokill image
+ export_cmd = "export NEO4J_REST_URL=http://localhost:7474/db/data/"
try:
os.system(export_cmd)
except (OSError, ValueError), e:
@@ -94,7 +127,8 @@
# make the output directory
if not os.path.exists(args.outputdir):
os.makedirs(args.outputdir)
-
+ time.sleep(60)
+ ctb_gene_runner.build_ctb_gene()
if __name__ == "__main__": main()
diff -r 51a48982f643 -r 3995dfb6b497 build_ctb_gene.xml
--- a/build_ctb_gene.xml Fri May 20 06:25:15 2016 -0400
+++ b/build_ctb_gene.xml Sun May 22 15:34:49 2016 -0400
@@ -9,7 +9,7 @@
- build_ctb_gene.py --outputdir "${os.path.join($outputFile1.files_path,'neo4jdb')}" --input_file ${input_file} --mount_point ${neo4j_data_mount_point} --username ${db_settings.neo4j_db_username} --password ${db_settings.neo4j_db_password} --url ${db_settings.neo4j_db_url} --port ${db_settings.neo4j_db_port} > ${outputFile1}
+ build_ctb_gene.py --outputdir "${os.path.join($outputFile1.files_path,'neo4jdb')}" --input_file "${input_file}" > ${outputFile1}