将所有数据标准化为 r 中的单个基因(观察)

normalize all data to single gene (observation) in r

我有一些来自 850 种蛋白质的蛋白质表达数据,我想将这些数据标准化为参考蛋白质。这是纠正技术错误的好方法。我是 R 的新手,只是想制作一个整洁的数据集。但是当我搜索规范化时——它主要是在缩放数据。我找不到与数据集中的数据点成比例的好方法。所以我有以下内容,其中 type=D 或 T,pt.num=1-8,并且在 612.9 kb 文件中有 859 个 GeneIDs 和 9952 个元素。

> head(df10g)
  GeneID type pt.num   value
1    A2M    D      1  8876.5
2   ABL1    D      1  2120.8
3   ACP1    D      1  1266.6
4   ACP5    D      1 67797.6
5 ACVRL1    D      1   650.1
6   ACY1    D      1  6264.8
318 IGF2R    D      1   6294.8

我想将每个 pt.num.type 标准化为 IGF2R。但我不太明白它的语义。我想要这种功能

Norm.ig2Fr=GeneID.type.pt.num(value)/IG2FR.type.pt.num(value)

Norm.ig2fr=ASM.D.1 (value)/IG2FR.D.1 (value)

Norm.ig2fr=8876.5/6294.8

所需的输出将是

GeneID type pt.num   value              Norm.ig2fr      log2Norm.ig2fr
    1    A2M    D      1  8876.5        1.41            0.49
    2   ABL1    D      1  2120.8
    3   ACP1    D      1  1266.6
    4   ACP5    D      1 67797.6

我想我可以使用 mutate 或 ddply 转换,但我缺少将比率的分母固定为相同 GeneID 值但改变 pt.num 和类型的东西。

df11 <- ddply(df10g, .(pt.num), transform, Norm.ig2b=value/IGF2R)

df10.igf2r<- mutate(df10t, .(type, pt.num), Norm.ig2fr=value/IG2FR)

dput(df10g)
structure(list(GeneID = structure(c(1L, 2L, 3L, 4L, 6L, 7L), .Label = c("A2M", 
"ABL1", "ACP1", "ACP5", "Activated Protein C", "ACVRL1", "ACY1"),class = "factor"), type = c("D", "D", "D", "D", "D", 
"D"), pt.num = c("1", "1", "1", "1", "1", "1"), value = c(8876.5, 
2120.8, 1266.6, 67797.6, 650.1, 6264.8)), .Names = c("GeneID", 
"type", "pt.num", "value"), row.names = c(NA, 6L), class = "data.frame")

如有任何建议或见解,我们将不胜感激。感谢您的帮助!

我想这可能就是你的意思。我想不出 plyr 的解决方案。但是,我想用 dplyr 提出一个建议。我在这里创建了一个示例数据来演示代码。我认为您想使用 group_by()typept.num 进行分组。然后,您想在 mutate() 中进行归一化。 value[GeneID == "IGF2R"] 指定每个组中 IGF2R 的值。例如D-1组,value[GeneID == "IGF2R"]为1281.000,T-1组,value[GeneID == "IGF2R"]为1561.364。使用这些值,R 对每个组进行归一化。

set.seed(111)
mydf <- data.frame(GeneID = rep(c("A2M", "ABL1", "ACP1", "ACP5",
                                  "ACVRL1", "ACY1", "IGF2R"), times = 2),
                   type = rep(c("D", "T"), each = 7),
                   pt.num = 1,
                   value = runif(14, 1200, 8800),
                   stringsAsFactors = FALSE)

#   GeneID type pt.num    value
#1     A2M    D      1 5706.658
#2    ABL1    D      1 6721.257
#3    ACP1    D      1 4015.207
#4    ACP5    D      1 5113.421
#5  ACVRL1    D      1 4070.240
#6    ACY1    D      1 4379.364
#7   IGF2R    D      1 1281.000
#8     A2M    T      1 5245.444
#9    ABL1    T      1 4484.421
#10   ACP1    T      1 1911.980
#11   ACP5    T      1 5423.927
#12 ACVRL1    T      1 5685.737
#13   ACY1    T      1 1710.273
#14  IGF2R    T      1 1561.364

library(dplyr)             
group_by(mydf, type, pt.num) %>%
mutate(out = value / value[GeneID == "IGF2R"])


#   GeneID type pt.num    value      out
#1     A2M    D      1 5706.658 4.454847
#2    ABL1    D      1 6721.257 5.246884
#3    ACP1    D      1 4015.207 3.134433
#4    ACP5    D      1 5113.421 3.991743
#5  ACVRL1    D      1 4070.240 3.177394
#6    ACY1    D      1 4379.364 3.418708
#7   IGF2R    D      1 1281.000 1.000000
#8     A2M    T      1 5245.444 3.359527
#9    ABL1    T      1 4484.421 2.872118
#10   ACP1    T      1 1911.980 1.224557
#11   ACP5    T      1 5423.927 3.473840
#12 ACVRL1    T      1 5685.737 3.641520
#13   ACY1    T      1 1710.273 1.095371
#14  IGF2R    T      1 1561.364 1.000000

data.table 中应用相同的过程,以下代码也有效。

library(data.table)
foo <- setDT(mydf)[, out := value / value[GeneID == "IGF2R"], by = list(type, pt.num)]
print(foo)

 #   GeneID type pt.num    value      out
 #1:    A2M    D      1 5706.658 4.454847
 #2:   ABL1    D      1 6721.257 5.246884
 #3:   ACP1    D      1 4015.207 3.134433
 #4:   ACP5    D      1 5113.421 3.991743
 #5: ACVRL1    D      1 4070.240 3.177394
 #6:   ACY1    D      1 4379.364 3.418708
 #7:  IGF2R    D      1 1281.000 1.000000
 #8:    A2M    T      1 5245.444 3.359527
 #9:   ABL1    T      1 4484.421 2.872118
#10:   ACP1    T      1 1911.980 1.224557
#11:   ACP5    T      1 5423.927 3.473840
#12: ACVRL1    T      1 5685.737 3.641520
#13:   ACY1    T      1 1710.273 1.095371
#14:  IGF2R    T      1 1561.364 1.000000