annotate dump_yaml.py @ 2:2f7a70c0d3ab draft default tip

Uploaded
author ieguinoa
date Mon, 21 Feb 2022 14:22:53 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
1 import sys
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
2 import yaml
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
3
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
4 def fetch_table_data(table_path):
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
5 data_dict = {}
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
6 with open(table_path) as table_to_load:
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
7 # load headers
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
8 headers = table_to_load.readline().strip('\n').split('\t')
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
9 row_id = 0
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
10 for line in table_to_load.readlines():
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
11 # print(line)
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
12 line_data = line.strip('\n').split('\t')
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
13 row_dict = {}
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
14 for col_num in range(len(headers)):
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
15 col_name = headers[col_num]
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
16 row_dict[col_name] = line_data[col_num]
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
17 data_dict[row_id] = row_dict
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
18 row_id += 1
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
19 return data_dict
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
20
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
21 all_data_dict = {}
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
22 print('YAML -------------')
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
23 studies_table_path = sys.argv[1]
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
24 table_data = fetch_table_data(studies_table_path)
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
25 all_data_dict['ENA_study'] = table_data
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
26 samples_table_path = sys.argv[2]
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
27 table_data = fetch_table_data(samples_table_path)
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
28 all_data_dict['ENA_sample'] = table_data
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
29 experiments_table_path = sys.argv[3]
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
30 table_data = fetch_table_data(experiments_table_path)
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
31 all_data_dict['ENA_experiment'] = table_data
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
32 runs_table_path = sys.argv[4]
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
33 table_data = fetch_table_data(runs_table_path)
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
34 all_data_dict['ENA_run'] = table_data
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
35 # print(all_data_dict)
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
36 print(yaml.dump(all_data_dict))
2f7a70c0d3ab Uploaded
ieguinoa
parents:
diff changeset
37 print('YAML -------------')