From cfcbc0bec3062d3bcc5586c0ef2601496bf33ebc Mon Sep 17 00:00:00 2001
From: Fontrodona Nicolas <nicolas.fontrodona@ens-lyon.fr>
Date: Tue, 26 Sep 2023 10:08:56 +0200
Subject: [PATCH] R/load_matrix.R: fix batch effect column handling

---
 R/load_matrix.R | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/R/load_matrix.R b/R/load_matrix.R
index 2487c61..9681ee6 100644
--- a/R/load_matrix.R
+++ b/R/load_matrix.R
@@ -49,7 +49,9 @@ load_matrix <- function(design_table, path, my_formula) {
     for (my_col in cn[3:length(cn)]) {
         sample_table[[my_col]] <- as.factor(sample_table[[my_col]])
     }
-    sample_table <- sample_table[, c("sampleName", "fileName", "condition")]
+    tmp_cn <- c("sampleName", "fileName", "condition")
+    tmp_cn <- unique(c(tmp_cn, cn[3:length(cn)]))
+    sample_table <- sample_table[, tmp_cn]
     sample_table$condition <- as.factor(sample_table$condition)
     dds_input <- DESeq2::DESeqDataSetFromHTSeqCount(
         sampleTable = as.data.frame(sample_table),
@@ -57,10 +59,10 @@ load_matrix <- function(design_table, path, my_formula) {
         design = as.formula(my_formula)
     )
     dds <- DESeq2::DESeq(dds_input)
-    if (length(cn) <= 3) {
+    if (length(tmp_cn) <= 3) {
         ac <- ""
     } else {
-        ac <- cn[4:length(cn)]
+        ac <- tmp_cn[4:length(tmp_cn)]
     }
     res <- list(dds = dds, acol = ac)
     return(res)
-- 
GitLab