options(knitr.table.format = "html") 
options(scipen=10)
knitr::opts_chunk$set(echo = TRUE, fig.path = file.path(results$savePath, 'report-figures//'))

title <- "scCancer"
if(!is.null(results$combName)){
  title <- paste0(results$combName, "  -  ", title)
}

if(!is.null(results$authorName)){
  userName <- results$authorName
}else{
  userName <- Sys.getenv("USERNAME")
}
reportMark <- Sys.time()
if(userName != ""){
  reportMark <- paste0(userName, " , ", reportMark)
}

h.i <- 1
h.ii <- 1

r title


r reportMark

r h.i Read data

The input samples are:

cat("| Sample name     | #cells after QC          |\n", sep="")
cat("| :-------------- | :----------------------- |\n", sep="")
for(s in results$sampleNames){
  cat("| ", s, " | ", sum(results$cell.annotation$sample == s), " |\n", sep = "")
}

h.i <- h.i + 1

r h.i Data preprocessing

After the quality control, we perform following preprocessing steps based on some functions of the R package Seurat V3.

results$seurat.plots$p.hvg
cat("<p align=\"right\">(Hi-res image: <a href=\"./figures/hvg.png\">view</a>)</p>\n")
h.i <- h.i + 1

r h.i Cells annotation

r h.i.r h.ii Markers expression profile

Here are the scatter plots colored by the normalized expression of some cell type markers.

if(results$bool.add.features){
  if(results$species == "human"){
    cat("| Cell Type       | Markers                  |\n", sep="")
    cat("| :-------------- | :----------------------- |\n", sep="")
    cat("| T cells (CD4+)  | PTPRC, CD3D, CD4         |\n", sep="")
    cat("| T cells (CD8+)  | PTPRC, CD3D, CD8A, CD8B  |\n", sep="")
    cat("| B cells         | PTPRC, CD79A             |\n", sep="")
    cat("| NK cell         | PTPRC, NKG7              |\n", sep="")
    cat("| Myeloid cells   | PTPRC, LYZ               |\n", sep="")
    cat("| Endothelial     | PLVAP                    |\n", sep="")
    cat("| Fibroblast      | ACTA2                    |\n", sep="")
    cat("| Epithelial      | EPCAM, KRT8              |\n", sep="")
  }else{
    cat("| Cell Type       | Markers                  |\n", sep="")
    cat("| :-------------- | :----------------------- |\n", sep="")
    cat("| T cells (CD4+)  | Ptprc, Cd3d, Cd4         |\n", sep="")
    cat("| T cells (CD8+)  | Ptprc, Cd3d, Cd8a, Cd8b  |\n", sep="")
    cat("| B cells         | Ptprc, Cd79a             |\n", sep="")
    cat("| NK cell         | Ptprc, Nkg7              |\n", sep="")
    cat("| Myeloid cells   | Ptprc, Lyz1, Lyz2        |\n", sep="")
    cat("| Endothelial     | Plvap                    |\n", sep="")
    cat("| Fibroblast      | Acta2                    |\n", sep="")
    cat("| Epithelial      | Epcam, Krt8              |\n", sep="")
  }
}
if(!is.null(results$show.features)){
  cat("| Input genes     | ", paste(results$show.features, collapse=", "), " |\n", sep="")
}

results$seurat.plots$p.markers.all

(Hi-res image: view, view single)

h.ii <- h.ii + 1

r h.i.r h.ii Clustering

In order to identify clusters of all single cells, we perform a graph-based clustering by running Seurat functions. The cluster information can be found in the column Cluster of the table file cellAnnotation.txt.

Here is the t-SNE plot colored by cell clusters.

results$seurat.plots$p.cluster.tsne

(Hi-res image: view)


h.ii <- h.ii + 1

r h.i.r h.ii Sample source

The sample source information can be found in the column sample of the table file cellAnnotation.txt. The method of batch effect correction is r results$comb.method.

Here is the the scatter plot colored by cell clusters.

results$p.sample

(Hi-res image: view)

Here is a bar plot showing the relationship between cell cluster and sample source.

results$p.bar.sample

(Hi-res image: view)

h.ii <- h.ii + 1





# if(is.null(results$tumor.clusters)){
#     cat("#### According to the results of cell type prediction and cell malignancy estimation, ",
#     "we couldn't identify tumor clusters, ", 
#     "so we use all clusters to perform following heterogeneity analyses.\n", sep = "")
# }else{
#     # cat("#### According to the results of cell type prediction and cell malignancy estimation, we identify the clusters `",
#     #     str_c(results$tumor.clusters, collapse = ", "),
#     #     "` as tumor clusters, and following intra-tumor heterogeneity analyses mainly focus on them.\n", sep = "")
#     cat("#### According to the results of cell type prediction and cell malignancy estimation, we identify the tumor clusters, ",
#         "and following intra-tumor heterogeneity analyses mainly focus on them.\n", sep = "")
# }
cat("#### In order to analyze <span style='color:red'>intra-tumor heterogeneity</span>, we select tumor clusters firstly based on the results of cell type prediction.\n")
if(is.null(results$tumor.clusters)){
    cat("#### <span style='color:red;font-size:19px'>Warning:</span> Here, we couldn't identify the tumor clusters, so we use <span style='color:red'>all clusters</span> to perform following analyses.\n")
}else{
    cat("#### Here, we identify <span style='color:red'>cluster `", str_c(results$tumor.clusters, collapse = ", "),
        "`</span> as tumor cells. And following analyses mainly focus on them.\n", sep = "")
}




h.i <- h.i + 1

r h.i Output

r.i <- 7

Running this script generates following files:

  1. Html report : report-scAnnoComb.html.
  2. Markdown report : report-scAnnoComb.md.
  3. Figure files : figures/.
  4. Figures used in the report : report-figures/.
  5. Seurat object : expr.RDS.
  6. Annotation of cells : cellAnnotation.txt.
cat(r.i, ". **Anchors for batch correction** : ", sep = "")
cat("[anchors.RDS](./anchors.RDS).\n", sep = "")
r.i <- r.i + 1
cat(r.i, ". **Differentially expressed genes' information for all clusters** : ", sep = "")
cat("[diff.expr.genes/](./diff.expr.genes/).\n", sep = "")
r.i <- r.i + 1
cat(r.i, ". **Results of expression programs identification** : [expr.programs/](./expr.programs/).\n", sep = "")
r.i <- r.i + 1



© G-Lab, Tsinghua University



wguo-research/scCancer documentation built on May 26, 2024, 9:12 p.m.