Browse code

ad output fixed, combinesce fixed, docs updated

Ming Liu authored on 05/07/2023 17:43:10
Showing 10 changed files

... ...
@@ -70,30 +70,36 @@
70 70
 }
71 71
 
72 72
 
73
-.mergeRowDataSCE <- function(sceList, by.r) {
74
-  feList <- lapply(sceList, function(x){
75
-    rw <- SummarizedExperiment::rowData(x)
76
-    rw[['rownames']] <- rownames(rw)
77
-    return(rw)
78
-  })
79
-  
80
-  ## Get merged rowData
81
-  by.r <- unique(c('rownames', by.r))
82
-  unionFe <- Reduce(function(r1, r2) merge(r1, r2, by=by.r, all=TRUE), feList)
83
-  allGenes <- unique(unlist(lapply(feList, rownames)))
84
-  
85
-  ## rowData
86
-  newFe <- unionFe
87
-  if (nrow(newFe) != length(allGenes)) {
88
-    warning("Conflicts were found when merging two rowData. ",
89
-            "Resolved the conflicts by choosing the first entries.",
90
-            "To avoid conflicts, please provide the 'by.r' arguments to ",
91
-            "specify columns in rowData that does not have conflict between two singleCellExperiment object. ")
92
-    newFe <- newFe[!duplicated(newFe$rownames), ]
93
-  }
94
-  rownames(newFe) <- newFe[['rownames']]
95
-  newFe <- newFe[allGenes,]
96
-  return(newFe)
73
+.mergeRowDataSCE <- function(sce.list, by.r) {
74
+    feList <- lapply(sce.list, function(x){
75
+        rw <- SummarizedExperiment::rowData(x)
76
+        rw[['rownames']] <- rownames(rw)
77
+        return(rw)
78
+    })
79
+    
80
+    ## Get merged rowData
81
+    if (is.null(by.r)) {
82
+        by.r <- unique(c('rownames', by.r))
83
+        unionFe <- Reduce(function(r1, r2) merge(r1, r2, by=unique(c(by.r, intersect(names(r1), names(r2)))), all=TRUE), feList)
84
+    }
85
+    else {
86
+      by.r <- unique(c('rownames', by.r))
87
+      unionFe <- Reduce(function(r1, r2) merge(r1, r2, by=by.r, all=TRUE), feList)
88
+    }
89
+    allGenes <- unique(unlist(lapply(feList, rownames)))
90
+    
91
+    ## rowData
92
+    newFe <- unionFe
93
+    if (nrow(newFe) != length(allGenes)) {
94
+        warning("Conflicts were found when merging two rowData. ",
95
+                "Resolved the conflicts by choosing the first entries.",
96
+                "To avoid conflicts, please provide the 'by.r' arguments to ",
97
+                "specify columns in rowData that does not have conflict between two singleCellExperiment object. ")
98
+        newFe <- newFe[!duplicated(newFe$rownames), ]
99
+    }
100
+    rownames(newFe) <- newFe[['rownames']]
101
+    newFe <- newFe[allGenes,]
102
+    return(newFe)
97 103
 }
98 104
 
99 105
 .mergeColDataSCE <- function(sceList, by.c) {
... ...
@@ -103,8 +109,15 @@
103 109
     return(cD)
104 110
   })
105 111
   
106
-  by.c <- unique(c("rownames", by.c))
107
-  unionCb <- Reduce(function(c1, c2) merge(c1, c2, by=by.c, all=TRUE), cbList)
112
+  # Merge columns
113
+  if (is.null(by.c)) {
114
+    by.c <- unique(c("rownames", by.c))
115
+    unionCb <- Reduce(function(c1, c2) merge(c1, c2, by=unique(c(by.c, intersect(names(c1), names(c2)))), all=TRUE), cbList)
116
+  }
117
+  else {
118
+    by.c <- unique(c("rownames", by.c))
119
+    unionCb <- Reduce(function(c1, c2) merge(c1, c2, by=by.c, all=TRUE), cbList)
120
+  }
108 121
   rownames(unionCb) <- unionCb[['rownames']]
109 122
   newCbList <- list()
110 123
   for (i in seq_along(sceList)) {
... ...
@@ -1,4 +1,4 @@
1
-#' @title Perform comprehensive single cell QC
1
+#' @title Single Cell QC checking
2 2
 #' @description Utility functions for runQC - checking cell input for validity
3 3
 #' @param FilterFile The cell QC object as rendered in R
4 4
 #' @param FilterDir The cell QC file location
... ...
@@ -50,7 +50,7 @@
50 50
     return(0)
51 51
 }
52 52
 
53
-#' @title Perform comprehensive single cell QC
53
+#' @title Single Cell QC checking
54 54
 #' @description Utility functions for runQC - checking droplet input for validity
55 55
 #' @param RawFile The droplet QC object as rendered in R
56 56
 #' @param RawDir The droplet QC file location
... ...
@@ -101,7 +101,7 @@
101 101
     return(0)
102 102
 }
103 103
 
104
-#' @title Perform comprehensive single cell QC
104
+#' @title Single Cell QC checking
105 105
 #' @description Utility functions for runQC - checking cell and droplet input for validity
106 106
 #' @param RawFile The droplet QC object as rendered in R
107 107
 #' @param RawDir The droplet QC file location
... ...
@@ -174,6 +174,7 @@
174 174
 #' @description QC execution function wrapper for cell SCE objects
175 175
 #' @param cellSCE The cell SCE object as rendered in R
176 176
 #' @param preproc The method that we are looking at, be it CellRanger, Seurat, SCE, AnnData, or otherwise. 
177
+#' @param geneSetCollection Reference library of genes
177 178
 #' @param Params The list of parameters we are using.
178 179
 #' @param cellQCAlgos The list of various QC algorithms to use.
179 180
 #' @param mitoInfo Reference library for MitoGenes
... ...
@@ -35,9 +35,7 @@
35 35
         AnnData$var_names <- rownames(SCE)
36 36
     }
37 37
     # uns  <- S4Vectors::metadata(SCE)
38
-    # if(length(uns) > 0){
39
-    #     AnnData$uns <- uns
40
-    # }
38
+    # if(length(uns) > 0){ AnnData$uns <- uns }
41 39
     obsmNames <- SingleCellExperiment::reducedDimNames(SCE)
42 40
     if(length(obsmNames) > 0){
43 41
         for (i in seq_along(obsmNames)) {
... ...
@@ -51,10 +49,7 @@
51 49
     for (i in seq_along(allAssayNames)) {
52 50
         oneName <- allAssayNames[i]
53 51
         if (!oneName == useAssay) {
54
-            AnnData$layers$'__setitem__'(oneName,
55
-                                         as.matrix(
56
-                                             t(SummarizedExperiment::assay(
57
-                                                 SCE, oneName))))
52
+            AnnData$layers$'__setitem__'(oneName, as.matrix(t(SummarizedExperiment::assay(SCE, oneName))))
58 53
         }
59 54
     }
60 55
     return(AnnData)
61 56
new file mode 100644
... ...
@@ -0,0 +1,37 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/runQCUtils.R
3
+\name{.checkBoth}
4
+\alias{.checkBoth}
5
+\title{Perform comprehensive single cell QC}
6
+\usage{
7
+.checkBoth(
8
+  RawFile,
9
+  FilterFile,
10
+  RawDir,
11
+  FilterDir,
12
+  basepath,
13
+  Reference,
14
+  process
15
+)
16
+}
17
+\arguments{
18
+\item{RawFile}{The droplet QC object as rendered in R}
19
+
20
+\item{FilterFile}{The cell QC object as rendered in R}
21
+
22
+\item{RawDir}{The droplet QC file location}
23
+
24
+\item{FilterDir}{The cell QC file location}
25
+
26
+\item{basepath}{The base/root directory of the QC files.}
27
+
28
+\item{Reference}{Reference library for MitoGenes}
29
+
30
+\item{process}{The method that we are looking at, be it CellRanger, Seurat, SCE, AnnData, or otherwise.}
31
+}
32
+\value{
33
+0 if the check is completed successfully, else a premature stop.
34
+}
35
+\description{
36
+Utility functions for runQC - checking cell and droplet input for validity
37
+}
0 38
new file mode 100644
... ...
@@ -0,0 +1,25 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/runQCUtils.R
3
+\name{.checkCell}
4
+\alias{.checkCell}
5
+\title{Perform comprehensive single cell QC}
6
+\usage{
7
+.checkCell(FilterFile, FilterDir, basepath, Reference, process)
8
+}
9
+\arguments{
10
+\item{FilterFile}{The cell QC object as rendered in R}
11
+
12
+\item{FilterDir}{The cell QC file location}
13
+
14
+\item{basepath}{The base/root directory of the QC files.}
15
+
16
+\item{Reference}{Reference library for MitoGenes}
17
+
18
+\item{process}{The method that we are looking at, be it CellRanger, Seurat, SCE, AnnData, or otherwise.}
19
+}
20
+\value{
21
+0 if the check is completed successfully, else a premature stop.
22
+}
23
+\description{
24
+Utility functions for runQC - checking cell input for validity
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,25 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/runQCUtils.R
3
+\name{.checkDroplet}
4
+\alias{.checkDroplet}
5
+\title{Perform comprehensive single cell QC}
6
+\usage{
7
+.checkDroplet(RawFile, RawDir, basepath, Reference, process)
8
+}
9
+\arguments{
10
+\item{RawFile}{The droplet QC object as rendered in R}
11
+
12
+\item{RawDir}{The droplet QC file location}
13
+
14
+\item{basepath}{The base/root directory of the QC files.}
15
+
16
+\item{Reference}{Reference library for MitoGenes}
17
+
18
+\item{process}{The method that we are looking at, be it CellRanger, Seurat, SCE, AnnData, or otherwise.}
19
+}
20
+\value{
21
+0 if the check is completed successfully, else a premature stop.
22
+}
23
+\description{
24
+Utility functions for runQC - checking droplet input for validity
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,27 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/runQCUtils.R
3
+\name{.runCell}
4
+\alias{.runCell}
5
+\title{Perform comprehensive single cell QC}
6
+\usage{
7
+.runCell(cellSCE, preproc, geneSetCollection, Params, cellQCAlgos, mitoInfo)
8
+}
9
+\arguments{
10
+\item{cellSCE}{The cell SCE object as rendered in R}
11
+
12
+\item{preproc}{The method that we are looking at, be it CellRanger, Seurat, SCE, AnnData, or otherwise.}
13
+
14
+\item{geneSetCollection}{Reference library of genes}
15
+
16
+\item{Params}{The list of parameters we are using.}
17
+
18
+\item{cellQCAlgos}{The list of various QC algorithms to use.}
19
+
20
+\item{mitoInfo}{Reference library for MitoGenes}
21
+}
22
+\value{
23
+No objects are returned, just runs the cell QC and throws an error if problems occur in subfunctions
24
+}
25
+\description{
26
+QC execution function wrapper for cell SCE objects
27
+}
0 28
new file mode 100644
... ...
@@ -0,0 +1,37 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/runQCUtils.R
3
+\name{.runDroplet}
4
+\alias{.runDroplet}
5
+\title{Perform comprehensive single cell QC}
6
+\usage{
7
+.runDroplet(
8
+  dropletSCE,
9
+  geneSetCollection,
10
+  Params,
11
+  mitoInfo,
12
+  cellQCAlgos,
13
+  detectCell,
14
+  cellCalling
15
+)
16
+}
17
+\arguments{
18
+\item{dropletSCE}{The cell SCE object as rendered in R}
19
+
20
+\item{geneSetCollection}{Reference library of genes}
21
+
22
+\item{Params}{The list of parameters we are using.}
23
+
24
+\item{mitoInfo}{Reference library for MitoGenes}
25
+
26
+\item{cellQCAlgos}{The list of various QC algorithms to use.}
27
+
28
+\item{detectCell}{Whether or not to detect the cell SCE object, or not}
29
+
30
+\item{cellCalling}{The cell algorithm to be used.}
31
+}
32
+\value{
33
+No objects are returned, just runs the cell QC and throws an error if problems occur in subfunctions
34
+}
35
+\description{
36
+QC execution function wrapper for droplet SCE objects
37
+}
... ...
@@ -6,7 +6,8 @@
6 6
 \usage{
7 7
 getSceParams(
8 8
   inSCE,
9
-  skip = c("scrublet", "runDecontX", "runBarcodeRanksMetaOutput"),
9
+  skip = c("runScrublet", "runDecontX", "runBarcodeRanksMetaOutput", "genesets",
10
+    "runSoupX"),
10 11
   ignore = c("algorithms", "estimates", "contamination", "z", "sample", "rank",
11 12
     "BPPARAM", "batch", "geneSetCollection", "barcodeArgs"),
12 13
   directory = "./",
13 14
Binary files a/tests/testthat/Rplots.pdf and b/tests/testthat/Rplots.pdf differ