library(knitr)
library(kableExtra)

knitr::opts_chunk$set(echo = TRUE, autodep=TRUE, cache.comments=FALSE, message=FALSE, warning=FALSE, dpi=300)

addLinkTag<-function(text,link) {
  result<-paste0("<a href='",link,"' target='_blank'>",text,"</a>")
  return(result)
}

getHeatmapHeight<-function(hdata){
  max(10, nrow(hdata) / 10)
}

hasCellTypes<-!is.null(plotData$ref.expr) 

Overview

scUnifrac is to quantify cell subpopulation diversity between two single-cell transcriptome profiles, which calculates the distance, estimates the statistical significance of the distance, identifies the subpopulations that are significant different between two profiles, finds genes that mark subpopulations, and predicts cell types of subpopulations. If two single-cell RNA-seq profiles have identical cell subpopulation structures (the same subpopulations with the same proportion), the distance is zero, whereas, the distance is one if completely different subpopulations.

if(hasDiffnodes){
  cat("* _**Subpopulation view**_ - heatmap of gene expression that mark the statistical significant subpopulations, and predicted cell types of these subpopulations based on Mouse Cell Atlas [Han et al., 2018, Cell, 1091-1107] if scRNA-seq are derived from mouse samples. \n")
}

Results Summary

Subpopulation structure:

count.table<-plotData$count.table
count.table<-data.frame(count.table, check.names = F)
count.table<-cbind(data.frame(Subpopulation=plotData$samplenames), count.table)
kable(count.table, caption=tabRef("tableCell", "The number of cells in each subpopulation in two scRNA-seq profiles"), row.names=FALSE, align="r") %>% kable_styling(bootstrap_options = c("striped", "hover"))

if(hasDiffnodes){
  df<-t(data.frame("R1"=c("Proportion difference", sprintf("%.2f", plotData$diffval))))
  colnames(df)<-c("Subpopulation", plotData$diffnodes)
  kable(df, caption=tabRef("tableDiff", "Significantly different subpopulations and their proportion difference between two scRNA-seq profiles"), row.names=FALSE, align="r") %>% kable_styling(bootstrap_options = c("striped", "hover"))
}else{
  cat("No significantly differential subproportion detected. <br>\n")
}

Plotdiff_tree(plotData$count.table,plotData$tree,plotData$diffpop_perm_max,plotData$relpop_perm_max,plotData$legendtxt)

Plotdiff_tSNE(plotData$count.table, plotData$hvgdata_pca, plotData$memb, plotData$diffnodes,plotData$colcluster,plotData$legendtxt)

subRmd<-paste0(outputFile, "_subpopulation.rmd")
fileContent<-c("# Subpopulation View \n")
#for (i in 1:2){
for (i in 1:length(plotData$diffnodes)){
  nodeName<-plotData$diffnodes[i]
  commonContent<-paste0("  nodeName<-plotData$diffnodes[", i, "]\n  clustertext<-paste0(\"Subpopulation \", nodeName, \", \", paste(plotData$count.table[, nodeName], collapse=\":\"))\n")

  fileContent<-c(fileContent, paste0("\\pagebreak\n\n## The cell subpopulation ", nodeName, "\n"))

  fileContent<-c(fileContent, paste0("```r"))

  fileContent<-c(fileContent, paste0(commonContent,"  Plotdiff_Markergene(plotData$normdata, plotData$memb, nodeName, plotData$colcluster, clustertext)"))

  fileContent<-c(fileContent, "```\n")

  if(hasCellTypes){
  fileContent<-c(fileContent, paste0("```r"))

  fileContent<-c(fileContent, paste0(commonContent, "  scUnifrac_predictCelltype(plotData$normdata[,plotData$memb==nodeName], plotData$ref.expr, clustertext)"))

  fileContent<-c(fileContent, "```\n")
  }
  fileContent<-c(fileContent, "<hr>\n")
}
writeLines(fileContent, subRmd)

file.remove(subRmd)

Session Info

devtools::session_info()


liuqivandy/scUnifrac documentation built on Jan. 21, 2021, 2:02 p.m.