[BioC] getURL in annaffy fails when object length==1 (or how to cope with collapsed lists, arrays, etc?)

Kasper Daniel Hansen khansen at stat.Berkeley.EDU
Wed Jan 30 20:18:02 CET 2008


On Jan 30, 2008, at 10:27 AM, Ana Rodrigues wrote:

> Dear gurus,
> I have recently hit upon the following problem whilst using the getURL
> method of the annaffy package:
>
> The method works fine when my aafGO object is of length > 1:
>
>> ann.affy.go[[4]]
> An object of class "aafGO"
> [[1]]
> An object of class "aafGOItem"
> @id   "GO:0000139"
> @name "Golgi membrane"
> @type "Cellular Component"
> @evid "IEA"
>
> [[2]]
> An object of class "aafGOItem"
> @id   "GO:0003827"
> @name "alpha-1,3-mannosylglycoprotein
> 2-beta-N-acetylglucosaminyltransferase activity"
> @type "Molecular Function"
> @evid "IEA"
>
> [[3]]
> An object of class "aafGOItem"
> @id   "GO:0006487"
> @name "protein amino acid N-linked glycosylation"
> @type "Biological Process"
> @evid "IEA"
>
>> getURL(ann.affy.go[[4]])
> [1] "http://amigo.geneontology.org/cgi-bin/amigo/go.cgi? 
> view=query&query=GO:0000139%0aGO:0003827%0aGO:0006487"
>
>
> The problem arises when using aafGO objects of length==1:
>
>> ann.affy.go[[37]]
> An object of class "aafGO"
> [[1]]
> An object of class "aafGOItem"
> @id   "GO:0016787"
> @name "hydrolase activity"
> @type "Molecular Function"
> @evid "IEA"
>
>> getURL(ann.affy.go[[37]])
> Error in object[[i]] : subscript out of bounds
>
> This is easily solved by checking length(ann.affy.go[[x]]) and further
> sub-setting the object:
>
>> getURL(ann.affy.go[[37]][[1]])
> [1] "http://amigo.geneontology.org/cgi-bin/amigo/go.cgi? 
> view=details&query=GO:0016787"
>
>
> What I am wondering, is if there is a better way to cope with these  
> situations.
>
> This seems to be something that I come across over and over again when
> writing R code.
> Accessing elements of a matrix which changes within some for loop,
> always involves some fumbling to check that the matrix has not
> collapsed into a vector, that can no longer be accessed using
> mat[3,1], since for that instance the data is now vec[3].

For this problem you can use matrix subsetting like
   [,,drop = FALSE]
which will always return a vector, say
   tmp = matrix(1:9,3,3)
   tmp[1,]  # a vector
   tmp[1,,drop = false]  # a 1x3 matrix

Kasper


> Do people have a standard way to cope with such situations?
> Thank you in advance,
> Ana
>
> -- 
> Ana P. C. Rodrigues, Ph.D.
> Salk Institute for Biological Studies
> T +1 858.453.4100 x1983
> W bioinformatics.salk.edu/people/ana/
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/ 
> gmane.science.biology.informatics.conductor



More information about the Bioconductor mailing list