Skip to content

Commit

Permalink
clean up report
Browse files Browse the repository at this point in the history
  • Loading branch information
hrehrauer committed Nov 9, 2022
1 parent 53cf6e4 commit 88922fb
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions inst/templates/ScSeurat.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
```

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -369,27 +371,28 @@ enrichrCalls <- paste0("<a href='javascript:void(0)' onClick='", jsCall,
```


```{r load enrichR terms, echo=FALSE, results='asis', eval= !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")
```

```{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]]))
Expand Down

0 comments on commit 88922fb

Please sign in to comment.