prepare_coords_df_visium_hd: Prepare coordinates data.frame for decreasing resolution

View source: R/p.R

prepare_coords_df_visium_hdR Documentation

Prepare coordinates data.frame for decreasing resolution

Description

This function prepares a data frame of spatial coordinates for Visium HD analysis by adjusting the coordinates to form a grid of evenly sized squares and grouping them into larger aggregate squares. It ensures the grid dimensions are divisible by a given factor, and it predicts missing coordinates.

Usage

prepare_coords_df_visium_hd(coords_df, fct)

Arguments

coords_df

A data frame containing the original spatial coordinates. It must include columns row, col, x_orig, and y_orig representing the spatial grid positions and original coordinates.

fct

An integer factor by which the dimensions of the grid should be divisible. This ensures the grid can be evenly divided into larger squares.

Details

The function adjusts the input coordinates to form a perfect rectangular grid of squares and groups them into larger squares based on the provided factor (fct). It ensures that both the row and column counts are divisible by fct by expanding the grid if necessary. The function then assigns new groupings to these aggregated squares and predicts missing x and y coordinates using linear models based on the original coordinates. The output is a data frame that includes these new groupings and predicted coordinates.

The main steps include:

  • Calculating scaling factors for the columns and rows.

  • Adjusting the grid to ensure divisibility by fct and equal lengths of rows and columns.

  • Creating new row and column groups and generating corresponding barcodes.

  • Predicting missing x and y coordinates using linear models.

Value

A data frame with adjusted spatial coordinates, new row and column groupings, predicted coordinates, and updated barcodes.


theMILOlab/SPATA2 documentation built on Feb. 8, 2025, 11:41 p.m.