From 31beb884a8d85a84d48a8a89fb3ecad406f10b9d Mon Sep 17 00:00:00 2001
From: aduvermy <arnaud.duvermy@ens-lyon.fr>
Date: Tue, 8 Feb 2022 16:17:47 +0000
Subject: [PATCH] add scr to run deseq2f

---
 src/run_deseq.R | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 src/run_deseq.R

diff --git a/src/run_deseq.R b/src/run_deseq.R
new file mode 100644
index 0000000..fedb44d
--- /dev/null
+++ b/src/run_deseq.R
@@ -0,0 +1,51 @@
+library("DESeq2")
+
+directory <- "mydatalocal/counts_simulation/results/"
+
+
+sampleFiles <- grep("*tsv",list.files(directory),value=TRUE)
+sampleName <- sub("*.tsv","",sampleFiles)
+
+sampleName
+
+sampleCondition <- as.character(sampleName)
+for (i in 1:length(sampleCondition)){
+  sampleCondition[i] <- gsub("_[A-B]", "", sampleCondition[i])
+}
+
+
+sampleCondition
+
+sampleTable <- data.frame(sampleName = sampleName,
+                          fileName = sampleFiles,
+                          condition = sampleCondition)
+sampleTable
+str(sampleTable)
+
+ddsInput <- DESeqDataSetFromHTSeqCount(sampleTable = sampleTable,
+                                       directory = directory,
+                                       design = ~ condition)
+
+
+
+dds <- DESeq(ddsInput)
+
+resultsNames(dds)
+
+resLFC <- lfcShrink(dds, coef=2, type="apeglm")
+resLFC
+# an alternate analysis: likelihood ratio test
+ddsLRT <- DESeq(dds, test="LRT", reduced= ~ 1)
+resLRT <- results(ddsLRT)
+resLRT
+
+dds$sizeFactor
+coef(dds)
+coef(dds, SE=TRUE)[1,]
+
+dds <- estimateSizeFactors(dds)
+dds$condition
+head(counts(dds, normalized=TRUE))
+
+resGA <- results(dds, contrast=c("condition","env1","env2"), lfcThreshold=.4, altHypothesis="greaterAbs")
+table(resGA$padj < 0.05)
-- 
GitLab