Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preview website #155

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.1.2
Version: 0.1.3
Authors@R: c(
person("Ruben", "Dries", email = "rubendries@gmail.com",
role = c("aut", "cre")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ exportMethods(createGiottoPoints)
exportMethods(createGiottoPolygon)
exportMethods(crop)
exportMethods(dim)
exportMethods(dimnames)
exportMethods(ext)
exportMethods(featIDs)
exportMethods(featType)
Expand Down
12 changes: 10 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@


# GiottoClass 0.1.3

## new
- vignette for image tools

## enhancements
- more subobjects respond to `colnames`, `rownames`, `dimnames`
# GiottoClass 0.1.2 (2024/01/02)

## Added
Expand All @@ -9,8 +17,8 @@
- 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
## bug fixes
- param fixes in raster `calculateOverlap()` workflows


# GiottoClass 0.1.1 (2023/12/16)
Expand Down
2 changes: 1 addition & 1 deletion R/auxilliary.R
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ addCellMetadata <- function(gobject,
# overwrite columns with same name
new_col_names <- colnames(new_metadata)
new_col_names <- new_col_names[new_col_names != column_cell_ID]
old_col_names <- colnames(cell_metadata[])
old_col_names <- colnames(cell_metadata)
old_col_names <- old_col_names[old_col_names != "cell_ID"]
same_col_names <- new_col_names[new_col_names %in% old_col_names]

Expand Down
46 changes: 46 additions & 0 deletions R/methods-names.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,56 @@ NULL
#' @return A character vector of row or col names
NULL

#' @title Dimnames of an object
#' @name dimnames
#' @description
#' Retrieve or set the dimnames of an object
#' @param x object
NULL

#' @rdname row-plus-colnames-generic
#' @export
setMethod("colnames", signature(x = "exprObj"), function(x) colnames(x[]))

#' @rdname row-plus-colnames-generic
#' @export
setMethod("colnames", signature(x = "cellMetaObj"), function(x) colnames(x[]))

#' @rdname row-plus-colnames-generic
#' @export
setMethod("colnames", signature(x = "featMetaObj"), function(x) colnames(x[]))

#' @rdname row-plus-colnames-generic
#' @export
setMethod("colnames", signature(x = "spatEnrObj"), function(x) colnames(x[]))

#' @rdname row-plus-colnames-generic
#' @export
setMethod("colnames", signature(x = "spatLocsObj"), function(x) colnames(x[]))

#' @rdname row-plus-colnames-generic
#' @export
setMethod("colnames", signature(x = "dimObj"), function(x) colnames(x[]))




#' @rdname row-plus-colnames-generic
#' @export
setMethod("rownames", signature(x = "exprObj"), function(x) rownames(x[]))

#' @rdname row-plus-colnames-generic
#' @export
setMethod("rownames", signature(x = "dimObj"), function(x) rownames(x[]))





#' @rdname dimnames
#' @export
setMethod("dimnames", signature(x = "exprObj"), function(x) dimnames(x[]))

#' @rdname dimnames
#' @export
setMethod("dimnames", signature(x = "dimObj"), function(x) dimnames(x[]))
11 changes: 9 additions & 2 deletions R/methods-show.R
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,15 @@ setMethod("show", signature = "giottoPolygon", function(object) {
cat(" centroids : NULL\n")
}

if (!is.null(object@overlaps)) {
cat(" overlaps : calculated")
if (!is.null(overlaps(object))) {
overlap_names <- names(overlaps(object))
if ("intensity" %in% overlap_names) {
non_intens_names <- overlap_names != "intensity"
intens_names <- names(overlaps(object)[["intensity"]])
overlap_names <- c(overlap_names[non_intens_names], intens_names)
}

cat(" overlaps :", paste(overlap_names, collapse = ", "))
} else {
cat(" overlaps : NULL")
}
Expand Down
2 changes: 2 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ navbar:
menu:
- text: Spatial Geometry Objects
href: articles/spatial_geometries.html
- text: Images
href: articles/image_tools.html
news:
text: News
href: news/index.html
Expand Down
18 changes: 18 additions & 0 deletions man/dimnames.Rd

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

18 changes: 18 additions & 0 deletions man/row-plus-colnames-generic.Rd

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

91 changes: 91 additions & 0 deletions vignettes/image_tools.Rmd
Original file line number Diff line number Diff line change
@@ -1,0 +1,91 @@
# Giotto Image Tools

## 1. Overview

Giotto uses `giottoLargeImage` to represent images and raster information. This
is an S4 class built based on the *terra* `SpatRaster`.

An older class called `giottoImage` based on the *magick* package also exists,
but is currently being phased out. Ideally, `giottoLargeImages` will also
be renamed to `giottoImage` afterwards, simplifying the naming scheme.

The object structure of `giottoLargeImage`
```
giottoLargeImage
\- name (object name)
\- raster_object (terra raster object)
\- extent (current spatial extent)
\- overall_extent (spatial extent of original image - experimental)
\- scale_factor (pixels per coordinate unit - experimental)
\- resolution (coordinate units covered per pixel)
\- max_intensity (approximate maximum intensity value)
\- min_intensity (approximate minimum intensity value)
\- max_window (value to set as maximum intensity in color scaling)
\- colors (vector of color mappings provided as hex codes)
\- is_int (whether values are integers)
\- file_path (filepath to the image)
\- OS_platform (operating system)
```


## 2. Sampling

Spatial images are often extremely large files. The high detail (resolution),
large spatial region captured, and precision of recorded values (bitdepth)
often results in files in the 10s of gigabytes. This makes the full size images
difficult to work with. One way to get around this is to perform regular
sampling of the image, touching only the values of the original image that are
needed generate a downscaled representation. This is implemented in *terra*
as `spatSample()`.

When plotting, *Giotto* optimizes the speed of this sampling by striking a balance
between `terra::crop()` and `terra::spatSample()` to try to prevent sampling from
unnecessary regions, but also avoid large crop operations on the fullsize image,
which can be very costly. This is done through `plot_auto_largeImage_resample()`

`giottoLargeImages` can also be resampled to other image formats (`magick` and
`EBImage`) in addition to `data.table` and `array` using `GiottoClass:::.spatraster_sample_values()`

These two functions are experimental and they will be exported using more common
function names in the future.

## 3 Color scaling
`distGiottoImage()` can be used to look at the values present within a
`giottoLargeImage`. It is often the case that the values recorded within an
image do not map to the full set of values allowed by its bitdepth.
*Giotto* plots images by guessing the bitdepth based on the estimated maximum
value detected. This mapping may not always be optimal.

```{r}
library(GiottoClass)
gimg <- GiottoData::loadSubObjectMini("giottoLargeImage", idx = 2)
gimg <- GiottoClass:::.update_giotto_image(gimg) # update older images that are missing slots

Check notice

Code scanning / lintr

Lines should not be more than 80 characters. This line is 93 characters. Note

Lines should not be more than 80 characters. This line is 93 characters.

plot(gimg)
distGiottoImage(giottoLargeImage = gimg)
```

Since there are few values beyond 70, try setting `max_window` to 70 in so
that the color mapping better represents the available information.

```{r}
gimg@max_window <- 70
plot(gimg)
# plot(gimg, max_intensity = 150) # can be used without setting the slot

Check notice

Code scanning / lintr

Commented code should be removed. Note

Commented code should be removed.
```


The colormap to use for an image can also be edited. The default for a greyscale
image is a monochrome black to white. Other color scales can be supplied.
For monochrome colorscales: `getMonochromeColors()`
```{r}
gimg@colors <- getMonochromeColors("green")
plot(gimg)
plot(gimg, col = GiottoVisuals::getColors("viridis", n = 256)) # can be used without setting the slot

Check notice

Code scanning / lintr

Lines should not be more than 80 characters. This line is 101 characters. Note

Lines should not be more than 80 characters. This line is 101 characters.
```


TODOs:
- provide accessor for these slots
- make *ggplot*-based plotting also obey these settings

Loading