Browse code

Update HVG PCA UMAP cluster UI

Yichen Wang authored on 23/05/2022 18:48:24
Showing1 changed files
... ...
@@ -82,17 +82,21 @@ runEnrichR <- function(inSCE,
82 82
       stop("Invalid featureName specification.")
83 83
     }
84 84
   }
85
-  
86 85
   internetConnection <- suppressWarnings(Biobase::testBioCConnection())
87 86
   #check for internet connection
88 87
   if (!internetConnection){
89 88
     stop("Please connect to the Internet and continue..")
90 89
   }
91
-  options(enrichR.base.address = "https://maayanlab.cloud/Enrichr/")
92
-  options(enrichR.live = TRUE)
90
+  err <- tryCatch(
91
+    {
92
+      attachNamespace("enrichR")
93
+    },
94
+    error = function(e) {}
95
+  )
96
+  #options(enrichR.base.address = "https://maayanlab.cloud/Enrichr/")
97
+  #options(enrichR.live = TRUE)
93 98
   temp_db <- enrichR::listEnrichrDbs()
94 99
   enrdb <- temp_db$libraryName
95
-  
96 100
   #test for db existing
97 101
   if (is.null(db)){
98 102
     db <- enrdb
Browse code

Refactor EnrichR UI

Yichen Wang authored on 22/04/2022 03:18:06
Showing1 changed files
... ...
@@ -10,13 +10,13 @@
10 10
 #' \code{features} do not have a match in \code{rownames(inSCE)}, users may 
11 11
 #' try to specify \code{by} to pass the check. 
12 12
 #' 
13
-#' EnrichR expects gene symbols/names as the input (i.e. Ensembl or entrez ID 
14
-#' might not work). When specified \code{features} are not qualified for this, 
15
-#' users may try to specify \code{featureName} to change the identifier type to
16
-#' pass to EnrichR. 
13
+#' EnrichR expects gene symbols/names as the input (i.e. Ensembl ID might not 
14
+#' work). When specified \code{features} are not qualified for this, users may 
15
+#' try to specify \code{featureName} to change the identifier type to pass to 
16
+#' EnrichR. 
17 17
 #' @param inSCE A \linkS4class{SingleCellExperiment} object.
18 18
 #' @param features Character vector, selected genes for enrichment analysis. 
19
-#' @param analysisName A string that identifies each specific analysis
19
+#' @param analysisName A string that identifies each specific analysis.
20 20
 #' @param db Character vector. Selected database name(s) from the enrichR 
21 21
 #' database list. If \code{NULL} then EnrichR will be run on all the available 
22 22
 #' databases on the enrichR database. See details. Default \code{NULL}
... ...
@@ -49,6 +49,9 @@ runEnrichR <- function(inSCE,
49 49
   if (!inherits(inSCE, "SingleCellExperiment")) {
50 50
     stop("inSCE has to inherit from SingleCellExperiment object.")
51 51
   }
52
+  if (is.null(analysisName)) {
53
+    stop("Have to specify analysisName.")
54
+  }
52 55
   if (by == "rownames") {
53 56
     if (!all(features %in% rownames(inSCE))) {
54 57
       stop("Not all features found in `rownames(inSCE)`.")
... ...
@@ -141,12 +144,12 @@ runEnrichR <- function(inSCE,
141 144
 #'   result <- getEnrichRResult(mouseBrainSubsetSCE, "analysis1")
142 145
 #' }
143 146
 setGeneric("getEnrichRResult<-", function(inSCE, analysisName, value) 
144
-  standardGeneric("getEnrichRResult<-") )
147
+  standardGeneric("getEnrichRResult<-"))
145 148
 
146 149
 #' @rdname getEnrichRResult
147 150
 #' @export
148 151
 setGeneric("getEnrichRResult", function(inSCE, analysisName) 
149
-  standardGeneric("getEnrichRResult") )
152
+  standardGeneric("getEnrichRResult"))
150 153
 
151 154
 #' @rdname getEnrichRResult
152 155
 #' @export
... ...
@@ -168,6 +171,9 @@ setMethod("getEnrichRResult",
168 171
 setReplaceMethod("getEnrichRResult", 
169 172
                  c("SingleCellExperiment"), 
170 173
                  function(inSCE, analysisName, value) {
174
+                   if (is.null(analysisName)) {
175
+                     stop("Have to specify analysisName.")
176
+                   }
171 177
                    S4Vectors::metadata(inSCE)$sctk$runEnrichR[[analysisName]] <- value
172 178
                    return(inSCE)
173 179
                  })
Browse code

Refine runEnrichR & add unit tests

Yichen Wang authored on 20/04/2022 22:46:07
Showing1 changed files
... ...
@@ -1,50 +1,83 @@
1 1
 #' Run EnrichR on SCE object
2 2
 #' @details 
3
-#' The list of gene to be analyzed could be specified in two ways. 
4
-#' Either by directly passing a character vector to \code{glist} and leave 
5
-#' \code{geneSetCollectionName} and \code{geneSetName} as \code{NULL}, or by 
6
-#' specifying the latter two arguments and leave \code{glist} as \code{NULL}.
3
+#' EnrichR works by querying the specified \code{features} to its online 
4
+#' databases, thus it requires the Internet connection. 
7 5
 #' 
8 6
 #' Available \code{db} options could be shown by running 
9 7
 #' \code{enrichR::listEnrichrDbs()$libraryName}
8
+#' 
9
+#' This function checks for the existence of features in the SCE object. When 
10
+#' \code{features} do not have a match in \code{rownames(inSCE)}, users may 
11
+#' try to specify \code{by} to pass the check. 
12
+#' 
13
+#' EnrichR expects gene symbols/names as the input (i.e. Ensembl or entrez ID 
14
+#' might not work). When specified \code{features} are not qualified for this, 
15
+#' users may try to specify \code{featureName} to change the identifier type to
16
+#' pass to EnrichR. 
10 17
 #' @param inSCE A \linkS4class{SingleCellExperiment} object.
11
-#' @param glist Character vector, selected genes for enrichment analysis using. 
12
-#' Default \code{NULL}.
13
-#' @param geneSetCollectionName Character. The name of an imported geneset 
14
-#' collection. Default \code{NULL}.
15
-#' @param geneSetName Character. The name of a geneset that should be found in 
16
-#' the geneset collection specified by \code{geneSetCollectionName}. Default 
17
-#' \code{NULL}. 
18
+#' @param features Character vector, selected genes for enrichment analysis. 
19
+#' @param analysisName A string that identifies each specific analysis
18 20
 #' @param db Character vector. Selected database name(s) from the enrichR 
19
-#' database list. If \code{NULL} then enrichR will be run on all the available 
20
-#' databases on the enrichR database. Default \code{NULL}
21
+#' database list. If \code{NULL} then EnrichR will be run on all the available 
22
+#' databases on the enrichR database. See details. Default \code{NULL}
23
+#' @param by Character. From where should we find the \code{features}? 
24
+#' \code{"rownames"} for from \code{rownames(inSCE)}, otherwise, from a column
25
+#' of feature metadata (\code{rowData(inSCE)[[by]]}). See details. Default 
26
+#' \code{"rownames"}.
27
+#' @param featureName Character. Indicates the actual feature identifiers to be
28
+#' passed to EnrichR. Can be \code{"rownames"}, a column in feature metadata 
29
+#' (\code{rowData(inSCE)[[featureName]]}), or a character vector with its length
30
+#' equals to \code{nrow(inSCE)}. See details. Default \code{"rownames"}.
21 31
 #' @return Updates \code{inSCE} metadata with a data.frame of enrichment terms 
22 32
 #' overlapping in the respective databases along with p-values, z-scores etc.
23 33
 #' @export
24 34
 #' @seealso \code{\link{getEnrichRResult}}
25 35
 #' @examples
26 36
 #' data("mouseBrainSubsetSCE")
27
-#' mouseBrainSubsetSCE <- runEnrichR(mouseBrainSubsetSCE, glist = "Cmtm5", 
28
-#'                                   db = "GO_Cellular_Component_2017")
37
+#' if (Biobase::testBioCConnection()) {
38
+#'   mouseBrainSubsetSCE <- runEnrichR(mouseBrainSubsetSCE, features = "Cmtm5", 
39
+#'                                     db = "GO_Cellular_Component_2017",
40
+#'                                     analysisName = "analysis1")
41
+#' }
42
+#' 
29 43
 runEnrichR <- function(inSCE, 
30
-                       glist=NULL,
31
-                       geneSetCollectionName=NULL, 
32
-                       geneSetName=NULL, 
33
-                       db = NULL) {
44
+                       features,
45
+                       analysisName,
46
+                       db = NULL,
47
+                       by = "rownames",
48
+                       featureName = NULL) {
34 49
   if (!inherits(inSCE, "SingleCellExperiment")) {
35 50
     stop("inSCE has to inherit from SingleCellExperiment object.")
36 51
   }
37
-  if (is.null(glist)) {
38
-    if (is.null(geneSetCollectionName) | is.null(geneSetName)) {
39
-      stop("Either `glist` or {`geneSetCollectionName` and `geneSetName`} ",
40
-           "should be specified.")
52
+  if (by == "rownames") {
53
+    if (!all(features %in% rownames(inSCE))) {
54
+      stop("Not all features found in `rownames(inSCE)`.")
41 55
     }
42
-    gsc <- .getGeneSetCollection(inSCE, geneSetCollectionName)
43
-    if (!geneSetName %in% names(gsc)) {
44
-      stop("Specified `geneSetName` not found in given `geneSetCollectionName`")
56
+    allFeatures <- rownames(inSCE)
57
+  } else {
58
+    if (!by %in% names(SummarizedExperiment::rowData(inSCE))) {
59
+      stop("`by` not found in rowData(inSCE).")
60
+    }
61
+    if (!all(features %in% SummarizedExperiment::rowData(inSCE)[[by]])) {
62
+      stop("Not all features found in `rowData(inSCE)$",by,"`.")
63
+    }
64
+    allFeatures <- SummarizedExperiment::rowData(inSCE)[[by]]
65
+  }
66
+  if (!is.null(featureName)) {
67
+    featureIdx <- allFeatures %in% features
68
+    if (length(featureName) == 1) {
69
+      if (featureName == "rownames") {
70
+        features <- rownames(inSCE)[featureIdx]
71
+      } else if (featureName %in% names(SummarizedExperiment::rowData(inSCE))) {
72
+        features <- SummarizedExperiment::rowData(inSCE[featureIdx,])[[featureName]]
73
+      } else {
74
+        stop("featureName not found in `rowData(inSCE)`.")
75
+      }
76
+    } else if (length(featureName) == nrow(inSCE)) {
77
+      features <- featureName[featureIdx]
78
+    } else {
79
+      stop("Invalid featureName specification.")
45 80
     }
46
-    gs <- gsc[[geneSetName]]
47
-    glist <- gs@geneIds
48 81
   }
49 82
   
50 83
   internetConnection <- suppressWarnings(Biobase::testBioCConnection())
... ...
@@ -65,7 +98,7 @@ runEnrichR <- function(inSCE,
65 98
     stop("database ", paste(db.notFound, collapse = ", "), " do not exist.")
66 99
   }
67 100
   
68
-  enriched <- enrichR::enrichr(glist, db)
101
+  enriched <- enrichR::enrichr(features, db)
69 102
   enriched <- data.frame(data.table::rbindlist(enriched, use.names = TRUE,
70 103
                                                fill = TRUE,
71 104
                                                idcol = "Database_selected"))
... ...
@@ -81,13 +114,19 @@ runEnrichR <- function(inSCE,
81 114
   #nums <- vapply(enriched, is.numeric, FUN.VALUE = logical(1))
82 115
   #enriched[, nums] <- round(enriched[, nums], digits = 7)
83 116
   
84
-  getEnrichRResult(inSCE) <- enriched
117
+  getEnrichRResult(inSCE, analysisName) <- list(result = enriched,
118
+                                                param = list(
119
+                                                  features = features,
120
+                                                  by = by,
121
+                                                  db = db
122
+                                                )) 
85 123
   return(inSCE)
86 124
 }
87 125
 
88 126
 #' @title Get or Set EnrichR Result
89 127
 #' @rdname getEnrichRResult
90 128
 #' @param inSCE A \linkS4class{SingleCellExperiment} object.
129
+#' @param analysisName A string that identifies each specific analysis
91 130
 #' @param value The EnrichR result table
92 131
 #' @return For getter method, a data.frame of the EnrichR result;
93 132
 #' For setter method, \code{inSCE} with EnrichR results updated.
... ...
@@ -95,30 +134,40 @@ runEnrichR <- function(inSCE,
95 134
 #' @seealso \code{\link{runEnrichR}}
96 135
 #' @examples 
97 136
 #' data("mouseBrainSubsetSCE")
98
-#' mouseBrainSubsetSCE <- runEnrichR(mouseBrainSubsetSCE, glist = "Cmtm5", 
99
-#'                                   db = "GO_Cellular_Component_2017")
100
-#' result <- getEnrichRResult(mouseBrainSubsetSCE)
101
-setGeneric("getEnrichRResult<-", function(inSCE, value) 
137
+#' if (Biobase::testBioCConnection()) {
138
+#'   mouseBrainSubsetSCE <- runEnrichR(mouseBrainSubsetSCE, features = "Cmtm5", 
139
+#'                                     db = "GO_Cellular_Component_2017",
140
+#'                                     analysisName = "analysis1")
141
+#'   result <- getEnrichRResult(mouseBrainSubsetSCE, "analysis1")
142
+#' }
143
+setGeneric("getEnrichRResult<-", function(inSCE, analysisName, value) 
102 144
   standardGeneric("getEnrichRResult<-") )
103 145
 
104 146
 #' @rdname getEnrichRResult
105 147
 #' @export
106
-setGeneric("getEnrichRResult", function(inSCE) 
148
+setGeneric("getEnrichRResult", function(inSCE, analysisName) 
107 149
   standardGeneric("getEnrichRResult") )
108 150
 
109 151
 #' @rdname getEnrichRResult
110 152
 #' @export
111 153
 setMethod("getEnrichRResult", 
112 154
           "SingleCellExperiment", 
113
-          function(inSCE){
114
-            return(S4Vectors::metadata(sce)$sctk$runEnrichR)
155
+          function(inSCE, analysisName){
156
+            if (!"runEnrichR" %in% names(S4Vectors::metadata(inSCE)$sctk)) {
157
+              stop("EnrichR analysis not performed yet. ",
158
+                   "Please run `runEnrichR()`")
159
+            }
160
+            if (!analysisName %in% names(S4Vectors::metadata(inSCE)$sctk$runEnrichR)) {
161
+              stop('"', analysisName, '" not found in EnrichR analysis names.')
162
+            }
163
+            return(S4Vectors::metadata(inSCE)$sctk$runEnrichR[[analysisName]])
115 164
           })
116 165
 
117 166
 #' @rdname getEnrichRResult
118 167
 #' @export
119 168
 setReplaceMethod("getEnrichRResult", 
120 169
                  c("SingleCellExperiment"), 
121
-                 function(inSCE, value) {
122
-                   S4Vectors::metadata(sce)$sctk$runEnrichR <- value
170
+                 function(inSCE, analysisName, value) {
171
+                   S4Vectors::metadata(inSCE)$sctk$runEnrichR[[analysisName]] <- value
123 172
                    return(inSCE)
124
-                 })
125 173
\ No newline at end of file
174
+                 })
Browse code

Refactored enrichR wrapper

Yichen Wang authored on 20/04/2022 20:08:32
Showing1 changed files
... ...
@@ -1,19 +1,52 @@
1
-#' enrichR
2
-#' Given a list of genes this function runs the enrichR() to perform Gene
3
-#' enrichment
4
-#'
5
-#' @param inSCE Input \linkS4class{SingleCellExperiment} object.
6
-#' @param glist selected genes for enrichment analysis using enrichR(). Required
7
-#' @param db selected database name from the enrichR database list. if NULL then
8
-#' enrichR will be run on all the available databases on the enrichR database.
9
-#'
10
-#' @return enrichRSCE(): returns a data.frame of enrichment terms overlapping in
11
-#' the respective databases along with p-values, z-scores etc.,
1
+#' Run EnrichR on SCE object
2
+#' @details 
3
+#' The list of gene to be analyzed could be specified in two ways. 
4
+#' Either by directly passing a character vector to \code{glist} and leave 
5
+#' \code{geneSetCollectionName} and \code{geneSetName} as \code{NULL}, or by 
6
+#' specifying the latter two arguments and leave \code{glist} as \code{NULL}.
7
+#' 
8
+#' Available \code{db} options could be shown by running 
9
+#' \code{enrichR::listEnrichrDbs()$libraryName}
10
+#' @param inSCE A \linkS4class{SingleCellExperiment} object.
11
+#' @param glist Character vector, selected genes for enrichment analysis using. 
12
+#' Default \code{NULL}.
13
+#' @param geneSetCollectionName Character. The name of an imported geneset 
14
+#' collection. Default \code{NULL}.
15
+#' @param geneSetName Character. The name of a geneset that should be found in 
16
+#' the geneset collection specified by \code{geneSetCollectionName}. Default 
17
+#' \code{NULL}. 
18
+#' @param db Character vector. Selected database name(s) from the enrichR 
19
+#' database list. If \code{NULL} then enrichR will be run on all the available 
20
+#' databases on the enrichR database. Default \code{NULL}
21
+#' @return Updates \code{inSCE} metadata with a data.frame of enrichment terms 
22
+#' overlapping in the respective databases along with p-values, z-scores etc.
12 23
 #' @export
24
+#' @seealso \code{\link{getEnrichRResult}}
13 25
 #' @examples
14 26
 #' data("mouseBrainSubsetSCE")
15
-#' enrichRSCE(mouseBrainSubsetSCE, "Cmtm5", "GO_Cellular_Component_2017")
16
-enrichRSCE <- function(inSCE, glist, db = NULL){
27
+#' mouseBrainSubsetSCE <- runEnrichR(mouseBrainSubsetSCE, glist = "Cmtm5", 
28
+#'                                   db = "GO_Cellular_Component_2017")
29
+runEnrichR <- function(inSCE, 
30
+                       glist=NULL,
31
+                       geneSetCollectionName=NULL, 
32
+                       geneSetName=NULL, 
33
+                       db = NULL) {
34
+  if (!inherits(inSCE, "SingleCellExperiment")) {
35
+    stop("inSCE has to inherit from SingleCellExperiment object.")
36
+  }
37
+  if (is.null(glist)) {
38
+    if (is.null(geneSetCollectionName) | is.null(geneSetName)) {
39
+      stop("Either `glist` or {`geneSetCollectionName` and `geneSetName`} ",
40
+           "should be specified.")
41
+    }
42
+    gsc <- .getGeneSetCollection(inSCE, geneSetCollectionName)
43
+    if (!geneSetName %in% names(gsc)) {
44
+      stop("Specified `geneSetName` not found in given `geneSetCollectionName`")
45
+    }
46
+    gs <- gsc[[geneSetName]]
47
+    glist <- gs@geneIds
48
+  }
49
+  
17 50
   internetConnection <- suppressWarnings(Biobase::testBioCConnection())
18 51
   #check for internet connection
19 52
   if (!internetConnection){
... ...
@@ -21,43 +54,71 @@ enrichRSCE <- function(inSCE, glist, db = NULL){
21 54
   }
22 55
   options(enrichR.base.address = "https://maayanlab.cloud/Enrichr/")
23 56
   options(enrichR.live = TRUE)
24
-  enrdb <- enrichR::listEnrichrDbs()$libraryName
25
-
26
-  if (!inherits(inSCE, "SingleCellExperiment")){
27
-    stop("Please use a SingleCellExperiment object")
28
-  }
29
-
30
-  #test for gene list existing
31
-  if (!all(glist %in% rownames(inSCE))){
32
-    stop("Gene in gene list not found in input object.")
33
-  }
34
-
57
+  temp_db <- enrichR::listEnrichrDbs()
58
+  enrdb <- temp_db$libraryName
59
+  
35 60
   #test for db existing
36
-  if (!all(db %in% enrdb)){
37
-    stop("database '", db, "' does not exist.")
61
+  if (is.null(db)){
62
+    db <- enrdb
63
+  } else if (!all(db %in% enrdb)){
64
+    db.notFound <- db[!db %in% enrdb]
65
+    stop("database ", paste(db.notFound, collapse = ", "), " do not exist.")
38 66
   }
67
+  
68
+  enriched <- enrichR::enrichr(glist, db)
69
+  enriched <- data.frame(data.table::rbindlist(enriched, use.names = TRUE,
70
+                                               fill = TRUE,
71
+                                               idcol = "Database_selected"))
72
+  
73
+  enriched$link <- vapply(enriched$Database_selected, function(x){
74
+    temp_db$link[temp_db$libraryName %in% x]
75
+  }, FUN.VALUE = character(1))
76
+  
77
+  #sort the results based on p-values
78
+  enriched <- enriched[order(enriched$P.value, decreasing = FALSE), ]
79
+  
80
+  #round the numeric values to their 7th digit
81
+  #nums <- vapply(enriched, is.numeric, FUN.VALUE = logical(1))
82
+  #enriched[, nums] <- round(enriched[, nums], digits = 7)
83
+  
84
+  getEnrichRResult(inSCE) <- enriched
85
+  return(inSCE)
86
+}
39 87
 
40
-  if (is.null(glist)){
41
-    stop("Please provide a gene list.")
42
-  } else {
43
-    if (is.null(db)){
44
-      db <- enrdb
45
-    }
46
-    enriched <- enrichR::enrichr(glist, db)
47
-    enriched <- data.frame(data.table::rbindlist(enriched, use.names = TRUE,
48
-                                                 fill = TRUE,
49
-                                                 idcol = "Database_selected"))
50
-    temp_db <- enrichR::listEnrichrDbs()
51
-    enriched$link <- vapply(enriched$Database_selected, function(x){
52
-      temp_db$link[which(temp_db$libraryName %in% x)]
53
-    }, FUN.VALUE = character(1))
88
+#' @title Get or Set EnrichR Result
89
+#' @rdname getEnrichRResult
90
+#' @param inSCE A \linkS4class{SingleCellExperiment} object.
91
+#' @param value The EnrichR result table
92
+#' @return For getter method, a data.frame of the EnrichR result;
93
+#' For setter method, \code{inSCE} with EnrichR results updated.
94
+#' @export
95
+#' @seealso \code{\link{runEnrichR}}
96
+#' @examples 
97
+#' data("mouseBrainSubsetSCE")
98
+#' mouseBrainSubsetSCE <- runEnrichR(mouseBrainSubsetSCE, glist = "Cmtm5", 
99
+#'                                   db = "GO_Cellular_Component_2017")
100
+#' result <- getEnrichRResult(mouseBrainSubsetSCE)
101
+setGeneric("getEnrichRResult<-", function(inSCE, value) 
102
+  standardGeneric("getEnrichRResult<-") )
54 103
 
55
-    #sort the results based on p-values
56
-    enriched <- enriched[base::order(enriched$P.value, decreasing = FALSE), ]
104
+#' @rdname getEnrichRResult
105
+#' @export
106
+setGeneric("getEnrichRResult", function(inSCE) 
107
+  standardGeneric("getEnrichRResult") )
57 108
 
58
-    #round the numeric values to their 7th digit
59
-    nums <- vapply(enriched, is.numeric, FUN.VALUE = logical(1))
60
-      enriched[, nums] <- base::round(enriched[, nums], digits = 7)
61
-  }
62
-  return(enriched)
63
-}
109
+#' @rdname getEnrichRResult
110
+#' @export
111
+setMethod("getEnrichRResult", 
112
+          "SingleCellExperiment", 
113
+          function(inSCE){
114
+            return(S4Vectors::metadata(sce)$sctk$runEnrichR)
115
+          })
116
+
117
+#' @rdname getEnrichRResult
118
+#' @export
119
+setReplaceMethod("getEnrichRResult", 
120
+                 c("SingleCellExperiment"), 
121
+                 function(inSCE, value) {
122
+                   S4Vectors::metadata(sce)$sctk$runEnrichR <- value
123
+                   return(inSCE)
124
+                 })
64 125
\ No newline at end of file
Browse code

Fixed R CMD check issues

Irzam Sarfraz authored on 20/12/2021 22:24:01
Showing1 changed files
... ...
@@ -11,6 +11,7 @@
11 11
 #' the respective databases along with p-values, z-scores etc.,
12 12
 #' @export
13 13
 #' @examples
14
+#' data("mouseBrainSubsetSCE")
14 15
 #' enrichRSCE(mouseBrainSubsetSCE, "Cmtm5", "GO_Cellular_Component_2017")
15 16
 enrichRSCE <- function(inSCE, glist, db = NULL){
16 17
   internetConnection <- suppressWarnings(Biobase::testBioCConnection())
Browse code

Fixed enrichR connection error

Yichen Wang authored on 11/05/2021 21:00:31
Showing1 changed files
... ...
@@ -11,16 +11,15 @@
11 11
 #' the respective databases along with p-values, z-scores etc.,
12 12
 #' @export
13 13
 #' @examples
14
-#' \dontrun{
15 14
 #' enrichRSCE(mouseBrainSubsetSCE, "Cmtm5", "GO_Cellular_Component_2017")
16
-#' }
17 15
 enrichRSCE <- function(inSCE, glist, db = NULL){
18 16
   internetConnection <- suppressWarnings(Biobase::testBioCConnection())
19 17
   #check for internet connection
20 18
   if (!internetConnection){
21 19
     stop("Please connect to the Internet and continue..")
22 20
   }
23
-
21
+  options(enrichR.base.address = "https://maayanlab.cloud/Enrichr/")
22
+  options(enrichR.live = TRUE)
24 23
   enrdb <- enrichR::listEnrichrDbs()$libraryName
25 24
 
26 25
   if (!inherits(inSCE, "SingleCellExperiment")){
Browse code

Example fixes

Yichen Wang authored on 11/05/2021 03:19:03
Showing1 changed files
... ...
@@ -11,7 +11,7 @@
11 11
 #' the respective databases along with p-values, z-scores etc.,
12 12
 #' @export
13 13
 #' @examples
14
-#' \donttest{
14
+#' \dontrun{
15 15
 #' enrichRSCE(mouseBrainSubsetSCE, "Cmtm5", "GO_Cellular_Component_2017")
16 16
 #' }
17 17
 enrichRSCE <- function(inSCE, glist, db = NULL){
Browse code

local BiocCheck error fix

Yichen Wang authored on 10/05/2021 22:58:10
Showing1 changed files
... ...
@@ -11,7 +11,7 @@
11 11
 #' the respective databases along with p-values, z-scores etc.,
12 12
 #' @export
13 13
 #' @examples
14
-#' \dontrun{
14
+#' \donttest{
15 15
 #' enrichRSCE(mouseBrainSubsetSCE, "Cmtm5", "GO_Cellular_Component_2017")
16 16
 #' }
17 17
 enrichRSCE <- function(inSCE, glist, db = NULL){
Browse code

Removed SCtkExperiment class and methods. Removed all references in the documentation

Joshua D. Campbell authored on 02/07/2020 04:10:40
Showing1 changed files
... ...
@@ -2,7 +2,7 @@
2 2
 #' Given a list of genes this function runs the enrichR() to perform Gene
3 3
 #' enrichment
4 4
 #'
5
-#' @param inSCE Input SCtkExperiment object. Required
5
+#' @param inSCE Input \linkS4class{SingleCellExperiment} object.
6 6
 #' @param glist selected genes for enrichment analysis using enrichR(). Required
7 7
 #' @param db selected database name from the enrichR database list. if NULL then
8 8
 #' enrichR will be run on all the available databases on the enrichR database.
... ...
@@ -23,9 +23,8 @@ enrichRSCE <- function(inSCE, glist, db = NULL){
23 23
 
24 24
   enrdb <- enrichR::listEnrichrDbs()$libraryName
25 25
 
26
-  if (!(class(inSCE) == "SingleCellExperiment" |
27
-        class(inSCE) == "SCtkExperiment")){
28
-    stop("Please use a singleCellTK or a SCtkExperiment object")
26
+  if (!inherits(inSCE, "SingleCellExperiment")){
27
+    stop("Please use a SingleCellExperiment object")
29 28
   }
30 29
 
31 30
   #test for gene list existing
Browse code

Don't run enrichr example because website is unstable

David Jenkins authored on 03/08/2019 20:13:19
Showing1 changed files
... ...
@@ -11,7 +11,9 @@
11 11
 #' the respective databases along with p-values, z-scores etc.,
12 12
 #' @export
13 13
 #' @examples
14
+#' \dontrun{
14 15
 #' enrichRSCE(mouseBrainSubsetSCE, "Cmtm5", "GO_Cellular_Component_2017")
16
+#' }
15 17
 enrichRSCE <- function(inSCE, glist, db = NULL){
16 18
   internetConnection <- suppressWarnings(Biobase::testBioCConnection())
17 19
   #check for internet connection
Browse code

Updates to diffex tab

David Jenkins authored on 09/10/2018 01:57:13
Showing0 changed files
Browse code

Changes to visualize tab, reordering and extra functionalities for saving diffex results analysed in the active sessionbut working on pulling results saved from previous sessions, biomarker genes input into enrichR and GSVA

Mohammed Muzamil Khan authored on 08/10/2018 23:14:34
Showing1 changed files
... ...
@@ -3,19 +3,19 @@
3 3
 #' enrichment
4 4
 #'
5 5
 #' @param inSCE Input SCtkExperiment object. Required
6
-#' @param useAssay The assay to use in the enrichment analysis. Required
7 6
 #' @param glist selected genes for enrichment analysis using enrichR(). Required
8
-#' @param db selected database name from the enrichR database list.
7
+#' @param db selected database name from the enrichR database list. if NULL then
8
+#' enrichR will be run on all the available databases on the enrichR database.
9 9
 #'
10 10
 #' @return enrichRSCE(): returns a data.frame of enrichment terms overlapping in
11 11
 #' the respective databases along with p-values, z-scores etc.,
12 12
 #' @export
13 13
 #'
14 14
 #' @examples
15
-#' enrichRSCE(mouseBrainSubsetSCE, "counts", "Cmtm5",
15
+#' enrichRSCE(mouseBrainSubsetSCE, "Cmtm5",
16 16
 #'            "GO_Cellular_Component_2017")
17 17
 #'
18
-enrichRSCE <- function(inSCE, useAssay, glist, db = NULL){
18
+enrichRSCE <- function(inSCE, glist, db = NULL){
19 19
   internetConnection <- suppressWarnings(Biobase::testBioCConnection())
20 20
   #check for internet connection
21 21
   if (!internetConnection){
... ...
@@ -29,11 +29,6 @@ enrichRSCE <- function(inSCE, useAssay, glist, db = NULL){
29 29
     stop("Please use a singleCellTK or a SCtkExperiment object")
30 30
   }
31 31
 
32
-  #test for assay existing
33
-  if (!all(useAssay %in% names(assays(inSCE)))){
34
-    stop("assay '", useAssay, "' does not exist.")
35
-  }
36
-
37 32
   #test for gene list existing
38 33
   if (!all(glist %in% rownames(inSCE))){
39 34
     stop("Gene in gene list not found in input object.")
Browse code

Support for improved assay manipulation

David Jenkins authored on 06/10/2018 20:26:19
Showing1 changed files
... ...
@@ -10,11 +10,9 @@
10 10
 #' @return enrichRSCE(): returns a data.frame of enrichment terms overlapping in
11 11
 #' the respective databases along with p-values, z-scores etc.,
12 12
 #' @export
13
-#'
14 13
 #' @examples
15 14
 #' enrichRSCE(mouseBrainSubsetSCE, "counts", "Cmtm5",
16 15
 #'            "GO_Cellular_Component_2017")
17
-#'
18 16
 enrichRSCE <- function(inSCE, useAssay, glist, db = NULL){
19 17
   internetConnection <- suppressWarnings(Biobase::testBioCConnection())
20 18
   #check for internet connection
... ...
@@ -55,15 +53,15 @@ enrichRSCE <- function(inSCE, useAssay, glist, db = NULL){
55 53
                                                  fill = TRUE,
56 54
                                                  idcol = "Database_selected"))
57 55
     temp_db <- enrichR::listEnrichrDbs()
58
-    enriched$link <- sapply(enriched$Database_selected, function(x){
56
+    enriched$link <- vapply(enriched$Database_selected, function(x){
59 57
       temp_db$link[which(temp_db$libraryName %in% x)]
60
-    })
58
+    }, FUN.VALUE = character(1))
61 59
 
62 60
     #sort the results based on p-values
63 61
     enriched <- enriched[base::order(enriched$P.value, decreasing = FALSE), ]
64 62
 
65 63
     #round the numeric values to their 7th digit
66
-    nums <- base::vapply(enriched, is.numeric, FUN.VALUE = logical(1))
64
+    nums <- vapply(enriched, is.numeric, FUN.VALUE = logical(1))
67 65
       enriched[, nums] <- base::round(enriched[, nums], digits = 7)
68 66
   }
69 67
   return(enriched)
Browse code

Lint package, fix indentation. Fix issue with org packages having non-interpretable names. Added additional linters. Added installation of lintr package from github for testing. Added Mohammed to the DESCRIPTION

David Jenkins authored on 24/07/2018 01:55:47
Showing1 changed files
... ...
@@ -1,64 +1,70 @@
1 1
 #' enrichR
2
-#' Given a list of genes this function runs the enrichR() to perform Gene 
3
-#' enrichment  
2
+#' Given a list of genes this function runs the enrichR() to perform Gene
3
+#' enrichment
4 4
 #'
5 5
 #' @param inSCE Input SCtkExperiment object. Required
6 6
 #' @param useAssay The assay to use in the enrichment analysis. Required
7 7
 #' @param glist selected genes for enrichment analysis using enrichR(). Required
8 8
 #' @param db selected database name from the enrichR database list.
9 9
 #'
10
-#' @return enrichRSCE(): returns a data.frame of enrichment terms overlapping in the respective 
11
-#'databases along with p-values, z-scores etc.,
10
+#' @return enrichRSCE(): returns a data.frame of enrichment terms overlapping in
11
+#' the respective databases along with p-values, z-scores etc.,
12 12
 #' @export
13 13
 #'
14
-#' @examples enrichRSCE(mouseBrainSubsetSCE,"counts","Cmtm5","GO_Cellular_Component_2017")
15
-#' 
14
+#' @examples
15
+#' enrichRSCE(mouseBrainSubsetSCE, "counts", "Cmtm5",
16
+#'            "GO_Cellular_Component_2017")
17
+#'
16 18
 enrichRSCE <- function(inSCE, useAssay, glist, db = NULL){
17 19
   internetConnection <- suppressWarnings(Biobase::testBioCConnection())
18 20
   #check for internet connection
19 21
   if (!internetConnection){
20 22
     stop("Please connect to the Internet and continue..")
21 23
   }
22
-  
24
+
23 25
   enrdb <- enrichR::listEnrichrDbs()$libraryName
24
-  
25
-  if (!(class(inSCE) == "SingleCellExperiment" | class(inSCE) == "SCtkExperiment")){
26
-      stop("Please use a singleCellTK or a SCtkExperiment object")
27
-    }
28
-    #test for assay existing
26
+
27
+  if (!(class(inSCE) == "SingleCellExperiment" |
28
+        class(inSCE) == "SCtkExperiment")){
29
+    stop("Please use a singleCellTK or a SCtkExperiment object")
30
+  }
31
+
32
+  #test for assay existing
29 33
   if (!all(useAssay %in% names(assays(inSCE)))){
30
-      stop("assay '", useAssay, "' does not exist.")
31
-    }
32
-    #test for gene list existing
34
+    stop("assay '", useAssay, "' does not exist.")
35
+  }
36
+
37
+  #test for gene list existing
33 38
   if (!all(glist %in% rownames(inSCE))){
34
-      stop("Gene in gene list not found in input object.")
35
-    }
36
-   #test for db existing
39
+    stop("Gene in gene list not found in input object.")
40
+  }
41
+
42
+  #test for db existing
37 43
   if (!all(db %in% enrdb)){
38 44
     stop("database '", db, "' does not exist.")
39 45
   }
40
-  
46
+
41 47
   if (is.null(glist)){
42 48
     stop("Please provide a gene list.")
43 49
   } else {
44 50
     if (is.null(db)){
45 51
       db <- enrdb
46
-      }
52
+    }
47 53
     enriched <- enrichR::enrichr(glist, db)
48
-    enriched <- data.frame(data.table::rbindlist(enriched, use.names = TRUE, fill = TRUE,
49
-                                      idcol = "Database_selected"))
50
-   
54
+    enriched <- data.frame(data.table::rbindlist(enriched, use.names = TRUE,
55
+                                                 fill = TRUE,
56
+                                                 idcol = "Database_selected"))
51 57
     temp_db <- enrichR::listEnrichrDbs()
52 58
     enriched$link <- sapply(enriched$Database_selected, function(x){
53
-      temp_db$link[which(temp_db$libraryName %in% x)] 
59
+      temp_db$link[which(temp_db$libraryName %in% x)]
54 60
     })
55
-    
61
+
56 62
     #sort the results based on p-values
57
-    enriched <- enriched[base::order(enriched$P.value, decreasing = FALSE),]
58
-    
63
+    enriched <- enriched[base::order(enriched$P.value, decreasing = FALSE), ]
64
+
59 65
     #round the numeric values to their 7th digit
60 66
     nums <- base::vapply(enriched, is.numeric, FUN.VALUE = logical(1))
61
-    enriched[,nums] <- base::round(enriched[,nums], digits = 7)
62
-    }
63
-return(enriched)
64
-} 
67
+      enriched[, nums] <- base::round(enriched[, nums], digits = 7)
68
+  }
69
+  return(enriched)
70
+}
Browse code

adding enrichR functionality, progress bar in enrichR tab, disable download button on empty content, version bump

Mohammed Muzamil Khan authored on 19/07/2018 18:35:38
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,64 @@
1
+#' enrichR
2
+#' Given a list of genes this function runs the enrichR() to perform Gene 
3
+#' enrichment  
4
+#'
5
+#' @param inSCE Input SCtkExperiment object. Required
6
+#' @param useAssay The assay to use in the enrichment analysis. Required
7
+#' @param glist selected genes for enrichment analysis using enrichR(). Required
8
+#' @param db selected database name from the enrichR database list.
9
+#'
10
+#' @return enrichRSCE(): returns a data.frame of enrichment terms overlapping in the respective 
11
+#'databases along with p-values, z-scores etc.,
12
+#' @export
13
+#'
14
+#' @examples enrichRSCE(mouseBrainSubsetSCE,"counts","Cmtm5","GO_Cellular_Component_2017")
15
+#' 
16
+enrichRSCE <- function(inSCE, useAssay, glist, db = NULL){
17
+  internetConnection <- suppressWarnings(Biobase::testBioCConnection())
18
+  #check for internet connection
19
+  if (!internetConnection){
20
+    stop("Please connect to the Internet and continue..")
21
+  }
22
+  
23
+  enrdb <- enrichR::listEnrichrDbs()$libraryName
24
+  
25
+  if (!(class(inSCE) == "SingleCellExperiment" | class(inSCE) == "SCtkExperiment")){
26
+      stop("Please use a singleCellTK or a SCtkExperiment object")
27
+    }
28
+    #test for assay existing
29
+  if (!all(useAssay %in% names(assays(inSCE)))){
30
+      stop("assay '", useAssay, "' does not exist.")
31
+    }
32
+    #test for gene list existing
33
+  if (!all(glist %in% rownames(inSCE))){
34
+      stop("Gene in gene list not found in input object.")
35
+    }
36
+   #test for db existing
37
+  if (!all(db %in% enrdb)){
38
+    stop("database '", db, "' does not exist.")
39
+  }
40
+  
41
+  if (is.null(glist)){
42
+    stop("Please provide a gene list.")
43
+  } else {
44
+    if (is.null(db)){
45
+      db <- enrdb
46
+      }
47
+    enriched <- enrichR::enrichr(glist, db)
48
+    enriched <- data.frame(data.table::rbindlist(enriched, use.names = TRUE, fill = TRUE,
49
+                                      idcol = "Database_selected"))
50
+   
51
+    temp_db <- enrichR::listEnrichrDbs()
52
+    enriched$link <- sapply(enriched$Database_selected, function(x){
53
+      temp_db$link[which(temp_db$libraryName %in% x)] 
54
+    })
55
+    
56
+    #sort the results based on p-values
57
+    enriched <- enriched[base::order(enriched$P.value, decreasing = FALSE),]
58
+    
59
+    #round the numeric values to their 7th digit
60
+    nums <- base::vapply(enriched, is.numeric, FUN.VALUE = logical(1))
61
+    enriched[,nums] <- base::round(enriched[,nums], digits = 7)
62
+    }
63
+return(enriched)
64
+}