diff --git a/_pkgdown.yml b/_pkgdown.yml index 4a805b754..5e4d497ad 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -166,6 +166,8 @@ navbar: href: articles/singlecell_prostate_standard.html - text: Prostate Integration href: articles/singlecell_prostate_integration.html + - text: Human Lung Adenocarcinoma + href: articles/singlecell_lung_adenocarcinoma.html news: text: News menu: @@ -287,6 +289,7 @@ articles: contents: - singlecell_prostate_standard - singlecell_prostate_integration + - singlecell_lung_adenocarcinoma news: cran_dates: false diff --git a/vignettes/images/singlecell_lung_adenocarcinoma/0-HVFplot.png b/vignettes/images/singlecell_lung_adenocarcinoma/0-HVFplot.png new file mode 100644 index 000000000..e035abb56 Binary files /dev/null and b/vignettes/images/singlecell_lung_adenocarcinoma/0-HVFplot.png differ diff --git a/vignettes/images/singlecell_lung_adenocarcinoma/3_scree_plot.png b/vignettes/images/singlecell_lung_adenocarcinoma/3_scree_plot.png new file mode 100644 index 000000000..f367d54af Binary files /dev/null and b/vignettes/images/singlecell_lung_adenocarcinoma/3_scree_plot.png differ diff --git a/vignettes/images/singlecell_lung_adenocarcinoma/4_Cluster.png b/vignettes/images/singlecell_lung_adenocarcinoma/4_Cluster.png new file mode 100644 index 000000000..cbfb39624 Binary files /dev/null and b/vignettes/images/singlecell_lung_adenocarcinoma/4_Cluster.png differ diff --git a/vignettes/images/singlecell_lung_adenocarcinoma/5_metaheatmap.png b/vignettes/images/singlecell_lung_adenocarcinoma/5_metaheatmap.png new file mode 100644 index 000000000..55631312d Binary files /dev/null and b/vignettes/images/singlecell_lung_adenocarcinoma/5_metaheatmap.png differ diff --git a/vignettes/images/singlecell_lung_adenocarcinoma/6_featureplot.png b/vignettes/images/singlecell_lung_adenocarcinoma/6_featureplot.png new file mode 100644 index 000000000..a0f1572cc Binary files /dev/null and b/vignettes/images/singlecell_lung_adenocarcinoma/6_featureplot.png differ diff --git a/vignettes/images/singlecell_lung_adenocarcinoma/6_heatmap_all_clusters_cell_types.png b/vignettes/images/singlecell_lung_adenocarcinoma/6_heatmap_all_clusters_cell_types.png new file mode 100644 index 000000000..b932abdf3 Binary files /dev/null and b/vignettes/images/singlecell_lung_adenocarcinoma/6_heatmap_all_clusters_cell_types.png differ diff --git a/vignettes/images/singlecell_lung_adenocarcinoma/7_Annotation.png b/vignettes/images/singlecell_lung_adenocarcinoma/7_Annotation.png new file mode 100644 index 000000000..81180b4aa Binary files /dev/null and b/vignettes/images/singlecell_lung_adenocarcinoma/7_Annotation.png differ diff --git a/vignettes/singlecell_lung_adenocarcinoma.Rmd b/vignettes/singlecell_lung_adenocarcinoma.Rmd new file mode 100644 index 000000000..5e86a671a --- /dev/null +++ b/vignettes/singlecell_lung_adenocarcinoma.Rmd @@ -0,0 +1,409 @@ +--- +title: "Single Cell Human Lung Adenocarcinoma" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Single Cell Human Lung Adenocarcinoma} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + + +```{r, eval=FALSE} +# Ensure Giotto Suite is installed. +if(!"Giotto" %in% installed.packages()) { + devtools::install_github("drieslab/Giotto") + } + +# Ensure GiottoData, a small, helper module for tutorials, is installed. +if(!"GiottoData" %in% installed.packages()) { + devtools::install_github("drieslab/GiottoData") + } + +# Ensure the Python environment for Giotto has been installed. +genv_exists = checkGiottoEnvironment() +if(!genv_exists){ +# The following command need only be run once to install the Giotto environment. + installGiottoEnvironment() + } +``` + + +## Set up Giotto Environment + +``` {r, eval=FALSE} +library(Giotto) +library(GiottoData) + +# 1. set working directory +results_folder = 'path/to/result' + +# Optional: Specify a path to a Python executable within a conda or miniconda +# environment. If set to NULL (default), the Python executable within the previously +# installed Giotto environment will be used. +my_python_path = NULL # alternatively, "/local/python/path/python" if desired. + +# 3. create giotto instructions +instrs = createGiottoInstructions(save_dir = results_folder, + save_plot = TRUE, + show_plot = FALSE, + python_path = my_python_path) +``` + +## Dataset Explanation + +[Maynard et al.](https://pubmed.ncbi.nlm.nih.gov/32822576/) Processed Illumina Single Cell RNAseq of metastatic lung cancer using 49 clinical biopsies obtained from 30 patients before and during targeted therapy. The raw data can be found [here](https://www.ncbi.nlm.nih.gov/bioproject/591860). + +To run this vignette, download the files from this [Google drive](https://drive.google.com/drive/folders/1sDzO0WOD4rnGC7QfTKwdcQTx3L36PFwX) + +## Part 1: Create Giotto object + +Load data +```{r, eval=FALSE} +raw.data <- read.csv("Data_input/csv_files/S01_datafinal.csv", + header=T, row.names = 1) +``` + +Load metadata +```{r, eval=FALSE} +metadata <- read.csv("Data_input/csv_files/S01_metacells.csv", + row.names=1, header=T) +``` + +Find ERCC's, compute the percent ERCC, and drop them from the raw data. +```{r, eval=FALSE} +erccs <- grep(pattern = "^ERCC-", + x = rownames(x = raw.data), + value = TRUE) +percent.ercc <- Matrix::colSums(raw.data[erccs, ])/Matrix::colSums(raw.data) +ercc.index <- grep(pattern = "^ERCC-", + x = rownames(x = raw.data), + value = FALSE) +raw.data <- raw.data[-ercc.index,] +``` + + +``` {r, eval=FALSE} +giotto_SC <- createGiottoObject(expression = raw.data, + instructions = instrs) +``` + +Calculate percent ribosomal genes and add to metadata +```{r, eval=FALSE} +ribo.genes <- grep(pattern = "^RP[SL][[:digit:]]", + x = rownames(raw.data), value = TRUE) +percent.ribo <- Matrix::colSums(raw.data[ribo.genes, ])/Matrix::colSums(raw.data) + +giotto_SC <- addCellMetadata(giotto_SC, + new_metadata = data.frame(percent_ribo = percent.ribo)) +``` + +## Part 2: Process Giotto Object + +``` {r, eval=FALSE} +giotto_SC <- filterGiotto(gobject = giotto_SC, + expression_threshold = 1, + feat_det_in_min_cells = 10, + min_det_feats_per_cell = 500, + expression_values = c('raw'), + verbose = T) + +## normalize +giotto_SC <- normalizeGiotto(gobject = giotto_SC, scalefactor = 6000) + +## add gene & cell statistics +giotto_SC <- addStatistics(gobject = giotto_SC, expression_values = 'raw') +``` + +## Part 3: Dimension Reduction + +``` {r, eval=FALSE} +## PCA ## +giotto_SC <- calculateHVF(gobject = giotto_SC) +giotto_SC <- runPCA(gobject = giotto_SC, + center = TRUE, + cale_unit = TRUE) +screePlot(giotto_SC, + ncp = 30, + save_param = list(save_name = '3_scree_plot')) +``` + +![](images/singlecell_lung_adenocarcinoma/3_scree_plot.png) + +## Part 4: Cluster + +``` {r, eval=FALSE} +## cluster and run UMAP ## +# sNN network (default) +giotto_SC <- createNearestNetwork(gobject = giotto_SC, + dim_reduction_to_use = 'pca', + dim_reduction_name = 'pca', + dimensions_to_use = 1:10, k = 15) + +# UMAP +giotto_SC = runUMAP(giotto_SC, dimensions_to_use = 1:10) + +# Leiden clustering +giotto_SC <- doLeidenCluster(gobject = giotto_SC, + resolution = 0.5, + n_iterations = 1000) + +plotUMAP(gobject = giotto_SC, + cell_color = 'leiden_clus', + show_NN_network = T, + point_size = 1.5, + save_param = list(save_name = "4_Cluster")) +``` + +![](images/singlecell_lung_adenocarcinoma/4_Cluster.png) + +## Part 5: Differential Expression + +``` {r, eval=FALSE} +markers_scran = findMarkers_one_vs_all(gobject=giotto_SC, + method="scran", + expression_values="normalized", + cluster_column='leiden_clus', + min_feats=3) +markergenes_scran = unique(markers_scran[, head(.SD, 2), by="cluster"][["feats"]]) + +plotMetaDataHeatmap(giotto_SC, + expression_values = "normalized", + metadata_cols = 'leiden_clus', + selected_feats = markergenes_scran, + y_text_size = 8, + show_values = 'zscores_rescaled', + save_param = list(save_name = '5_metaheatmap')) +``` + +![](images/singlecell_lung_adenocarcinoma/5_metaheatmap.png) + +## Part 6: FeaturePlot + +``` {r, eval=FALSE} +# Plot known marker genes across different cell types. e.g. EPCAM for epithelial cells +dimFeatPlot2D(giotto_SC, + feats = c("EPCAM", "PMEL", "C1QA","COL1A1"), + cow_n_col = 2, + save_param = list(save_name = "6_featureplot")) +``` + +![](images/singlecell_lung_adenocarcinoma/6_featureplot.png) + +## Part 7: Cell type Annotation + +```{r} +marker_genes = list( + T_cells = c("CD2", "CD3D", "CD3E", "CD3G"), + macrophages = c("MARCO", "CSF1R", "CD68", "GLDN", "APOE", "CCL3L1", "TREM2", "C1QB", "NUPR1", "FOLR2", "RNASE1", "C1QA"), + dendritic = c("CD1E", "CD1C", "FCER1A", "PKIB", "CYP2S1", "NDRG2"), + mast= c("CMA1", "TPSAB1", "TPSB2"), + B_cells = c("IGLL5", "MZB1", "JCHAIN", "DERL3", "SDC1", "MS$A1", "BANK1", "PAX5", "CD79A"), + B_cells_PB = c("PRDM1", "XSP1", "IRF4"), + B_cell_mem = c("MS4A1", "IRF8"), + housekeeping = c("ACTB", "GAPDH", "MALAT1"), + neutrophils = c("FCGR3B", "ALPL", "CXCR1", "CXCR2", "ADGRG3", "CMTM2", "PROK2", "MME", "MMP25", "TNFRSF10C"), + pdcs = c("SLC32A1", "SHD", "LRRC26", "PACSIN1", "LILRA4", "CLEC4C", "DNASE1L3", "SCT", "LAMP5"), + carcinoma_cells = c("FCER1G", "IFI30", "LAPTM5", "ARHGDIB", "MALAT1"), + epithelial = c("EPCAM", "CD151") +) +``` + +```{r, eval=FALSE} +library(dplyr) +library(ComplexHeatmap) +heatmap_table <- calculateMetaTable(gobject = giotto_SC, + expression_values = 'normalized', + metadata_cols = 'leiden_clus', + selected_feats = unlist(marker_genes)) + +zscores = value = zscores_rescaled_per_feat = NULL + +heatmap_table[, zscores := scale(value), by = c('variable')] +heatmap_table[, zscores_rescaled_per_feat := scales::rescale(zscores, to = c(-1,1)), by = c('variable')] + +heatmap_table$cell_types_markers <- heatmap_table$variable + +heatmap_table <- heatmap_table %>% + mutate(cell_types_markers = case_when( + cell_types_markers %in% marker_genes[["B_cell_mem"]] ~ "B_cell_mem", + cell_types_markers %in% marker_genes[["B_cells"]] ~ "B_cells", + cell_types_markers %in% marker_genes[["carcinoma_cells"]] ~ "carcinoma_cells", + cell_types_markers %in% marker_genes[["dendritic"]] ~ "dendritic", + cell_types_markers %in% marker_genes[["epithelial"]] ~ "epithelial", + cell_types_markers %in% marker_genes[["housekeeping"]] ~ "housekeeping", + cell_types_markers %in% marker_genes[["macrophages"]] ~ "macrophages", + cell_types_markers %in% marker_genes[["mast"]] ~ "mast", + cell_types_markers %in% marker_genes[["neutrophils"]] ~ "neutrophils", + cell_types_markers %in% marker_genes[["pdcs"]] ~ "pdcs", + cell_types_markers %in% marker_genes[["T_cells"]] ~ "T_cells" + )) + +heatmap_matrix <- heatmap_table[,c("leiden_clus", "variable","zscores_rescaled_per_feat")] +heatmap_matrix <- tidyr::pivot_wider(heatmap_matrix, + names_from = "leiden_clus", + values_from = "zscores_rescaled_per_feat") +rownames_matrix <- heatmap_matrix$variable +colnames_matrix <- colnames(heatmap_matrix) + +heatmap_matrix <- as.matrix(heatmap_matrix[,-1]) +rownames(heatmap_matrix) <- rownames_matrix + +cell_types_heatmap <- unique(heatmap_table[,c("variable", "cell_types_markers")]) +colnames(cell_types_heatmap)[2] <- "cell_types" + +cell_types_heatmap <- cell_types_heatmap[order(cell_types),] + +n_leiden_clusters = max(giotto_SC@cell_metadata$cell$rna@metaDT$leiden_clus) + +panel_fun = function(index, nm) { + grid.rect() + grid.text(nm, 0.5, 0.5, gp = gpar(fontsize = 6)) +} + +## heatmap z-score per leiden cluster +png(filename = "results/6_heatmap_all_clusters_cell_types.png", + width = 2000, + height = 1500, + res = 300) +Heatmap(heatmap_matrix, + cluster_rows = FALSE, + cluster_columns = FALSE, + row_order = cell_types_heatmap$variable, + column_order = as.character(1:n_leiden_clusters), + row_names_gp = gpar(fontsize = 5), + column_names_gp = gpar(fontsize = 8), + column_names_rot = 45, + heatmap_legend_param = list(title = "", + labels_gp = gpar(fontsize = 8)), + left_annotation = rowAnnotation(cell_types = anno_block(align_to = list( + B_cell_mem = c("IRF8", "MS4A1"), + B_cells = c("IGLL5", "MZB1", "JCHAIN", "DERL3", "SDC1", "MS$A1", "BANK1", "PAX5", "CD79A"), + T_cells = c("CD2", "CD3D", "CD3E", "CD3G"), + B_cells_PB = c("PRDM1", "XSP1", "IRF4"), + carcinoma_cells = c("FCER1G", "IFI30", "LAPTM5", "ARHGDIB", "MALAT1"), + dendritic = c("CD1E", "CD1C", "FCER1A", "PKIB", "CYP2S1", "NDRG2"), + epithelial = c("EPCAM", "CD151"), + housekeeping = c("ACTB", "GAPDH"), + macrophages = c("MARCO", "CSF1R", "CD68", "GLDN", "APOE", "CCL3L1", "TREM2", "C1QB", "NUPR1", "FOLR2", "RNASE1", "C1QA"), + mast = c("CMA1", "TPSAB1", "TPSB2"), + neutrophils = c("FCGR3B", "ALPL", "CXCR1", "CXCR2", "ADGRG3", "CMTM2", "PROK2", "MME", "MMP25", "TNFRSF10C"), + pdcs = c("SLC32A1", "SHD", "LRRC26", "PACSIN1", "LILRA4", "CLEC4C", "DNASE1L3", "SCT", "LAMP5") + ), + panel_fun = panel_fun, + width = unit(2, "cm") + ) ) +) +dev.off() +``` + +![](images/singlecell_lung_adenocarcinoma/6_heatmap_all_clusters_cell_types.png) + +``` {r, eval=FALSE} +lung_labels<-c("carcinoma_cells",#1 + "epithelial",#2 + "T_cells",#3 + "macrophages",#4 + "T_cells",#5 + "epithelial",#6 + "T_cells",#7 + "epithelial",#8 + "macrophages",#9 + "carcinoma_cells",#10 + "epithelial",#11 + "carcinoma_cells",#12 + "carcinoma_cells",#13 + "B_cells_PB",#14 + "neutrophils",#15 + "pDCs",#16 + "carcinoma_cells",#17 + "carcinoma_cells",#18 + "mast",#19 + "epithelial",#20 + "carcinoma_cells",#21 + "B_cells",#22 + "T_cells",#23 + "carcinoma_cells",#24 + "carcinoma_cells",#25 + "epithelial",#26 + "carcinoma_cells",#27 + "housekeeping",#28 + "housekeeping",#29 + "B_cells", #30 + "dendritic", #31, + "neutrophils" #32 +) + +names(lung_labels) <- 1:32 +giotto_SC <- annotateGiotto(gobject = giotto_SC, + annotation_vector = lung_labels , + cluster_column = 'leiden_clus', + name = 'lung_labels') +dimPlot2D(gobject = giotto_SC, + dim_reduction_name = 'umap', + cell_color = "lung_labels", + show_NN_network = T, + point_size = 1.5, + save_param = list(save_name = "7_Annotation")) +``` + +![](images/singlecell_lung_adenocarcinoma/7_Annotation.png) + +```{r, eval=FALSE} +sessionInfo() +``` + +```{r, eval=FALSE} +R version 4.3.2 (2023-10-31) +Platform: x86_64-apple-darwin20 (64-bit) +Running under: macOS Sonoma 14.3 + +Matrix products: default +BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib +LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0 + +locale: +[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 + +time zone: America/New_York +tzcode source: internal + +attached base packages: +[1] stats graphics grDevices utils datasets methods base + +other attached packages: +[1] Giotto_4.0.2 GiottoClass_0.1.3 + +loaded via a namespace (and not attached): + [1] generics_0.1.3 utf8_1.2.4 + [3] SparseArray_1.2.3 bitops_1.0-7 + [5] gtools_3.9.5 lattice_0.21-9 + [7] magrittr_2.0.3 grid_4.3.2 + [9] Matrix_1.6-5 GenomeInfoDb_1.38.5 +[11] fansi_1.0.6 SingleCellExperiment_1.24.0 +[13] scales_1.3.0 codetools_0.2-19 +[15] abind_1.4-5 cli_3.6.2 +[17] rlang_1.1.3 crayon_1.5.2 +[19] XVector_0.42.0 Biobase_2.62.0 +[21] munsell_0.5.0 colorRamp2_0.1.0 +[23] DelayedArray_0.28.0 S4Arrays_1.2.0 +[25] parallel_4.3.2 tools_4.3.2 +[27] GiottoUtils_0.1.3 dplyr_1.1.4 +[29] colorspace_2.1-0 ggplot2_3.4.4 +[31] SpatialExperiment_1.12.0 GenomeInfoDbData_1.2.11 +[33] SummarizedExperiment_1.32.0 BiocGenerics_0.48.1 +[35] vctrs_0.6.5 R6_2.5.1 +[37] matrixStats_1.2.0 stats4_4.3.2 +[39] lifecycle_1.0.4 magick_2.8.2 +[41] zlibbioc_1.48.0 GiottoVisuals_0.1.2 +[43] S4Vectors_0.40.2 IRanges_2.36.0 +[45] pkgconfig_2.0.3 terra_1.7-65 +[47] pillar_1.9.0 gtable_0.3.4 +[49] data.table_1.14.10 glue_1.7.0 +[51] Rcpp_1.0.12 tidyselect_1.2.0 +[53] tibble_3.2.1 GenomicRanges_1.54.1 +[55] rstudioapi_0.15.0 MatrixGenerics_1.14.0 +[57] rjson_0.2.21 compiler_4.3.2 +[59] RCurl_1.98-1.14 +``` + + diff --git a/vignettes/visium_cytassist_lungcancer.Rmd b/vignettes/visium_cytassist_lungcancer.Rmd index 1f0d1de22..945d005cc 100644 --- a/vignettes/visium_cytassist_lungcancer.Rmd +++ b/vignettes/visium_cytassist_lungcancer.Rmd @@ -286,12 +286,19 @@ Visium spatial transcriptomics does not provide single-cell resolution, making c - Rank - DWLS -[Deconvolution](https://genomebiology.biomedcentral.com/articles/10.1186/s13059-021-02362-7) Corresponded Single cell dataset can be generated from [here](http://mousebrain.org/). Giotto_SC is processed from the downsampled [Loom](https://satijalab.org/loomr/loomr_tutorial) file and can also be downloaded from getSpatialDataset. +Corresponded Single cell dataset can be generated from [Single Cell Human Lung Adenocarcinoma](https://drieslab.github.io/Giotto/articles/singlecell_lung_adenocarcinoma.html) vignette. You can also download the Giotto object, or count matrix and metadata from [here](https://drive.google.com/drive/folders/1lv3KYkJoTy4vzJxyRT0zhm6RALVO89M8) + +Load the single-cell object + +```{r, eval=FALSE} +giotto_SC <- Giotto::loadGiotto("sc_lung_carcinoma") +``` ## PAGE The cell-type specific signature gene list was obtained from a previous study focused on investigating the therapy-induced evolution of lung cancer revealed by single-cell RNA sequencing. More information about the paper and scRNA-seq dataset can be found [here](https://doi.org/10.1016/j.cell.2020.07.017). + ```{r, eval=FALSE} # umap plots # Create PAGE matrix