From a57a4e3acbd67042aa2fe1ab47f7b6414e413913 Mon Sep 17 00:00:00 2001 From: George Chen <72078254+jiajic@users.noreply.github.com> Date: Wed, 31 Jul 2024 17:35:51 -0400 Subject: [PATCH] chore: naming change and document - `performCellposeSegmentation()` -> `doCellposeSegmentation()` --- NAMESPACE | 4 +- R/cell_segmentation.R | 92 +++++++++---------- ...mentation.Rd => doCellposeSegmentation.Rd} | 8 +- man/dot-compute_dbMatrix.Rd | 16 ++++ man/getONTraCv2Input.Rd | 45 +++++++++ man/plotCTCompositionInNicheCluster.Rd | 6 +- man/plotCTCompositionInProbCluster.Rd | 47 ++++++++++ man/plotCellTypeNTScore.Rd | 4 +- man/plotDiscreteAlongContinuous.Rd | 45 +++++++++ 9 files changed, 211 insertions(+), 56 deletions(-) rename man/{performCellposeSegmentation.Rd => doCellposeSegmentation.Rd} (91%) create mode 100644 man/dot-compute_dbMatrix.Rd create mode 100644 man/getONTraCv2Input.Rd create mode 100644 man/plotCTCompositionInProbCluster.Rd create mode 100644 man/plotDiscreteAlongContinuous.Rd diff --git a/NAMESPACE b/NAMESPACE index 6fa2ade63..f9eddf16a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -167,6 +167,7 @@ export(dimPlot2D) export(dimPlot3D) export(distGiottoImage) export(doCellSegmentation) +export(doCellposeSegmentation) export(doClusterProjection) export(doFeatureSetEnrichment) export(doGiottoClustree) @@ -241,6 +242,7 @@ export(getGiottoImage) export(getMultiomics) export(getNearestNetwork) export(getONTraCv1Input) +export(getONTraCv2Input) export(getPolygonInfo) export(getRainbowColors) export(getSpatialEnrichment) @@ -294,12 +296,12 @@ export(overlapToMatrix) export(overlapToMatrixMultiPoly) export(overlaps) export(pDataDT) -export(performCellposeSegmentation) export(pieCellTypesFromEnrichment) export(plotCCcomDotplot) export(plotCCcomHeatmap) export(plotCPF) export(plotCTCompositionInNicheCluster) +export(plotCTCompositionInProbCluster) export(plotCellProximityFeatSpot) export(plotCellProximityFeats) export(plotCellTypeNTScore) diff --git a/R/cell_segmentation.R b/R/cell_segmentation.R index a411e320a..8090cd603 100644 --- a/R/cell_segmentation.R +++ b/R/cell_segmentation.R @@ -92,10 +92,10 @@ doCellSegmentation <- function( #' #' @title perform cellpose segmentation #' @description -#' +#' #' perform the Giotto Wrapper of cellpose segmentation. This is for a model inference to generate segmentation mask file from input image. #' main parameters needed -#' @name performCellposeSegmentation +#' @name doCellposeSegmentation #' @param image_dir character, required. Provide a path to a gray scale or a three channel image. #' @param python_path python environment with cellpose installed. default = "giotto_cellpose". #' @param mask_output required. Provide a path to the output mask file. @@ -127,88 +127,88 @@ doCellSegmentation <- function( #' @returns No return variable, as this will write directly to output path provided. #' @examples #' # example code -#' performCellposeSegmentation(image_dir = input_image, mask_output = output, channel_1 = 2, channel_2 = 1, model_name = 'cyto3',batch_size=4) +#' doCellposeSegmentation(image_dir = input_image, mask_output = output, channel_1 = 2, channel_2 = 1, model_name = 'cyto3',batch_size=4) #' @export -performCellposeSegmentation <- function(python_env = 'giotto_cellpose', +doCellposeSegmentation <- function(python_env = 'giotto_cellpose', image_dir, mask_output, channel_1 = 0, channel_2 = 0, model_name = 'cyto3', - batch_size=8, - resample=TRUE, + batch_size=8, + resample=TRUE, channel_axis=NULL, - z_axis=NULL, - normalize=TRUE, - invert=FALSE, - rescale=NULL, + z_axis=NULL, + normalize=TRUE, + invert=FALSE, + rescale=NULL, diameter=NULL, - flow_threshold=0.4, - cellprob_threshold=0.0, - do_3D=FALSE, + flow_threshold=0.4, + cellprob_threshold=0.0, + do_3D=FALSE, anisotropy=NULL, - stitch_threshold=0.0, - min_size=15, - niter=NULL, - augment=FALSE, + stitch_threshold=0.0, + min_size=15, + niter=NULL, + augment=FALSE, tile=TRUE, - tile_overlap=0.1, - bsize=224, - interp=TRUE, + tile_overlap=0.1, + bsize=224, + interp=TRUE, compute_masks=TRUE, progress=NULL, verbose = TRUE,...){ - - + + #Check Input arguments model_name <- match.arg(model_name, unique(c('cyto3', 'cyto2', 'cyto','nuclei', model_name))) ## Load required python libraries GiottoClass::set_giotto_python_path(python_env) GiottoUtils::package_check('cellpose',repository = 'pip') - + cellpose <- reticulate::import("cellpose") np <- reticulate::import("numpy") cv2 <- reticulate::import("cv2") torch <- reticulate::import("torch") message('successfully loaded giotto environment with cellpose.') - + if (!(torch$cuda$is_available())){ warning('GPU is not available for this session, inference may be slow.\n ') } - + GiottoUtils::vmsg(.v = verbose, .is_debug = F,'Loading Image from ',image_dir) - + img <- cellpose$io$imread(image_dir) GiottoUtils::vmsg(.v = verbose, .is_debug = F,'Loading Model...') - + model_to_seg <- cellpose$models$Cellpose(model_type=model_name,gpu = torch$cuda$is_available()) channel_to_seg <- as.integer(c(channel_1,channel_2)) - + GiottoUtils::vmsg(.v = verbose, .is_debug = F,'Segmenting Image...') segmentation <- model_to_seg$eval - - result <- segmentation(img, - diameter=diameter, + + result <- segmentation(img, + diameter=diameter, channels=channel_to_seg, batch_size = batch_size, - resample=resample, + resample=resample, channel_axis=channel_axis, - z_axis=z_axis, - normalize=normalize, - invert=invert, - rescale=rescale, - flow_threshold=flow_threshold, - cellprob_threshold=cellprob_threshold, - do_3D=do_3D, + z_axis=z_axis, + normalize=normalize, + invert=invert, + rescale=rescale, + flow_threshold=flow_threshold, + cellprob_threshold=cellprob_threshold, + do_3D=do_3D, anisotropy=anisotropy, - stitch_threshold=stitch_threshold, - min_size=min_size, - niter=niter, - augment=augment, + stitch_threshold=stitch_threshold, + min_size=min_size, + niter=niter, + augment=augment, tile=tile, - tile_overlap=tile_overlap, - bsize=bsize, - interp=interp, + tile_overlap=tile_overlap, + bsize=bsize, + interp=interp, compute_masks=compute_masks, progress=progress) masks <- result[[1]] diff --git a/man/performCellposeSegmentation.Rd b/man/doCellposeSegmentation.Rd similarity index 91% rename from man/performCellposeSegmentation.Rd rename to man/doCellposeSegmentation.Rd index 92e8e3b11..084d3148e 100644 --- a/man/performCellposeSegmentation.Rd +++ b/man/doCellposeSegmentation.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/cell_segmentation.R -\name{performCellposeSegmentation} -\alias{performCellposeSegmentation} +\name{doCellposeSegmentation} +\alias{doCellposeSegmentation} \title{perform cellpose segmentation} \usage{ -performCellposeSegmentation( +doCellposeSegmentation( python_env = "giotto_cellpose", image_dir, mask_output, @@ -103,5 +103,5 @@ main parameters needed } \examples{ # example code -performCellposeSegmentation(image_dir = input_image, mask_output = output, channel_1 = 2, channel_2 = 1, model_name = 'cyto3',batch_size=4) +doCellposeSegmentation(image_dir = input_image, mask_output = output, channel_1 = 2, channel_2 = 1, model_name = 'cyto3',batch_size=4) } diff --git a/man/dot-compute_dbMatrix.Rd b/man/dot-compute_dbMatrix.Rd new file mode 100644 index 000000000..d630ed00b --- /dev/null +++ b/man/dot-compute_dbMatrix.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/auxiliary_giotto.R +\name{.compute_dbMatrix} +\alias{.compute_dbMatrix} +\title{compute_dbMatrix} +\usage{ +.compute_dbMatrix(dbMatrix, name, verbose = TRUE) +} +\description{ +saves dbMatrix to db if global option is set +} +\details{ +Set \code{options(giotto.dbmatrix_compute = FALSE)} if saving dbMatrix +after each step of normalization workflow is not desired. +} +\keyword{internal} diff --git a/man/getONTraCv2Input.Rd b/man/getONTraCv2Input.Rd new file mode 100644 index 000000000..fb4336bb8 --- /dev/null +++ b/man/getONTraCv2Input.Rd @@ -0,0 +1,45 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ONTraC_wrapper.R +\name{getONTraCv2Input} +\alias{getONTraCv2Input} +\title{getONTraCv2Input} +\usage{ +getONTraCv2Input( + gobject, + cell_type, + output_path = getwd(), + spat_unit = NULL, + feat_type = NULL, + verbose = TRUE +) +} +\arguments{ +\item{gobject}{giotto object} + +\item{cell_type}{the cell type column name in the metadata} + +\item{output_path}{the path to save the output file} + +\item{spat_unit}{spatial unit (e.g. "cell")} + +\item{feat_type}{feature type (e.g. "rna", "dna", "protein")} + +\item{verbose}{be verbose} +} +\value{ +data.table with columns: Cell_ID, Sample, x, y, Cell_Type +} +\description{ +generate the input data for ONTraC v2 +} +\details{ +This function generate the input data for ONTraC v2 +} +\examples{ +g <- GiottoData::loadGiottoMini("visium") + +getONTraCv2Input( + gobject = g, + cell_type = "custom_leiden" +) +} diff --git a/man/plotCTCompositionInNicheCluster.Rd b/man/plotCTCompositionInNicheCluster.Rd index 24c9a7109..e121ae78f 100644 --- a/man/plotCTCompositionInNicheCluster.Rd +++ b/man/plotCTCompositionInNicheCluster.Rd @@ -23,11 +23,11 @@ plotCTCompositionInNicheCluster( \item{cell_type}{the cell type column name in the metadata} -\item{values}{name of the expression matrix stored connectivity values} +\item{values}{name of the expression matrix stored probability of each cell assigned to each niche cluster} \item{spat_unit}{name of spatial unit niche stored cluster features} -\item{feat_type}{name of the feature type stored niche cluster connectivities} +\item{feat_type}{name of the feature type stored probability matrix} \item{show_plot}{logical. show plot} @@ -43,5 +43,5 @@ plotCTCompositionInNicheCluster( plot cell type composition within each niche cluster } \details{ -This function plots the niche cluster connectivity matrix +This function plots the cell type composition within each niche cluster } diff --git a/man/plotCTCompositionInProbCluster.Rd b/man/plotCTCompositionInProbCluster.Rd new file mode 100644 index 000000000..7116b6bd4 --- /dev/null +++ b/man/plotCTCompositionInProbCluster.Rd @@ -0,0 +1,47 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ONTraC_wrapper.R +\name{plotCTCompositionInProbCluster} +\alias{plotCTCompositionInProbCluster} +\title{plotCTCompositionInProbCluster} +\usage{ +plotCTCompositionInProbCluster( + gobject, + cell_type, + values = "prob", + spat_unit = "cell", + feat_type = "niche cluster", + show_plot = NULL, + return_plot = NULL, + save_plot = NULL, + save_param = list(), + theme_param = list(), + default_save_name = "plotCTCompositionInProbCluster" +) +} +\arguments{ +\item{gobject}{giotto object} + +\item{cell_type}{the cell type column name in the metadata} + +\item{values}{name of the expression matrix stored probability of each cell assigned to each probabilistic cluster} + +\item{spat_unit}{name of spatial unit niche stored cluster features} + +\item{feat_type}{name of the feature type stored niche cluster connectivities} + +\item{show_plot}{logical. show plot} + +\item{return_plot}{logical. return ggplot object} + +\item{save_plot}{logical. save the plot} + +\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} + +\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} +} +\description{ +plot cell type composition within each probabilistic cluster +} +\details{ +This function plots the cell type composition within each probabilistic cluster +} diff --git a/man/plotCellTypeNTScore.Rd b/man/plotCellTypeNTScore.Rd index c24a73bd9..5938c5c37 100644 --- a/man/plotCellTypeNTScore.Rd +++ b/man/plotCellTypeNTScore.Rd @@ -9,13 +9,13 @@ plotCellTypeNTScore( cell_type, values = "NTScore", spat_unit = "cell", - feat_type = "rna", + feat_type = "niche cluster", show_plot = NULL, return_plot = NULL, save_plot = NULL, save_param = list(), theme_param = list(), - default_save_name = "CellTypeNTScore" + default_save_name = "discreteAlongContinuous" ) } \arguments{ diff --git a/man/plotDiscreteAlongContinuous.Rd b/man/plotDiscreteAlongContinuous.Rd new file mode 100644 index 000000000..e5fe7e131 --- /dev/null +++ b/man/plotDiscreteAlongContinuous.Rd @@ -0,0 +1,45 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ONTraC_wrapper.R +\name{plotDiscreteAlongContinuous} +\alias{plotDiscreteAlongContinuous} +\alias{plotCellTypeNTScore} +\title{plotDiscreteAlongContinuous} +\usage{ +plotCellTypeNTScore( + gobject, + cell_type, + values = "NTScore", + spat_unit = "cell", + feat_type = "niche cluster", + show_plot = NULL, + return_plot = NULL, + save_plot = NULL, + save_param = list(), + theme_param = list(), + default_save_name = "discreteAlongContinuous" +) +} +\arguments{ +\item{gobject}{giotto object} + +\item{cell_type}{the column name of discrete annotation in cell metadata} + +\item{values}{the column name of continuous values in cell metadata} + +\item{spat_unit}{spatial unit (e.g. "cell")} + +\item{feat_type}{feature type (e.g. "rna", "dna", "protein")} + +\item{show_plot}{logical. show plot} + +\item{return_plot}{logical. return ggplot object} + +\item{save_plot}{logical. save the plot} + +\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} + +\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} +} +\description{ +plot density of a discrete annotation along a continuou values +}