annotate data_manager/shapeit_ref.py @ 4:094bd0114876 draft

planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit 06f9376308b504cd2ab7a4ff0126ae70d73faacc
author sanbi-uwc
date Thu, 13 Sep 2018 14:35:09 -0400
parents 203133a92000
children f0c7cab2f547
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
1 #!/usr/bin/env python3
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
2
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
3 from __future__ import division, print_function
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
4 import argparse
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
5 import json
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
6 import os
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
7 import os.path
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
8
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
9
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
10 def _add_data_table_entry(data_manager_dict, data_table_name, data_table_entry):
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
11 data_manager_dict['data_tables'] = data_manager_dict.get('data_tables', {})
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
12 data_manager_dict['data_tables'][data_table_name] = data_manager_dict['data_tables'].get(data_table_name, [])
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
13 data_manager_dict['data_tables'][data_table_name].append(data_table_entry)
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
14 return data_manager_dict
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
15
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
16
1
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
17 _add_data_table_entry.__annotations__ = {'data_manager': dict, 'data_table_name': str, 'data_table_entry': dict, 'return': dict}
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
18
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
19
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
20 def assert_prefix_exists(prefix, path, prefix_type):
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
21 prefix_exists = False
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
22 for filename in os.listdir(path):
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
23 if filename.startswith(prefix):
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
24 prefix_exists = True
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
25 break
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
26 else:
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
27 if not prefix_exists:
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
28 exit("Unable to find a file with {} prefix {} in {}".format(prefix_type, prefix, path))
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
29
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
30
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
31 assert_prefix_exists.__annotations__ = {'prefix': str, 'path': str, 'prefix_type': str, 'return': None}
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
32
0
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
33 if __name__ == '__main__':
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
34 parser = argparse.ArgumentParser(description='Generate a data manager output for SHAPEIT reference data')
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
35 parser.add_argument('key', help='Short key to identify this reference set (no spaces)')
4
094bd0114876 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit 06f9376308b504cd2ab7a4ff0126ae70d73faacc
sanbi-uwc
parents: 3
diff changeset
36 parser.add_argument('name', help='Description of reference set')
0
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
37 parser.add_argument('path', help='Filesystem path to directory containing this reference set')
1
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
38 parser.add_argument('reference_prefix', help='Filename prefix for the reference (.hap / .legend / .sample) files')
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
39 parser.add_argument('map_prefix', help='Filename prefix for map files in this reference set')
0
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
40 parser.add_argument('output_file', type=argparse.FileType('w'), help='JSON file used to write data manager values to')
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
41 args = parser.parse_args()
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
42
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
43 if not os.path.exists(args.path):
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
44 exit("Unable to find specified path {}".format(args.path))
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
45
1
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
46 assert_prefix_exists(args.reference_prefix, args.path, 'reference')
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
47 assert_prefix_exists(args.map_prefix, args.path, 'map')
0
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
48
4
094bd0114876 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit 06f9376308b504cd2ab7a4ff0126ae70d73faacc
sanbi-uwc
parents: 3
diff changeset
49 for column in ('key', 'name', 'path', 'reference_prefix', 'map_prefix'):
0
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
50 value = getattr(args, column)
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
51 if '\t' in value:
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
52 exit("TAB character found in {} argument".format(column))
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
53
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
54 data_manager_dict = {}
4
094bd0114876 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit 06f9376308b504cd2ab7a4ff0126ae70d73faacc
sanbi-uwc
parents: 3
diff changeset
55 data_table_entry = dict(value=args.key, name=args.name, path=args.path,
1
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
56 reference_prefix=args.reference_prefix, map_prefix=args.map_prefix)
0
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
57 _add_data_table_entry(data_manager_dict, 'shapeit_ref', data_table_entry)
f86c65c60056 planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit c9acc04bcb85873e6eb78b4163d1a7daa2679f22
sanbi-uwc
parents:
diff changeset
58
1
52f0767fe68d planemo upload for repository https://github.com/pvanheus/data_manager_shapeit_reference commit b42d6cc8358088a50bc4463367c740c1e9dc71d8
sanbi-uwc
parents: 0
diff changeset
59 args.output_file.write(json.dumps(data_manager_dict, sort_keys=True) + '\n')