@@ -45,17 +45,16 @@ library(Seurat)
4545library(AUCell)
4646library(ezRun)
4747library(HDF5Array)
48+ library(enrichR)
4849knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, knitr.table.format = "html")
49- ```
5050
51- ``` {r}
5251clusterInfoFile <- "clusterInfos.xlsx"
5352posMarkers <- readxl::read_xlsx("posMarkers.xlsx")
5453scData <- readRDS("scData.rds")
5554output <- readRDS("output.rds")
5655scData$qc.doublet <- scData$doubletClass %in% "doublet"
5756allCellsMeta <- readRDS("allCellsMeta.rds")
58- param = readRDS("param.rds")
57+ param <- readRDS("param.rds")
5958species <- getSpecies(param$refBuild)
6059if (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)
233232barplot = ggplot(data=cellIdents_perSample, aes(x=ident, fill=Sample)) + geom_bar(stat="Count")
234233barplot + 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")
237237kable(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)}
294294genesToPlot <- gsub("_", "-", param$controlSeqs)
295295genesToPlot <- 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'}
384376enrichrTable <- 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+ }
387389kable(enrichrTable, format="html", escape=FALSE,
388390 caption=paste0("GeneSet enrichment")) %>%
389391kable_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)}
394397for (cluster in names(enrichRout)) {
395398 enrichRDataFrame <- as.data.frame(do.call(rbind, enrichRout[[cluster]]))
0 commit comments