Skip to content

Commit

Permalink
readGct correctly handles case with no column annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
assaron committed Aug 28, 2024
1 parent eb17a1d commit f45afaf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 4 additions & 5 deletions R/gct.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ readGct <- function(gct) {
rownames(fdata) <- rn


if (ann.col > 0) {
# parse pData
{
pdata.raw <- t(fread(gct, skip = 2, nrows = ann.col + 1, header=FALSE,
colClasses = "character"))
pdata <- data.frame(pdata.raw[seq_len(ncol(exp)) + 1 + ann.row,],
Expand All @@ -80,9 +81,7 @@ readGct <- function(gct) {
pdata <- makeAnnotated(pdata)

res <- ExpressionSet(exp, featureData = fdata, phenoData = pdata)
} else {
res <- ExpressionSet(exp, featureData = fdata)
}
}

res
}
Expand Down Expand Up @@ -117,7 +116,7 @@ writeGct <- function(es, file, gzip=FALSE) {
nrow(es), ncol(es),
ann.row-1, ann.col-1), con)

if (ann.col == 0 && ann.row == 0) {
if (ann.col == 0 || ann.row == 0) {
stop("There should be at least one row and one column annotation")
}

Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-gct.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ test_that("writeGct and readGct support id column names", {
expect_identical(pData(es), pData(es2))
})

test_that("readGct support emptry annotations", {
gctFile <- system.file("extdata/testdata/gct/centers.gct", package="phantasusLite")
es <- readGct(gctFile)
expect_true(ncol(fData(es)) >= 1)
expect_true(ncol(pData(es)) >= 1)
})

test_that("readGct column indexing works with GSE141540.gct file", {
gctFile <- system.file("extdata/testdata/gct/GSE141540.gct", package="phantasusLite")
Expand Down

0 comments on commit f45afaf

Please sign in to comment.