Skip to content

Commit

Permalink
Replace all mentions of ImageJ with Fiji. Closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Eagles committed Jul 23, 2024
1 parent 9e4c9c5 commit 482170b
Show file tree
Hide file tree
Showing 17 changed files with 178 additions and 178 deletions.
6 changes: 3 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
export(add_array_coords)
export(add_overlap_info)
export(build_spe)
export(prep_imagej_coords)
export(prep_imagej_image)
export(rescale_imagej_inputs)
export(prep_fiji_coords)
export(prep_fiji_image)
export(rescale_fiji_inputs)
export(spe_to_seurat)
export(spot_plot)
import(DropletUtils)
Expand Down
20 changes: 10 additions & 10 deletions R/add_array_coords.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' @param coords_dir A \code{character(1)} vector giving the directory
#' containing sample directories each with \code{tissue_positions.csv},
#' \code{scalefactors_json.json}, and \code{tissue_lowres_image.png} files
#' produced from refinement with \code{prep_imagej_*()} functions
#' produced from refinement with \code{prep_fiji_*()} functions
#' @param overwrite A \code{logical(1)} vector indicating whether to overwrite
#' \code{spatialCoords(spe)}, and \code{colData(spe)} columns \code{array_row},
#' \code{array_col}, \code{pixel_row_in_fullres}, and
Expand Down Expand Up @@ -65,20 +65,20 @@
#' sr_dir, sample_info$capture_area, "outs", "spatial"
#' )
#'
#' # Add ImageJ-output-related columns
#' imagej_dir <- tempdir()
#' # Add Fiji-output-related columns
#' fiji_dir <- tempdir()
#' temp <- unzip(
#' spatialLIBD::fetch_data("visiumStitched_brain_ImageJ_out"),
#' exdir = imagej_dir
#' spatialLIBD::fetch_data("visiumStitched_brain_Fiji_out"),
#' exdir = fiji_dir
#' )
#' sample_info$imagej_xml_path <- temp[grep("xml$", temp)]
#' sample_info$imagej_image_path <- temp[grep("png$", temp)]
#' sample_info$fiji_xml_path <- temp[grep("xml$", temp)]
#' sample_info$fiji_image_path <- temp[grep("png$", temp)]
#'
#' sample_info <- rescale_imagej_inputs(sample_info, out_dir = tempdir())
#' sample_info <- rescale_fiji_inputs(sample_info, out_dir = tempdir())
#'
#' spe_input_dir <- tempdir()
#' prep_imagej_coords(sample_info, out_dir = spe_input_dir)
#' prep_imagej_image(sample_info, out_dir = spe_input_dir)
#' prep_fiji_coords(sample_info, out_dir = spe_input_dir)
#' prep_fiji_image(sample_info, out_dir = spe_input_dir)
#'
#' ########################################################################
#' # Add array coordinates
Expand Down
18 changes: 9 additions & 9 deletions R/build_spe.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@
#' sr_dir, sample_info$capture_area, "outs", "spatial"
#' )
#'
#' # Add ImageJ-output-related columns
#' imagej_dir <- tempdir()
#' # Add Fiji-output-related columns
#' fiji_dir <- tempdir()
#' temp <- unzip(
#' spatialLIBD::fetch_data("visiumStitched_brain_ImageJ_out"),
#' exdir = imagej_dir
#' spatialLIBD::fetch_data("visiumStitched_brain_Fiji_out"),
#' exdir = fiji_dir
#' )
#' sample_info$imagej_xml_path <- temp[grep("xml$", temp)]
#' sample_info$imagej_image_path <- temp[grep("png$", temp)]
#' sample_info$fiji_xml_path <- temp[grep("xml$", temp)]
#' sample_info$fiji_image_path <- temp[grep("png$", temp)]
#'
#' sample_info <- rescale_imagej_inputs(sample_info, out_dir = tempdir())
#' sample_info <- rescale_fiji_inputs(sample_info, out_dir = tempdir())
#'
#' spe_input_dir <- tempdir()
#' prep_imagej_coords(sample_info, out_dir = spe_input_dir)
#' prep_imagej_image(sample_info, out_dir = spe_input_dir)
#' prep_fiji_coords(sample_info, out_dir = spe_input_dir)
#' prep_fiji_image(sample_info, out_dir = spe_input_dir)
#'
#' ########################################################################
#' # Build the SpatialExperiment
Expand Down
44 changes: 22 additions & 22 deletions R/prep_imagej_coords.R → R/prep_fiji_coords.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Apply transform info from ImageJ XML output
#' Apply transform info from Fiji XML output
#'
#' Given a \code{tibble} of sample information (\code{sample_info}) with
#' columns \code{capture_area}, \code{group}, and \code{imagej_xml_path},
#' expected to have one unique path to ImageJ XML output per group, read in
#' columns \code{capture_area}, \code{group}, and \code{fiji_xml_path},
#' expected to have one unique path to Fiji XML output per group, read in
#' the pixel coordinates from each capture area's \code{tissue_positions.csv}
#' file from Spaceranger, and transform using the rotation matrix specified
#' by ImageJ. Write one new \code{tissue_positions.csv} file per group.
#' by Fiji. Write one new \code{tissue_positions.csv} file per group.
#'
#' @param sample_info A \code{tibble} with columns \code{capture_area},
#' \code{group}, \code{imagej_xml_path}, \code{intra_group_scalar}, and
#' \code{group}, \code{fiji_xml_path}, \code{intra_group_scalar}, and
#' \code{group_hires_scalef}
#' @param out_dir A character(1) vector giving a path to a directory to place
#' the output pixel coordinates CSVs. Provided the parent exists, \code{out_dir}
Expand Down Expand Up @@ -40,23 +40,23 @@
#' sr_dir, sample_info$capture_area, "outs", "spatial"
#' )
#'
#' # Add ImageJ-output-related columns
#' imagej_dir <- tempdir()
#' # Add Fiji-output-related columns
#' fiji_dir <- tempdir()
#' temp <- unzip(
#' spatialLIBD::fetch_data("visiumStitched_brain_ImageJ_out"),
#' exdir = imagej_dir
#' spatialLIBD::fetch_data("visiumStitched_brain_Fiji_out"),

This comment has been minimized.

Copy link
@lcolladotor

lcolladotor Jul 23, 2024

Member

I'll help you make this change in spatialLIBD @Nick-Eagles

#' exdir = fiji_dir
#' )
#' sample_info$imagej_xml_path <- temp[grep("xml$", temp)]
#' sample_info$imagej_image_path <- temp[grep("png$", temp)]
#' sample_info$fiji_xml_path <- temp[grep("xml$", temp)]
#' sample_info$fiji_image_path <- temp[grep("png$", temp)]
#'
#' sample_info <- rescale_imagej_inputs(sample_info, out_dir = tempdir())
#' sample_info <- rescale_fiji_inputs(sample_info, out_dir = tempdir())
#'
#' spe_input_dir <- tempdir()
#' prep_imagej_coords(sample_info, out_dir = spe_input_dir)
#' prep_fiji_coords(sample_info, out_dir = spe_input_dir)
#'
#' # A file of spatial coordinates for the stitched Br2719 was produced
#' list.files(spe_input_dir)
prep_imagej_coords <- function(sample_info, out_dir) {
prep_fiji_coords <- function(sample_info, out_dir) {
## For R CMD check
group <- barcode <- key <- pxl_col_in_fullres <- pxl_row_in_fullres <- NULL

Expand All @@ -67,7 +67,7 @@ prep_imagej_coords <- function(sample_info, out_dir) {

# State assumptions about columns expected to be in sample_info
expected_cols <- c(
"capture_area", "group", "imagej_xml_path", "intra_group_scalar",
"capture_area", "group", "fiji_xml_path", "intra_group_scalar",
"group_hires_scalef"
)
if (!all(expected_cols %in% colnames(sample_info))) {
Expand All @@ -79,8 +79,8 @@ prep_imagej_coords <- function(sample_info, out_dir) {
)
}

if (!all(file.exists(sample_info$imagej_xml_path))) {
stop("All files in 'sample_info$imagej_xml_path' must exist.")
if (!all(file.exists(sample_info$fiji_xml_path))) {
stop("All files in 'sample_info$fiji_xml_path' must exist.")
}

dir.create(out_dir, recursive = TRUE, showWarnings = FALSE)
Expand All @@ -89,13 +89,13 @@ prep_imagej_coords <- function(sample_info, out_dir) {
this_sample_info <- sample_info |>
dplyr::filter(group == this_group)

if (length(unique(this_sample_info$imagej_xml_path)) > 1) {
stop("Expected one unique path for 'imagej_xml_path' per group in 'sample_info'.")
if (length(unique(this_sample_info$fiji_xml_path)) > 1) {
stop("Expected one unique path for 'fiji_xml_path' per group in 'sample_info'.")
}

# Find all XML elements containing input image paths and
# transformation matrices
transform_nodes <- this_sample_info$imagej_xml_path[1] |>
transform_nodes <- this_sample_info$fiji_xml_path[1] |>
read_xml() |>
suppressWarnings() |>
xml_find_all(".//t2_patch")
Expand All @@ -107,14 +107,14 @@ prep_imagej_coords <- function(sample_info, out_dir) {
this_sample_info$capture_area, function(x) grep(x, input_paths)
)
if (length(input_paths) != nrow(this_sample_info) || any(is.na(input_indices))) {
stop("Expected each capture area to be present exactly once in the input filenames to ImageJ for each group.")
stop("Expected each capture area to be present exactly once in the input filenames to Fiji for each group.")
}

coords_list <- list()

# Loop through all capture areas in this group
for (i in seq(nrow(this_sample_info))) {
# Parse the rotation matrix from the ImageJ XML, and scale
# Parse the rotation matrix from the Fiji XML, and scale
# translations from high to fullres
rot <- transform_nodes[input_indices[i]] |>
xml_attr("transform") |>
Expand Down
38 changes: 19 additions & 19 deletions R/prep_imagej_image.R → R/prep_fiji_image.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Create low-res images and scale factors from high-res ImageJ output images
#' Create low-res images and scale factors from high-res Fiji output images
#'
#' After stitching all groups in \code{sample_info} with ImageJ, images of
#' After stitching all groups in \code{sample_info} with Fiji, images of
#' various resolutions (pixel dimensions) are left. This function creates copies
#' of each image whose largest dimension is \code{lowres_max_size} pixels. It
#' also creates a corresponding \code{scalefactors_json.json} file much like
#' Spaceranger's. In conjunction with \code{prep_imagej_image()}, this function
#' Spaceranger's. In conjunction with \code{prep_fiji_image()}, this function
#' prepares for building the \code{SpatialExperiment} with \code{build_spe()}.
#'
#' @param sample_info A \code{tibble} with columns \code{capture_area},
#' \code{group}, \code{imagej_image_path}, \code{spaceranger_dir},
#' \code{group}, \code{fiji_image_path}, \code{spaceranger_dir},
#' \code{intra_group_scalar}, and \code{group_hires_scalef}
#' @param out_dir A character(1) vector giving a path to a directory to place
#' the output image(s) and scale factors. Provided the parent exists, \code{out_dir}
Expand Down Expand Up @@ -41,19 +41,19 @@
#' sr_dir, sample_info$capture_area, "outs", "spatial"
#' )
#'
#' # Add ImageJ-output-related columns
#' imagej_dir <- tempdir()
#' # Add Fiji-output-related columns
#' fiji_dir <- tempdir()
#' temp <- unzip(
#' spatialLIBD::fetch_data("visiumStitched_brain_ImageJ_out"),
#' exdir = imagej_dir
#' spatialLIBD::fetch_data("visiumStitched_brain_Fiji_out"),
#' exdir = fiji_dir
#' )
#' sample_info$imagej_xml_path <- temp[grep("xml$", temp)]
#' sample_info$imagej_image_path <- temp[grep("png$", temp)]
#' sample_info$fiji_xml_path <- temp[grep("xml$", temp)]
#' sample_info$fiji_image_path <- temp[grep("png$", temp)]
#'
#' sample_info <- rescale_imagej_inputs(sample_info, out_dir = tempdir())
#' sample_info <- rescale_fiji_inputs(sample_info, out_dir = tempdir())
#'
#' spe_input_dir <- tempdir()
#' prep_imagej_image(
#' prep_fiji_image(
#' sample_info,
#' out_dir = spe_input_dir, lowres_max_size = 1000
#' )
Expand All @@ -64,13 +64,13 @@
#' file.path(spe_input_dir, "Br2719", "tissue_lowres_image.png")
#' )
#' dim(this_image)
prep_imagej_image <- function(sample_info, out_dir, lowres_max_size = 1200) {
prep_fiji_image <- function(sample_info, out_dir, lowres_max_size = 1200) {
## For R CMD check
group <- NULL

# State assumptions about columns expected to be in sample_info
expected_cols <- c(
"capture_area", "group", "imagej_image_path", "intra_group_scalar",
"capture_area", "group", "fiji_image_path", "intra_group_scalar",
"group_hires_scalef", "spaceranger_dir"
)
if (!all(expected_cols %in% colnames(sample_info))) {
Expand All @@ -82,8 +82,8 @@ prep_imagej_image <- function(sample_info, out_dir, lowres_max_size = 1200) {
)
}

if (!all(file.exists(sample_info$imagej_image_path))) {
stop("All files in 'sample_info$imagej_image_path' must exist.")
if (!all(file.exists(sample_info$fiji_image_path))) {
stop("All files in 'sample_info$fiji_image_path' must exist.")
}

dir.create(out_dir, showWarnings = FALSE)
Expand All @@ -92,11 +92,11 @@ prep_imagej_image <- function(sample_info, out_dir, lowres_max_size = 1200) {
this_sample_info <- sample_info |>
dplyr::filter(group == this_group)

if (length(unique(this_sample_info$imagej_image_path)) > 1) {
stop("Expected one unique path for 'imagej_image_path' per group in 'sample_info'.")
if (length(unique(this_sample_info$fiji_image_path)) > 1) {
stop("Expected one unique path for 'fiji_image_path' per group in 'sample_info'.")
}

this_image <- imager::load.image(this_sample_info$imagej_image_path[1])
this_image <- imager::load.image(this_sample_info$fiji_image_path[1])

# Combine info about the original scalefactors of the first capture
# area with group-related scalars to form a new scalefactors JSON
Expand Down
22 changes: 11 additions & 11 deletions R/rescale_imagej_inputs.R → R/rescale_fiji_inputs.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Write same-scale hires images for input to ImageJ
#' Write same-scale hires images for input to Fiji
#'
#' Given a \code{tibble} of sample information (\code{sample_info}) with
#' columns \code{capture_area}, \code{group}, and \code{spaceranger_dir},
#' Write new high-resolution images for use as input to ImageJ. Particularly
#' Write new high-resolution images for use as input to Fiji. Particularly
#' when capture areas come from different slides, there is a risk of significant
#' scale differences among Spaceranger's \code{tissue_hires_image.png} images;
#' that is, the physical distance represented by a pixel from each capture area
Expand Down Expand Up @@ -48,25 +48,25 @@
#' sr_dir, sample_info$capture_area, "outs", "spatial"
#' )
#'
#' # Add ImageJ-output-related columns
#' imagej_dir <- tempdir()
#' # Add Fiji-output-related columns
#' fiji_dir <- tempdir()
#' temp <- unzip(
#' spatialLIBD::fetch_data("visiumStitched_brain_ImageJ_out"),
#' exdir = imagej_dir
#' spatialLIBD::fetch_data("visiumStitched_brain_Fiji_out"),
#' exdir = fiji_dir
#' )
#' sample_info$imagej_xml_path <- temp[grep("xml$", temp)]
#' sample_info$imagej_image_path <- temp[grep("png$", temp)]
#' sample_info$fiji_xml_path <- temp[grep("xml$", temp)]
#' sample_info$fiji_image_path <- temp[grep("png$", temp)]
#'
#' out_dir <- tempdir()
#' sample_info_new <- rescale_imagej_inputs(sample_info, out_dir = out_dir)
#' sample_info_new <- rescale_fiji_inputs(sample_info, out_dir = out_dir)
#'
#' # Scale factors are computed that are necessary downstream (i.e. with
#' # prep_imagej_*() functions)
#' # prep_fiji_*() functions)
#' sample_info_new[, setdiff(colnames(sample_info_new), colnames(sample_info))]
#'
#' # Image are produced that are ready for alignment in Fiji
#' list.files(out_dir)
rescale_imagej_inputs <- function(sample_info, out_dir) {
rescale_fiji_inputs <- function(sample_info, out_dir) {
## For R CMD check
group <- spot_diameter_fullres <- intra_group_scalar <- tissue_hires_scalef <- intra_group_scalar_image <- NULL

Expand Down
20 changes: 10 additions & 10 deletions man/add_array_coords.Rd

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

Loading

0 comments on commit 482170b

Please sign in to comment.