Browse code

Update `modelSearch()`: documentation + code style

Milan Malfait authored on 01/06/2021 10:53:38
Showing 3 changed files

... ...
@@ -16,7 +16,6 @@ import(methods)
16 16
 importFrom(Matrix,colSums)
17 17
 importFrom(SpatialExperiment,"spatialCoordsNames<-")
18 18
 importFrom(SpatialExperiment,spatialCoords)
19
-importFrom(SpatialExperiment,spatialCoordsNames)
20 19
 importFrom(SummarizedExperiment,assay)
21 20
 importFrom(basilisk,BasiliskEnvironment)
22 21
 importFrom(checkmate,assert_data_frame)
... ...
@@ -1,6 +1,6 @@
1
-#' Classify SVGenes to interpretable fitting classes
1
+#' Classify Spatially Variable Genes to interpretable fitting classes
2 2
 #'
3
-#' Compare model fits with different models. 
3
+#' Compare model fits with different models, using the
4 4
 #' [**SpatialDE**](https://github.com/Teichlab/SpatialDE) Python package.
5 5
 #'
6 6
 #' @param x \linkS4class{SpatialExperiment} object.
... ...
@@ -24,12 +24,13 @@
24 24
 #'
25 25
 #' ## Run spatialDE with S4 integration
26 26
 #' de_results <- spatialDE(spe)
27
-#' 
27
+#'
28 28
 #' ## Run model search with S4 integration
29
-#' model_search <- modelSearch(spe, assay_type = "counts", 
30
-#' de_results = de_results, qval_thresh = NULL, verbose = FALSE)
31
-#' 
32
-#' 
29
+#' model_search <- modelSearch(spe, de_results = de_results,
30
+#'     qval_thresh = NULL, verbose = FALSE
31
+#' )
32
+#'
33
+#'
33 34
 #' @seealso
34 35
 #' The individual steps performed by this function: [stabilize()],
35 36
 #' [regress_out()] and [model_search()].
... ...
@@ -43,21 +44,21 @@
43 44
 #' of the Python package used under the hood.
44 45
 #'
45 46
 #' @author Davide Corso, Milan Malfait
46
-#' @name model-search
47
+#' @name modelSearch
47 48
 NULL
48 49
 
49 50
 #' @importFrom Matrix colSums
50
-.modelSearch <- function(counts_spe, coordinates_spe, de_results, 
51
+.modelSearch <- function(counts_spe, coordinates_spe, de_results,
51 52
                          verbose = FALSE) {
52 53
   sample_info <- data.frame(coordinates_spe, total_counts = colSums(counts_spe))
53
-  
54
+
54 55
   out <- basilisk::basiliskRun(
55
-    env = spatialDE_env,
56
-    fun = .run_model_search,
57
-    counts_spe=counts_spe, 
58
-    sample_info=sample_info, 
59
-    de_results=de_results,
60
-    verbose=verbose
56
+      env = spatialDE_env,
57
+      fun = .run_model_search,
58
+      counts_spe = counts_spe,
59
+      sample_info = sample_info,
60
+      de_results = de_results,
61
+      verbose = verbose
61 62
   )
62 63
   out
63 64
 }
... ...
@@ -67,44 +68,46 @@ NULL
67 68
   ## Normalization
68 69
   stabilized <- .naiveDE_stabilize(counts = counts_spe)
69 70
   regressed <- .naiveDE_regress_out(counts = stabilized, sample_info)
70
-  
71
+
71 72
   coordinates <- sample_info[, c("x", "y")]
72
-  .spatialDE_model_search(x = regressed, coordinates = coordinates,
73
-                          de_results = de_results, verbose = verbose)
73
+  .spatialDE_model_search(
74
+      x = regressed, coordinates = coordinates,
75
+      de_results = de_results, verbose = verbose
76
+  )
74 77
 }
75 78
 
76
-#' 
77 79
 #' @import methods
78 80
 #' @export
79
-#' @rdname model-search
80
-setGeneric("modelSearch", function(x, ...) 
81
-  standardGeneric("modelSearch"))
81
+#' @rdname modelSearch
82
+setGeneric("modelSearch", function(x, ...) standardGeneric("modelSearch"))
82 83
 
83 84
 #' @export
84
-#' @rdname model-search
85
+#' @rdname modelSearch
85 86
 #' @importFrom SummarizedExperiment assay
86
-#' @importFrom SpatialExperiment spatialCoords spatialCoordsNames
87
+#' @importFrom SpatialExperiment spatialCoords spatialCoordsNames<-
87 88
 #' @importFrom checkmate assert_data_frame assert_number assert_flag
88 89
 setMethod("modelSearch", "SpatialExperiment",
89
-  function(x, assay_type = "counts", de_results, qval_thresh=0.05, 
90
+  function(x, assay_type = "counts", de_results, qval_thresh=0.05,
90 91
            verbose = FALSE) {
91 92
     assert_data_frame(de_results, all.missing = FALSE)
92 93
     assert_number(qval_thresh, null.ok = TRUE)
93 94
     assert_flag(verbose)
94
-    
95
+
95 96
     ## Rename spatialCoords columns to "x", "y"
96 97
     spatialCoordsNames(x) <- c("x", "y")
97 98
     coordinates_spe <- as.data.frame(spatialCoords(x))
98 99
     counts_spe <- assay(x, assay_type)
99
-    
100
+
100 101
     ## Filter de_results
101 102
     if (!is.null(qval_thresh)) {
102 103
       de_results <- .filter_de_results(
103 104
         de_results = de_results, qval_thresh = qval_thresh
104 105
       )
105 106
     }
106
-    
107
-    .modelSearch(counts_spe=counts_spe, coordinates_spe=coordinates_spe,
108
-                 de_results=de_results, verbose = FALSE)
107
+
108
+    .modelSearch(
109
+        counts_spe = counts_spe, coordinates_spe = coordinates_spe,
110
+        de_results = de_results, verbose = FALSE
111
+    )
109 112
   }
110 113
 )
111 114
similarity index 88%
112 115
rename from man/model-search.Rd
113 116
rename to man/modelSearch.Rd
... ...
@@ -1,10 +1,9 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/msearch.R
3
-\name{model-search}
4
-\alias{model-search}
3
+\name{modelSearch}
5 4
 \alias{modelSearch}
6 5
 \alias{modelSearch,SpatialExperiment-method}
7
-\title{Classify SVGenes to interpretable fitting classes}
6
+\title{Classify Spatially Variable Genes to interpretable fitting classes}
8 7
 \usage{
9 8
 modelSearch(x, ...)
10 9
 
... ...
@@ -37,7 +36,7 @@ Python package.}
37 36
 \code{data.frame} of model_search results.
38 37
 }
39 38
 \description{
40
-Compare model fits with different models.
39
+Compare model fits with different models, using the
41 40
 \href{https://github.com/Teichlab/SpatialDE}{\strong{SpatialDE}} Python package.
42 41
 }
43 42
 \examples{
... ...
@@ -49,8 +48,9 @@ spe <- mockSVG(size = 10, tot_genes = 200, de_genes = 20, return_SPE = TRUE)
49 48
 de_results <- spatialDE(spe)
50 49
 
51 50
 ## Run model search with S4 integration
52
-model_search <- modelSearch(spe, assay_type = "counts", 
53
-de_results = de_results, qval_thresh = NULL, verbose = FALSE)
51
+model_search <- modelSearch(spe, de_results = de_results,
52
+    qval_thresh = NULL, verbose = FALSE
53
+)
54 54
 
55 55
 
56 56
 }