Mercurial > repos > iuc > data_manager_bwameth_index_builder
annotate data_manager/bwameth_index_builder.py @ 3:e7ca32457e36 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 471c497769f0dbfa92ec1a91f4044062cb5f7a83
author | iuc |
---|---|
date | Thu, 21 Sep 2017 13:05:25 -0400 |
parents | a7fb84abef45 |
children | 5ab25caa7b7d |
rev | line source |
---|---|
0
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
2 # Based heavily on the HISAT2 data manager wrapper |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
3 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
4 import argparse |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
5 import os |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
6 import subprocess |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
7 import sys |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
8 from json import dumps, loads |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
9 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
10 DEFAULT_DATA_TABLE_NAME = "bwameth_indexes" |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
11 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
12 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
13 def build_bwameth_index(data_manager_dict, params, args): |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
14 data_table_name = args.data_table_name |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
15 target_directory = params[ 'output_data' ][0]['extra_files_path'] |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
16 if not os.path.exists( target_directory ): |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
17 os.mkdir( target_directory ) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
18 fasta_base_name = os.path.basename(args.fasta_filename) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
19 sym_linked_fasta_filename = os.path.join(target_directory, fasta_base_name) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
20 os.symlink(os.path.abspath(args.fasta_filename), sym_linked_fasta_filename) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
21 cmd = ['bwameth.py', 'index', sym_linked_fasta_filename] |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
22 proc = subprocess.Popen(args=cmd, shell=False, cwd=target_directory) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
23 return_code = proc.wait() |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
24 if return_code: |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
25 print >> sys.stderr, "Error building index." |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
26 sys.exit( return_code ) |
3
e7ca32457e36
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 471c497769f0dbfa92ec1a91f4044062cb5f7a83
iuc
parents:
0
diff
changeset
|
27 data_table_entry = dict(value=args.dbkey, dbkey=args.dbkey, name=args.name, path=sym_linked_fasta_filename) |
0
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
28 _add_data_table_entry(data_manager_dict, data_table_name, data_table_entry) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
29 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
30 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
31 def _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry ): |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
32 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} ) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
33 data_manager_dict['data_tables'][ data_table_name ] = data_manager_dict['data_tables'].get( data_table_name, [] ) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
34 data_manager_dict['data_tables'][ data_table_name ].append( data_table_entry ) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
35 return data_manager_dict |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
36 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
37 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
38 def main(): |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
39 # Parse Command Line |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
40 parser = argparse.ArgumentParser() |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
41 parser.add_argument( '--output', default=None ) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
42 parser.add_argument( '--fasta_filename', default=None ) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
43 parser.add_argument( '--dbkey', default=None ) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
44 parser.add_argument( '--name', default=None ) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
45 parser.add_argument( '--description', default=None ) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
46 parser.add_argument( '--data_table_name', default=DEFAULT_DATA_TABLE_NAME ) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
47 args = parser.parse_args() |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
48 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
49 filename = args.output |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
50 params = loads(open(filename).read()) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
51 data_manager_dict = {} |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
52 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
53 if args.dbkey in [ None, '', '?' ]: |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
54 raise Exception('"%s" is not a valid dbkey. You must specify a valid dbkey.' % (args.dbkey)) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
55 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
56 # build the index |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
57 build_bwameth_index(data_manager_dict, params, args) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
58 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
59 # save info to json file |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
60 open(filename, 'wb').write(dumps(data_manager_dict)) |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
61 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
62 |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
63 if __name__ == "__main__": |
a7fb84abef45
planemo upload for repository https://github.com/galaxyproject/tools-iuc/data_managers/data_manager_bwameth_index_builder commit 30192223eeb60f33a42046921351c6ba3c80c90c
iuc
parents:
diff
changeset
|
64 main() |