Data Handling

SpaHDmap provides several functions and classes for handling spatial transcriptomics data. This module includes tools for data preparation, preprocessing, and feature selection.

class SpaHDmap.data.STData(adata, section_name, radius, scale_rate=1.0, select_hvgs=True, gene_list=None, swap_coord=True, create_mask=True, image_type=None, color_norm=False)[source]

A class for handling and managing spatial transcriptomics data.

Parameters:
  • adata (AnnData) – AnnData object containing the spatial transcriptomics data.

  • section_name (str) – Name of the tissue section.

  • radius (float) – Radius of spots in original scale.

  • scale_rate (float) – Scale rate for adjusting coordinates and image size.

  • select_hvgs (bool) – Whether to select highly variable genes (HVGs) from the data.

  • gene_list (Optional[List[str]]) – List of genes to arrange the data by. If provided, select_hvgs will be set to False. Missing genes will be added with zero expression.

  • swap_coord (bool) – Whether to swap the x and y coordinates.

  • create_mask (bool) – Whether to create a mask for the image.

  • image_type (Optional[str]) – Type of the image (‘HE’ or ‘Immunofluorescence’). If None, will be auto-detected.

  • color_norm (bool) – Whether to apply Reinhard color normalization. Only works for H&E images.

static load(path)[source]

Load STData object from file.

Parameters:

path (str) – Path to load the STData object from. Should end with ‘.st’

Returns:

Loaded STData object

Return type:

STData

save(path)[source]

Save STData object to file.

Parameters:

path (str) – Path to save the STData object. Should end with ‘.st’

show(scale=4.0)[source]

Visualizes the spots and the tissue mask on the image.

Parameters:

scale (float) – The scale factor for visualization.

data.prepare_stdata([section_name, st_path, ...])

Prepare an STData object from various data sources, with a specific loading priority.

data.select_svgs(section[, n_top_genes, method])

Select the top SVGs based on Moran's I or SPARK-X or BSP for a given section or list of sections.