Last updated: 2020-08-04

Checks: 7 0

Knit directory: Embryoid_Body_Pilot_Workflowr/

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.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

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(20200804) 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.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

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 c6c3247. 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/

Untracked files:
    Untracked:  analysis/child/

Unstaged changes:
    Modified:   .Rprofile
    Modified:   .gitattributes
    Modified:   .gitignore
    Modified:   Embryoid_Body_Pilot_Workflowr.Rproj
    Modified:   README.md
    Modified:   _workflowr.yml
    Modified:   analysis/_site.yml
    Modified:   analysis/about.Rmd
    Modified:   analysis/index.Rmd
    Modified:   analysis/license.Rmd
    Modified:   code/README.md
    Modified:   data/README.md
    Modified:   output/README.md

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/SampleFilteringandSCT_Batch1Lane1.Rmd) and HTML (docs/SampleFilteringandSCT_Batch1Lane1.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 c6c3247 KLRhodes 2020-08-04 testing knit_expand again
html 2626c9b KLRhodes 2020-08-04 Build site.
Rmd 422197b KLRhodes 2020-08-04 testing knit expand

library(knitr)
library(Seurat)
library(Matrix)
library(DropletUtils)
library(ggplot2)
library(dplyr)
library(here)

load rds

samp.obj<- readRDS('/project2/gilad/katie/Pilot_HumanEBs/HumanEB_QCmetadata/Batch1_Lane1_seurat_NoNorm_QCMetaAdded.rds')
qc<- knitr::knit_expand(file = here::here("analysis/child/SampleFilteringAndSCT.Rmd"))

load libraries

library(Seurat)
library(Matrix)
library(DropletUtils)
library(ggplot2)
library(dplyr)
options(future.globals.maxSize= 4000*1024^2) # allow global exceeding 4Gb
#print(params$samp)
#samp.obj<- readRDS(paste0(params$samp),".rds"))
head(samp.obj)
An object of class Seurat 
1 features across 4702 samples within 1 assay 
Active assay: RNA (1 features, 0 variable features)
#remove doublets
samp.obj<- subset(samp.obj, subset = individual != 'Doublet')

#remove cells assigned to individuals not actually in this sample
samp.obj<- subset(samp.obj, subset = individual != 'SNG-SCM-12.variant')
samp.obj<- subset(samp.obj, subset = individual != 'SNG-SCM-13.variant')
samp.obj<- subset(samp.obj, subset = individual != 'SNG-SCM-6.variant')
samp.obj<- subset(samp.obj, subset = individual != 'SNG-SCM-7.variant')
samp.obj<- subset(samp.obj, subset = individual != 'SNG-SCM-8.variant')
head(samp.obj)
An object of class Seurat 
1 features across 3550 samples within 1 assay 
Active assay: RNA (1 features, 0 variable features)
samp.obj<- subset(samp.obj, subset = EmptyDrops.FDR < .0001) # very strict, may lose some "good" cells, but limits set to high quality cells and there are enough cells remaining for downstream analyses
head(samp.obj)
An object of class Seurat 
1 features across 2442 samples within 1 assay 
Active assay: RNA (1 features, 0 variable features)
VlnPlot(samp.obj, features= "percent.mt", group.by = "individual", pt.size = 0)

#visualize feature-feature relationships with FeatureScatter
plot1<- FeatureScatter(samp.obj, feature1 = "nCount_RNA", feature2 = "percent.mt", group.by = "individual")
plot2<- FeatureScatter(samp.obj, feature1 = "nCount_RNA", feature2 = "nFeature_RNA", group.by = "individual")
CombinePlots(plots= list(plot1, plot2), legend = "right")
Warning: CombinePlots is being deprecated. Plots should now be combined using
the patchwork system.

#filtering out cells with high percent.mt. cutting cells with >20% mt based on the figure above and previous analysis of processed data. 
samp.obj<- subset(samp.obj, subset = percent.mt < 20)
samp.obj<- subset(samp.obj, subset = percent.mt > 3) #because low mt cells cluster together into cluster of low quality cells downstream, can eliminate them here. this is very strict and will throw out potentially good cells from "good" clusters too. but those clusters have a range of mt percentage and will not be eliminated entirely like the junk clusters will.
head(samp.obj)
An object of class Seurat 
1 features across 2003 samples within 1 assay 
Active assay: RNA (1 features, 0 variable features)
VlnPlot(samp.obj, features = "nCount_RNA",group.by = "individual", pt.size = 0)

VlnPlot(samp.obj, features = "nFeature_RNA",group.by = "individual", pt.size = 0)

head(samp.obj)
An object of class Seurat 
1 features across 2003 samples within 1 assay 
Active assay: RNA (1 features, 0 variable features)
summary(samp.obj$nFeature_RNA)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   1577    2482    3086    3539    4164    9632 
#set a feature threshold
samp.obj<- subset(samp.obj, subset = nFeature_RNA > 1500) #again, very strict, may lose some "good" cells, but limits set to high quality cells and there are enough cells remaining for downstream analyses
head(samp.obj)
An object of class Seurat 
1 features across 2003 samples within 1 assay 
Active assay: RNA (1 features, 0 variable features)
#in seurat SCTransform vignette, they regress out MT percentage, but we don't. Reasoning is that MT percentage probably correlates with cell type for us so its still useful information for clustering.

samp.obj<- suppressWarnings(SCTransform(samp.obj, verbose=F))
samp.obj<- RunPCA(samp.obj, npcs= 100, verbose = F)
DimPlot(samp.obj, reduction = "pca")

DimPlot(samp.obj, reduction = "pca", group.by = "individual")

VizDimLoadings(samp.obj, dims = 1:2, reduction = "pca")

VizDimLoadings(samp.obj, dims = 3:4, reduction = "pca")

VizDimLoadings(samp.obj, dims = 5:6, reduction = "pca")

xlim <- c(min(samp.obj@reductions$pca@cell.embeddings[,'PC_1']),
          max(samp.obj@reductions$pca@cell.embeddings[,'PC_1']))
ylim <- c(min(samp.obj@reductions$pca@cell.embeddings[,'PC_2']),
          max(samp.obj@reductions$pca@cell.embeddings[,'PC_2']))

individuals <- table(samp.obj$individual)
individuals <- individuals[individuals>50]
individuals <- names(individuals)
for (i in individuals)
{
  print(DimPlot(samp.obj, reduction = "pca", 
                cells = WhichCells(samp.obj, expression = individual == i)) +
          xlim(xlim) + ylim(ylim) + ggtitle(i))
}

#Keep all dims that explain more than 1% of variance
pva<- samp.obj@reductions$pca@stdev^2/samp.obj@reductions$pca@misc$total.variance
ndim <- length(which(pva>=0.01))
ElbowPlot(samp.obj, ndims = ndim*2) + geom_vline(xintercept=ndim, linetype="dashed", color = "red")

ndim
[1] 7
samp.clust<- FindNeighbors(samp.obj, dims = 1:ndim, verbose = F)
samp.clust<- FindClusters(samp.clust, verbose = F)
samp.clust<- RunUMAP(samp.clust, dims=1:ndim, verbose = F)
Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric
To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation'
This message will be shown once per session
samp.clust<- RunTSNE(samp.clust, dims=1:ndim, verbose = F)
DimPlot(samp.clust, reduction = "umap")

DimPlot(samp.clust, reduction = "umap", group.by = "orig.ident")

DimPlot(samp.clust, reduction = "umap", group.by = "individual")

xlim <- c(min(samp.clust@reductions$umap@cell.embeddings[,'UMAP_1']),
          max(samp.clust@reductions$umap@cell.embeddings[,'UMAP_1']))
ylim <- c(min(samp.clust@reductions$umap@cell.embeddings[,'UMAP_2']),
          max(samp.clust@reductions$umap@cell.embeddings[,'UMAP_2']))
for (i in individuals)
{
  print(DimPlot(samp.clust, reduction = "umap", 
                cells = WhichCells(samp.clust, expression = individual == i)) +
          xlim(xlim) + ylim(ylim) + ggtitle(i))
}

FeaturePlot(samp.clust, features = c("POU5F1", "PAX6", "HAND1", "SOX17"), pt.size = 0.2, ncol=3)

FeaturePlot(samp.clust, features = c("ALB", "AFP", "HNF4A", "GFB", "TTR", "ASGR1"), pt.size = 0.2, ncol=3)
Warning: Could not find ALB in the default search locations, found in RNA assay
instead
Warning in FetchData(object = object, vars = c(dims, "ident", features), : The
following requested variables were not found: GFB

DimPlot(samp.clust, reduction = "tsne")

DimPlot(samp.clust, reduction = "tsne", group.by = "orig.ident")

DimPlot(samp.clust, reduction = "tsne", group.by = "individual")

xlim <- c(min(samp.clust@reductions$tsne@cell.embeddings[,'tSNE_1']),
          max(samp.clust@reductions$tsne@cell.embeddings[,'tSNE_1']))
ylim <- c(min(samp.clust@reductions$tsne@cell.embeddings[,'tSNE_2']),
          max(samp.clust@reductions$tsne@cell.embeddings[,'tSNE_2']))
for (i in individuals)
{
  print(DimPlot(samp.clust, reduction = "tsne", 
                cells = WhichCells(samp.clust, expression = individual == i)) +
          xlim(xlim) + ylim(ylim) + ggtitle(i))
}

samp<- samp.clust@meta.data$SampleID[1]
saveRDS(samp.clust, file=paste0('/project2/gilad/katie/Pilot_HumanEBs/SampleQCrds/',samp,'.seurat.rds'))
#Not rerunning the save, already these saved. 
FeaturePlot(samp.clust, features = "nFeature_RNA")

FeaturePlot(samp.clust, features = "nCount_RNA")

VlnPlot(samp.clust, features = "nFeature_RNA", pt.size = 0)

VlnPlot(samp.clust, features = "percent.mt", pt.size = 0)

#how many cells per cluster from each individual?
table(samp.clust@meta.data$SCT_snn_res.0.8, samp.clust@meta.data$individual)
    
     SNG-NA18511.variant2 SNG-NA18858.variant2 SNG-NA19160.variant2
  0                     1                  298                    2
  1                   118                   33                   57
  2                    68                    5                   48
  3                     9                    5                   66
  4                    32                    2                   52
  5                     6                    0                   78
  6                    20                    4                   35
  7                    25                    6                   30
  8                    17                    2                   43
  9                     7                   86                    6
  10                   18                    6                   17
  11                    2                    0                   17
  12                    2                    0                   22
    
     SNG-SCM-10.variant SNG-SCM-9.variant
  0                   0                 1
  1                  50                24
  2                  46                50
  3                  26                74
  4                  46                44
  5                  28                43
  6                  45                29
  7                  23                30
  8                  26                22
  9                   0                 4
  10                 33                26
  11                 21                36
  12                 12                19

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Scientific Linux 7.4 (Nitrogen)

Matrix products: default
BLAS/LAPACK: /software/openblas-0.2.19-el7-x86_64/lib/libopenblas_haswellp-r0.2.19.so

locale:
[1] C

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

other attached packages:
 [1] here_0.1-11                 dplyr_1.0.0                
 [3] ggplot2_3.3.2               DropletUtils_1.6.1         
 [5] SingleCellExperiment_1.8.0  SummarizedExperiment_1.16.1
 [7] DelayedArray_0.12.3         BiocParallel_1.20.1        
 [9] matrixStats_0.56.0          Biobase_2.46.0             
[11] GenomicRanges_1.38.0        GenomeInfoDb_1.22.1        
[13] IRanges_2.20.2              S4Vectors_0.24.4           
[15] BiocGenerics_0.32.0         Matrix_1.2-18              
[17] Seurat_3.2.0                knitr_1.29                 
[19] workflowr_1.6.2            

loaded via a namespace (and not attached):
  [1] backports_1.1.8        plyr_1.8.6             igraph_1.2.5          
  [4] lazyeval_0.2.2         splines_3.6.1          listenv_0.8.0         
  [7] digest_0.6.25          htmltools_0.5.0        gdata_2.18.0          
 [10] magrittr_1.5           tensor_1.5             cluster_2.1.0         
 [13] ROCR_1.0-7             limma_3.42.2           globals_0.12.5        
 [16] R.utils_2.9.2          colorspace_1.4-1       rappdirs_0.3.1        
 [19] ggrepel_0.8.2          xfun_0.16              crayon_1.3.4          
 [22] RCurl_1.98-1.2         jsonlite_1.7.0         spatstat_1.64-1       
 [25] spatstat.data_1.4-3    survival_3.2-3         zoo_1.8-8             
 [28] ape_5.3                glue_1.4.1             polyclip_1.10-0       
 [31] gtable_0.3.0           zlibbioc_1.32.0        XVector_0.26.0        
 [34] leiden_0.3.3           Rhdf5lib_1.8.0         future.apply_1.6.0    
 [37] HDF5Array_1.14.4       abind_1.4-5            scales_1.1.1          
 [40] edgeR_3.28.1           miniUI_0.1.1.1         Rcpp_1.0.5            
 [43] viridisLite_0.3.0      xtable_1.8-4           dqrng_0.2.1           
 [46] reticulate_1.16        rsvd_1.0.3             htmlwidgets_1.5.1     
 [49] httr_1.4.2             gplots_3.0.4           RColorBrewer_1.1-2    
 [52] ellipsis_0.3.1         ica_1.0-2              farver_2.0.3          
 [55] pkgconfig_2.0.3        R.methodsS3_1.8.0      uwot_0.1.8            
 [58] deldir_0.1-28          locfit_1.5-9.4         labeling_0.3          
 [61] tidyselect_1.1.0       rlang_0.4.7            reshape2_1.4.4        
 [64] later_1.1.0.1          munsell_0.5.0          tools_3.6.1           
 [67] generics_0.0.2         ggridges_0.5.2         evaluate_0.14         
 [70] stringr_1.4.0          fastmap_1.0.1          yaml_2.2.1            
 [73] goftest_1.2-2          npsurv_0.4-0           fs_1.4.2              
 [76] fitdistrplus_1.0-14    caTools_1.18.0         purrr_0.3.4           
 [79] RANN_2.6.1             pbapply_1.4-2          future_1.18.0         
 [82] nlme_3.1-140           whisker_0.4            mime_0.9              
 [85] R.oo_1.23.0            compiler_3.6.1         plotly_4.9.2.1        
 [88] png_0.1-7              lsei_1.2-0             spatstat.utils_1.17-0 
 [91] tibble_3.0.3           stringi_1.4.6          RSpectra_0.16-0       
 [94] lattice_0.20-38        vctrs_0.3.2            pillar_1.4.6          
 [97] lifecycle_0.2.0        lmtest_0.9-37          RcppAnnoy_0.0.16      
[100] data.table_1.13.0      cowplot_1.0.0          bitops_1.0-6          
[103] irlba_2.3.3            httpuv_1.5.4           patchwork_1.0.1       
[106] R6_2.4.1               promises_1.1.1         KernSmooth_2.23-15    
[109] gridExtra_2.3          codetools_0.2-16       MASS_7.3-51.4         
[112] gtools_3.8.2           rhdf5_2.30.1           rprojroot_1.3-2       
[115] withr_2.2.0            sctransform_0.2.1      GenomeInfoDbData_1.2.2
[118] mgcv_1.8-28            grid_3.6.1             rpart_4.1-15          
[121] tidyr_1.1.0            rmarkdown_2.3          Rtsne_0.15            
[124] git2r_0.26.1           shiny_1.5.0