From 128d8b93255b229896267ff723fa417c4d55abc7 Mon Sep 17 00:00:00 2001 From: George Chen <72078254+jiajic@users.noreply.github.com> Date: Tue, 21 May 2024 16:50:00 -0400 Subject: [PATCH] fix examples for createCrossSection and addHMRF --- R/cross_section.R | 13 +++++++++++-- R/python_hmrf.R | 25 +++++++++++++++++++++---- man/addHMRF.Rd | 25 +++++++++++++++++++++---- man/createCrossSection.Rd | 13 +++++++++++-- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/R/cross_section.R b/R/cross_section.R index 873a88047..5d0dcb0d9 100644 --- a/R/cross_section.R +++ b/R/cross_section.R @@ -522,9 +522,18 @@ create_mesh_grid_lines <- function( #' network object. The users need to provide the definition of the cross #' section plane (see method). #' @examples -#' g <- GiottoData::loadGiottoMini("visium") +#' g <- GiottoData::loadGiottoMini("starmap") #' -#' createCrossSection(gobject = g, spatial_network_name = "spatial_network") +#' g <- createCrossSection( +#' gobject = g, +#' method = "equation", +#' equation=c(0,1,0,600), +#' extend_ratio = 0.6, +#' name = "new_cs", +#' return_gobject = TRUE +#' ) +#' +#' crossSectionPlot(g, name = "new_cs") #' @export createCrossSection <- function(gobject, spat_unit = NULL, diff --git a/R/python_hmrf.R b/R/python_hmrf.R index fa11c4a75..2f7504179 100644 --- a/R/python_hmrf.R +++ b/R/python_hmrf.R @@ -555,11 +555,28 @@ writeHMRFresults <- function(gobject, #' g <- GiottoData::loadGiottoMini("visium") #' spat_genes <- binSpect(g) #' -#' output_folder <- tempdir() -#' doHMRF(g, spatial_genes = spat_genes[seq_len(10)]$feats, -#' output_folder = output_folder) +#' output_folder <- file.path(tempdir(), 'HMRF') +#' if(!file.exists(output_folder)) dir.create(output_folder, recursive = TRUE) +#' +#' out <- doHMRF( +#' g, spatial_genes = spat_genes[seq_len(20)]$feats, +#' expression_values = "scaled", +#' spatial_network_name = "Delaunay_network", +#' k = 6, betas = c(0, 10, 5), +#' output_folder = output_folder +#' ) +#' +#' g <- addHMRF( +#' gobject = g, +#' HMRFoutput = out, +#' k = 6, +#' betas_to_add = 20, +#' hmrf_name = "HMRF" +#' ) #' -#' addHMRF(gobject = g, HMRFoutput = doHMRF) +#' spatPlot( +#' gobject = g, cell_color = 'HMRF_k6_b.20', +#' ) #' @export addHMRF <- function(gobject, spat_unit = NULL, diff --git a/man/addHMRF.Rd b/man/addHMRF.Rd index d2aff7dbc..6a751fa6d 100644 --- a/man/addHMRF.Rd +++ b/man/addHMRF.Rd @@ -39,9 +39,26 @@ Add selected results from doHMRF to the giotto object g <- GiottoData::loadGiottoMini("visium") spat_genes <- binSpect(g) -output_folder <- tempdir() -doHMRF(g, spatial_genes = spat_genes[seq_len(10)]$feats, -output_folder = output_folder) +output_folder <- file.path(tempdir(), 'HMRF') +if(!file.exists(output_folder)) dir.create(output_folder, recursive = TRUE) -addHMRF(gobject = g, HMRFoutput = doHMRF) +out <- doHMRF( + g, spatial_genes = spat_genes[seq_len(20)]$feats, + expression_values = "scaled", + spatial_network_name = "Delaunay_network", + k = 6, betas = c(0, 10, 5), + output_folder = output_folder +) + +g <- addHMRF( + gobject = g, + HMRFoutput = out, + k = 6, + betas_to_add = 20, + hmrf_name = "HMRF" +) + +spatPlot( + gobject = g, cell_color = 'HMRF_k6_b.20', +) } diff --git a/man/createCrossSection.Rd b/man/createCrossSection.Rd index 4f538c67c..c80dce48b 100644 --- a/man/createCrossSection.Rd +++ b/man/createCrossSection.Rd @@ -106,7 +106,16 @@ network object. The users need to provide the definition of the cross section plane (see method). } \examples{ -g <- GiottoData::loadGiottoMini("visium") +g <- GiottoData::loadGiottoMini("starmap") + +g <- createCrossSection( + gobject = g, + method = "equation", + equation=c(0,1,0,600), + extend_ratio = 0.6, + name = "new_cs", + return_gobject = TRUE +) -createCrossSection(gobject = g, spatial_network_name = "spatial_network") +crossSectionPlot(g, name = "new_cs") }