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

Add: createMerscopeLargeImage() #800

Merged
merged 1 commit into from
Nov 18, 2023
Merged
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export(createGiottoPolygonsFromGeoJSON)
export(createGiottoPolygonsFromMask)
export(createGiottoVisiumObject)
export(createGiottoXeniumObject)
export(createMerscopeLargeImage)
export(createMetafeats)
export(createNearestNetObj)
export(createSpatEnrObj)
Expand Down
56 changes: 56 additions & 0 deletions R/convenience.R
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,62 @@ visium_spot_poly <- function(spatLocsObj = NULL,

## MERSCOPE ####


#' @title Create Vizgen MERSCOPE largeImage
#' @name createMerscopeLargeImage
#' @description
#' Read MERSCOPE stitched images as giottoLargeImage. Images will also be
#' transformed to match the spatial coordinate reference system of the paired
#' points and polygon data.
#' @param image_file character. Path to one or more MERSCOPE images to load
#' @param transforms_file character. Path to MERSCOPE transforms file. Usually
#' in the same folder as the images and named
#' 'micron_to_mosaic_pixel_transform.csv'
#' @param name character. name to assign the image. Multiple should be provided
#' if image_file is a list.
#' @export
createMerscopeLargeImage <- function(image_file,
transforms_file,
name = 'image') {

checkmate::assert_character(transforms_file)
tfsDT <- data.table::fread(transforms_file)
if (inherits(image_file, "character")) {
image_file <- as.list(image_file)
}
checkmate::assert_list(image_file)

scalef <- c(1/tfsDT[[1,1]], 1/tfsDT[[2,2]])
x_shift <- -tfsDT[[1,3]]/tfsDT[[1,1]]
y_shift <- -tfsDT[[2,3]]/tfsDT[[2,2]]

out <- lapply(seq_along(image_file), function(i) {
gimg <- createGiottoLargeImage(
raster_object = image_file[[i]],
name = name[[i]],
scale_factor = scalef,
negative_y = FALSE
)

gimg <- spatShift(gimg, dx = x_shift, dy = y_shift)

gimg@extent <- terra::ext(gimg@raster_object)
return(gimg)
})

if (length(out) == 1L) {
out <- unlist(out)
}

return(out)
}







#' @title Create Vizgen MERSCOPE Giotto Object
#' @name createGiottoMerscopeObject
#' @description Given the path to a MERSCOPE experiment directory, creates a Giotto
Expand Down
23 changes: 23 additions & 0 deletions man/createMerscopeLargeImage.Rd

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