Skip to content

Commit

Permalink
Merge pull request #138 from jiajic/dev
Browse files Browse the repository at this point in the history
v0.1.2
  • Loading branch information
jiajic authored Jan 3, 2024
2 parents 058ccca + d8cd853 commit 493fe80
Show file tree
Hide file tree
Showing 22 changed files with 609 additions and 87 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/dev_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Checkout repo for workflow access
uses: actions/checkout@v3

- name: Setup pandoc
uses: r-lib/actions/setup-pandoc@v2

- name: Set up R environment
uses: r-lib/actions/setup-r@v2
with:
Expand All @@ -43,14 +46,7 @@ jobs:
_R_CHECK_RD_XREFS: false
with:
dependencies: '"hard"' # do not use suggested dependencies
extra-packages: any::rcmdcheck, any::testthat, any::rlang, any::R.utils, any::remotes, any::sp, any::stars, any::raster, any::sf

- name: Set up dependencies (GiottoData)
run: |
suppressWarnings({
remotes::install_github('drieslab/GiottoData', build = FALSE)
})
shell: Rscript {0}
extra-packages: any::rcmdcheck, any::testthat, any::rlang, any::R.utils, any::sp, any::stars, any::raster, any::sf, any::scattermore, any::exactextractr, github::drieslab/GiottoData

- name: Run R CMD check
uses: r-lib/actions/check-r-package@v2
Expand Down
7 changes: 5 additions & 2 deletions 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.1.1
Version: 0.1.2
Authors@R: c(
person("Ruben", "Dries", email = "rubendries@gmail.com",
role = c("aut", "cre")),
Expand Down Expand Up @@ -34,7 +34,7 @@ Imports:
data.table (>= 1.12.2),
dbscan (>= 1.1-3),
deldir (>= 1.0.6),
GiottoUtils (>= 0.1.0.1),
GiottoUtils (>= 0.1.2),
igraph (>= 1.2.4.1),
magick,
Matrix (>= 1.6.2),
Expand All @@ -54,11 +54,13 @@ Suggests:
geometry,
GiottoData,
HDF5Array (>= 1.18.1),
knitr,
R.utils,
raster,
remotes,
rhdf5,
rlang,
rmarkdown,
RTriangle (>= 1.6-0.10),
S4Vectors,
ScaledMatrix,
Expand Down Expand Up @@ -135,3 +137,4 @@ Collate:
'suite_reexports.R'
'zzz.R'
URL: https://drieslab.github.io/GiottoClass/
VignetteBuilder: knitr
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Generated by roxygen2: do not edit by hand

S3method(.DollarNames,dimObj)
S3method(.DollarNames,metaData)
S3method(.DollarNames,spatEnrObj)
S3method(.DollarNames,spatLocsObj)
S3method(.DollarNames,terraVectData)
S3method(as.data.table,SpatVector)
S3method(as.data.table,giottoPoints)
S3method(as.data.table,giottoPolygon)
Expand Down Expand Up @@ -107,6 +112,7 @@ export(getExpression)
export(getFeatureInfo)
export(getFeatureMetadata)
export(getGiottoImage)
export(getMonochromeColors)
export(getMultiomics)
export(getNearestNetwork)
export(getPolygonInfo)
Expand Down Expand Up @@ -368,6 +374,7 @@ importFrom(methods,show)
importFrom(methods,slot)
importFrom(methods,slotNames)
importFrom(methods,validObject)
importFrom(utils,.DollarNames)
importMethodsFrom(Matrix,t)
importMethodsFrom(terra,"ext<-")
importMethodsFrom(terra,as.data.frame)
Expand Down
20 changes: 18 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@

# Giotto Class 0.1.1 (2023/12/16)
# GiottoClass 0.1.2 (2024/01/02)

## Added
- Added: `max_window` and `colors` slots to `giottoLargeImage`. Use `GiottoClass:::.update_giotto_image()` to update outdated objects.
- Added: `.bitdepth()` internal function to detect image bitdepth from sampled values
- Added: re-export `getMonochromeColors()` from *GiottoUtils*
- Added: `giottoPolygon`, `giottoLargeImage` method for `calculateOverlap()`
- Added: vignette for working with spatial classes
- Added: `output` param to `.spatraster_sample_values()`. Can now return as sampled `data.frame`, `array`, `magick`, `EBImage`

## Changes
- Fixes: Updates to raster `calculateOverlap()` workflows


# GiottoClass 0.1.1 (2023/12/16)

## Breaking Changes
- Removed: `getRainbowColors()` to *GiottoUtils*
Expand All @@ -24,7 +38,9 @@
- Changed: `giottoPolygon` `plot()` now automatically switches to centroid plotting with more than 1e4 polys
- Changed: Package internal functions now have `.` prefix

# Giotto Class 0.1.0 (23/11/29)


# GiottoClass 0.1.0 (2023/11/29)

## Breaking Changes

Expand Down
40 changes: 38 additions & 2 deletions R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,31 @@ setMethod(
)


# * giottoPolygon giottoLargeImage ####
#' @rdname calculateOverlap
#' @export
setMethod(
"calculateOverlap", signature(x = "giottoPolygon", y = "giottoLargeImage"),
function(
x, y,
name_overlap = NULL,
poly_subset_ids = NULL,
return_gpolygon = TRUE,
verbose = TRUE,
...
) {
calculateOverlap(
x = x,
y = y@raster_object,
name_overlap = objName(y),
poly_subset_ids = poly_subset_ids,
verbose = verbose,
...
)
}
)


# * giottoPolygon SpatRaster ####
#' @rdname calculateOverlap
#' @export
Expand All @@ -307,6 +332,10 @@ setMethod(
return_gpolygon = TRUE,
verbose = TRUE,
...) {
if (is.null(name_overlap)) {
.gstop("calculateOverlap: name_overlap must be given")
}

res <- calculateOverlap(
x = x[],
y = y,
Expand Down Expand Up @@ -1189,13 +1218,20 @@ setMethod(
)
}

# pass to SpatVector method
overlapToMatrix(
argslist <- list(
x = overlaps_data,
count_info_column = count_info_column,
output = output,
...
)

# this arg not accepted by method
if (type == "intensity") {
argslist$count_info_column <- NULL
}

# pass to SpatVector method
do.call(overlapToMatrix, args = argslist)
}
)

Expand Down
70 changes: 62 additions & 8 deletions R/classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@ updateGiottoObject <- function(gobject) {
gobject@h5_file <- NULL
}

# GiottoClass 0.1.2 adds max_window and colors slots to giottoLargeImage
if (!is.null(gobject@largeImages)) {
gobject@largeImages <- lapply(gobject@largeImages, .update_giotto_image)
}

# # 3.3.X release adds mirai slot
# if (is.null(attr(gobject, "mirai"))) {
# attr(gobject, "mirai") <- list()
Expand Down Expand Up @@ -1464,8 +1469,10 @@ giottoImage <- setClass(
#' @slot overall_extent terra extent object covering the original extent of image
#' @slot scale_factor image scaling relative to spatial locations
#' @slot resolution spatial location units covered per pixel
#' @slot max_intensity value to set as maximum intensity in color scaling
#' @slot min_intensity minimum value found
#' @slot max_intensity approximate maximum value
#' @slot min_intensity approximate minimum value
#' @slot max_window value to set as maximum intensity in color scaling
#' @slot colors color mappings in hex codes
#' @slot is_int values are integers
#' @slot file_path file path to the image if given
#' @slot OS_platform Operating System to run Giotto analysis on
Expand All @@ -1476,12 +1483,14 @@ giottoLargeImage <- setClass(
slots = c(
name = "ANY",
raster_object = "ANY",
extent = "ANY",
overall_extent = "ANY",
extent = "ANY", # REMOVE?
overall_extent = "ANY", # REMOVE? New slot px_dims as replacement?
scale_factor = "ANY",
resolution = "ANY",
max_intensity = "ANY",
min_intensity = "ANY",
max_intensity = "numeric",
min_intensity = "numeric",
max_window = "numeric", # NEW
colors = 'character', # NEW
is_int = "ANY",
file_path = "ANY",
OS_platform = "ANY"
Expand All @@ -1493,10 +1502,55 @@ giottoLargeImage <- setClass(
overall_extent = NULL,
scale_factor = NULL,
resolution = NULL,
max_intensity = NULL,
min_intensity = NULL,
max_intensity = NA_real_,
min_intensity = NA_real_,
max_window = NA_real_,
colors = grDevices::grey.colors(n = 256, start = 0, end = 1, gamma = 1),
is_int = NULL,
file_path = NULL,
OS_platform = NULL
)
)

# function for updating image objects if structure definitions have changed
.update_giotto_image = function(x) {
# 0.1.2 release adds colors & max_window slots
if (is.null(attr(x, "colors"))) {
attr(x, "colors") <- grDevices::grey.colors(n = 256, start = 0, end = 1, gamma = 1)
}
if (is.null(attr(x, "max_window"))) {
# get a max intensity value
if (!is.null(x@max_intensity)) {
x@max_intensity <- .spatraster_intensity_range(x@raster_object)[["max"]]
}

attr(x, "max_window") <- .bitdepth(x@max_intensity, return_max = TRUE)
}

# 0.1.x release adds giottoImageStack
# deprecate

return(x)
}



## giottoImageStack class ####

## * definition ####
# giottoImageStack class

# giottoImageStack <- setClass(
# Class = "giottoImageStack",
#
# slots = c(
# name = 'character',
# images = 'giottoLargeImage',
# weight = 'numeric'
# )
# )





5 changes: 4 additions & 1 deletion R/create.R
Original file line number Diff line number Diff line change
Expand Up @@ -2840,7 +2840,10 @@ createGiottoLargeImage <- function(raster_object,
## 6. extent object
g_imageL@extent <- g_imageL@overall_extent <- as.vector(terra::ext(raster_object))

## 7. return image object
## 7. Assign discovered bitdepth max value as max window
g_imageL@max_window <- .bitdepth(g_imageL@max_intensity, return_max = TRUE)

## 8. return image object
return(g_imageL)
}

Expand Down
Loading

0 comments on commit 493fe80

Please sign in to comment.