-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathnormalize_data.py
More file actions
64 lines (53 loc) · 3.1 KB
/
Copy pathnormalize_data.py
File metadata and controls
64 lines (53 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pathlib
import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler
from joblib import dump
import sys
sys.path.append("../utils")
from load_utils import compile_mitocheck_batch_data
from normalization_utils import get_normalization_scaler, get_normalized_mitocheck_data
extracted_features_path = pathlib.Path(f"../1.idr_streams/extracted_features/")
dataset_types = ["ic", "no_ic"]
# iterate through dataset types (with/without illumination correction)
for dataset_type in dataset_types:
# get normalization scaler from negative control features (normalization population)
print("Getting normalization scaler...")
negative_control_data_path = pathlib.Path(f"{extracted_features_path}/negative_control_data__{dataset_type}/merged_features")
normalization_scaler = get_normalization_scaler(negative_control_data_path)
# save normalization scaler
norm_scaler_save_path = pathlib.Path(f"scaler/normalization_scaler__{dataset_type}.joblib")
norm_scaler_save_path.parent.mkdir(parents=True, exist_ok=True)
dump(normalization_scaler, norm_scaler_save_path)
# make results dir if it does not already exist
results_dir = pathlib.Path("normalized_data/")
results_dir.mkdir(parents=True, exist_ok=True)
# normalize the data at the following paths
training_data_path = pathlib.Path(f"{extracted_features_path}/training_data__{dataset_type}/merged_features")
negative_control_data_path = pathlib.Path(f"{extracted_features_path}/negative_control_data__{dataset_type}/merged_features")
positive_control_data_path = pathlib.Path(f"{extracted_features_path}/positive_control_data__{dataset_type}/merged_features")
# normalize training data
print("Normalizing training data...")
data = pd.read_csv(training_data_path, compression="gzip", index_col=0)
normalized_data = get_normalized_mitocheck_data(data, normalization_scaler)
# save normalized training data
save_path = pathlib.Path(f"{results_dir}/{training_data_path.name}")
normalized_data.to_csv(save_path, compression="gzip")
# normalize negative control data
print("Loading negative control data...")
data = compile_mitocheck_batch_data(negative_control_data_path)
print("Normalizing negative control data...")
normalized_data = get_normalized_mitocheck_data(data, normalization_scaler)
# save normalized negative control data
save_path = pathlib.Path(f"{results_dir}/{negative_control_data_path.name}")
print("Saving normalized negative control data...")
normalized_data.to_csv(save_path, compression="gzip", index=False)
# normalize positive control data
print("Loading positive control data...")
data = compile_mitocheck_batch_data(positive_control_data_path)
print("Normalizing positive control data...")
normalized_data = get_normalized_mitocheck_data(data, normalization_scaler)
# save normalized positive control data
save_path = pathlib.Path(f"{results_dir}/{positive_control_data_path.name}")
print("Saving normalized positive control data...")
normalized_data.to_csv(save_path, compression="gzip", index=False)