Search code examples
rloopsmetadatabioconductorncbi

Using Meta() function with variable in loop: Error unable to find an inherited method for function?


I'm trying to extract a single value from the meta data of a GSM .soft file. I can do this without error by using Meta(GSM971958)$characteristics_ch1[3], but I get an error when trying to run this same type of command with a variable via a loop. I don't understand why the former works fine, but the latter doesn't.

Here's my full code with the error message:

library(Biobase)
library(GEOquery)

for (i in 971958:972456){
  GSMName <- paste("GSM", i, sep = "") 

  if(Meta(GSMName)$characteristics_ch1[1]!="dataset: discovery"){
    next
  }
  print(Meta(GSMName)$characteristics_ch1[3])
}


     ##Error in (function (classes, fdef, mtable)  : 
          unable to find an inherited method for function ‘Meta’ for signature ‘"character"’

Solution

  • I needed to pass back through getGEO() even though I hard already imported the data:

    library(Biobase)
    library(GEOquery)
    
    for (i in 971958:972456){
      GSMName <- paste("GSM", i, sep = "") 
      GSM <- getGEO(GSMName, destdir=".")
      if(Meta(GSM)$characteristics_ch1[1]!="dataset: discovery"){
        next
      }
      print(Meta(GSM)$characteristics_ch1[3])
    }