annotate data_manager/ariba_database_builder.py @ 3:b13f7ba85697 draft

Update ariba_database_builder.py
author thanhlv
date Mon, 14 Jan 2019 07:01:15 -0500
parents a8bb47cc7625
children be46816110b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
1 # Thanh Le Viet
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
2 # 7-Jan-2019
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
3
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
4 import argparse
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
5 import json
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
6 import os
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
7 import shutil
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
8
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
9
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
10 def main(args):
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
11 output_path = os.getcwd()
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
12 db_folder = [d for d in os.listdir(output_path) if os.path.isdir(d)]
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
13 params = json.loads(open(args.output).read())
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
14 target_directory = params['output_data'][0]['extra_files_path']
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
15 os.mkdir(target_directory)
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
16 data_manager_entry = []
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
17 for db in db_folder:
3
b13f7ba85697 Update ariba_database_builder.py
thanhlv
parents: 0
diff changeset
18 print("Current: ".format(os.path.join(output_path, d)))
b13f7ba85697 Update ariba_database_builder.py
thanhlv
parents: 0
diff changeset
19 print("Target: {}".format(target_directory))
0
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
20 shutil.move(os.path.join(output_path, d), os.path.join(target_directory, d))
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
21 data_manager_entry.append(dict(value=db.lower(),
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
22 name=db,
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
23 path=target_directory)
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
24 )
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
25 data_manager_json = dict(data_tables=dict(ariba_databases=data_manager_entry))
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
26 file(args.output, 'w').write(json.dumps(data_manager_json))
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
27
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
28
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
29 if __name__ == '__main__':
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
30 parser = argparse.ArgumentParser(description='Create data manager json.')
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
31 parser.add_argument('--out', dest='output', action='store', help='JSON filename')
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
32 args = parser.parse_args()
a8bb47cc7625 planemo upload for repository tbd commit 0af229dbbda0496819ca95938c2e0628db689134
thanhlv
parents:
diff changeset
33 main(args)