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
| library(DESeq2) library(sva) f_DESeq2_sva <- 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) group <- as.factor(c(rep("Ctl",length(ControlN)), rep("Trt",length(TreatN)))) mod1 <- model.matrix(~group) print(mod1) mod0 <- cbind(mod1[,1]) svseq <- svaseq(as.matrix(cts_b),mod1,mod0,n.sv=2) colData_b$SVa <- svseq$sv[,1] colData_b$SVb <- svseq$sv[,2] print(colData_b) ddssva <- DESeqDataSetFromMatrix(countData = cts_b, colData = colData_b, design = ~ SVa + SVb + conditions) ddssva <- DESeq(ddssva) res <- results(ddssva, contrast=c("conditions","Treat","Control")) rres <- cbind(rowInfo, data.frame(res)) if(rm.NA){rres <- rres[!is.na(rres$padj),]} rres <- rres[order(rres$log2FoldChange, decreasing = T),] rres }
|