Browse code

Fix "length > 1 in coercion to logical" bugs

Affected functions: getGOParents() and getGOChildren()

Hervé Pagès authored on 27/01/2020 02:04:47
Showing 2 changed files

... ...
@@ -1,6 +1,6 @@
1 1
 Package: annotate
2 2
 Title: Annotation for microarrays
3
-Version: 1.65.0
3
+Version: 1.65.1
4 4
 Author: R. Gentleman
5 5
 Description: Using R enviroments for annotation.
6 6
 Maintainer: Bioconductor Package Maintainer <maintainer@bioconductor.org>
... ...
@@ -87,25 +87,23 @@ hasGOannote <- function(x, which="MF") {
87 87
      if(length(x) == 0 )
88 88
          return(list())
89 89
      loadNamespace("GO.db")
90
-     hasMF <- mget(x, envir=GO.db::GOMFPARENTS, ifnotfound=NA)
91
-     hasBP <- mget(x, envir=GO.db::GOBPPARENTS, ifnotfound=NA)
92
-     hasCC <- mget(x, envir=GO.db::GOCCPARENTS, ifnotfound=NA)
93
-     lenx <- length(x)
94
-     rval <- vector("list", length=lenx)
95
-     names(rval) <- x
96
-     rval <- vector("list", length=lenx)
97
-     names(rval) <- x
98
-     for(i in 1:lenx) {
99
-         if( (length(hasMF[[i]]) > 1 ) || !is.na(hasMF[[i]]) )
100
-             rval[[i]] <- list(Ontology="MF", Parents=hasMF[[i]])
101
-         else if( (length(hasMF[[i]]) > 1 ) || !is.na(hasBP[[i]]) )
102
-             rval[[i]] <- list(Ontology="BP", Parents=hasBP[[i]])
103
-         else if( (length(hasMF[[i]]) > 1 ) || !is.na(hasCC[[i]]) )
104
-             rval[[i]] <- list(Ontology="CC", Parents=hasCC[[i]])
105
-         else
106
-             stop(paste(x[i], "is not a member of any ontology"))
107
-     }
108
-     return(rval)
90
+     MF_parents <- mget(x, envir=GO.db::GOMFPARENTS, ifnotfound=NA)
91
+     BP_parents <- mget(x, envir=GO.db::GOBPPARENTS, ifnotfound=NA)
92
+     CC_parents <- mget(x, envir=GO.db::GOCCPARENTS, ifnotfound=NA)
93
+     lapply(setNames(seq_along(x), x),
94
+         function(i) {
95
+             xi_parents <- MF_parents[[i]]
96
+             if (!identical(xi_parents, NA))
97
+                 return(list(Ontology="MF", Parents=xi_parents))
98
+             xi_parents <- BP_parents[[i]]
99
+             if (!identical(xi_parents, NA))
100
+                 return(list(Ontology="BP", Parents=xi_parents))
101
+             xi_parents <- CC_parents[[i]]
102
+             if (!identical(xi_parents, NA))
103
+                 return(list(Ontology="CC", Parents=xi_parents))
104
+             stop(paste(x[[i]], "is not a member of any ontology"))
105
+         }
106
+     )
109 107
  }
110 108
 
111 109
  getGOChildren <- function(x) {
... ...
@@ -114,23 +112,23 @@ hasGOannote <- function(x, which="MF") {
114 112
      if(length(x) == 0 )
115 113
          return(list())
116 114
      loadNamespace("GO.db")
117
-     hasMF <- mget(x, envir=GO.db::GOMFCHILDREN, ifnotfound=NA)
118
-     hasBP <- mget(x, envir=GO.db::GOBPCHILDREN, ifnotfound=NA)
119
-     hasCC <- mget(x, envir=GO.db::GOCCCHILDREN, ifnotfound=NA)
120
-     lenx <- length(x)
121
-     rval <- vector("list", length=lenx)
122
-     names(rval) <- x
123
-     for(i in 1:lenx) {
124
-         if( (length(hasMF[[i]]) > 1 ) || !is.na(hasMF[[i]]) )
125
-             rval[[i]] <- list(Ontology="MF", Children=hasMF[[i]])
126
-         else if( (length(hasMF[[i]]) > 1 ) || !is.na(hasBP[[i]]) )
127
-             rval[[i]] <- list(Ontology="BP", Children=hasBP[[i]])
128
-         else if( (length(hasMF[[i]]) > 1 ) || !is.na(hasCC[[i]]) )
129
-             rval[[i]] <- list(Ontology="CC", Children=hasCC[[i]])
130
-         else
131
-             rval[[i]] <- list()
132
-     }
133
-     return(rval)
115
+     MF_children <- mget(x, envir=GO.db::GOMFCHILDREN, ifnotfound=NA)
116
+     BP_children <- mget(x, envir=GO.db::GOBPCHILDREN, ifnotfound=NA)
117
+     CC_children <- mget(x, envir=GO.db::GOCCCHILDREN, ifnotfound=NA)
118
+     lapply(setNames(seq_along(x), x),
119
+         function(i) {
120
+             xi_children <- MF_children[[i]]
121
+             if (!identical(xi_children, NA))
122
+                 return(list(Ontology="MF", Children=xi_children))
123
+             xi_children <- BP_children[[i]]
124
+             if (!identical(xi_children, NA))
125
+                 return(list(Ontology="BP", Children=xi_children))
126
+             xi_children <- CC_children[[i]]
127
+             if (!identical(xi_children, NA))
128
+                 return(list(Ontology="CC", Children=xi_children))
129
+             list()  # not an error (unlike for getGOParents() above)
130
+         }
131
+     )
134 132
  }
135 133
 
136 134
  getGOTerm <- function(x) {