From 88922fb8d01104778a82229a1f9078febd17ba0d Mon Sep 17 00:00:00 2001 From: hrehrauer Date: Wed, 9 Nov 2022 16:18:23 +0100 Subject: [PATCH] clean up report --- inst/templates/ScSeurat.Rmd | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/inst/templates/ScSeurat.Rmd b/inst/templates/ScSeurat.Rmd index 315d8cfae..b9ea6a676 100644 --- a/inst/templates/ScSeurat.Rmd +++ b/inst/templates/ScSeurat.Rmd @@ -45,17 +45,16 @@ library(Seurat) library(AUCell) library(ezRun) library(HDF5Array) +library(enrichR) knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, knitr.table.format = "html") -``` -```{r} clusterInfoFile <- "clusterInfos.xlsx" posMarkers <- readxl::read_xlsx("posMarkers.xlsx") scData <- readRDS("scData.rds") output <- readRDS("output.rds") scData$qc.doublet <- scData$doubletClass %in% "doublet" allCellsMeta <- readRDS("allCellsMeta.rds") -param = readRDS("param.rds") +param <- readRDS("param.rds") species <- getSpecies(param$refBuild) if (file.exists("singler.results.rds")){ singler.results <- readRDS("singler.results.rds") @@ -233,7 +232,8 @@ cellIdents_perSample <- data.frame(ident = Idents(scData), Sample=scData$Sample) barplot = ggplot(data=cellIdents_perSample, aes(x=ident, fill=Sample)) + geom_bar(stat="Count") barplot + labs(x="Cluster", y = "Number of cells", fill = "Sample") -cells_prop = cellsProportion(scData, groupVar1 = "ident", groupVar2 = "Sample") + +cells_prop = cellsProportion(scData, groupVar1 = "seurat_clusters", groupVar2 = "Sample") kable(cells_prop,row.names=FALSE, format="html",caption="Cell proportions") %>% kable_styling(bootstrap_options = "striped", full_width = F, position = "float_right") ``` @@ -293,7 +293,9 @@ FeaturePlot(scData, features="negLog10CellPValue", label = TRUE) ```{r, fig.width=12, fig.height=shrinkToRange(length(param$controlSeqs)*3/4, c(6, 18)), eval=ezIsSpecified(param$controlSeqs)} genesToPlot <- gsub("_", "-", param$controlSeqs) genesToPlot <- intersect(genesToPlot, rownames(scData)) -FeaturePlot(scData, genesToPlot) + NoLegend() +if (length(genesToPlot) > 0){ + FeaturePlot(scData, genesToPlot) + NoLegend() +} ``` #### Cluster resolution @@ -369,27 +371,28 @@ enrichrCalls <- paste0("% - group_by(., Cluster, database) %>% - summarise(topTerms = paste(Term, collapse = "; ")) %>% - as.data.frame() -enrichRTerm <- dcast(enrichRTerm, ... ~ database) -enrichrTable <- merge(enrichrTable, enrichRTerm, by = "Cluster") -``` ```{r enrichr markers, echo=FALSE, results='asis'} enrichrTable <- tibble(Cluster=names(genesPerCluster), "# of posMarkers"=lengths(genesPerCluster), "Enrichr link"=enrichrCalls) +if (!is.null(enrichRout)){ + enrichRTerm <- as.data.frame(do.call(rbind, lapply(enrichRout, as.vector))) + enrichRTerm <- map_df(enrichRTerm, ~ map_df(.x, ~ replace(.x, is.null(.x), NA)), .id = "database") + enrichRTerm <- enrichRTerm %>% + group_by(., Cluster, database) %>% + summarise(topTerms = paste(Term, collapse = "; ")) %>% + as.data.frame() + enrichRTerm <- dcast(enrichRTerm, ... ~ database) + enrichrTable <- merge(enrichrTable, enrichRTerm, by = "Cluster") +} kable(enrichrTable, format="html", escape=FALSE, caption=paste0("GeneSet enrichment")) %>% kable_styling("striped", full_width = F, position = "left") ``` + ```{r plot enrichR per cluster, fig.height=5, fig.width=10, eval= !is.null(enrichRout)} for (cluster in names(enrichRout)) { enrichRDataFrame <- as.data.frame(do.call(rbind, enrichRout[[cluster]]))