adds a new sort utility to order h5ad files for faster cell load#251
adds a new sort utility to order h5ad files for faster cell load#251abhinadduri wants to merge 1 commit intomainfrom
Conversation
Summary of ChangesHello @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 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| import logging | ||
| from pathlib import Path |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
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