Skip to content

Commit

Permalink
Merge pull request #221 from drieslab/dev2
Browse files Browse the repository at this point in the history
v0.3.5
  • Loading branch information
jiajic authored Aug 28, 2024
2 parents 57cf471 + 2610542 commit 0ccc659
Show file tree
Hide file tree
Showing 53 changed files with 1,705 additions and 1,197 deletions.
20 changes: 14 additions & 6 deletions .github/workflows/dev_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,24 @@ jobs:
with:
python-version: "3.10"

- name: Test python env install
- name: setup giotto_env
shell: Rscript {0}
run: |
if (!GiottoClass::checkGiottoEnvironment()) {
if (!GiottoClass::checkGiottoEnvironment(envname = "giotto_env")) {
GiottoClass::installGiottoEnvironment()
}
reticulate::py_list_packages(envname = "giotto_env")
reticulate::conda_install(envname = 'giotto_env',packages = 'scanpy',pip = TRUE)
shell: Rscript {0}

reticulate::conda_install(
envname = 'giotto_env',
packages = 'scanpy',
pip = TRUE
)
path_to_python <- GiottoClass::set_giotto_python_path()
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
Sys.getenv("GITHUB_ENV"))
- name: Run R CMD check
uses: r-lib/actions/check-r-package@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: GiottoClass
Title: Giotto Suite object definitions and framework
Version: 0.3.4
Version: 0.3.5
Authors@R: c(
person("Ruben", "Dries", email = "rubendries@gmail.com",
role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7650-7754")),
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ S3method(.DollarNames,terraVectData)
S3method(as.data.table,SpatVector)
S3method(as.data.table,giottoPoints)
S3method(as.data.table,giottoPolygon)
S3method(print,giottoInstructions)
S3method(t,spatLocsObj)
S3method(t,spatialNetworkObj)
export(addCellMetadata)
Expand Down Expand Up @@ -324,6 +325,7 @@ exportMethods("spatUnit<-")
exportMethods(activeFeatType)
exportMethods(activeSpatUnit)
exportMethods(affine)
exportMethods(as.character)
exportMethods(as.matrix)
exportMethods(as.points)
exportMethods(as.polygons)
Expand Down Expand Up @@ -408,8 +410,10 @@ importMethodsFrom(terra,as.points)
importMethodsFrom(terra,as.polygons)
importMethodsFrom(terra,centroids)
importMethodsFrom(terra,crop)
importMethodsFrom(terra,density)
importMethodsFrom(terra,ext)
importMethodsFrom(terra,flip)
importMethodsFrom(terra,hist)
importMethodsFrom(terra,ncol)
importMethodsFrom(terra,nrow)
importMethodsFrom(terra,plot)
Expand Down
21 changes: 21 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@

# GiottoClass 0.3.5 (2024/08/28)

## breaking changes
- `set_giotto_python_path()` will now also initialize python env to set by default and print which python env is active, but otherwise do nothing if any python env has already been initialized.
- deprecated `readGiottoInstructions()`, `showGiottoInstructions()`, `changeGiottoInstructions()`, `replaceGiottoInstructions()` in favor of `instructions()` generic

## bug fixes
- intensity images now automatically scale to estimated highest value
- `giottoPolygon` `plot()` default `max_poly` raised to `1e6`
- `giottoInstructions` no longer lose class when specific params are replaced
- `ometif_to_tif()` now checks for _imagecodecs_ package as well
- `anndataToGiotto()` and `giottoToAnndata` now check for _anndata_ package as well.
- fix `joinGiottoObjects()` `"z_stack"` join method
- fix error in documentation [#214](https://github.com/drieslab/GiottoClass/issues/214) by shaojunyu
- fix error in `installGiottoEnvironment()` [#1006](https://github.com/drieslab/Giotto/issues/1006) by 13954380607

## enhancements
- `print()` method for `giottoInstructions`
- `rbind()` for `spatLocsObj`


# GiottoClass 0.3.4 (2024/08/04)

## bug fixes
Expand Down
11 changes: 9 additions & 2 deletions R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ utils::globalVariables(
"python_leiden", "python_louvain", "python_spatial_genes",
"Spatial_DE_AEH", "Spatial_DE", "silhouette_rank",
"python_scrublet", "python_create_mesmer_app",
"python_segment_image", "ad_guard", "dir_guard", "ad_obj",
"python_segment_image",
# anndata interop
"ad_guard", "dir_guard", "ad_obj",
"lay_inv", "set_adg_layer_data", "set_adg_spat_locs",
"set_adg_metadata", "set_adg_pca", "set_adg_umap",
"set_adg_tsne", "write_ad_h5ad", "read_anndata_from_path",
Expand All @@ -15,6 +17,11 @@ utils::globalVariables(
"extract_layered_data", "set_adg_nn", "find_NN_keys",
"extract_NN_connectivities", "extract_NN_distances",
"extract_NN_info", "align_network_data", "extract_SN_connectivities",
"extract_SN_distances", "set_adg_sn", "create_AnnData", "ometif_2_tif"
"extract_SN_distances", "set_adg_sn", "create_AnnData",
# tifffile
"ometif_2_tif",
# spatialdata interop
"createSpatialData", "read_spatialdata_from_path", "extract_spatial",
"extract_image"
)
)
37 changes: 26 additions & 11 deletions R/images.R
Original file line number Diff line number Diff line change
Expand Up @@ -2644,23 +2644,31 @@ distGiottoImage <- function(
#' gimg <- createGiottoLargeImage(f, use_rast_ext = TRUE)
#'
#' density(gimg)
NULL

#' @rdname density
#' @export
setMethod(
"density", signature("giottoLargeImage"),
function(x, show_max = TRUE, ...) {
a <- list(x = x@raster_object, ...)
res <- do.call(terra::density, args = a)

if (isFALSE(a$plot)) {
return(res)
}

if (isTRUE(show_max)) {
graphics::abline(v = x@max_window, col = "red")
}
a <- get_args_list(...)
do.call(.density_giottolargeimage, args = a)
}
)

.density_giottolargeimage <- function(x, show_max = TRUE, ...) {
a <- list(x = x@raster_object, ...)
res <- do.call(terra::density, args = a)

if (isFALSE(a$plot)) {
return(res)
}

if (isTRUE(show_max)) {
graphics::abline(v = x@max_window, col = "red")
}
}


#' @name hist
#' @title Histogram
Expand All @@ -2677,6 +2685,9 @@ setMethod(
#' gimg <- createGiottoLargeImage(f, use_rast_ext = TRUE, verbose = FALSE)
#'
#' hist(gimg)
NULL

#' @rdname hist
#' @export
setMethod(
"hist", signature("giottoLargeImage"),
Expand Down Expand Up @@ -2745,7 +2756,11 @@ ometif_to_tif <- function(input_file,
a <- list(input_file = input_file)

# get tifffile py
package_check("tifffile", repository = "pip:tifffile")
package_check(
pkg_name = c("tifffile", "imagecodecs"),
repository = c("pip:tifffile", "pip:imagecodecs")
)

ometif2tif_path <- system.file(
"python", "ometif_convert.py",
package = "GiottoClass"
Expand Down
74 changes: 57 additions & 17 deletions R/instructions.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Giotto instructions ####


#' @title Create instructions for giotto functions
#' @name createGiottoInstructions
#' @description Function to set global instructions for giotto functions
#' @rdname giotto_instructions
#' @param python_path path to python binary to use or directory one level
#' up from the `env` directory (similar to output of
#' `reticulate::miniconda_path()`)
Expand All @@ -22,11 +20,6 @@
#' @param fiji_path path to fiji executable
#' @param no_python_warn turn off warning that no compatible python env has
#' been detected
#' @returns named vector with giotto instructions
#' @seealso More online information can be found
#' here \url{http://giottosuite.com}
#' @examples
#' createGiottoInstructions()
#' @export
createGiottoInstructions <- function(
python_path = getOption("giotto.py_path"),
Expand Down Expand Up @@ -175,7 +168,13 @@ create_giotto_instructions <- function(python_path = NULL,
}


#' @title Read giotto instructions associated with giotto object

# deprecated ####

# These functions have been made internal. They will stop being exported
# in a future version of GiottoClass

#' @title deprecated
#' @name readGiottoInstructions
#' @description Retrieves the instruction associated with the provided parameter
#' @param giotto_instructions giotto object or result from
Expand All @@ -190,9 +189,17 @@ create_giotto_instructions <- function(python_path = NULL,
#' param = "show_plot"
#' )
#' @export
#' @keywords internal
readGiottoInstructions <- function(giotto_instructions,
param = NULL,
default) {

deprecate_soft(
when = "0.3.5",
what = "readGiottoInstructions()",
with = "instructions()"
)

# get instructions if provided the giotto object
if (inherits(giotto_instructions, "giotto")) {
giotto_instructions <- giotto_instructions@instructions
Expand All @@ -213,7 +220,7 @@ readGiottoInstructions <- function(giotto_instructions,
}


#' @title Show giotto instructions associated with giotto object
#' @title deprecated
#' @name showGiottoInstructions
#' @description Function to display all instructions from giotto object
#' @param gobject giotto object
Expand All @@ -223,13 +230,21 @@ readGiottoInstructions <- function(giotto_instructions,
#'
#' showGiottoInstructions(g)
#' @export
#' @keywords internal
showGiottoInstructions <- function(gobject) {

deprecate_soft(
when = "0.3.5",
what = "showGiottoInstructions()",
with = "instructions()"
)

instrs <- gobject@instructions
return(instrs)
}


#' @title Change giotto instruction(s) associated with giotto object
#' @title deprecated
#' @name changeGiottoInstructions
#' @description Function to change one or more instructions from giotto object.
#' If more than one item is supplied to \code{params} and \code{new_values}, use
Expand All @@ -248,11 +263,20 @@ showGiottoInstructions <- function(gobject) {
#' new_values = TRUE
#' )
#' @export
#' @keywords internal
changeGiottoInstructions <- function(gobject,
params = NULL,
new_values = NULL,
return_gobject = TRUE,
init_gobject = TRUE) {

deprecate_soft(
when = "0.3.5",
what = "changeGiottoInstructions()",
with = "instructions()"
)


instrs <- gobject@instructions

if (is.null(params) | is.null(new_values)) {
Expand All @@ -263,10 +287,6 @@ changeGiottoInstructions <- function(gobject,
stop("\t length of params need to be the same as new values \t")
}

# if(!all(params %in% names(instrs))) {
# stop('\t all params need to be part of Giotto instructions \t')
# }

## swap with new values
instrs[params] <- new_values

Expand All @@ -289,7 +309,7 @@ changeGiottoInstructions <- function(gobject,
})

names(new_instrs) <- names(instrs)

class(new_instrs) <- "giottoInstructions"


if (isTRUE(return_gobject)) {
Expand All @@ -303,7 +323,7 @@ changeGiottoInstructions <- function(gobject,



#' @title Replace all giotto instructions in giotto object
#' @title deprecated
#' @name replaceGiottoInstructions
#' @description Function to replace all instructions from giotto object. Does
#' not call \code{initialize} on the giotto object
Expand All @@ -321,9 +341,17 @@ changeGiottoInstructions <- function(gobject,
#' instructions = createGiottoInstructions()
#' )
#' @export
#' @keywords internal
replaceGiottoInstructions <- function(gobject,
instructions = NULL,
init_gobject = TRUE) {

deprecate_soft(
when = "0.3.5",
what = "replaceGiottoInstructions()",
with = "instructions()"
)

instrs_needed <- names(create_giotto_instructions())

# validate new instructions
Expand All @@ -338,3 +366,15 @@ replaceGiottoInstructions <- function(gobject,
return(gobject)
}
}


# internals ####

#' @export
print.giottoInstructions <- function(x, ...) {
cat(sprintf("<%s>\n", class(x)[1]))
print_list(x)
}



Loading

0 comments on commit 0ccc659

Please sign in to comment.