From a8511e6a87c1b0c4c33bf7482825db6292a02028 Mon Sep 17 00:00:00 2001 From: Mark Keller <7525285+keller-mark@users.noreply.github.com> Date: Sun, 24 Sep 2023 15:01:34 -0400 Subject: [PATCH] Comment out vignette code --- pkgdown/_pkgdown.yml | 6 - vignettes/giotto.Rmd | 70 ++--- vignettes/session_info.Rmd | 2 +- vignettes/seurat_azimuth.Rmd | 428 +++++++++++++-------------- vignettes/seurat_basic.Rmd | 108 +++---- vignettes/seuratdata.Rmd | 74 ++--- vignettes/single_cell_experiment.Rmd | 66 ++--- vignettes/spatial_experiment.Rmd | 52 ++-- 8 files changed, 400 insertions(+), 406 deletions(-) diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 0a065bb..0dc0bcb 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -53,13 +53,7 @@ reference: - giotto_to_anndata_zarr articles: - - title: Articles - navbar: Developer guides - contents: - - dev_wrapper_class - - dev_wrapper_subclass - title: Articles navbar: Troubleshooting contents: - - debugging - session_info diff --git a/vignettes/giotto.Rmd b/vignettes/giotto.Rmd index be60e8b..20efb68 100644 --- a/vignettes/giotto.Rmd +++ b/vignettes/giotto.Rmd @@ -121,41 +121,41 @@ SS_seqfish <- runtSNE(SS_seqfish, dimensions_to_use = 1:15) Set up the Vitessce widget: ```r -library(vitessceR) - -w <- GiottoWrapper$new( - SS_seqfish, - cell_set_metas = c("cell_types"), - cell_set_meta_names = c("Cell Types"), - cell_embeddings = c("pca", "tsne"), - cell_embedding_names = c("PCA", "t-SNE"), - out_dir = file.path("data", "giotto") -) - -vc <- VitessceConfig$new("My config") -dataset <- vc$add_dataset("My dataset")$add_object(w) -spatial <- vc$add_view(dataset, Component$SPATIAL) -scatterplot_tsne <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "t-SNE") -cell_sets <- vc$add_view(dataset, Component$CELL_SETS) -status <- vc$add_view(dataset, Component$STATUS) -desc <- vc$add_view(dataset, Component$DESCRIPTION) -desc <- desc$set_props(description = "Visualization of a Giotto object.") - -vc$layout( - hconcat( - vconcat( - spatial, - scatterplot_tsne - ), - vconcat( - cell_sets, - hconcat(desc, status) - ) - ) -) - -# Render the Vitessce widget -vc$widget(theme = "light") +# library(vitessceR) + +# w <- GiottoWrapper$new( +# SS_seqfish, +# cell_set_metas = c("cell_types"), +# cell_set_meta_names = c("Cell Types"), +# cell_embeddings = c("pca", "tsne"), +# cell_embedding_names = c("PCA", "t-SNE"), +# out_dir = file.path("data", "giotto") +# ) + +# vc <- VitessceConfig$new("My config") +# dataset <- vc$add_dataset("My dataset")$add_object(w) +# spatial <- vc$add_view(dataset, Component$SPATIAL) +# scatterplot_tsne <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "t-SNE") +# cell_sets <- vc$add_view(dataset, Component$CELL_SETS) +# status <- vc$add_view(dataset, Component$STATUS) +# desc <- vc$add_view(dataset, Component$DESCRIPTION) +# desc <- desc$set_props(description = "Visualization of a Giotto object.") + +# vc$layout( +# hconcat( +# vconcat( +# spatial, +# scatterplot_tsne +# ), +# vconcat( +# cell_sets, +# hconcat(desc, status) +# ) +# ) +# ) + +# # Render the Vitessce widget +# vc$widget(theme = "light") ``` diff --git a/vignettes/session_info.Rmd b/vignettes/session_info.Rmd index 24081eb..13e834d 100644 --- a/vignettes/session_info.Rmd +++ b/vignettes/session_info.Rmd @@ -11,6 +11,6 @@ This page runs the `sessionInfo()` function and prints the results. The output can be used to check the dependency versions that were used to run tests. ```{r include=TRUE, echo=TRUE} -library(vitessceR) +library(vitessceAnalysisR) sessionInfo() ``` diff --git a/vignettes/seurat_azimuth.Rmd b/vignettes/seurat_azimuth.Rmd index 826679e..86eadcb 100644 --- a/vignettes/seurat_azimuth.Rmd +++ b/vignettes/seurat_azimuth.Rmd @@ -24,219 +24,219 @@ devtools::install_github("mojaveazure/seurat-disk") Download the dataset and map the query to the reference: ```r -library(vitessceR) -library(Seurat) -library(Azimuth) -source("https://raw.githubusercontent.com/satijalab/azimuth/master/R/helpers.R") -library(Matrix) - -# Download query dataset -url <- "https://www.dropbox.com/s/cmbvq2og93lnl9z/pbmc_10k_v3_filtered_feature_bc_matrix.h5?dl=1" -data_dir <- file.path("data", "azimuth") -h5_file <- file.path(data_dir, "pbmc_10k_v3_filtered_feature_bc_matrix.h5") -dir.create(data_dir, showWarnings = FALSE) -if(!file.exists(h5_file)) { - download.file(url, destfile = h5_file) -} - -# Download the reference -# Change the file path based on where the reference is located on your system. -reference <- LoadReference(path = "https://seurat.nygenome.org/azimuth/references/v1.0.0/human_pbmc", seconds = 30L) - -# Load the query object for mapping -# Change the file path based on where the query file is located on your system. -query <- LoadFileInput(path = h5_file) - -# Calculate nCount_RNA and nFeature_RNA if the query does not -# contain them already -if (!all(c("nCount_RNA", "nFeature_RNA") %in% c(colnames(x = query[[]])))) { - calcn <- as.data.frame(x = Seurat:::CalcN(object = query)) - colnames(x = calcn) <- paste( - colnames(x = calcn), - "RNA", - sep = '_' - ) - query <- AddMetaData( - object = query, - metadata = calcn - ) - rm(calcn) -} - -# Calculate percent mitochondrial genes if the query contains genes -# matching the regular expression "^MT-" -if (any(grepl(pattern = '^MT-', x = rownames(x = query)))) { - query <- PercentageFeatureSet( - object = query, - pattern = '^MT-', - col.name = 'percent.mt', - assay = "RNA" - ) -} - -# Filter cells based on the thresholds for nCount_RNA and nFeature_RNA -# you set in the app -cells.use <- query[["nCount_RNA", drop = TRUE]] <= 79534 & - query[["nCount_RNA", drop = TRUE]] >= 501 & - query[["nFeature_RNA", drop = TRUE]] <= 7211 & - query[["nFeature_RNA", drop = TRUE]] >= 54 - -# If the query contains mitochondrial genes, filter cells based on the -# thresholds for percent.mt you set in the app -if ("percent.mt" %in% c(colnames(x = query[[]]))) { - cells.use <- cells.use & (query[["percent.mt", drop = TRUE]] <= 97 & - query[["percent.mt", drop = TRUE]] >= 0) -} - -# Remove filtered cells from the query -query <- query[, cells.use] - -# Preprocess with SCTransform -query <- SCTransform( - object = query, - assay = "RNA", - new.assay.name = "refAssay", - residual.features = rownames(x = reference$map), - reference.SCT.model = reference$map[["refAssay"]]@SCTModel.list$refmodel, - method = 'glmGamPoi', - ncells = 2000, - n_genes = 2000, - do.correct.umi = FALSE, - do.scale = FALSE, - do.center = TRUE -) - -# Find anchors between query and reference -anchors <- FindTransferAnchors( - reference = reference$map, - query = query, - k.filter = NA, - reference.neighbors = "refdr.annoy.neighbors", - reference.assay = "refAssay", - query.assay = "refAssay", - reference.reduction = "refDR", - normalization.method = "SCT", - features = intersect(rownames(x = reference$map), VariableFeatures(object = query)), - dims = 1:50, - n.trees = 20, - mapping.score.k = 100 -) - -# Transfer cell type labels and impute protein expression -# -# Transferred labels are in metadata columns named "predicted.*" -# The maximum prediction score is in a metadata column named "predicted.*.score" -# The prediction scores for each class are in an assay named "prediction.score.*" -# The imputed assay is named "impADT" if computed - -refdata <- lapply(X = "celltype.l2", function(x) { - reference$map[[x, drop = TRUE]] -}) -names(x = refdata) <- "celltype.l2" -if (TRUE) { - refdata[["impADT"]] <- GetAssayData( - object = reference$map[['ADT']], - slot = 'data' - ) -} -query <- TransferData( - reference = reference$map, - query = query, - dims = 1:50, - anchorset = anchors, - refdata = refdata, - n.trees = 20, - store.weights = TRUE -) - -# Calculate the embeddings of the query data on the reference SPCA -query <- IntegrateEmbeddings( - anchorset = anchors, - reference = reference$map, - query = query, - reductions = "pcaproject", - reuse.weights.matrix = TRUE -) - -# Calculate the query neighbors in the reference -# with respect to the integrated embeddings -query[["query_ref.nn"]] <- FindNeighbors( - object = Embeddings(reference$map[["refDR"]])[, 1:50], - query = Embeddings(query[["integrated_dr"]]), - return.neighbor = TRUE, - l2.norm = TRUE, - n.trees = 20 -) - -# The reference used in the app is downsampled compared to the reference on which -# the UMAP model was computed. This step, using the helper function NNTransform, -# corrects the Neighbors to account for the downsampling. -query <- NNTransform( - object = query, - meta.data = reference$map[[]] -) - -# Project the query to the reference UMAP. -query[["umap.proj"]] <- RunUMAP( - object = query[["query_ref.nn"]], - reduction.model = reference$map[["refUMAP"]], - reduction.key = 'UMAP_' -) - -# Calculate mapping score and add to metadata -query <- AddMetaData( - object = query, - metadata = MappingScore(anchors = anchors), - col.name = "mapping.score" -) - -ref_obj <- reference$plot -qry_obj <- query - -# Trick SeuratDisk into saving the UMAP even though it is not based on an internal assay -ref_obj@reductions$refUMAP@assay.used <- "RNA" - -#### Use Vitessce for visualization #### - -# Create Vitessce view config -vc <- VitessceConfig$new("Azimuth") -ref_dataset <- vc$add_dataset("Reference")$add_object( - SeuratWrapper$new( - ref_obj, - assay = Seurat::DefaultAssay(ref_obj), - cell_embeddings = c("refUMAP"), - cell_embedding_names = c("UMAP"), - cell_set_metas = c("celltype.l2"), - out_dir = file.path(data_dir, "reference"), overwrite = TRUE - ) -) -qry_dataset <- vc$add_dataset("Query")$add_object( - SeuratWrapper$new( - qry_obj, - assay = Seurat::DefaultAssay(qry_obj), - cell_embeddings = c("umap.proj"), - cell_embedding_names = c("UMAP"), - cell_set_metas = c("predicted.celltype.l2"), - cell_set_meta_names = c("celltype.l2"), - cell_set_meta_scores = c("predicted.celltype.l2.score"), - out_dir = file.path(data_dir, "query"), overwrite = TRUE - ) -) - -ref_plot <- vc$add_view(ref_dataset, Component$SCATTERPLOT, mapping = "UMAP") -qry_plot <- vc$add_view(qry_dataset, Component$SCATTERPLOT, mapping = "UMAP") -cell_sets <- vc$add_view(ref_dataset, Component$CELL_SETS) -cell_sets_2 <- vc$add_view(qry_dataset, Component$CELL_SETS) - -vc$link_views( - c(ref_plot, qry_plot), - c(CoordinationType$EMBEDDING_ZOOM, CoordinationType$EMBEDDING_TARGET_X, CoordinationType$EMBEDDING_TARGET_Y), - c_values = c(1, 0, 0) -) - -vc$layout(hconcat(vconcat(ref_plot, qry_plot), vconcat(cell_sets, cell_sets_2))) - -# Render the Vitessce widget -vc$widget(theme = "light") +# library(vitessceR) +# library(Seurat) +# library(Azimuth) +# source("https://raw.githubusercontent.com/satijalab/azimuth/master/R/helpers.R") +# library(Matrix) + +# # Download query dataset +# url <- "https://www.dropbox.com/s/cmbvq2og93lnl9z/pbmc_10k_v3_filtered_feature_bc_matrix.h5?dl=1" +# data_dir <- file.path("data", "azimuth") +# h5_file <- file.path(data_dir, "pbmc_10k_v3_filtered_feature_bc_matrix.h5") +# dir.create(data_dir, showWarnings = FALSE) +# if(!file.exists(h5_file)) { +# download.file(url, destfile = h5_file) +# } + +# # Download the reference +# # Change the file path based on where the reference is located on your system. +# reference <- LoadReference(path = "https://seurat.nygenome.org/azimuth/references/v1.0.0/human_pbmc", seconds = 30L) + +# # Load the query object for mapping +# # Change the file path based on where the query file is located on your system. +# query <- LoadFileInput(path = h5_file) + +# # Calculate nCount_RNA and nFeature_RNA if the query does not +# # contain them already +# if (!all(c("nCount_RNA", "nFeature_RNA") %in% c(colnames(x = query[[]])))) { +# calcn <- as.data.frame(x = Seurat:::CalcN(object = query)) +# colnames(x = calcn) <- paste( +# colnames(x = calcn), +# "RNA", +# sep = '_' +# ) +# query <- AddMetaData( +# object = query, +# metadata = calcn +# ) +# rm(calcn) +# } + +# # Calculate percent mitochondrial genes if the query contains genes +# # matching the regular expression "^MT-" +# if (any(grepl(pattern = '^MT-', x = rownames(x = query)))) { +# query <- PercentageFeatureSet( +# object = query, +# pattern = '^MT-', +# col.name = 'percent.mt', +# assay = "RNA" +# ) +# } + +# # Filter cells based on the thresholds for nCount_RNA and nFeature_RNA +# # you set in the app +# cells.use <- query[["nCount_RNA", drop = TRUE]] <= 79534 & +# query[["nCount_RNA", drop = TRUE]] >= 501 & +# query[["nFeature_RNA", drop = TRUE]] <= 7211 & +# query[["nFeature_RNA", drop = TRUE]] >= 54 + +# # If the query contains mitochondrial genes, filter cells based on the +# # thresholds for percent.mt you set in the app +# if ("percent.mt" %in% c(colnames(x = query[[]]))) { +# cells.use <- cells.use & (query[["percent.mt", drop = TRUE]] <= 97 & +# query[["percent.mt", drop = TRUE]] >= 0) +# } + +# # Remove filtered cells from the query +# query <- query[, cells.use] + +# # Preprocess with SCTransform +# query <- SCTransform( +# object = query, +# assay = "RNA", +# new.assay.name = "refAssay", +# residual.features = rownames(x = reference$map), +# reference.SCT.model = reference$map[["refAssay"]]@SCTModel.list$refmodel, +# method = 'glmGamPoi', +# ncells = 2000, +# n_genes = 2000, +# do.correct.umi = FALSE, +# do.scale = FALSE, +# do.center = TRUE +# ) + +# # Find anchors between query and reference +# anchors <- FindTransferAnchors( +# reference = reference$map, +# query = query, +# k.filter = NA, +# reference.neighbors = "refdr.annoy.neighbors", +# reference.assay = "refAssay", +# query.assay = "refAssay", +# reference.reduction = "refDR", +# normalization.method = "SCT", +# features = intersect(rownames(x = reference$map), VariableFeatures(object = query)), +# dims = 1:50, +# n.trees = 20, +# mapping.score.k = 100 +# ) + +# # Transfer cell type labels and impute protein expression +# # +# # Transferred labels are in metadata columns named "predicted.*" +# # The maximum prediction score is in a metadata column named "predicted.*.score" +# # The prediction scores for each class are in an assay named "prediction.score.*" +# # The imputed assay is named "impADT" if computed + +# refdata <- lapply(X = "celltype.l2", function(x) { +# reference$map[[x, drop = TRUE]] +# }) +# names(x = refdata) <- "celltype.l2" +# if (TRUE) { +# refdata[["impADT"]] <- GetAssayData( +# object = reference$map[['ADT']], +# slot = 'data' +# ) +# } +# query <- TransferData( +# reference = reference$map, +# query = query, +# dims = 1:50, +# anchorset = anchors, +# refdata = refdata, +# n.trees = 20, +# store.weights = TRUE +# ) + +# # Calculate the embeddings of the query data on the reference SPCA +# query <- IntegrateEmbeddings( +# anchorset = anchors, +# reference = reference$map, +# query = query, +# reductions = "pcaproject", +# reuse.weights.matrix = TRUE +# ) + +# # Calculate the query neighbors in the reference +# # with respect to the integrated embeddings +# query[["query_ref.nn"]] <- FindNeighbors( +# object = Embeddings(reference$map[["refDR"]])[, 1:50], +# query = Embeddings(query[["integrated_dr"]]), +# return.neighbor = TRUE, +# l2.norm = TRUE, +# n.trees = 20 +# ) + +# # The reference used in the app is downsampled compared to the reference on which +# # the UMAP model was computed. This step, using the helper function NNTransform, +# # corrects the Neighbors to account for the downsampling. +# query <- NNTransform( +# object = query, +# meta.data = reference$map[[]] +# ) + +# # Project the query to the reference UMAP. +# query[["umap.proj"]] <- RunUMAP( +# object = query[["query_ref.nn"]], +# reduction.model = reference$map[["refUMAP"]], +# reduction.key = 'UMAP_' +# ) + +# # Calculate mapping score and add to metadata +# query <- AddMetaData( +# object = query, +# metadata = MappingScore(anchors = anchors), +# col.name = "mapping.score" +# ) + +# ref_obj <- reference$plot +# qry_obj <- query + +# # Trick SeuratDisk into saving the UMAP even though it is not based on an internal assay +# ref_obj@reductions$refUMAP@assay.used <- "RNA" + +# #### Use Vitessce for visualization #### + +# # Create Vitessce view config +# vc <- VitessceConfig$new("Azimuth") +# ref_dataset <- vc$add_dataset("Reference")$add_object( +# SeuratWrapper$new( +# ref_obj, +# assay = Seurat::DefaultAssay(ref_obj), +# cell_embeddings = c("refUMAP"), +# cell_embedding_names = c("UMAP"), +# cell_set_metas = c("celltype.l2"), +# out_dir = file.path(data_dir, "reference"), overwrite = TRUE +# ) +# ) +# qry_dataset <- vc$add_dataset("Query")$add_object( +# SeuratWrapper$new( +# qry_obj, +# assay = Seurat::DefaultAssay(qry_obj), +# cell_embeddings = c("umap.proj"), +# cell_embedding_names = c("UMAP"), +# cell_set_metas = c("predicted.celltype.l2"), +# cell_set_meta_names = c("celltype.l2"), +# cell_set_meta_scores = c("predicted.celltype.l2.score"), +# out_dir = file.path(data_dir, "query"), overwrite = TRUE +# ) +# ) + +# ref_plot <- vc$add_view(ref_dataset, Component$SCATTERPLOT, mapping = "UMAP") +# qry_plot <- vc$add_view(qry_dataset, Component$SCATTERPLOT, mapping = "UMAP") +# cell_sets <- vc$add_view(ref_dataset, Component$CELL_SETS) +# cell_sets_2 <- vc$add_view(qry_dataset, Component$CELL_SETS) + +# vc$link_views( +# c(ref_plot, qry_plot), +# c(CoordinationType$EMBEDDING_ZOOM, CoordinationType$EMBEDDING_TARGET_X, CoordinationType$EMBEDDING_TARGET_Y), +# c_values = c(1, 0, 0) +# ) + +# vc$layout(hconcat(vconcat(ref_plot, qry_plot), vconcat(cell_sets, cell_sets_2))) + +# # Render the Vitessce widget +# vc$widget(theme = "light") ``` diff --git a/vignettes/seurat_basic.Rmd b/vignettes/seurat_basic.Rmd index be6794b..d8f4082 100644 --- a/vignettes/seurat_basic.Rmd +++ b/vignettes/seurat_basic.Rmd @@ -22,60 +22,60 @@ devtools::install_github("mojaveazure/seurat-disk") Download the dataset, load and preprocess the Seurat object, and configure the Vitessce widget: ```r -library(vitessceR) -library(Seurat) - -# Download example dataset -url <- "https://cf.10xgenomics.com/samples/cell/pbmc3k/pbmc3k_filtered_gene_bc_matrices.tar.gz" -save_dir <- file.path("data", "seurat") -dir.create(save_dir) -download.file(url, destfile = file.path(save_dir, "filtered_gene_bc_matrices.tar.gz")) -untar(file.path(save_dir, "filtered_gene_bc_matrices.tar.gz"), exdir = save_dir) - -# Load example dataset -pbmc.data <- Read10X(data.dir = file.path(save_dir, "filtered_gene_bc_matrices", "hg19")) - -# Process example dataset (run PCA and cluster) -pbmc <- CreateSeuratObject(counts = pbmc.data, project = "pbmc3k", min.cells = 3, min.features = 200) -pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-") -pbmc <- subset(pbmc, subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5) -pbmc <- NormalizeData(pbmc, normalization.method = "LogNormalize", scale.factor = 10000) -pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000) -all.genes <- rownames(pbmc) -pbmc <- ScaleData(pbmc, features = all.genes) -pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc)) -pbmc <- FindNeighbors(pbmc, dims = 1:10) -pbmc <- FindClusters(pbmc, resolution = 0.5) - -pbmc <- ScaleData(pbmc, features = all.genes, do.center = FALSE) - -# Create Vitessce view config -vc <- VitessceConfig$new("My config") -dataset <- vc$add_dataset("My dataset")$add_object(SeuratWrapper$new( - pbmc, - cell_set_metas = c("seurat_clusters"), - cell_embeddings = c("pca"), - cell_embedding_names = c("PCA"), - out_dir = file.path("data", "seurat_basic"), use_cache = TRUE -)) -scatterplot <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "PCA") -status <- vc$add_view(dataset, Component$STATUS) -desc <- vc$add_view(dataset, Component$DESCRIPTION) -desc <- desc$set_props(description = "Visualization of a Seurat object containing the PBMC 3K dataset.") -genes <- vc$add_view(dataset, Component$GENES) -heatmap <- vc$add_view(dataset, Component$HEATMAP) -vc$link_views( - list(scatterplot, heatmap), - list(CoordinationType$GENE_EXPRESSION_COLORMAP_RANGE), - list(c(0.0, 0.05)) -) -vc$layout(hconcat( - vconcat(scatterplot, heatmap), - vconcat(genes, vconcat(desc, status)) -)) - -# Render the Vitessce widget -vc$widget(theme = "light") +# library(vitessceR) +# library(Seurat) + +# # Download example dataset +# url <- "https://cf.10xgenomics.com/samples/cell/pbmc3k/pbmc3k_filtered_gene_bc_matrices.tar.gz" +# save_dir <- file.path("data", "seurat") +# dir.create(save_dir) +# download.file(url, destfile = file.path(save_dir, "filtered_gene_bc_matrices.tar.gz")) +# untar(file.path(save_dir, "filtered_gene_bc_matrices.tar.gz"), exdir = save_dir) + +# # Load example dataset +# pbmc.data <- Read10X(data.dir = file.path(save_dir, "filtered_gene_bc_matrices", "hg19")) + +# # Process example dataset (run PCA and cluster) +# pbmc <- CreateSeuratObject(counts = pbmc.data, project = "pbmc3k", min.cells = 3, min.features = 200) +# pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-") +# pbmc <- subset(pbmc, subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5) +# pbmc <- NormalizeData(pbmc, normalization.method = "LogNormalize", scale.factor = 10000) +# pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000) +# all.genes <- rownames(pbmc) +# pbmc <- ScaleData(pbmc, features = all.genes) +# pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc)) +# pbmc <- FindNeighbors(pbmc, dims = 1:10) +# pbmc <- FindClusters(pbmc, resolution = 0.5) + +# pbmc <- ScaleData(pbmc, features = all.genes, do.center = FALSE) + +# # Create Vitessce view config +# vc <- VitessceConfig$new("My config") +# dataset <- vc$add_dataset("My dataset")$add_object(SeuratWrapper$new( +# pbmc, +# cell_set_metas = c("seurat_clusters"), +# cell_embeddings = c("pca"), +# cell_embedding_names = c("PCA"), +# out_dir = file.path("data", "seurat_basic"), use_cache = TRUE +# )) +# scatterplot <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "PCA") +# status <- vc$add_view(dataset, Component$STATUS) +# desc <- vc$add_view(dataset, Component$DESCRIPTION) +# desc <- desc$set_props(description = "Visualization of a Seurat object containing the PBMC 3K dataset.") +# genes <- vc$add_view(dataset, Component$GENES) +# heatmap <- vc$add_view(dataset, Component$HEATMAP) +# vc$link_views( +# list(scatterplot, heatmap), +# list(CoordinationType$GENE_EXPRESSION_COLORMAP_RANGE), +# list(c(0.0, 0.05)) +# ) +# vc$layout(hconcat( +# vconcat(scatterplot, heatmap), +# vconcat(genes, vconcat(desc, status)) +# )) + +# # Render the Vitessce widget +# vc$widget(theme = "light") ``` diff --git a/vignettes/seuratdata.Rmd b/vignettes/seuratdata.Rmd index cb7b0cd..c2f4b6e 100644 --- a/vignettes/seuratdata.Rmd +++ b/vignettes/seuratdata.Rmd @@ -22,46 +22,46 @@ devtools::install_github("mojaveazure/seurat-disk") Download the dataset, load and preprocess the Seurat object, and configure the Vitessce widget: ```r -library(vitessceR) -library(SeuratData) -library(Seurat) +# library(vitessceR) +# library(SeuratData) +# library(Seurat) -SeuratData::InstallData("pbmc3k") -data("pbmc3k.final") -force(pbmc3k.final) +# SeuratData::InstallData("pbmc3k") +# data("pbmc3k.final") +# force(pbmc3k.final) -all.genes <- rownames(pbmc3k.final) -pbmc3k.final <- ScaleData(pbmc3k.final, features = all.genes, do.center = FALSE) +# all.genes <- rownames(pbmc3k.final) +# pbmc3k.final <- ScaleData(pbmc3k.final, features = all.genes, do.center = FALSE) -vc <- VitessceConfig$new("My config") -dataset <- vc$add_dataset("My dataset") -dataset <- dataset$add_object(SeuratWrapper$new( - pbmc3k.final, - cell_embeddings = c("pca", "umap"), - cell_embedding_names = c("PCA", "UMAP"), - cell_set_metas = c("seurat_annotations", "seurat_clusters"), - out_dir = file.path("data", "seuratdata") -)) -scatterplot_pca <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "PCA") -scatterplot_umap <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "UMAP") -cell_sets <- vc$add_view(dataset, Component$CELL_SETS) -genes <- vc$add_view(dataset, Component$GENES) -heatmap <- vc$add_view(dataset, Component$HEATMAP) -vc$link_views( - list(scatterplot_pca, scatterplot_umap, heatmap), - list(CoordinationType$GENE_EXPRESSION_COLORMAP_RANGE), - list(c(0.0, 0.035)) -) -vc$link_views( - list(scatterplot_pca, scatterplot_umap), - list("embeddingCellSetLabelsVisible"), - list(TRUE) -) -vc$layout(vconcat( - hconcat(scatterplot_pca, scatterplot_umap), - hconcat(cell_sets, genes, heatmap) -)) -vc$widget(theme = "light") +# vc <- VitessceConfig$new("My config") +# dataset <- vc$add_dataset("My dataset") +# dataset <- dataset$add_object(SeuratWrapper$new( +# pbmc3k.final, +# cell_embeddings = c("pca", "umap"), +# cell_embedding_names = c("PCA", "UMAP"), +# cell_set_metas = c("seurat_annotations", "seurat_clusters"), +# out_dir = file.path("data", "seuratdata") +# )) +# scatterplot_pca <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "PCA") +# scatterplot_umap <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "UMAP") +# cell_sets <- vc$add_view(dataset, Component$CELL_SETS) +# genes <- vc$add_view(dataset, Component$GENES) +# heatmap <- vc$add_view(dataset, Component$HEATMAP) +# vc$link_views( +# list(scatterplot_pca, scatterplot_umap, heatmap), +# list(CoordinationType$GENE_EXPRESSION_COLORMAP_RANGE), +# list(c(0.0, 0.035)) +# ) +# vc$link_views( +# list(scatterplot_pca, scatterplot_umap), +# list("embeddingCellSetLabelsVisible"), +# list(TRUE) +# ) +# vc$layout(vconcat( +# hconcat(scatterplot_pca, scatterplot_umap), +# hconcat(cell_sets, genes, heatmap) +# )) +# vc$widget(theme = "light") ``` diff --git a/vignettes/single_cell_experiment.Rmd b/vignettes/single_cell_experiment.Rmd index 4c2554c..4913fdc 100644 --- a/vignettes/single_cell_experiment.Rmd +++ b/vignettes/single_cell_experiment.Rmd @@ -20,44 +20,44 @@ BiocManager::install("scater") Download the dataset, load and preprocess the SingleCellExperiment object, and configure the Vitessce widget: ```r -library(vitessceR) -library(scRNAseq) -library(scater) +# library(vitessceR) +# library(scRNAseq) +# library(scater) -sce_zeisel <- ZeiselBrainData() +# sce_zeisel <- ZeiselBrainData() -sce_zeisel <- addPerCellQC(sce_zeisel, subsets=list(Mito = grep("mt-", rownames(sce_zeisel)))) -sce_zeisel <- logNormCounts(sce_zeisel) -sce_zeisel <- runPCA(sce_zeisel) +# sce_zeisel <- addPerCellQC(sce_zeisel, subsets=list(Mito = grep("mt-", rownames(sce_zeisel)))) +# sce_zeisel <- logNormCounts(sce_zeisel) +# sce_zeisel <- runPCA(sce_zeisel) -# Create Vitessce view config -vc <- VitessceConfig$new("My config") -dataset <- vc$add_dataset("My dataset")$add_object(SCEWrapper$new( - sce_zeisel, - cell_set_metas = c("tissue", "level1class", "level2class"), - cell_set_meta_names = c("Tissue", "Cell Type Level 1", "Cell Type Level 2"), - cell_embeddings = c("PCA"), - out_dir = file.path("data", "sce") -)) -scatterplot <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "PCA") -status <- vc$add_view(dataset, Component$STATUS) -desc <- vc$add_view(dataset, Component$DESCRIPTION) -desc <- desc$set_props(description = "Visualization of a SingleCellExperiment object.") -cell_sets <- vc$add_view(dataset, Component$CELL_SETS) -heatmap <- vc$add_view(dataset, Component$HEATMAP) -vc$link_views( - list(scatterplot, heatmap), - list(CoordinationType$GENE_EXPRESSION_COLORMAP_RANGE), - list(c(0.0, 0.05)) -) -vc$layout(hconcat( - vconcat(scatterplot, heatmap), - vconcat(cell_sets, vconcat(desc, status)) -)) +# # Create Vitessce view config +# vc <- VitessceConfig$new("My config") +# dataset <- vc$add_dataset("My dataset")$add_object(SCEWrapper$new( +# sce_zeisel, +# cell_set_metas = c("tissue", "level1class", "level2class"), +# cell_set_meta_names = c("Tissue", "Cell Type Level 1", "Cell Type Level 2"), +# cell_embeddings = c("PCA"), +# out_dir = file.path("data", "sce") +# )) +# scatterplot <- vc$add_view(dataset, Component$SCATTERPLOT, mapping = "PCA") +# status <- vc$add_view(dataset, Component$STATUS) +# desc <- vc$add_view(dataset, Component$DESCRIPTION) +# desc <- desc$set_props(description = "Visualization of a SingleCellExperiment object.") +# cell_sets <- vc$add_view(dataset, Component$CELL_SETS) +# heatmap <- vc$add_view(dataset, Component$HEATMAP) +# vc$link_views( +# list(scatterplot, heatmap), +# list(CoordinationType$GENE_EXPRESSION_COLORMAP_RANGE), +# list(c(0.0, 0.05)) +# ) +# vc$layout(hconcat( +# vconcat(scatterplot, heatmap), +# vconcat(cell_sets, vconcat(desc, status)) +# )) -# Render the Vitessce widget -vc$widget(theme = "light") +# # Render the Vitessce widget +# vc$widget(theme = "light") ``` diff --git a/vignettes/spatial_experiment.Rmd b/vignettes/spatial_experiment.Rmd index 5c817d9..893cd24 100644 --- a/vignettes/spatial_experiment.Rmd +++ b/vignettes/spatial_experiment.Rmd @@ -19,32 +19,32 @@ BiocManager::install("STexampleData") Download the dataset, load and preprocess the SpatialExperiment object, and configure the Vitessce widget: ```r -library(vitessceR) -library(STexampleData) - -spe_visium <- STexampleData::Visium_mouseCoronal() - -w <- SPEWrapper$new( - spe_visium, - sample_id = "sample01", - image_id = "hires", - out_dir = file.path("data", "spe") -) - -# Create Vitessce view config -vc <- VitessceConfig$new("My config") -dataset <- vc$add_dataset("My dataset")$add_object(w) -spatial <- vc$add_view(dataset, Component$SPATIAL) -status <- vc$add_view(dataset, Component$STATUS) -desc <- vc$add_view(dataset, Component$DESCRIPTION) -desc <- desc$set_props(description = "Visualization of a SpatialExperiment object.") - -vc$layout( - hconcat(spatial, vconcat(desc, status)) -) - -# Render the Vitessce widget -vc$widget(theme = "light") +# library(vitessceR) +# library(STexampleData) + +# spe_visium <- STexampleData::Visium_mouseCoronal() + +# w <- SPEWrapper$new( +# spe_visium, +# sample_id = "sample01", +# image_id = "hires", +# out_dir = file.path("data", "spe") +# ) + +# # Create Vitessce view config +# vc <- VitessceConfig$new("My config") +# dataset <- vc$add_dataset("My dataset")$add_object(w) +# spatial <- vc$add_view(dataset, Component$SPATIAL) +# status <- vc$add_view(dataset, Component$STATUS) +# desc <- vc$add_view(dataset, Component$DESCRIPTION) +# desc <- desc$set_props(description = "Visualization of a SpatialExperiment object.") + +# vc$layout( +# hconcat(spatial, vconcat(desc, status)) +# ) + +# # Render the Vitessce widget +# vc$widget(theme = "light") ```