getURL in annaffy fails when object length==1 (or how to cope with collapsed lists, arrays, etc?)
2
0
Entering edit mode
@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/
annaffy annaffy • 1.3k views
ADD COMMENT
0
Entering edit mode
@kasper-daniel-hansen-2979
Last seen 17 months ago
United States
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
ADD COMMENT
0
Entering edit mode
Florian Hahne ▴ 540
@florian-hahne-2471
Last seen 10.2 years ago
Dear Ana, you could use drop=FALSE when subsetting your matrix/ dataframe to pevent collapsing to vectors: mar[1:4,1,drop=FALSE] will retain the dimensions of the matrix Best Florian Florian Hahne Computational Biolology Group Fred Hutchinson Cancer Research Center, Seattle fhahne at fhrcr.org On 30.01.2008, at 13:27, "Ana Rodrigues" <arodrigues at="" salk.edu=""> 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]. > > 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
ADD COMMENT

Login before adding your answer.

Traffic: 911 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6