-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathhelper_functions.py
More file actions
33 lines (22 loc) · 877 Bytes
/
helper_functions.py
File metadata and controls
33 lines (22 loc) · 877 Bytes
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
#!/usr/bin/env python
from __future__ import annotations
import numpy as np
from numpy.typing import ArrayLike
def normalize(
input_data: list[float],
calibration_data: list[float] | ArrayLike,
) -> list[float]:
"""normalizes by dividing by `calibration_data` and also applies SNV_transform"""
input_data = np.asarray(input_data)
calibration_data = np.asarray(calibration_data)
# scale by calibration measurement
data_rescaled = input_data / calibration_data
data_snv = snv_transform(data_rescaled)
return list(data_snv)
def snv_transform(data: ArrayLike | list[float]) -> list[float]:
"""SNV transform
Subtract the mean and divide by the standarddiviation
"""
return list((np.asarray(data) - np.mean(data)) / np.std(data))
def list_to_string(data: list[float]) -> list[str]:
return [f"{i:.7f}" for i in data]