From eb17a1dbae0deb53b75b9904ed76465168b49f5c Mon Sep 17 00:00:00 2001 From: Alexey Sergushichev Date: Wed, 28 Aug 2024 13:37:26 -0500 Subject: [PATCH] readGct support for duplicate column names --- DESCRIPTION | 4 ++-- R/gct.R | 8 ++++++++ tests/testthat/test-gct.R | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1cd2a4e..9ca574a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: phantasusLite Type: Package Title: Loading and annotation RNA-seq counts matrices -Version: 1.3.2 +Version: 1.3.3 Authors@R: c(person("Rita", "Sablina", role = "aut"), person("Maxim", "Kleverov", role = "aut"), person("Alexey", "Sergushichev", email = "alsergbox@gmail.com", role = c("aut", "cre"))) @@ -22,7 +22,7 @@ biocViews: GeneExpression, Transcriptomics, RNASeq License: MIT + file LICENSE Encoding: UTF-8 LazyData: true -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Suggests: testthat (>= 3.0.0), knitr, diff --git a/R/gct.R b/R/gct.R index 4fab695..c72a508 100644 --- a/R/gct.R +++ b/R/gct.R @@ -55,6 +55,14 @@ readGct <- function(gct) { exp <- as.matrix(t[, exp.cols, with=FALSE]) rownames(exp) <- rn + cn <- colnames(exp) + if (any(duplicated(cn))) { + warning(sprintf("duplicated row IDs: %s; they were renamed", + paste0(cn[head(which(duplicated(cn)))], collapse = " "))) + cn <- make.unique(cn) + colnames(exp) <- cn + } + fdata <- makeAnnotated(t[, seq_len(ann.row + 1), with=FALSE]) diff --git a/tests/testthat/test-gct.R b/tests/testthat/test-gct.R index bf43576..66a2d1e 100644 --- a/tests/testthat/test-gct.R +++ b/tests/testthat/test-gct.R @@ -20,10 +20,14 @@ test_that("readGct works with gct #1.2", { expect_true(ncol(t) == 4) }) -test_that("readGct works with duplicate row names", { +test_that("readGct works with duplicate row or column names", { gctFile <- system.file("extdata/testdata/gct/test_dup.gct", package="phantasusLite") expect_warning(t <- readGct(gctFile), "duplicate") expect_true(!is.null(t)) + + gctFile <- system.file("extdata/testdata/gct/test_dupcol.gct", package="phantasusLite") + expect_warning(t <- readGct(gctFile), "duplicate") + expect_true(!is.null(t)) }) test_that("writeGct and readGct work", {