问题描述
我正在尝试对RNAseq数据的TPM值矩阵进行t检验,但是我的代码出现错误。我是R的新手,所以我仍在学习编写脚本。我的文件有7列-第一个是基因列表,2:4是group1中的重复项,而5:7是group2中的重复项。我遇到的错误是在t.test.default(x,y)中:没有足够的'x'观测值。
# Read file
T <- read.table("./rnaseq_tpm_matrix_S_24v0.csv",sep=",",header=TRUE)
# Assign groups of data
x <- T[i,grep('^Sample_S_0',names(T))]
y <- T[i,grep('^Sample_S_24',names(T))]
# Calculate average of each group for each gene
group1_avg <- as.matrix(sum(x)/length(x))
group2_avg <- as.matrix(sum(y)/length(y))
# Calculate log2 (TPM +1)
x <- log2(as.matrix(group1_avg)+1)
y <- log2(as.matrix(group2_avg)+1)
dat <- data.frame(values=c(x,y),vars = rep(c("Sample_SKOV3_0","Sample_SKOV3_24"),times = c(length(x),length(y))))
# Apply t-test
results <- apply(dat,1,function(dat) {
t.test(x,y)$p.value})
#Bind p-values into matrix
cbind(dat,pvals = results)
Error in t.test.default(x = dat[1:x],y = dat[(x + 1):(x + y)]) :
not enough 'x' observations
Error during wrapup: arguments imply differing number of rows: 2,5
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
dput(head(T,20))
structure(list(Sample_H_repA = c("5S_rRNA","5_8S_rRNA","6M1-18","7M1-2","7SK","A1BG","A1BG-AS1","A1CF","A2M","A2M-AS1","A2ML1","A2MP1","A3galT2","A4galT","A4GNT","AA06","AAAS","AACS","AACSP1","AADAC"),Sample_S_0_rep1 = c(0,2478.55,3.91,0.69,0.63,1.94,3.37,71.22,20.3,1.6),Sample_S_0_rep2 = c(0,789.63,2.98,0.15,8.12,109.03,8.84,0.11,0),Sample_S_0_rep3 = c(0,802.76,2.99,0.02,5.59,108.95,10.69,Sample_S_24_rep1 = c(0,993.88,3.71,0.35,2.9,106.5,17.53,0.09,Sample_S_24_rep2 = c(0,896.23,3.48,6.95,110.04,15.05,0.12,Sample_S_24_rep3 = c(0,947.83,4.02,7.04,110.49,12.71,0.06,0)),row.names = c(NA,20L),class = "data.frame")
样本数据: Sample Data
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)