... | ... |
@@ -26,7 +26,6 @@ knitr::opts_chunk$set( |
26 | 26 |
### Installation |
27 | 27 |
|
28 | 28 |
```{r installation, eval=FALSE} |
29 |
- |
|
30 | 29 |
if(!requireNamespace("BiocManager", quietly = TRUE)) |
31 | 30 |
install.packages("BiocManager") |
32 | 31 |
BiocManager::install("SpatialDecon") |
... | ... |
@@ -132,19 +131,103 @@ heatmap(sweep(safeTME, 1, apply(safeTME, 1, max), "/"), |
132 | 131 |
For studies of other tissue types, we have provided a library of cell profile |
133 | 132 |
matrices, available on Github and downloadable with the "download_profile_matrix" function. |
134 | 133 |
|
135 |
-For a complete list of matrices, see ?download_profile_matrix. |
|
134 |
+For a complete list of matrices, see [CellProfileLibrary GitHub Page](https://github.com/Nanostring-Biostats/CellProfileLibrary/tree/NewProfileMatrices) |
|
136 | 135 |
|
137 | 136 |
Below we download a matrix of cell profiles derived from scRNA-seq of a mouse |
138 |
-brain. |
|
137 |
+spleen. |
|
138 |
+ |
|
139 |
+```{r downloadmatrix, fig.height=7, fig.width=10, fig.cap = "The Mouse Spleen profile matrix", eval=T} |
|
140 |
+mousespleen <- download_profile_matrix(species = "Mouse", |
|
141 |
+ age_group = "Adult", |
|
142 |
+ matrixname = "Spleen_MCA") |
|
143 |
+dim(mousespleen) |
|
144 |
+ |
|
145 |
+mousespleen[1:4,1:4] |
|
146 |
+ |
|
147 |
+head(cellGroups) |
|
148 |
+ |
|
149 |
+metadata |
|
150 |
+ |
|
151 |
+heatmap(sweep(mousespleen, 1, apply(mousespleen, 1, max), "/"), |
|
152 |
+ labRow = NA, margins = c(10, 5), cexCol = 0.7) |
|
139 | 153 |
|
140 |
-```{r downloadmatrix, fig.height=7, fig.width=10, fig.cap = "The Mouse Brain profile matrix"} |
|
141 |
-profile_matrix <- download_profile_matrix(species = "Mouse", age_group = "Adult", matrixname = "Brain_AllenBrainAtlas") |
|
142 |
-profile_matrix <- as.matrix(profile_matrix) |
|
143 |
-heatmap(sweep(profile_matrix, 1, apply(profile_matrix, 1, max), "/")[1:1000, ], |
|
144 |
- labRow = NA, margins = c(12, 5), cexCol = 0.7) |
|
145 | 154 |
``` |
146 | 155 |
|
147 | 156 |
|
157 |
+For studies where the provided cell profile matrices aren't sufficient or if a specific single cell dataset is wanted, we can make a custom profile matrix using the function create_profile_matrix(). |
|
158 |
+ |
|
159 |
+This mini single cell dataset is a fraction of the data from Kinchen, J. et al. Structural Remodeling of the Human Colonic Mesenchyme in Inflammatory Bowel Disease. Cell 175, 372-386.e17 (2018). |
|
160 |
+ |
|
161 |
+```{r single cell data} |
|
162 |
+data("mini_singleCell_dataset") |
|
163 |
+ |
|
164 |
+mtx@Dim # genes x cells |
|
165 |
+ |
|
166 |
+as.matrix(mtx)[1:4,1:4] |
|
167 |
+ |
|
168 |
+head(annots) |
|
169 |
+ |
|
170 |
+table(annots$LabeledCellType) |
|
171 |
+ |
|
172 |
+``` |
|
173 |
+ |
|
174 |
+**Pericyte cell** and **smooth muscle cell of colon** will be dropped from this matrix due to low cell count. The average expression across all cells of one type is returned so the more cells of one type, the better reflection of the true gene expression. The confidence in these averages can be changed using the minCellNum filter. |
|
175 |
+ |
|
176 |
+```{r creatematrix, fig.height=7, fig.width=10, fig.cap = "Custom profile matrix"} |
|
177 |
+custom_mtx <- create_profile_matrix(mtx = mtx, # cell x gene count matrix |
|
178 |
+ cellAnnots = annots, # cell annotations with cell type and cell name as columns |
|
179 |
+ cellTypeCol = "LabeledCellType", # column containing cell type |
|
180 |
+ cellNameCol = "CellID", # column containing cell ID/name |
|
181 |
+ matrixName = "custom_mini_colon", # name of final profile matrix |
|
182 |
+ outDir = NULL, # path to desired output directory, set to NULL if matrix should not be written |
|
183 |
+ normalize = FALSE, # Should data be normalized? |
|
184 |
+ minCellNum = 5, # minimum number of cells of one type needed to create profile, exclusive |
|
185 |
+ minGenes = 10, # minimum number of genes expressed in a cell, exclusive |
|
186 |
+ scalingFactor = 5, # what should all values be multiplied by for final matrix |
|
187 |
+ discardCellTypes = TRUE) # should cell types be filtered for types like mitotic, doublet, low quality, unknown, etc. |
|
188 |
+ |
|
189 |
+head(custom_mtx) |
|
190 |
+ |
|
191 |
+heatmap(sweep(custom_mtx, 1, apply(custom_mtx, 1, max), "/"), |
|
192 |
+ labRow = NA, margins = c(10, 5), cexCol = 0.7) |
|
193 |
+ |
|
194 |
+``` |
|
195 |
+ |
|
196 |
+Custom matrices can be created from all single cell data classes as long as a counts matrix and cell annotations can be passed to the function. Here is an example of creating a matrix using a Seurat object. |
|
197 |
+ |
|
198 |
+```{r createSeuratmatrix} |
|
199 |
+if(!requireNamespace("Seurat", quietly = TRUE)) |
|
200 |
+ install.packages("Seurat") |
|
201 |
+ |
|
202 |
+library(Seurat) |
|
203 |
+ |
|
204 |
+data("mini_singleCell_dataset") |
|
205 |
+ |
|
206 |
+rownames(annots) <- annots$CellID |
|
207 |
+ |
|
208 |
+seuratObject <- CreateSeuratObject(counts = mtx, meta.data = annots) |
|
209 |
+Idents(seuratObject) <- seuratObject$LabeledCellType |
|
210 |
+ |
|
211 |
+rm(mtx, annots) |
|
212 |
+ |
|
213 |
+annots <- data.frame(cbind(cellType=as.character(Idents(seuratObject)), |
|
214 |
+ cellID=names(Idents(seuratObject)))) |
|
215 |
+ |
|
216 |
+custom_mtx_seurat <- create_profile_matrix(mtx = seuratObject@assays$RNA@counts, |
|
217 |
+ cellAnnots = annots, |
|
218 |
+ cellTypeCol = "cellType", |
|
219 |
+ cellNameCol = "cellID", |
|
220 |
+ matrixName = "custom_mini_colon", |
|
221 |
+ outDir = NULL, |
|
222 |
+ normalize = FALSE, |
|
223 |
+ minCellNum = 5, |
|
224 |
+ minGenes = 10) |
|
225 |
+ |
|
226 |
+head(custom_mtx_seurat) |
|
227 |
+ |
|
228 |
+paste("custom_mtx and custom_mtx_seurat are identical", all(custom_mtx == custom_mtx_seurat)) |
|
229 |
+``` |
|
230 |
+ |
|
148 | 231 |
### Performing basic deconvolution with the spatialdecon function |
149 | 232 |
|
150 | 233 |
Now our data is ready for deconvolution. |
... | ... |
@@ -26,7 +26,6 @@ knitr::opts_chunk$set( |
26 | 26 |
### Installation |
27 | 27 |
|
28 | 28 |
```{r installation, eval=FALSE} |
29 |
- |
|
30 | 29 |
if(!requireNamespace("BiocManager", quietly = TRUE)) |
31 | 30 |
install.packages("BiocManager") |
32 | 31 |
BiocManager::install("SpatialDecon") |
... | ... |
@@ -122,19 +121,66 @@ heatmap(sweep(safeTME, 1, apply(safeTME, 1, max), "/"), |
122 | 121 |
For studies of other tissue types, we have provided a library of cell profile |
123 | 122 |
matrices, available on Github and downloadable with the "download_profile_matrix" function. |
124 | 123 |
|
125 |
-For a complete list of matrices, see ?download_profile_matrix. |
|
124 |
+For a complete list of matrices, see [CellProfileLibrary GitHub Page](https://github.com/Nanostring-Biostats/CellProfileLibrary/tree/NewProfileMatrices). |
|
126 | 125 |
|
127 | 126 |
Below we download a matrix of cell profiles derived from scRNA-seq of a mouse |
128 |
-brain. |
|
127 |
+spleen. |
|
128 |
+ |
|
129 |
+```{r downloadmatrix, fig.height=7, fig.width=10, fig.cap = "The Mouse Spleen profile matrix", eval=T} |
|
130 |
+mousespleen <- download_profile_matrix(species = "Mouse", |
|
131 |
+ age_group = "Adult", |
|
132 |
+ matrixname = "Spleen_MCA") |
|
133 |
+dim(mousespleen) |
|
134 |
+ |
|
135 |
+mousespleen[1:4,1:4] |
|
136 |
+ |
|
137 |
+head(cellGroups) |
|
138 |
+ |
|
139 |
+metadata |
|
129 | 140 |
|
130 |
-```{r downloadmatrix, fig.height=7, fig.width=10, fig.cap = "The Mouse Brain profile matrix"} |
|
131 |
-profile_matrix <- download_profile_matrix(species = "Mouse", age_group = "Adult", matrixname = "Brain_AllenBrainAtlas") |
|
132 |
-profile_matrix <- as.matrix(profile_matrix) |
|
133 |
-heatmap(sweep(profile_matrix, 1, apply(profile_matrix, 1, max), "/")[1:1000, ], |
|
134 |
- labRow = NA, margins = c(12, 5), cexCol = 0.7) |
|
141 |
+heatmap(sweep(mousespleen, 1, apply(mousespleen, 1, max), "/"), |
|
142 |
+ labRow = NA, margins = c(10, 5), cexCol = 0.7) |
|
135 | 143 |
|
136 | 144 |
``` |
137 | 145 |
|
146 |
+For studies where the provided cell profile matrices aren't sufficient or if a specific single cell dataset is wanted, we can make a custom profile matrix using the function create_profile_matrix(). |
|
147 |
+ |
|
148 |
+This mini single cell dataset is a fraction of the data from Kinchen, J. et al. Structural Remodeling of the Human Colonic Mesenchyme in Inflammatory Bowel Disease. Cell 175, 372-386.e17 (2018). |
|
149 |
+ |
|
150 |
+```{r single cell data} |
|
151 |
+data("mini_singleCell_dataset") |
|
152 |
+ |
|
153 |
+mtx@Dim # genes x cells |
|
154 |
+ |
|
155 |
+as.matrix(mtx)[1:4,1:4] |
|
156 |
+ |
|
157 |
+head(annots) |
|
158 |
+ |
|
159 |
+table(annots$LabeledCellType) |
|
160 |
+ |
|
161 |
+``` |
|
162 |
+ |
|
163 |
+**Pericyte cell** and **smooth muscle cell of colon** will be dropped from this matrix due to low cell count. The average expression across all cells of one type is returned so the more cells of one type, the better reflection of the true gene expression. The confidence in these averages can be changed using the minCellNum filter. |
|
164 |
+ |
|
165 |
+```{r creatematrix, fig.height=7, fig.width=10, fig.cap = "Custom profile matrix"} |
|
166 |
+custom_mtx <- create_profile_matrix(mtx = mtx, # cell x gene count matrix |
|
167 |
+ cellAnnots = annots, # cell annotations with cell type and cell name as columns |
|
168 |
+ cellTypeCol = "LabeledCellType", # column containing cell type |
|
169 |
+ cellNameCol = "CellID", # column containing cell ID/name |
|
170 |
+ matrixName = "custom_mini_colon", # name of final profile matrix |
|
171 |
+ outDir = NULL, # path to desired output directory, set to NULL if matrix should not be written |
|
172 |
+ normalize = FALSE, # Should data be normalized? |
|
173 |
+ minCellNum = 5, # minimum number of cells of one type needed to create profile, exclusive |
|
174 |
+ minGenes = 10, # minimum number of genes expressed in a cell, exclusive |
|
175 |
+ scalingFactor = 5, # what should all values be multiplied by for final matrix |
|
176 |
+ discardCellTypes = TRUE) # should cell types be filtered for types like mitotic, doublet, low quality, unknown, etc. |
|
177 |
+ |
|
178 |
+head(custom_mtx) |
|
179 |
+ |
|
180 |
+heatmap(sweep(custom_mtx, 1, apply(custom_mtx, 1, max), "/"), |
|
181 |
+ labRow = NA, margins = c(10, 5), cexCol = 0.7) |
|
182 |
+ |
|
183 |
+``` |
|
138 | 184 |
|
139 | 185 |
### Performing basic deconvolution with the spatialdecon function |
140 | 186 |
|