|
a |
|
b/project_utils.py |
|
|
1 |
import json |
|
|
2 |
import jsonlines |
|
|
3 |
|
|
|
4 |
import sys |
|
|
5 |
import pickle |
|
|
6 |
import project_config |
|
|
7 |
|
|
|
8 |
|
|
|
9 |
############################################## |
|
|
10 |
# Read in/write patients |
|
|
11 |
|
|
|
12 |
def read_patients(filename): |
|
|
13 |
patients = [] |
|
|
14 |
with jsonlines.open(filename) as reader: |
|
|
15 |
for patient in reader: |
|
|
16 |
patients.append(patient) |
|
|
17 |
return patients |
|
|
18 |
|
|
|
19 |
|
|
|
20 |
def write_patients(patients, filename): |
|
|
21 |
with open(filename, "w") as output_file: |
|
|
22 |
for patient_dict in patients: |
|
|
23 |
json.dump(patient_dict, output_file) |
|
|
24 |
output_file.write('\n') |
|
|
25 |
|
|
|
26 |
|
|
|
27 |
def read_dicts(): |
|
|
28 |
with open(project_config.KG_DIR / f'hpo_to_idx_dict_{project_config.CURR_KG}.pkl', 'rb') as handle: |
|
|
29 |
hpo_to_idx_dict = pickle.load(handle) |
|
|
30 |
|
|
|
31 |
with open(str(project_config.KG_DIR / f'ensembl_to_idx_dict_{project_config.CURR_KG}.pkl'), 'rb') as handle: |
|
|
32 |
ensembl_to_idx_dict = pickle.load(handle) |
|
|
33 |
|
|
|
34 |
with open(project_config.KG_DIR / f'mondo_to_idx_dict_{project_config.CURR_KG}.pkl', 'rb') as handle: |
|
|
35 |
disease_to_idx_dict = pickle.load(handle) |
|
|
36 |
|
|
|
37 |
with open(str(project_config.PROJECT_DIR / 'preprocess' / 'orphanet' / 'orphanet_to_mondo_dict.pkl'), 'rb') as handle: |
|
|
38 |
orpha_mondo_map = pickle.load(handle) |
|
|
39 |
|
|
|
40 |
return hpo_to_idx_dict, ensembl_to_idx_dict, disease_to_idx_dict, orpha_mondo_map |