path1输入你的第一个Excel
path2输入你的第二个Excel
DEG.dig <- function(path1,path2) {
require(xlsx)
require(tidyverse)
require(limma)
require(edgeR)
E<- read.xlsx (path1,sheetIndex = 1,header = 1) %>% column_to_rownames(var ="NA." )
type<- read.xlsx (path2,sheetIndex = 1,header = 1) %>% select(type)
type <- type$type
type <- factor(type,levels = c(0,1),labels = c("tumor","normal"))
design <- model.matrix(~0+type)
rownames(design) = colnames(E)
colnames(design) = c("normal","tumor")
dge <- DGEList(counts = E)
dge$E %>% dim
keep_gene <- rowSums(cpm(dge) > 1) >= 2
dge <- dge[keep_gene,,keep.lib.sizes=FALSE]
dge$E %>% dim
dge <- calcNormFactors( dge )
dge$sample
pdf(file = "MDS.pdf")
plotMDS(dge)
dev.off()
v <- voom(dge, design, plot = F, normalize = "quantile")
fit <- lmFit(v, design)
cont.matrix <- makeContrasts(tumorvsnormal=tumor-normal, levels = design)
fit2 <- contrasts.fit(fit, cont.matrix)
fit2 <- eBayes(fit2)
nrDEG_limma_voom <- topTable(fit2, n = 100) %>% na.omit()
head(nrDEG_limma_voom)
write.csv(nrDEG_limma_voom,"结果.csv")
}