annotate build_ctb_gene.py @ 12:7d49ea27d9f6 draft

planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9ba2424793e47546990c750ac5f1129bd1e3a77c
author sanbi-uwc
date Tue, 17 May 2016 04:39:41 -0400
parents 517691812452
children 3ef417806df9
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
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
9 from subprocess import check_call, CalledProcessError
4
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
10
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
11 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
12
d89a58d00a92 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 74c1cc58782b9960175753e731dfdd120f234b4c
sanbi-uwc
parents: 6
diff changeset
13 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
14
7
d89a58d00a92 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 74c1cc58782b9960175753e731dfdd120f234b4c
sanbi-uwc
parents: 6
diff changeset
15
10
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
16 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
17
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
18 def __init__(self, args=None):
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
19 '''
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
20 Initializes an object to run CtbRunner in Galaxy.
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
21 '''
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
22
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
23 # Check whether the options are specified and saves them into the object
11
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
24 #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
25 self.args = args
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
26
12
7d49ea27d9f6 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9ba2424793e47546990c750ac5f1129bd1e3a77c
sanbi-uwc
parents: 11
diff changeset
27 def build_ctb_gene(self):
11
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
28 #cmdline_str = "build_ctb_gene goterms ${}".format(input_file)
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
29 #cmdline_str = "build_ctb_gene goterms --help"
12
7d49ea27d9f6 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9ba2424793e47546990c750ac5f1129bd1e3a77c
sanbi-uwc
parents: 11
diff changeset
30 cmdline_str = "touch /tmp/foo.bar >> %s" %self.args.outputdir
10
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
31 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
32 try:
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
33 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
34 except CalledProcessError:
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
35 print("Error running the build_ctb_gene gotermS", file=sys.stderr)
4
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
36
11
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
37 self.copy_output_file_to_dataset()
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
38 self.args.output_file1 = self.args.outputdir
10
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
39
11
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
40 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
41 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
42 lex.quotes = '"'
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
43 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
44 lex.commenters = ''
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
45 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
46
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
47 def copy_output_file_to_dataset(self):
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
48 '''
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
49 Retrieves the output files from the output directory and copies them to the Galaxy output files
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
50 '''
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
51
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
52 # retrieve neo4j files to the working gx directory
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
53 result_file = glob.glob(self.args.mount_point + '/*')
11
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
54 for file_name in result_file:
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
55 shutil.copy(file_name, self.args.outputdir)
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
56
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
57 #with open(result_file[0], 'rb') as fsrc:
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
58 #with open(self.args.outputdir, 'wb') as fdest:
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
59 #shutil.copy(fsrc, self.args.outputdir)
4
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
60
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
61
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
62 def main():
10
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
63 parser = argparse.ArgumentParser(description="Tool used to extract data about genes using locus_tags")
4
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
64 parser.add_argument('output_file1')
8
56555326a056 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 333add5fa185ac676c1a09b9b62e4d6c07b3bafa
sanbi-uwc
parents: 7
diff changeset
65 parser.add_argument('--outputdir')
4
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
66 parser.add_argument('--input_file')
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
67 parser.add_argument('--mount_point')
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
68 parser.add_argument('--username')
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
69 parser.add_argument('--password')
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
70 parser.add_argument('--url')
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
71 parser.add_argument('--port')
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
72 args = parser.parse_args()
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
73
5
6098213127d7 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 225901c2aced445746de69c7e8733cfa59681869
sanbi-uwc
parents: 4
diff changeset
74 export_cmd = "export NEO4J_REST_URL=http://${args.username}:${args.password}@${args.url}:${args.port}/db/data/"
4
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
75 try:
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
76 os.system(export_cmd)
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
77 except:
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
78 log.debug("Error exporting the NEO4J db environmental values")
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
79
10
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
80 # make the output directory
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
81 if not os.path.exists(args.outputdir):
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
82 os.makedirs(args.outputdir)
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
83
cb322069c7bc planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit f3af88f047a6081a46925bdbb50161ad1244b4f1
sanbi-uwc
parents: 9
diff changeset
84 ctb_gene_runner = BuildCtbRunner(args)
12
7d49ea27d9f6 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 9ba2424793e47546990c750ac5f1129bd1e3a77c
sanbi-uwc
parents: 11
diff changeset
85 ctb_gene_runner.build_ctb_gene()
7
d89a58d00a92 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 74c1cc58782b9960175753e731dfdd120f234b4c
sanbi-uwc
parents: 6
diff changeset
86
4
714cbeae0b96 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 43f091b6ac53f9754906c0be9ab6ced467cb3535
sanbi-uwc
parents:
diff changeset
87 if __name__ == "__main__": main()
11
517691812452 planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc.git commit 3f5361a7226127ec8b8d6cb5591b5bb4f52bb6fe
sanbi-uwc
parents: 10
diff changeset
88