Skip to content

Commit

Permalink
chore: naming change and document
Browse files Browse the repository at this point in the history
- `performCellposeSegmentation()` -> `doCellposeSegmentation()`
  • Loading branch information
jiajic committed Jul 31, 2024
1 parent 3a5667e commit a57a4e3
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 56 deletions.
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export(dimPlot2D)
export(dimPlot3D)
export(distGiottoImage)
export(doCellSegmentation)
export(doCellposeSegmentation)
export(doClusterProjection)
export(doFeatureSetEnrichment)
export(doGiottoClustree)
Expand Down Expand Up @@ -241,6 +242,7 @@ export(getGiottoImage)
export(getMultiomics)
export(getNearestNetwork)
export(getONTraCv1Input)
export(getONTraCv2Input)
export(getPolygonInfo)
export(getRainbowColors)
export(getSpatialEnrichment)
Expand Down Expand Up @@ -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)
Expand Down
92 changes: 46 additions & 46 deletions R/cell_segmentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions man/dot-compute_dbMatrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions man/getONTraCv2Input.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/plotCTCompositionInNicheCluster.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions man/plotCTCompositionInProbCluster.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/plotCellTypeNTScore.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions man/plotDiscreteAlongContinuous.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a57a4e3

Please sign in to comment.