Skip to content

adds a new sort utility to order h5ad files for faster cell load#251

Open
abhinadduri wants to merge 1 commit intomainfrom
aadduri/add_sort_utility
Open

adds a new sort utility to order h5ad files for faster cell load#251
abhinadduri wants to merge 1 commit intomainfrom
aadduri/add_sort_utility

Conversation

@abhinadduri
Copy link
Collaborator

sorts an h5ad file according to a --context-col and a --pert-col, so that cells with the same (context, pert) appear consecutively in the h5ad file

@abhinadduri abhinadduri requested a review from a team as a code owner January 26, 2026 19:46
@gemini-code-assist
Copy link

Summary of Changes

Hello @abhinadduri, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new command-line utility designed to optimize the loading performance of H5AD files. By allowing users to sort H5AD files based on specific observational columns like context, perturbation, and optionally batch, the utility ensures that related cells are stored contiguously. This structural change is intended to improve data access efficiency for downstream analysis and model training.

Highlights

  • New Sort Utility: A new sort subcommand has been added to the CLI, allowing users to reorder H5AD files. This utility sorts cells based on specified context, perturbation, and an optional batch column.
  • Performance Optimization: The primary goal of this sorting utility is to group cells with similar characteristics consecutively within the H5AD file, which is expected to lead to faster cell loading times for downstream analysis and model training.
  • Dependency Update: The cell-load dependency has been updated to version >=0.9.0, and the project version has been incremented to 0.10.3.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new sort utility to the command-line interface, designed to reorder cells within an .h5ad file based on specified columns. This is a useful feature for optimizing data loading. The implementation is well-contained in a new module, and it's correctly integrated into the existing CLI structure. My review includes a few suggestions for the new _sort.py module to enhance code style, logging practices, and to simplify some logic.

Comment on lines +40 to +41
import logging
from pathlib import Path

Choose a reason for hiding this comment

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

medium

For better code organization and adherence to PEP 8, standard library imports like logging and pathlib should be placed at the top of the file. While it's a good practice to delay importing heavy libraries like anndata inside a function for CLI tools to improve startup time for other subcommands, this doesn't apply to lightweight standard libraries.


import anndata as ad

logging.basicConfig(level=logging.INFO)

Choose a reason for hiding this comment

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

medium

logging.basicConfig() should ideally be called only once at the application's entry point (e.g., in src/state/__main__.py). Calling it within subcommand functions can lead to unpredictable logging behavior, as it only has an effect the first time it's called. If another part of the application has already configured logging, this call will be ignored. Centralizing logging configuration would make it more robust.

adata_sorted = adata[order].copy()

output_dir = Path(output_path).parent
if output_dir and not output_dir.exists():

Choose a reason for hiding this comment

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

medium

The check if output_dir is redundant because Path(output_path).parent always returns a Path object, which is truthy. You can simplify the condition to just check for the directory's existence.

Suggested change
if output_dir and not output_dir.exists():
if not output_dir.exists():

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.

1 participant