Last updated: 2021-02-09

Checks: 5 2

Knit directory: Human_Development_snRNAseq/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20200812) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Using absolute paths to the files within your workflowr project makes it difficult for you and others to run your code on a different machine. Change the absolute path(s) below to the suggested relative path(s) to make your code more reproducible.

absolute relative
/Users/phipsonbelinda/Documents/MCRI_collab/Porrello/Human_Development_snRNAseq/code/normCounts.R code/normCounts.R
/Users/phipsonbelinda/Documents/MCRI_collab/Porrello/Human_Development_snRNAseq/code/findModes.R code/findModes.R
/Users/phipsonbelinda/Documents/MCRI_collab/Porrello/Human_Development_snRNAseq/code/ggplotColors.R code/ggplotColors.R
/Users/phipsonbelinda/Documents/MCRI_collab/Porrello/Human_Development_snRNAseq/data/targets.txt data/targets.txt

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version ffb8763. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/.DS_Store

Untracked files:
    Untracked:  data/adult-clust.txt
    Untracked:  data/cellinfoALL.Rdata
    Untracked:  data/dcm-clust.txt
    Untracked:  data/fetal-clust.txt
    Untracked:  data/gstlist-adult.Rdata
    Untracked:  data/gstlist-dcm-res03.Rdata
    Untracked:  data/gstlist-dcm.Rdata
    Untracked:  data/gstlist-fetal.Rdata
    Untracked:  data/gstlist-young.Rdata
    Untracked:  data/heart-markers-long.txt
    Untracked:  data/immune-markers-long.txt
    Untracked:  data/pseudobulk.Rds
    Untracked:  data/targets.txt
    Untracked:  data/targets_pools.txt
    Untracked:  data/young-clust.txt
    Untracked:  output/adult-int.Rds
    Untracked:  output/adultObjs.Rdata
    Untracked:  output/endo-int-FYA-filtered.Rds
    Untracked:  output/fetal-int.Rds
    Untracked:  output/fetalObjs.Rdata
    Untracked:  output/heartFYA.Rds
    Untracked:  output/young-int.Rds
    Untracked:  output/youngObjs.Rdata

Unstaged changes:
    Modified:   analysis/11-ClustEndo.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/11-ClustEndo.Rmd) and HTML (docs/11-ClustEndo.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd ffb8763 bphipson 2021-02-08 Added all analysis files

Load libraries and functions

library(edgeR)
library(RColorBrewer)
library(org.Hs.eg.db)
library(limma)
library(Seurat)
library(monocle)
library(cowplot)
library(DelayedArray)
library(scran)
library(NMF)
library(workflowr)
library(ggplot2)
library(clustree)
library(dplyr)
targets <- read.delim("/Users/phipsonbelinda/Documents/MCRI_collab/Porrello/Human_Development_snRNAseq/data/targets.txt",header=TRUE, stringsAsFactors = FALSE)
targets$FileName2 <- paste(targets$FileName,"/",sep="")
targets$Group_ID2 <- gsub("LV_","",targets$Group_ID)
group <- c("Fetal_1","Fetal_2","Fetal_3",
           "Young_1","Young_2","Young_3",
           "Adult_1","Adult_2","Adult_3", 
           "Diseased_1","Diseased_2",
           "Diseased_3","Diseased_4")
m <- match(group, targets$Group_ID2)
targets <- targets[m,]
fetal.integrated <- readRDS(file="./output/fetal-int.Rds")
load(file="./output/fetalObjs.Rdata")

young.integrated <- readRDS(file="./output/young-int.Rds")
load(file="./output/youngObjs.Rdata")

adult.integrated <- readRDS(file="./output/adult-int.Rds")
load(file="./output/adultObjs.Rdata")

Set default clustering resolution

# Default 0.3
Idents(fetal.integrated) <- fetal.integrated$integrated_snn_res.0.3
DimPlot(fetal.integrated, reduction = "tsne",label=TRUE,label.size = 6)+NoLegend()

# Default 0.3
DimPlot(young.integrated, reduction = "tsne",label=TRUE,label.size = 6)+NoLegend()

# Default 0.6
DimPlot(adult.integrated, reduction = "tsne",label=TRUE,label.size = 6)+NoLegend()

Merge all data together

heart <- merge(fetal.integrated, y = c(young.integrated, adult.integrated), project = "heart")
table(heart$orig.ident)
DefaultAssay(object = heart) <- "RNA"

Get endothelial cells only

endo <- subset(heart,subset = Broad_celltype == "Endothelial cells")
dim(endo)

Check for poor quality cells

Check for cells with very low number of uniquely detected genes.

par(mfrow=c(1,2))
plot(density(endo$nFeature_RNA),main="Number of genes detected")
abline(v=500,col=2)
plot(density(endo$nCount_RNA),main="Library size")
abline(v=2500,col=2)

#endo <- subset(endo, subset = nFeature_RNA > 500 & nCount_RNA > 2500)
dim(endo)
[1] 17926  5501
table(endo$biorep)

  a1   a2   a3   f1   f2   f3   y1   y2   y3 
 599  466  165  735  715 1298  511  462  550 

Run new integration with SCtransform normalisation

endo.list <- SplitObject(endo, split.by = "biorep")
for (i in 1:length(endo.list)) {
    endo.list[[i]] <- SCTransform(endo.list[[i]], verbose = FALSE)
}
kf <- min(sapply(endo.list, ncol))
endo.anchors <- FindIntegrationAnchors(object.list = endo.list, dims=1:30,anchor.features = 3000,k.filter=kf)
endo.integrated <- IntegrateData(anchorset = endo.anchors,dims=1:30)

Perform clustering

DefaultAssay(object = endo.integrated) <- "integrated"

Perform scaling and PCA

endo.integrated <- ScaleData(endo.integrated, verbose = FALSE)
endo.integrated <- RunPCA(endo.integrated, npcs = 50, verbose = FALSE)
ElbowPlot(endo.integrated,ndims=50)

VizDimLoadings(endo.integrated, dims = 1:4, reduction = "pca")

DimPlot(endo.integrated, reduction = "pca",group.by="orig.ident")

DimPlot(endo.integrated, reduction = "pca",group.by="biorep")

DimPlot(endo.integrated, reduction = "pca",group.by="sex")

DimPlot(endo.integrated, reduction = "pca",group.by="batch")

DimHeatmap(endo.integrated, dims = 1:15, cells = 500, balanced = TRUE)

DimHeatmap(endo.integrated, dims = 16:30, cells = 500, balanced = TRUE)

#DimHeatmap(endo.integrated, dims = 31:45, cells = 500, balanced = TRUE)

Perform nearest neighbours clustering

endo.integrated <- FindNeighbors(endo.integrated, dims = 1:20)
endo.integrated <- FindClusters(endo.integrated, resolution = 0.1)
table(Idents(endo.integrated))

   0    1    2    3    4    5    6 
2059 1623  760  428  367  142  122 
par(mfrow=c(1,1))
par(mar=c(5,4,2,2))
barplot(table(Idents(endo.integrated)),ylab="Number of cells",xlab="Clusters")
title("Number of cells in each cluster")

Visualisation with TSNE

set.seed(10)
endo.integrated <- RunTSNE(endo.integrated, reduction = "pca", dims = 1:20)
DimPlot(endo.integrated, reduction = "tsne",label=TRUE,label.size = 6,pt.size = 0.5)+NoLegend()

pdf(file="./output/Figures/tsne-endoALL-res01.pdf",width=10,height=8,onefile = FALSE)
DimPlot(endo.integrated, reduction = "tsne",label=TRUE,label.size = 6,pt.size = 0.5)+NoLegend()
dev.off()
DimPlot(endo.integrated, reduction = "tsne", group.by = "orig.ident")

DimPlot(endo.integrated, reduction = "tsne", split.by = "orig.ident")

DimPlot(endo.integrated, reduction = "tsne", group.by = "biorep")

DimPlot(endo.integrated, reduction = "tsne", group.by = "sex")

DimPlot(endo.integrated, reduction = "tsne", split.by = "sex")

DimPlot(endo.integrated, reduction = "tsne", group.by = "batch")

par(mfrow=c(1,1))
par(mar=c(4,4,2,2))
tab <- table(Idents(endo.integrated),endo.integrated$biorep)
barplot(t(tab/rowSums(tab)),beside=TRUE,col=ggplotColors(9),legend=TRUE)

par(mfrow=c(1,1))
par(mar=c(4,4,2,2))
tab <- table(Idents(endo.integrated),endo.integrated$orig.ident)
barplot(t(tab/rowSums(tab)),beside=TRUE,col=ggplotColors(3))
legend("topleft",legend=colnames(tab),fill=ggplotColors(3))

Visualisation with clustree

clusres <- c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2)
for(i in 1:length(clusres)){
  endo.integrated <- FindClusters(endo.integrated, 
                                   resolution = clusres[i])
}
pct.male <- function(x) {mean(x=="m")}
pct.female <- function(x) {mean(x=="f")}
pct.fetal <- function(x) {mean(x=="fetal")}
pct.young <- function(x) {mean(x=="young")}
pct.adult <- function(x) {mean(x=="adult")}
clustree(endo.integrated, prefix = "integrated_snn_res.")

clustree(endo.integrated, prefix = "integrated_snn_res.",
         node_colour = "sex", node_colour_aggr = "pct.female",assay="RNA")

clustree(endo.integrated, prefix = "integrated_snn_res.",
         node_colour = "sex", node_colour_aggr = "pct.male",assay="RNA")

clustree(endo.integrated, prefix = "integrated_snn_res.",
         node_colour = "orig.ident", node_colour_aggr = "pct.fetal",assay="RNA")

clustree(endo.integrated, prefix = "integrated_snn_res.",
         node_colour = "orig.ident", node_colour_aggr = "pct.young",assay="RNA")

clustree(endo.integrated, prefix = "integrated_snn_res.",
         node_colour = "orig.ident", node_colour_aggr = "pct.adult",assay="RNA")

Save Seurat object

DefaultAssay(endo.integrated) <- "RNA"
Idents(endo.integrated) <- endo.integrated$integrated_snn_res.0.1
# saveRDS(endo.integrated,file="./output/RDataObjects/endo-int-FYA-filtered.Rds")
#endo.integrated <- readRDS(file="./output/RDataObjects/endo-int-FYA.Rds")
# Load unfiltered counts matrix for every sample (object all)
#load("./output/RDataObjects/all-counts.Rdata")

sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
 [1] splines   parallel  stats4    stats     graphics  grDevices utils    
 [8] datasets  methods   base     

other attached packages:
 [1] dplyr_1.0.2                 clustree_0.4.3             
 [3] ggraph_2.0.4                NMF_0.23.0                 
 [5] cluster_2.1.0               rngtools_1.5               
 [7] pkgmaker_0.32.2             registry_0.5-1             
 [9] scran_1.18.1                SingleCellExperiment_1.12.0
[11] SummarizedExperiment_1.20.0 GenomicRanges_1.42.0       
[13] GenomeInfoDb_1.26.1         DelayedArray_0.16.0        
[15] MatrixGenerics_1.2.0        matrixStats_0.57.0         
[17] cowplot_1.1.0               monocle_2.18.0             
[19] DDRTree_0.1.5               irlba_2.3.3                
[21] VGAM_1.1-4                  ggplot2_3.3.2              
[23] Matrix_1.2-18               Seurat_3.2.2               
[25] org.Hs.eg.db_3.12.0         AnnotationDbi_1.52.0       
[27] IRanges_2.24.0              S4Vectors_0.28.0           
[29] Biobase_2.50.0              BiocGenerics_0.36.0        
[31] RColorBrewer_1.1-2          edgeR_3.32.0               
[33] limma_3.46.0                workflowr_1.6.2            

loaded via a namespace (and not attached):
  [1] reticulate_1.18           tidyselect_1.1.0         
  [3] RSQLite_2.2.1             htmlwidgets_1.5.2        
  [5] grid_4.0.2                combinat_0.0-8           
  [7] docopt_0.7.1              BiocParallel_1.24.1      
  [9] Rtsne_0.15                munsell_0.5.0            
 [11] codetools_0.2-18          ica_1.0-2                
 [13] statmod_1.4.35            future_1.20.1            
 [15] miniUI_0.1.1.1            withr_2.3.0              
 [17] colorspace_2.0-0          fastICA_1.2-2            
 [19] highr_0.8                 knitr_1.30               
 [21] rstudioapi_0.13           ROCR_1.0-11              
 [23] tensor_1.5                listenv_0.8.0            
 [25] labeling_0.4.2            git2r_0.27.1             
 [27] slam_0.1-47               GenomeInfoDbData_1.2.4   
 [29] polyclip_1.10-0           farver_2.0.3             
 [31] bit64_4.0.5               pheatmap_1.0.12          
 [33] rprojroot_2.0.2           parallelly_1.21.0        
 [35] vctrs_0.3.5               generics_0.1.0           
 [37] xfun_0.19                 R6_2.5.0                 
 [39] doParallel_1.0.16         graphlayouts_0.7.1       
 [41] rsvd_1.0.3                locfit_1.5-9.4           
 [43] bitops_1.0-6              spatstat.utils_1.17-0    
 [45] assertthat_0.2.1          promises_1.1.1           
 [47] scales_1.1.1              gtable_0.3.0             
 [49] beachmat_2.6.2            globals_0.14.0           
 [51] goftest_1.2-2             tidygraph_1.2.0          
 [53] rlang_0.4.9               lazyeval_0.2.2           
 [55] checkmate_2.0.0           yaml_2.2.1               
 [57] reshape2_1.4.4            abind_1.4-5              
 [59] backports_1.2.0           httpuv_1.5.4             
 [61] tools_4.0.2               gridBase_0.4-7           
 [63] ellipsis_0.3.1            ggridges_0.5.2           
 [65] Rcpp_1.0.5                plyr_1.8.6               
 [67] sparseMatrixStats_1.2.0   zlibbioc_1.36.0          
 [69] purrr_0.3.4               RCurl_1.98-1.2           
 [71] densityClust_0.3          rpart_4.1-15             
 [73] deldir_0.2-3              pbapply_1.4-3            
 [75] viridis_0.5.1             zoo_1.8-8                
 [77] ggrepel_0.8.2             fs_1.5.0                 
 [79] magrittr_2.0.1            data.table_1.13.2        
 [81] lmtest_0.9-38             RANN_2.6.1               
 [83] whisker_0.4               fitdistrplus_1.1-1       
 [85] patchwork_1.1.0           mime_0.9                 
 [87] evaluate_0.14             xtable_1.8-4             
 [89] sparsesvd_0.2             gridExtra_2.3            
 [91] HSMMSingleCell_1.10.0     compiler_4.0.2           
 [93] tibble_3.0.4              KernSmooth_2.23-18       
 [95] crayon_1.3.4              htmltools_0.5.0          
 [97] mgcv_1.8-33               later_1.1.0.1            
 [99] tidyr_1.1.2               DBI_1.1.0                
[101] tweenr_1.0.1              MASS_7.3-53              
[103] igraph_1.2.6              pkgconfig_2.0.3          
[105] plotly_4.9.2.1            scuttle_1.0.3            
[107] foreach_1.5.1             dqrng_0.2.1              
[109] XVector_0.30.0            stringr_1.4.0            
[111] digest_0.6.27             sctransform_0.3.1        
[113] RcppAnnoy_0.0.17          spatstat.data_1.5-2      
[115] rmarkdown_2.5             leiden_0.3.5             
[117] uwot_0.1.9                DelayedMatrixStats_1.12.1
[119] shiny_1.5.0               lifecycle_0.2.0          
[121] nlme_3.1-150              jsonlite_1.7.1           
[123] BiocNeighbors_1.8.1       viridisLite_0.3.0        
[125] pillar_1.4.7              lattice_0.20-41          
[127] fastmap_1.0.1             httr_1.4.2               
[129] survival_3.2-7            glue_1.4.2               
[131] qlcMatrix_0.9.7           FNN_1.1.3                
[133] spatstat_1.64-1           png_0.1-7                
[135] iterators_1.0.13          bluster_1.0.0            
[137] bit_4.0.4                 ggforce_0.3.2            
[139] stringi_1.5.3             blob_1.2.1               
[141] BiocSingular_1.6.0        memoise_1.1.0            
[143] future.apply_1.6.0