comparison data_manager/kma_build_index.py @ 0:889cc43b72d6 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_kma_index/ commit cf775591e6aa55798abe20c77572761076cc535f"
author iuc
date Tue, 18 Feb 2020 16:24:23 -0500
parents
children 8c2e674a93bb
comparison
equal deleted inserted replaced
-1:000000000000 0:889cc43b72d6
1 #!/usr/bin/env python
2
3 from __future__ import print_function
4
5 import argparse
6 import errno
7 import json
8 import os
9 import subprocess
10 import uuid
11
12
13 DATA_TABLE_NAME = "kma_index"
14
15
16 def kma_build_index(kma_index_args, index_name, target_directory, data_table_name=DATA_TABLE_NAME):
17 UUID = str(uuid.uuid4())
18
19 os.mkdir(os.path.join(target_directory, UUID))
20
21 args = [
22 '-k', str(kma_index_args["k"]),
23 '-k_t', str(kma_index_args["k_t"]),
24 '-k_i', str(kma_index_args["k_i"]),
25 '-ML', str(kma_index_args["ML"]),
26 '-ht', str(kma_index_args["ht"]),
27 '-hq', str(kma_index_args["hq"]),
28 '-o', os.path.join(UUID, "index"),
29 '-i', " ".join(kma_index_args["fasta"]),
30 ]
31
32 subprocess.check_call(' '.join(['kma index'] + args), cwd=target_directory, shell=True)
33
34 data_table_entry = {
35 'data_tables': {
36 data_table_name: [
37 {
38 "value": UUID,
39 "name": index_name,
40 "path": os.path.join(UUID, "index"),
41 }
42 ]
43 }
44 }
45
46 return data_table_entry
47
48
49 def main(args):
50
51 data_manager_input = json.loads(open(args.data_manager_json).read())
52
53 target_directory = data_manager_input['output_data'][0]['extra_files_path']
54
55 try:
56 os.mkdir( target_directory )
57 except OSError as exc:
58 if exc.errno == errno.EEXIST and os.path.isdir( target_directory ):
59 pass
60 else:
61 raise
62
63 data_manager_output = {}
64
65 kma_index_args = {
66 "k": args.k,
67 "k_t": args.k_t,
68 "k_i": args.k_i,
69 "ML": args.ML,
70 "ht": args.ht,
71 "hq": args.hq,
72 "fasta": args.fasta,
73 }
74
75 data_manager_output = kma_build_index(
76 kma_index_args,
77 args.index_name,
78 target_directory,
79 )
80
81 open(args.data_manager_json, 'w').write(json.dumps(data_manager_output))
82
83
84 if __name__ == "__main__":
85 parser = argparse.ArgumentParser()
86 parser.add_argument('data_manager_json')
87 parser.add_argument('--k', dest='k', type=int, default=16, help='')
88 parser.add_argument('--k_t', dest='k_t', type=int, default=16, help='')
89 parser.add_argument('--k_i', dest='k_i', type=int, default=16, help='')
90 parser.add_argument('--ML', dest='ML', type=int, default=16, help='')
91 parser.add_argument('--ht', dest='ht', type=float, default=1.0, help='')
92 parser.add_argument('--hq', dest='hq', type=float, default=1.0, help='')
93 parser.add_argument('--name', dest='index_name', help='')
94 parser.add_argument('fasta', nargs='+', help='fasta file(s) to index')
95 args = parser.parse_args()
96 main(args)