Skip to content

Commit 88922fb

Browse files
committed
clean up report
1 parent 53cf6e4 commit 88922fb

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

inst/templates/ScSeurat.Rmd

+18-15
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,16 @@ library(Seurat)
4545
library(AUCell)
4646
library(ezRun)
4747
library(HDF5Array)
48+
library(enrichR)
4849
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, knitr.table.format = "html")
49-
```
5050
51-
```{r}
5251
clusterInfoFile <- "clusterInfos.xlsx"
5352
posMarkers <- readxl::read_xlsx("posMarkers.xlsx")
5453
scData <- readRDS("scData.rds")
5554
output <- readRDS("output.rds")
5655
scData$qc.doublet <- scData$doubletClass %in% "doublet"
5756
allCellsMeta <- readRDS("allCellsMeta.rds")
58-
param = readRDS("param.rds")
57+
param <- readRDS("param.rds")
5958
species <- getSpecies(param$refBuild)
6059
if (file.exists("singler.results.rds")){
6160
singler.results <- readRDS("singler.results.rds")
@@ -233,7 +232,8 @@ cellIdents_perSample <- data.frame(ident = Idents(scData), Sample=scData$Sample)
233232
barplot = ggplot(data=cellIdents_perSample, aes(x=ident, fill=Sample)) + geom_bar(stat="Count")
234233
barplot + labs(x="Cluster", y = "Number of cells", fill = "Sample")
235234
236-
cells_prop = cellsProportion(scData, groupVar1 = "ident", groupVar2 = "Sample")
235+
236+
cells_prop = cellsProportion(scData, groupVar1 = "seurat_clusters", groupVar2 = "Sample")
237237
kable(cells_prop,row.names=FALSE, format="html",caption="Cell proportions") %>% kable_styling(bootstrap_options = "striped", full_width = F, position = "float_right")
238238
```
239239

@@ -293,7 +293,9 @@ FeaturePlot(scData, features="negLog10CellPValue", label = TRUE)
293293
```{r, fig.width=12, fig.height=shrinkToRange(length(param$controlSeqs)*3/4, c(6, 18)), eval=ezIsSpecified(param$controlSeqs)}
294294
genesToPlot <- gsub("_", "-", param$controlSeqs)
295295
genesToPlot <- intersect(genesToPlot, rownames(scData))
296-
FeaturePlot(scData, genesToPlot) + NoLegend()
296+
if (length(genesToPlot) > 0){
297+
FeaturePlot(scData, genesToPlot) + NoLegend()
298+
}
297299
```
298300

299301
#### Cluster resolution
@@ -369,27 +371,28 @@ enrichrCalls <- paste0("<a href='javascript:void(0)' onClick='", jsCall,
369371
```
370372

371373

372-
```{r load enrichR terms, echo=FALSE, results='asis', eval= !is.null(enrichRout)}
373-
enrichRTerm <- as.data.frame(do.call(rbind, lapply(enrichRout, as.vector)))
374-
enrichRTerm <- map_df(enrichRTerm, ~ map_df(.x, ~ replace(.x, is.null(.x), NA)), .id = "database")
375-
enrichRTerm <- enrichRTerm %>%
376-
group_by(., Cluster, database) %>%
377-
summarise(topTerms = paste(Term, collapse = "; ")) %>%
378-
as.data.frame()
379-
enrichRTerm <- dcast(enrichRTerm, ... ~ database)
380-
enrichrTable <- merge(enrichrTable, enrichRTerm, by = "Cluster")
381-
```
382374

383375
```{r enrichr markers, echo=FALSE, results='asis'}
384376
enrichrTable <- tibble(Cluster=names(genesPerCluster),
385377
"# of posMarkers"=lengths(genesPerCluster),
386378
"Enrichr link"=enrichrCalls)
379+
if (!is.null(enrichRout)){
380+
enrichRTerm <- as.data.frame(do.call(rbind, lapply(enrichRout, as.vector)))
381+
enrichRTerm <- map_df(enrichRTerm, ~ map_df(.x, ~ replace(.x, is.null(.x), NA)), .id = "database")
382+
enrichRTerm <- enrichRTerm %>%
383+
group_by(., Cluster, database) %>%
384+
summarise(topTerms = paste(Term, collapse = "; ")) %>%
385+
as.data.frame()
386+
enrichRTerm <- dcast(enrichRTerm, ... ~ database)
387+
enrichrTable <- merge(enrichrTable, enrichRTerm, by = "Cluster")
388+
}
387389
kable(enrichrTable, format="html", escape=FALSE,
388390
caption=paste0("GeneSet enrichment")) %>%
389391
kable_styling("striped", full_width = F, position = "left")
390392
```
391393

392394

395+
393396
```{r plot enrichR per cluster, fig.height=5, fig.width=10, eval= !is.null(enrichRout)}
394397
for (cluster in names(enrichRout)) {
395398
enrichRDataFrame <- as.data.frame(do.call(rbind, enrichRout[[cluster]]))

0 commit comments

Comments
 (0)