-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_norm.py
40 lines (33 loc) · 1.12 KB
/
test_norm.py
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
import numpy as np
# import scanpy.api as sc
import pandas as pd
def norm(x, reverse=False):
if reverse:
y = np.power(10, x) - 1.01
y = np.around(y).astype(np.int32)
return y
else:
return np.log10(x + 1.01)
def minmax_0_to_1(x, reverse=False, minmax=1):
if reverse:
# x -> [0, 1]
minmax_x = x * minmax
# minmax_x -> [0, 6]
return norm(minmax_x, reverse)
else:
norm_x = norm(x, reverse)
minmax_x = norm_x / np.max(norm_x)
return minmax_x
array = [0, 1, 2, 3, 150, 134]
x = np.asarray(array)
print(minmax_0_to_1(x))
print(minmax_0_to_1(minmax_0_to_1(x), True, np.max(norm(x))))
print("-----------------")
# def normalization(express_data):
# adata = sc.AnnData(express_data.T.values)
# sc.pp.normalize_per_cell(adata)
# sc.pp.log1p(adata)
# return pd.DataFrame(adata.X.T, columns=express_data.columns.tolist(), index=express_data.index.tolist())
# a = pd.read_csv("./data/true_counts_simulated_dataset1_dropout0.05.csv")
# print(normalization(a))
# print(normalization(a).describe())