This function reduces the spatial resolution of Visium HD data by aggregating spatial spots into larger units, recalculating the count matrix, and generating a new SPATA2 object with the reduced resolution.

reduceResolutionVisiumHD(
  object,
  res_new,
  new_sample_name = "{sample_name}_redResHD",
  genes = getGenes(object),
  batch_size = 1000,
  workers = 1,
  verbose = NULL
)

Arguments

object

An object of class SPATA2 or, in case of S4 generics, objects of classes for which a method has been defined.

res_new

Distance measure. The new spatial resolution in micrometers (um). It must be lower than the current resolution and divisible by the current resolution.

new_sample_name

Character string for the name of the new sample after resolution reduction. Default is "{sample_name}_redResHD". Given to glue::glue() to create the final name.

genes

Character vector specifying which genes to include in the reduced object. Reducing the number of genes can dramatically spead up the process. See identifyVariableMolecules() and examples.

batch_size

Integer specifying the number of spatial spots to process in each batch. Default is 1000.

workers

Integer specifying the number of parallel workers to use for processing. Default is 1, which defaults to no parallel workers. If 2 or more, the furrr package is required.

verbose

Logical. If TRUE, informative messages regarding the computational progress will be printed.

(Warning messages will always be printed.)

...

Additional arguments passed to other methods.

Value

The updated input object, containing the added, removed or computed results.

Details

The reduceResolutionVisiumHD() function reduces the spatial resolution of a Visium HD dataset by aggregating neighboring spots into larger units and recalculating the count matrix for the new resolution. The process involves the following key steps:

  • Resolution check: Ensures the new resolution (res_new) is greater than the current resolution and is divisible by it.

  • Coordinate preparation: Uses the prepare_coords_df_visium_hd() function to adjust the spatial coordinates, creating a grid where both row and column counts are divisible by a factor derived from the resolution change. This function also ensures equal row and column lengths and predicts missing coordinates.

  • Resolution reduction: Applies the reduce_coords_df_visium_hd() function to aggregate the prepared coordinates at the new resolution. This function groups the data by new barcodes, summarizes the spot counts, and calculates the theoretical versus actual number of spots in each aggregated unit.

    (Since tissue is rarely a perfect rectangle, the new grid of squares often contains squares that, if located at the edge of the tissue, contain aggregated data of the fewer resolution squares than if not located on the tissue edge. This information is stored in the meta variables n_square_exp, n_square_actual and n_square_perc. See examples.)

  • Count matrix summarization: The count matrix is recalculated by summing up the counts of each new square. This step is optimized with parallel processing if multiple workers are specified.

  • SPATA2 object creation: A new SPATA2 object is generated with the reduced resolution data, including updated spatial data and metadata.

The assignment of barcodes under high resolution and new barcodes under which they have been aggrated is stored in a list in slot object@obj_info$reduceResolutionVisiumHD$aggregated_barcodes.

Note

Only works on SPATA2 object for platform VisiumHD.