aibiology

Artificial intelligence in biology

0%

分位数标准化

分位数标准化 Quantile normalization

分位数标准化就是使得两个分布在统计属性上相同的技术手法。 该方法在基因芯片中经常使用。

例子

如图我们有三个基因芯片的数据,假设有A,B,C,D四个基因

表格Table1

Gene Sample1 Sample2 Sample3
A 5 4 3
B 2 1 4
C 3 4 6
D 4 2 8

对每一列进行排序,按照从小到大的顺序。 表格Table2

Gene Sample1 Sample2 Sample3
A iv iii i
B i i ii
C ii iii iii
D iii ii iv

这个排序好的列表(Table2)后续会用到。回到第一个数据表(Table1),重排每一列的数据,根据从小到大的顺序依次排列。 第一列原始的数据是5,2,3,4 ---> 2,3,4,5 第二列原始的数据是4,1,4,2 ---> 1,2,4,4 第三列原始的数据是3,4,6,8 ---> 3,4,6,8(原始已经是从小大,不变)

表格Table3

Gene Sample1 Sample2 Sample3
A 2 1 3
B 3 2 4
C 4 4 6
D 5 4 8

计算Table3每一行的均值,找到新的排序, A (2+1+3)/3 = 2.00 = rank i

B (3+2+4)/3 = 3.00 = rank ii

C (4+4+6)/3 = 4.67 = rank iii

D (5+4+8)/3 = 5.67 = rank iv

根据原始数据的排序Table2,和上面新排序对应的值, 将原始值根据对应的排序进行值的替换。

第一次标准化 表格Table4

Gene Sample1 Sample2 Sample3
A 5.67 4.67 2.00
B 2.00 2.00 3.00
C 3.00 4.67 4.67
D 4.67 3.00 5.67

注意,在第二列中有并列的值,这些并列的值应该被平均值替换,于是在这里我们替换第二列中并列的值, 使用4.67和5.67的(4.67+5.67)/2=5.17平均值来替换。

第二次标准化 表格Table5

Gene Sample1 Sample2 Sample3
A 5.67 5.17 2.00
B 2.00 2.00 3.00
C 3.00 5.17 4.67
D 4.67 3.00 5.67

新的值符合相同的分布,我们现在来看看一些统计量,发现这些值比较相近。

Sample1 Sample2 Sample3
Min. :2.000 Min. :2.000 Min. :2.000
1st Qu.:2.750 1st Qu.:2.750 1st Qu.:2.750
Median :3.833 Median :4.083 Median :3.833
Mean :3.833 Mean :3.833 Mean :3.833
3rd Qu.:4.917 3rd Qu.:5.167 3rd Qu.:4.917
Max. :5.667 Max. :5.167 Max. :5.667

python实现quantile normalize

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

import numpy as np
import pandas as pd

def quantileNormalize(df_input):
df = df_input.copy()
#compute rank
dic = {}
for col in df:
dic.update({col : sorted(df[col])})
sorted_df = pd.DataFrame(dic)
rank = sorted_df.mean(axis = 1).tolist()
#sort
for col in df:
t = np.searchsorted(np.sort(df[col]), df[col])
df[col] = [rank[i] for i in t]
return df