Browse code

Fix CHECK errors due to SingleR updates

Yichen Wang authored on 25/10/2022 15:39:08
Showing 6 changed files

... ...
@@ -80,7 +80,7 @@ Imports:
80 80
     Seurat (>= 3.1.3),
81 81
     shiny,
82 82
     shinyjs,
83
-    SingleR,
83
+    SingleR (>= 1.99.2),
84 84
     SoupX,
85 85
     sva,
86 86
     reshape2,
... ...
@@ -43,10 +43,10 @@ runSingleR <- function(inSCE,
43 43
                        featureType = c("symbol", "ensembl"),
44 44
                        labelByCluster = NULL) {
45 45
     # Input checks
46
-    if(!inherits(inSCE, "SingleCellExperiment")){
46
+    if (!inherits(inSCE, "SingleCellExperiment")) {
47 47
         stop('"inSCE" should be a SingleCellExperiment inherited Object.')
48 48
     }
49
-    if(!useAssay %in% expDataNames(inSCE)){
49
+    if (!useAssay %in% expDataNames(inSCE)) {
50 50
         stop('"useAssay" name: ', useAssay, ' not found.')
51 51
     }
52 52
 
... ...
@@ -91,7 +91,7 @@ runSingleR <- function(inSCE,
91 91
             if (!isTRUE(useEnsembl)) {
92 92
                 rownames(ref) <- SummarizedExperiment::rowData(ref)$symbol
93 93
             }
94
-            ref <- ref[,!is.na(ref$label) & ref$label!="unclear"]
94
+            ref <- ref[,!is.na(ref$label) & ref$label != "unclear"]
95 95
             ref <- scaterlogNormCounts(ref, assayName = "logcounts")
96 96
             labelColName <- "label"
97 97
             warning("MuraroPancreasData does not have multiple levels of ",
... ...
@@ -375,20 +375,21 @@ Ontology information. For more information, please click on the function
375 375
 name and see the reference page of this function.</p>
376 376
 <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
377 377
 <code class="sourceCode R"><span><span class="va">sce</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/runSingleR.html">runSingleR</a></span><span class="op">(</span>inSCE <span class="op">=</span> <span class="va">sce</span>, useAssay <span class="op">=</span> <span class="st">"logcounts"</span>, useBltinRef <span class="op">=</span> <span class="st">"hpca"</span>, level <span class="op">=</span> <span class="st">"main"</span>, featureType <span class="op">=</span> <span class="st">"symbol"</span><span class="op">)</span></span></code></pre></div>
378
-<p>Four results from SingleR will be stored in <code><a href="https://rdrr.io/pkg/SummarizedExperiment/man/SummarizedExperiment-class.html" class="external-link">colData()</a></code>
378
+<p>Four results from SingleR will be stored in <code>colData()</code>
379 379
 slot with the same prefix as
380 380
 <code>"SingleR_{reference abbr}_{annotation level}_"</code>, then
381
-<code>"score"</code>, <code>"first.labels"</code>, <code>"labels"</code>
382
-and <code>"pruned.labels"</code>, respectively.
383
-<code>"first.labels"</code> refers to the labeling initially indicated
384
-by the scores, <code>"labels"</code> is fine-tuned, and
385
-<code>"pruned.labels"</code> is the pruned result.</p>
381
+<code>"score"</code>, <code>"labels"</code>, <code>"delta.next"</code>
382
+and <code>"pruned.labels"</code>, respectively. <code>"labels"</code>
383
+contains the predicted label, basing only on the maximum entry in
384
+scores. <code>"delta.next"</code> contains difference between the best
385
+and next-best score. <code>"pruned.labels"</code> contains predictions
386
+where “low-quality” labels are replaced with <code>NA</code>s.</p>
386 387
 <p>Besides, users can also use their own labeled reference datasets
387 388
 wrapped in a <a href="https://rdrr.io/bioc/SingleCellExperiment/man/SingleCellExperiment.html" class="external-link">SingleCellExperiment</a>
388 389
 object. Refer to argument <code>useSCERef</code> and
389 390
 <code>labelColName</code>. Additionally, the labeling can also be done
390 391
 on cluster label if users have already performed clustering on their
391
-dataset and have the result stored in <code><a href="https://rdrr.io/pkg/SummarizedExperiment/man/SummarizedExperiment-class.html" class="external-link">colData()</a></code> slot. Refer
392
+dataset and have the result stored in <code>colData()</code> slot. Refer
392 393
 to argument <code>labelByCluster</code>.</p>
393 394
 <p><strong>Visualization</strong></p>
394 395
 <p>Users can choose to visualize the labeling result on a scatter plot.
395 396
Binary files a/docs/articles/cell_type_labeling_files/figure-html/visualization-1.png and b/docs/articles/cell_type_labeling_files/figure-html/visualization-1.png differ
... ...
@@ -7,10 +7,17 @@ sce <- scaterlogNormCounts(sce, "logcounts")
7 7
 rownames(sce) <- rowData(sce)$feature_name
8 8
 
9 9
 test_that(desc = "Testing SingleR", {
10
-  sce <- runSingleR(sce)
11
-
12
-  testthat::expect_true("SingleR_hpca_main_pruned.labels" %in% names(colData(sce)))
13
-  testthat::expect_true("SingleR_hpca_main_labels" %in% names(colData(sce)))
14
-  testthat::expect_true("SingleR_hpca_main_first.labels" %in% names(colData(sce)))
15
-  testthat::expect_true("SingleR_hpca_main_scores" %in% names(colData(sce)))
10
+  tryCatch({
11
+    ref <- celldex::HumanPrimaryCellAtlasData()
12
+  }, error = function(e) {
13
+    message("Error importing reference with `celldex` library. ",
14
+            "Skipping runSingleR test.")
15
+  }, finally = {
16
+    sce <- runSingleR(sce)
17
+    testthat::expect_true("SingleR_hpca_main_scores" %in% names(colData(sce)))
18
+    testthat::expect_true("SingleR_hpca_main_labels" %in% names(colData(sce)))
19
+    #testthat::expect_true("SingleR_hpca_main_first.labels" %in% names(colData(sce)))
20
+    #testthat::expect_true("SingleR_hpca_main_delta.next" %in% names(colData(sce)))
21
+    testthat::expect_true("SingleR_hpca_main_pruned.labels" %in% names(colData(sce)))
22
+  })
16 23
 })
... ...
@@ -94,7 +94,7 @@ Then users can use `runSingleR()` to invoke the algorithm. Here we choose to use
94 94
 sce <- runSingleR(inSCE = sce, useAssay = "logcounts", useBltinRef = "hpca", level = "main", featureType = "symbol")
95 95
 ```
96 96
 
97
-Four results from SingleR will be stored in `colData()` slot with the same prefix as `"SingleR_{reference abbr}_{annotation level}_"`, then `"score"`, `"first.labels"`, `"labels"` and `"pruned.labels"`, respectively. `"first.labels"` refers to the labeling initially indicated by the scores, `"labels"` is fine-tuned, and `"pruned.labels"` is the pruned result.  
97
+Four results from SingleR will be stored in `colData()` slot with the same prefix as `"SingleR_{reference abbr}_{annotation level}_"`, then `"score"`, `"labels"`, `"delta.next"` and `"pruned.labels"`, respectively. `"labels"` contains the predicted label, basing only on the maximum entry in scores. `"delta.next"` contains difference between the best and next-best score. `"pruned.labels"` contains predictions where "low-quality" labels are replaced with `NA`s. 
98 98
 
99 99
 Besides, users can also use their own labeled reference datasets wrapped in a [SingleCellExperiment](https://rdrr.io/bioc/SingleCellExperiment/man/SingleCellExperiment.html) object. Refer to argument `useSCERef` and `labelColName`. Additionally, the labeling can also be done on cluster label if users have already performed clustering on their dataset and have the result stored in `colData()` slot. Refer to argument `labelByCluster`.  
100 100