annotate data_manager/path_name_value_key_manager.py @ 1:8495c49cd056 draft default tip

planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
author rhpvorderman
date Mon, 16 Jul 2018 10:58:36 -0400
parents 5f8d9309058b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
1 #!/usr/bin/env python3
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
2 """Script to create data manager jsons"""
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
3
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
4 import argparse
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
5 import json
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
6 from pathlib import Path
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
7
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
8 import yaml
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
9 from schema import Schema, Optional
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
10
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
11
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
12 def indexes_schema():
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
13 return Schema(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
14 {'name': str,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
15 Optional('prefix'): bool,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
16 Optional('extensions'): [str],
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
17 Optional('prefix_strip_extension'): bool,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
18 Optional('extra_columns'): [str],
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
19 Optional('folder'): [str]})
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
20
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
21
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
22 def argument_parser():
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
23 parser = argparse.ArgumentParser()
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
24 parser.add_argument('--value', type=str, help='value')
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
25 parser.add_argument('--dbkey', type=str, help='dbkey')
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
26 parser.add_argument('--name', type=str, help='name')
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
27 parser.add_argument('--path', type=Path, help='path',
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
28 required=True)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
29 parser.add_argument('--data_table_name', action='store', type=str,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
30 help='Name of the data table',
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
31 required=True)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
32 parser.add_argument('--json_output_file', action='store', type=Path,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
33 help='Json output file',
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
34 required=True)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
35 parser.add_argument("--extra-columns", type=str,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
36 help='Yaml formatted string with extra columns '
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
37 'and their values. For example '
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
38 '\'{"with-gtf":"0"}\' for STAR indexes')
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
39 return parser
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
40
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
41
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
42 def check_tab(name: str, value: str):
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
43 if '\t' in value:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
44 raise ValueError(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
45 "'{0}' is not a valid '{1}'. It may not contain a tab because "
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
46 "these are used as seperators by galaxy .".format(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
47 value, name))
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
48
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
49
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
50 def prefix_plus_extension_exists(directory: Path, prefix: str, extension: str):
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
51 """checks if files exist with prefix in a directory. Returns Boolean"""
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
52 matched_files = [directory_file for directory_file in directory.iterdir()
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
53 if
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
54 directory_file.name.startswith(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
55 prefix) and directory_file.suffix == extension]
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
56 # Empty list should return False
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
57 return bool(matched_files)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
58
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
59
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
60 class DataTable(object):
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
61
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
62 def __init__(self,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
63 index_path: Path,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
64 data_table_name: str,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
65 indexes_properties_file: Path,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
66 name: str = None,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
67 dbkey: str = None,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
68 value: str = None,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
69 extra_columns: dict = None
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
70 ):
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
71 self.index_path = index_path
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
72 self.data_table_name = data_table_name
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
73 self.name = name if name else str(self.index_path.with_suffix(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
74 '').name)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
75 self.value = value if value else self.name
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
76 self.dbkey = dbkey if dbkey else self.value
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
77 self.extra_columns = extra_columns if extra_columns is not None else {}
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
78 self.indexes_properties_file = indexes_properties_file
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
79
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
80 self.check_params()
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
81
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
82 self.index_properties = self.get_index_properties()
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
83
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
84 self.check_index_file_presence()
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
85
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
86 def check_params(self):
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
87
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
88 check_tab('name', self.name)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
89 check_tab('index_path', str(self.index_path.absolute().name))
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
90 check_tab('value', self.value)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
91 check_tab('dbkey', self.dbkey)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
92 self.check_extra_columns()
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
93
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
94 def check_extra_columns(self):
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
95 index_properties = self.get_index_properties()
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
96 index_extra_columns = set(index_properties.get("extra_columns", []))
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
97 given_extra_columns = self.extra_columns.keys()
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
98 if index_extra_columns != given_extra_columns:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
99 if len(index_extra_columns) > 0:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
100 raise ValueError(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
101 "Values for the following columns should be "
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
102 "supplied: {0}.".format(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
103 str(index_extra_columns).strip("{}")))
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
104 if len(index_extra_columns) == 0:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
105 raise ValueError(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
106 "The table '{0}' does not have extra columns".format(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
107 self.data_table_name))
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
108 for key, value in self.extra_columns.items():
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
109 check_tab(key, value)
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
110
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
111 def get_index_properties(self) -> dict:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
112 with self.indexes_properties_file.open('r') as properties_file:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
113 indexes = yaml.safe_load(properties_file)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
114 index_properties = indexes.get(self.data_table_name)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
115 if index_properties is None:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
116 raise ValueError(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
117 "'{0}' not a supported table name".format(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
118 self.data_table_name))
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
119 return indexes_schema().validate(index_properties)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
120
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
121 def check_index_file_presence(self):
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
122 index_name = self.index_properties.get('name')
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
123 if index_name is None:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
124 raise NotImplementedError(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
125 "Property 'name' not defined for '{0}',"
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
126 " please contact the developers to correct the mistake.")
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
127 index_extensions = self.index_properties.get('extensions', [''])
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
128
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
129 # Sometimes an index path is a prefix.
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
130 # For example, with BWA. 'reference.fa' is the index.
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
131 # But the actual index files are
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
132 # 'reference.fa.amb', 'reference.fa.ann' etc.
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
133
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
134 # If the index is not a prefix,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
135 # the index file is taken to be the path itself.
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
136 index_is_a_prefix = self.index_properties.get('prefix', True)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
137 prefix_strip_extension = self.index_properties.get(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
138 'prefix_strip_extension', False)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
139 if index_is_a_prefix:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
140 if prefix_strip_extension:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
141 prefix = str(self.index_path.with_suffix("").name)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
142 else:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
143 prefix = str(self.index_path.name)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
144 for extension in index_extensions:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
145 if not prefix_plus_extension_exists(self.index_path.parent,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
146 prefix, extension):
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
147 raise FileNotFoundError(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
148 "Unable to find files with prefix '{0}' "
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
149 "and extension '{1}' in {2}. Is this a valid {3}?"
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
150 .format(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
151 prefix,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
152 extension,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
153 str(self.index_path.parent),
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
154 index_name))
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
155 elif self.index_properties.get('folder') is not None:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
156 for file in self.index_properties.get('folder'):
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
157 if not (self.index_path / Path(file)).exists():
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
158 raise FileNotFoundError(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
159 "A file named '{0}' was not found in '{1}'".format(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
160 file, str(self.index_path)))
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
161 elif not self.index_path.exists() and not self.index_path.is_dir():
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
162 raise FileNotFoundError(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
163 'Unable to find path {0}.'.format(self.index_path))
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
164 elif self.index_path.is_dir() and self.index_properties.get(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
165 'folder') is None:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
166 raise IsADirectoryError(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
167 '{0} is a directory not a file'.format(self.index_path))
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
168 elif self.index_path.exists():
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
169 pass
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
170 else:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
171 raise NotImplementedError("This condition was not expected "
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
172 "and should not be reached. Please "
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
173 "contact the developers.")
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
174
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
175 @property
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
176 def data_manager_dict(self) -> dict:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
177 data_table_entry = dict(value=self.value, dbkey=self.dbkey,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
178 name=self.name,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
179 path=str(self.index_path),
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
180 **self.extra_columns)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
181 data_manager_dict = dict(data_tables=dict())
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
182 data_manager_dict["data_tables"][
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
183 self.data_table_name] = [data_table_entry]
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
184 return data_manager_dict
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
185
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
186 @property
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
187 def data_manager_json(self) -> str:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
188 return json.dumps(self.data_manager_dict)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
189
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
190
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
191 def main():
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
192 options = argument_parser().parse_args()
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
193
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
194 if options.json_output_file.exists():
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
195 pass # Do not raise error.
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
196
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
197 if options.extra_columns is None:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
198 extra_columns = dict()
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
199 else:
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
200 try:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
201 extra_columns = yaml.safe_load(options.extra_columns)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
202 except yaml.parser.ParserError as e:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
203 raise yaml.parser.ParserError(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
204 "Invalid yaml string for --extra_indexes. \nError {0}".format(
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
205 e))
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
206
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
207 index_properties_file = Path(__file__).parent / Path("indexes.yml")
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
208 data_table = DataTable(index_path=options.path,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
209 data_table_name=options.data_table_name,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
210 name=options.name,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
211 value=options.value,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
212 dbkey=options.dbkey,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
213 indexes_properties_file=index_properties_file,
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
214 extra_columns=extra_columns)
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
215
1
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
216 # save info to json file
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
217 with options.json_output_file.open('w') as output_file:
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
218 output_file.write(data_table.data_manager_json)
8495c49cd056 planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit 9061997af3bc94f49653ffd42f10b973578e371d
rhpvorderman
parents: 0
diff changeset
219
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
220
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
221 if __name__ == "__main__":
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
222 main()