遍历不同输入数据帧的脚本

时间:2019-03-21 06:41:06

标签: r for-loop

我想在以下以这些名称加载到同一R对象中的多个输入数据帧上运行我的代码:

列表:

list <- c(ACC,BLCA,BRCA,CESC,CHOL,COAD,DLBC,ESCA,GBM)

如何创建一个循环来替换每一轮的数据帧,并对每个数据帧执行单独的分析并保存唯一的输出?

代码

ACC.t <- as.data.frame(t(ACC))
dat.dge <- DGEList(ACC.t)
Factor <- dat.dge[grep("ENSG00000008517",rownames(dat.dge)),]$counts
q <- quantile(Factor,seq(0,1,0.05))
up.q <- quantile(Factor,0.85)
low.q <- quantile(Factor,0.15)
Factor <- as.numeric(as.character(Factor))
Factor[as.numeric(Factor) > up.q] <- "High"
Factor[as.numeric(Factor) <= low.q] <- "Low"
Factor <- factor(Factor)
table(Factor)

dat.dge$samples$lib.size <- colSums(dat.dge$counts) # recalculate size factors
method <- "TMM" # c("TMM","RLE","upperquartile","none")
dat.dge <- calcNormFactors(dat.dge, method=method)
des <- model.matrix(~Factor)
head(des)
colnames(des) <- c("Intercept", "cond")
v <- voom(dat.dge,plot = F)
fit <- lmFit(v, des)
fit <- eBayes(fit)
contrasts <- makeContrasts(cond=cond, levels=des) 
fit2 <- contrasts.fit(fit, -contrasts)
fit2 <- eBayes(fit2)
colSums(decideTests(fit2) != 0)
top <- topTable(fit2,coef="cond",sort.by="P", adjust.method="BH", n=Inf)
head(top,10)
top$ENSEMBL <- rownames(top)
top.sign <- top[top$adj.P.Val < 0.05,]
top.sign
top.sign.up <- top.sign[top.sign$logFC >0,]
write.table(top, file="ACC.top_LimmaHighLowIL32_15PercentileHighLow.csv",quote = F)

0 个答案:

没有答案