Skip to content

Conversation

@QiangweiPeng
Copy link
Contributor

This pull request introduces two new spatial correlation functions to the spateo package:

spatial_bv_moran_obs_genes: Calculates the bivariate global Moran’s I index for a cell's feature with specificed genes.

spatial_bv_local_moran_obs_genes: Calculates the bivariate local Moran’s I index for any two cell's features.

@Xiaojieqiu Xiaojieqiu requested a review from Copilot August 1, 2025 04:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces bivariate spatial correlation functionality to the spateo package by adding two new functions for calculating bivariate Moran's I statistics. The implementation provides both global and local spatial correlation analysis between spatial variables and gene expression data.

  • Adds global bivariate Moran's I calculation between spatial variables and genes
  • Adds local bivariate Moran's I calculation between any two spatial features
  • Integrates the new functions into the tools module's public API

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
spateo/tools/spatial_correlation.py New module implementing bivariate Moran's I functions with comprehensive parameter validation and result handling
spateo/tools/init.py Exports the new spatial correlation functions to make them available in the public API

copy: bool = False,
) -> Optional[pd.DataFrame]:
"""
Calculate global bivariate Moran's I between a spatial variable and gene expression
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring incorrectly describes the function as calculating 'global bivariate Moran's I' when the function name and implementation clearly indicate it calculates 'local bivariate Moran's I'. This should be corrected to 'Calculate local bivariate Moran's I between two spatial features'.

Suggested change
Calculate global bivariate Moran's I between a spatial variable and gene expression
Calculate local bivariate Moran's I between two spatial features

Copilot uses AI. Check for mistakes.
feature1_key
Key in `adata.obs` for the first variable or gene_name
feature2_key
Key in `adata.obs` for the seconda variable or gene_name
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo in the parameter description: 'seconda' should be 'second'.

Suggested change
Key in `adata.obs` for the seconda variable or gene_name
Key in `adata.obs` for the second variable or gene_name

Copilot uses AI. Check for mistakes.
Comment on lines +227 to +230
raise KeyError(f"'{feature1_key}' not found in adata.obs and a gene name")

if feature2_key not in adata.obs and feature2_key not in adata.var_names:
raise KeyError(f"'{feature2_key}' not found in adata.obs and a gene name")
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is grammatically incorrect and unclear. It should be: "'{feature1_key}' not found in adata.obs or as a gene name".

Suggested change
raise KeyError(f"'{feature1_key}' not found in adata.obs and a gene name")
if feature2_key not in adata.obs and feature2_key not in adata.var_names:
raise KeyError(f"'{feature2_key}' not found in adata.obs and a gene name")
raise KeyError(f"'{feature1_key}' not found in adata.obs or as a gene name")
if feature2_key not in adata.obs and feature2_key not in adata.var_names:
raise KeyError(f"'{feature2_key}' not found in adata.obs or as a gene name")

Copilot uses AI. Check for mistakes.
Comment on lines +227 to +230
raise KeyError(f"'{feature1_key}' not found in adata.obs and a gene name")

if feature2_key not in adata.obs and feature2_key not in adata.var_names:
raise KeyError(f"'{feature2_key}' not found in adata.obs and a gene name")
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is grammatically incorrect and unclear. It should be: "'{feature2_key}' not found in adata.obs or as a gene name".

Suggested change
raise KeyError(f"'{feature1_key}' not found in adata.obs and a gene name")
if feature2_key not in adata.obs and feature2_key not in adata.var_names:
raise KeyError(f"'{feature2_key}' not found in adata.obs and a gene name")
raise KeyError(f"'{feature1_key}' not found in adata.obs or as a gene name")
if feature2_key not in adata.obs and feature2_key not in adata.var_names:
raise KeyError(f"'{feature2_key}' not found in adata.obs or as a gene name")

Copilot uses AI. Check for mistakes.
y = np.array(adata.obs[feature2_key].values, dtype=np.float64)
else:
idx = adata.var_names.get_loc(feature2_key)
print(hasattr(adata.X[:, idx], "toarray"))
Copy link

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug print statement should be removed from production code as it serves no functional purpose and will clutter the output.

Suggested change
print(hasattr(adata.X[:, idx], "toarray"))

Copilot uses AI. Check for mistakes.
@Xiaojieqiu Xiaojieqiu merged commit 622a20f into aristoteleo:main Aug 1, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants