Posted on

最近很多人借TIDE账号,也有人问我如何进行数据标准化,按照网站说明,对于没有Control样本的测序数据,把表达量减去每个基因在所有样本中的平均值即可,即按照行计算平均值,再拿这一行所有表达量-该平均值。

https://www.jingege.wang/wp-content/uploads/2021/10/c-users-jinwan1-appdata-local-temp-16331085931.png
#读取数据
Expr <- read.delim("TIDE_COAD.txt",sep = "\t",row.names = 1)
#使用apply函数
Expr <- t(apply(Expr, 1, function(x)x-(mean(x)))) 

一句代码就得到标准化矩阵

测试代码:

ma <- matrix(c(1:4, 1, 6:8), nrow = 2)
ma
#     [,1] [,2] [,3] [,4]
#[1,]    1    3    1    7
#[2,]    2    4    6    8
apply(ma, 2, function(x)x-(mean(x)))  ##按列计算
#     [,1] [,2] [,3] [,4]
#[1,] -0.5 -0.5 -2.5 -0.5
#[2,]  0.5  0.5  2.5  0.5
apply(ma, 1, function(x)x-(mean(x)))  ##按行计算
#     [,1] [,2]
#[1,]   -2   -3
#[2,]    0   -1
#[3,]   -2    1
#[4,]    4    3

转置一下即可:

t(apply(ma, 1, function(x)x-(mean(x))))
#     [,1] [,2] [,3] [,4]
#[1,]   -2    0   -2    4
#[2,]   -3   -1    1    3

apply函数参数帮助。

apply(X, MARGIN, FUN, …)


Arguments

X

an array, including a matrix.

MARGIN

a vector giving the subscripts which the function will be applied over. E.g., for a matrix 1 indicates rows, 2 indicates columns, c(1, 2) indicates rows and columns. Where X has named dimnames, it can be a character vector selecting dimension names.

FUN
the function to be applied: see ‘Details’. In the case of functions like +, %*%, etc., the function name must be backquoted or quoted.


optional arguments to FUN.

15 Replies to “TIDE数据标准化:R语言每行减去平均值”

  1. > Expr <- t(apply(tumor, 1, function(x)x-(mean(x))))
    Error in apply(tumor, 1, function(x) x – (mean(x))) :
    dim(X)的值必需是正数 为什么他会说dim(x)必须是正数

  2. 请问我在输入数据之后,网站提示必须是TAB制表符文件才能识别,但是我的文件制表符没问题,请问要怎么解决

  3. 进哥,请问TIDE网站是不能用了吗?我用TIDE网站,点了predict response后为啥都是Page unavailable?还是我哪儿弄错了o(╥﹏╥)o,卡好久了

  4. 请问数据应该在哪里下载呢,可不可以用UCSC中TCGA-BRCA的gene expression RNAseq中的IlluminaHiSeq (n=1,218) TCGA Hub数据,它是RSEM数据

    1. 应该可以的,不要取log的数据,标准化之后上传TIDE
      试试看吧 我也不是很清楚
      不过TIDE上提供了计算好的TCGA数据 直接下载即可

  5. 进哥,我想问一下,这个标准化后的矩阵应该怎么输出呢?

发表评论

邮箱地址不会被公开。 必填项已用*标注