Entering edit mode
Ana Rodrigues
▴
30
@ana-rodrigues-2623
Last seen 10.2 years ago
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&que
ry=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].
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/