This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error subsetting gset

Hello every body, I am trying to subset data in an gset, but I am running into issue. Here's essentially what I'm attempting:

library(Biobase) 
library(GEOquery) 
library(limma)

dataset <- "GSE21942" 
platform <- "GPL570"

load series and platform data from GEO

gset <- getGEO(dataset, GSEMatrix =TRUE, AnnotGPL=TRUE, destdir ="../data/" )

if (length(gset) > 1) idx <- grep(platform, attr(gset, "names")) else idx <- 1 
gset <- gset[[idx]]

ex <- exprs(gset)

data normalization

ex <- log2(ex) 
ex <- normalizeQuantiles(ex)

sub-setting data

colnames(ex) <- c(paste("control", 1:15), paste("MS", 1:14)) 
ex <- ex[,!colnames(ex) %in% c("MS 10", "MS 11", "MS 13")] 
gr <- c(rep("control",15), rep("MS",11)) 
pData(gset) <- read.table("../source/phenod1.txt", header = T, sep="\t" )

exprs(gset) <- ex

After returning ex in to gset I encountered to this error:

Error in .validate_assayDataElementReplace(obj, value) : object and replacement value have different dimensions

I know that now my assayData is different from my pData How can I solve the problem?

r microarray

I use this command:

assayData <- assayData[,!colnames(gset) %in% c("GSM545842", "GSM545843", "GSM545845")]

which is has equal sample names of "MS 10", "MS 11", "MS 13" but this Error apear:

Error in assayData[, !colnames(gset) %in% c("GSM545842", "GSM545843",  : 
  object of type 'closure' is not subsettable

please kindly help me!

Try this:

assayData <- assayData[,-which(colnames(gset) %in% c("GSM545842", "GSM545843", "GSM545845"))]

Your other command should be:

ex <- ex[,-which(colnames(ex) %in% c("MS 10", "MS 11", "MS 13"))]

Hi thank you for your replay but this Error appear:

Error in assayData[, -which(colnames(gset) %in% c("GSM545842", "GSM545843", : object of type 'closure' is not subsettable

Dear Kevin, Before I updating my R and RStudio, I didn't have this problem. It means I subsetted ex and it automatically changed the other objects in the ExpressionSet and there was no difference in ex and assayData dimensions. But now, I don't know....why?

Why are you trying to filter the assayData object with the colnames from ex? You can just filter on the ex ExpressionSet object, an that will then automatically the other objects in the ExpressionSet object.

Your comments do not match up to your initial post...

Dear Kevin, Before I updating my R and RStudio, I didn't have this problem. It means I subsetted ex and it automatically changed the other objects in the ExpressionSet and there was no difference in ex and assayData dimensions. But now, I don't know....why?

Okay, yes, different things can change across different versions of R.

How are you creating / reading in the assayData object? Can you share all code related to assayData?

This is my code for reading assayData:

> sampleNames(assayData(gset))
 [1] "GSM545818" "GSM545819" "GSM545820" "GSM545821" "GSM545822" "GSM545823"
 [7] "GSM545824" "GSM545825" "GSM545826" "GSM545827" "GSM545828" "GSM545829"
[13] "GSM545830" "GSM545831" "GSM545832" "GSM545833" "GSM545834" "GSM545835"
[19] "GSM545836" "GSM545837" "GSM545838" "GSM545839" "GSM545840" "GSM545841"
[25] "GSM545842" "GSM545843" "GSM545844" "GSM545845" "GSM545846"

and this is colnames(ex) after subsitting:

> colnames(ex)
 [1] "control 1"  "control 2"  "control 3"  "control 4"  "control 5"  "control 6" 
 [7] "control 7"  "control 8"  "control 9"  "control 10" "control 11" "control 12"
[13] "control 13" "control 14" "control 15" "MS 1"       "MS 2"       "MS 3"      
[19] "MS 4"       "MS 5"       "MS 6"       "MS 7"       "MS 8"       "MS 9"      
[25] "MS 12"      "MS 14"

which is without MS 10, MS 11, MS 13.

I can not return ex to my gset:

> exprs(gset) <- ex
Error in .validate_assayDataElementReplace(obj, value) : 
  object and replacement value have different dimensions

Okay, so you could try:

assayData(gset)[,-which(colnames(assayData(gset)) %in% c("GSM545842", "GSM545843", "GSM545845"))]

I try that, unfortunately this error appears:

Error in assayData(gset)[, -which(colnames(assayData(gset)) %in% c("GSM545842",  : 
  object of type 'environment' is not subsettable

> str(assayData(gset))
<environment: 0x000000000f955b98>
> str(assayData(gset))
<environment: 0x000000000f955b98>

As I have limitation in comment insertion, I answer you by editing this comment

Dear Kevin, It don't work again!!!

exprs(gset) <- exprs(gset)[,-which(colnames(exprs(gset)) %in% c("GSM545842", "GSM545843", "GSM545845"))]
Error in .validate_assayDataElementReplace(obj, value) : 
  object and replacement value have different dimensions

assayData is just a reference to the expression values, which can be accessed with exprs()

Try this:

exprs(gset)[,-which(colnames(exprs(gset)) %in% c("GSM545842", "GSM545843", "GSM545845"))]

Also, why are you using this line: exprs(gset) <- ex ? That will cause a lot of issues.

Dear Kevin Thank you very much for your support and help, it finally worked in R version 3.1.2 instead of 3.4.3. Thanks a lot again!

1 answer

Dear Kevin Thank you very much for your support and help, all my first codes finally worked in R version 3.1.2 instead of 3.4.3. it seems that the R version is important for running my codes. Thanks a lot again!

Log in to answer this question.