1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| library(DESeq2) count_all <- read.csv("~/upload/zl_liu/star_data/yyz_01/yyz_01.csv",header=TRUE) count_all cts_b <- count_all[ ,c(-1,-2,-3)] rownames(cts_b) <- count_all$ID keep <- rowSums(cts_b) > ncol(cts_b) cts_b[keep,] f_DESeq2 <- function(cts_bb, rowInfo, ControlN, TreatN, rm.NA=T){ cts_b <- cts_bb[,c(ControlN, TreatN)] conditions <- factor(c(rep("Control",length(ControlN)), rep("Treat",length(TreatN)))) colData_b <- data.frame(row.names = colnames(cts_b), conditions) print(colData_b) dds <- DESeqDataSetFromMatrix(countData = cts_b, colData = colData_b, design = ~ conditions) dds <- DESeq(dds) res <- results(dds) rres <- cbind(rowInfo, data.frame(res)) if(rm.NA){rres <- rres[!is.na(rres$padj),]} rres <- rres[order(rres$log2FoldChange, decreasing = T),] saveRDS(rres, paste('DEGs', paste(TreatN, collapse = '_'), 'vs.', paste(ControlN, collapse = '_'), 'DESeq2.rds',sep = '_')) rres } Ct1 <- c('X1.control.DMSO', 'X2.control.DMSO') Tt1 <- c('X1.OE.DMSO', 'X2.OE.DMSO') Ct2 <- c('X1.OE.DMSO', 'X2.OE.DMSO') Tt2 <- c('X1.OE.Enz', 'X2.OE.Enz') Ct3 <- c('X1.control.Enz', 'X2.control.Enz') Tt3 <- c('X1.OE.Enz', 'X2.OE.Enz') Ct4 <- c('X1.CAF.DMSO', 'X2.CAF.DMSO') Tt4 <- c('X1.CAF.Enz', 'X2.CAF.Enz') r1 <- f_DESeq2(cts_b[keep,], count_all[keep,c(1,2,3)], Ct1, Tt1) r2 <- f_DESeq2(cts_b[keep,], count_all[keep,c(1,2,3)], Ct2, Tt2) r3 <- f_DESeq2(cts_b[keep,], count_all[keep,c(1,2,3)], Ct3, Tt3) r4 <- f_DESeq2(cts_b[keep,], count_all[keep,c(1,2,3)], Ct4, Tt4)
|