Skip to content

Conversation

@YifanLu2000
Copy link
Collaborator

Fix bugs in paste alignment

Motivation

Fixes an issue where paste_align would crash due to the incorrect use of the align_preprocess function (Closes #341).

What’s Changed

  • Restored the paste_align_preprocess function, which had previously been removed when introducing the new align_preprocess.
  • Added a default value for return_index in the NumpyBackend.unique() function.
  • Fixed a bug where paste_align failed to call the correct cg function because of API changes in different versions of the POT package.

Validation

  • Verified functionality of st.align.paste_align.

Impact

Backward compatible, no API changes.

@YifanLu2000 YifanLu2000 requested a review from Copilot September 30, 2025 20:32
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 PR fixes bugs in the paste alignment functionality by restoring the paste_align_preprocess function and correcting API compatibility issues. The changes ensure that paste_align works correctly without crashing due to incorrect function usage.

  • Restores the paste_align_preprocess function that was previously removed
  • Adds a default value for return_index parameter in the NumpyBackend.unique() method
  • Fixes API compatibility by using the correct cg function call

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
spateo/alignment/methods/paste.py Updates function calls to use paste_align_preprocess and correct cg function
spateo/alignment/methods/deprecated_utils.py Adds the restored paste_align_preprocess function implementation
spateo/alignment/methods/backend.py Adds default value for return_index parameter in unique() method
spateo/alignment/methods/init.py Exports the restored paste_align_preprocess function

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

nx, type_as = check_backend(device=device, dtype=dtype)
# Subset for common genes
new_samples = [s.copy() for s in samples]
all_samples_genes = [s[0].var.index for s in new_samples]
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

The indexing s[0] appears incorrect. Each element in new_samples should be an AnnData object, so it should be s.var.index instead of s[0].var.index.

Suggested change
all_samples_genes = [s[0].var.index for s in new_samples]
all_samples_genes = [s.var.index for s in new_samples]

Copilot uses AI. Check for mistakes.
spatial_coords, normalize_scale_list, normalize_mean_list = normalize_coords(
coords=spatial_coords, nx=nx, verbose=verbose
)
if normalize_g and ((use_rep is None) or (not isinstance(use_rep, str)) or (use_rep not in samples[0].obsm.keys()) or (use_rep not in samples[1].obsm.keys())):
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

This complex condition is duplicated from line 779 and should be extracted into a helper function or variable to improve maintainability and reduce code duplication.

Copilot uses AI. Check for mistakes.
coords=spatial_coords, nx=nx, verbose=verbose
)
if normalize_g and ((use_rep is None) or (not isinstance(use_rep, str)) or (use_rep not in samples[0].obsm.keys()) or (use_rep not in samples[1].obsm.keys())):
exp_matrices = normalize_exps(matrices=exp_matrices, nx=nx, verbose=verbose)
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

The normalize_exps function expects exp_layers parameter but matrices is being passed. Based on the function signature, this should be exp_layers=exp_matrices.

Suggested change
exp_matrices = normalize_exps(matrices=exp_matrices, nx=nx, verbose=verbose)
exp_matrices = normalize_exps(exp_layers=exp_matrices, nx=nx, verbose=verbose)

Copilot uses AI. Check for mistakes.
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.

TypeError in st.tdr.cell_directions() Due to Unexpected layer Argument (Tutorials: 2.morphogenesis vector fields and trajectories)

2 participants