Hi Radek,
Radek Blatny <blatny at biomed.cas.cz> writes:
> Dear colleagues,
> I've just come across a problem with the following command which is a
> part of the "metaOverview.R" code file provided as an monography-
> accompanying file at
> http://www.bioconductor.org/docs/mogr/metadata:
The appropriate place to ask about Bioconductor packages (and the BCBS
monograph) is on the bioconductor list. I've cc'd the bioconductor
list, please send further replies or questions there.
> ##################################
> R> hasChr <- eapply(GOTERM, function(x)
> + x[grep("chromosome", Term(x))])
>
> Error in x[grep("chromosome", Term(x))] : object is not
subsettable
> ##################################
>
> I have run the command in the (PPC) Mac OS X R 2.4.1 and (AMD Ubuntu)
> Linux R 2.4.0 with the same result so it shouldn't be any
> distribution-dependent problem. Obviously the "metaOverview.R" is
not
> up-to-date since I had few problems before as well (e.g. that a
> function is in another package in BioC 1.9 etc.) but I was able to
> "repair" everything myself. However, this one I don't
understand.
> Anyone can help? Some classes have changed?!
You are correct that this code is out of date. The reason is actually
due to changes in R. Since R 2.4.0, S4 classes now have their own
internal type and do not act like lists. This is a very good thing,
but it means that some code that relied on it will break.
The elements of the GOTERM environment are instances of the "GOTerms"
class defined in the annotate package. So taking a look at the old
code:
hasChr <- eapply(GOTERM, function(x)
x[grep("chromosome", Term(x))])
This is looping over all GOTerms instances in the GOTERM environment
and calling grep on the term summary:
grep("chromosome", Term(x))
Since Term(x) returns a character vector of length one, if a match is
found the return value of grep will be 1. If no match is found it
will be integer(0) (a zero-length integer vector).
If x (the GOTerms instance) was a list, then we would have either x[1]
or x[integer(0)]. But since x is an S4 class with no "[" method
defined, you now get an error.
The code example is just trying to count the number of GO Terms that
have "chromosome" in their description. You can achieve this as
follows:
hasChr <- eapply(GOTERM, function(x)
length(grep("chromosome", Term(x))))
sum(unlist(hasChr))
+ seth
--
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org