Skip to content

refactor(transforms): map genes from the FASTA only, drop biopython and mygene - #312

Merged
ypriverol merged 3 commits into
devfrom
refactor/gene-map-fasta-only
Sep 12, 2026
Merged

ypriverol merged 3 commits into
devfrom
refactor/gene-map-fasta-only

Conversation

@ypriverol

Copy link
Copy Markdown
Contributor

Follow-up to #311, which stopped a null gene column from killing the h5mu write. This removes the reason the column was empty in the first place being hard to fix: gene-map could not run where we needed it.

Why

qpxc transform gene-map needed two optional dependencies for work the FASTA already carries:

  • biopython — only used to iterate records so GN= could be read from the header.
  • mygene — queried MyGene.info for genomic accessions. That is what --species was for; it never affected gene names.

Neither ships in the published container: the Dockerfile runs a bare pip install . with no extras. Verified in ghcr.io/bigbio/qpx:1.1.3 on our cluster — import Bio raises ModuleNotFoundError, so the command cannot run there, and the MyGene lookup would fail soft and return nothing.

A single --species is also wrong for the databases we search (human + contaminants, sometimes human+mouse entrapment), so any accessions fetched would be partly wrong.

What

Parse the FASTA headers directly. Only header lines are read (sequences skipped) and .gz opens transparently, so mapping is offline, reproducible, and faster on large databases.

gg_accessions is no longer overwritten from the API: a value written by a converter survives, and the column is created as NULL when absent.

Removed: the [transforms] extra (with biopython and mygene), the --species option, and the fetch_accessions / include_accessions arguments.

Tests

Four new tests cover header shapes (three-field, two-field, bare), entries without GN=, gzip input, and that existing gg_accessions survives annotation. Full unit suite: 227 passed.

…nd mygene

Gene mapping needed two optional dependencies for work the FASTA already
carries. biopython only iterated records so the GN= field could be read from
the header, and mygene queried MyGene.info for genomic accessions, which is
what --species was for.

Neither ships in the published container (the Dockerfile installs a bare
`pip install .`), so `qpxc transform gene-map` could not run there at all:
importing Bio raised, and the MyGene lookup silently returned nothing.

Parse the headers directly instead. Only header lines are read, sequences are
skipped, and .gz is opened transparently, so the mapping is offline,
reproducible and faster on large databases. gg_accessions is no longer
overwritten from the API — a converter's value survives, and the column is
created as NULL when absent.

Removes the [transforms] extra, the --species option, and the
fetch_accessions / include_accessions arguments.
@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 7ecc9a66-ded1-4e10-b81a-28161e4b1943

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Parse gene mappings directly from FASTA headers

🐞 Bug fix ✨ Enhancement 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Replaces Biopython and MyGene.info with direct, gzip-aware FASTA header parsing.
• Keeps gene mapping offline and preserves converter-provided genomic accessions.
• Removes obsolete species controls and dependency extras, with regression coverage.
Diagram

graph TD
  FASTA["FASTA or gzip"] -->|header lines| Parser["Header parser"] -->|builds| Map["Protein gene map"] -->|annotates| Transform["Gene transform"] -->|writes| Output["QPX parquet"]
  CLI["gene-map CLI"] -->|invokes| Transform
Loading
High-Level Assessment

Direct header parsing is the best fit because the required gene symbols already exist in the search FASTA, and the implementation only needs header lines rather than full sequence objects. Bundling Biopython would retain unnecessary installation overhead, while keeping MyGene.info would preserve network dependence, mixed-species ambiguity, and accidental overwriting of converter-provided accessions.

Files changed (9) +140 / -187

Bug fix (1) +63 / -165
gene_mapping.pyReplace external gene lookup with direct FASTA header parsing +63/-165

Replace external gene lookup with direct FASTA header parsing

• Adds lightweight parsing for UniProt, two-field, and bare FASTA identifiers with transparent gzip support. Removes Biopython and MyGene integration, eliminates accession-fetching arguments, and preserves existing gg_accessions values while creating a null column when absent.

qpx/transforms/gene_mapping.py

Refactor (1) +4 / -10
transform.pySimplify gene-map CLI to use FASTA-only mapping +4/-10

Simplify gene-map CLI to use FASTA-only mapping

• Removes the species option and constructs the transform using only the FASTA path. Updates command help and examples to describe offline GN-field annotation.

qpx/cli/transform.py

Tests (1) +65 / -2
test_gene_mapping.pyCover dependency-free FASTA parsing and accession preservation +65/-2

Cover dependency-free FASTA parsing and accession preservation

• Adds tests for plain and gzipped FASTA files, supported identifier shapes, missing GN fields, and multi-protein annotation. Verifies that converter-provided genomic accessions survive gene annotation.

tests/unit/test_gene_mapping.py

Documentation (4) +6 / -6
CHANGELOG.mdDocument removed gene-mapping dependencies and API lookup +2/-0

Document removed gene-mapping dependencies and API lookup

• Records removal of the transforms extra, Biopython, MyGene, the species option, and network accession lookup. Clarifies that gene names now come from FASTA headers and existing genomic accessions remain intact.

CHANGELOG.md

README.mdRemove the obsolete transforms installation extra +0/-1

Remove the obsolete transforms installation extra

• Removes the transforms extra from the optional installation examples because gene mapping now works with the default package dependencies.

README.md

transform.mdRevise gene-map usage for FASTA-only annotation +4/-4

Revise gene-map usage for FASTA-only annotation

• Removes the species argument from the command example and explains that mappings should use the search FASTA. Documents that entries without a GN field remain unmapped.

docs/guide/transform.md

llms-full.txtRemove transforms extra from generated installation guidance +0/-1

Remove transforms extra from generated installation guidance

• Drops the obsolete Biopython and MyGene transforms extra from the consolidated documentation.

docs/llms-full.txt

Other (2) +2 / -4
environment.ymlRemove optional gene-mapping packages +0/-2

Remove optional gene-mapping packages

• Removes commented Biopython and MyGene environment entries because the transform no longer requires either package.

environment.yml

pyproject.tomlDrop Biopython and MyGene dependency extras +2/-2

Drop Biopython and MyGene dependency extras

• Removes the transforms optional dependency group and excludes Biopython and MyGene from the all extra. Notes that FASTA header parsing has no additional dependency.

pyproject.toml

@codacy-production

codacy-production Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 12 complexity · 0 duplication

Metric Results
Complexity 12
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@qodo-code-review

qodo-code-review Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Git install guidance names a dead extra 🐞 Bug ⚙ Maintainability
Description
Removing the transforms entry from project.optional-dependencies leaves the README's Git
installation command requesting qpx[quantify,transforms,plotting]. Users following that command
request an undefined extra and are incorrectly told that transforms still require optional
installation.
Code

pyproject.toml[37]

-transforms = ["biopython", "mygene>=1.0.0"]
+# Gene mapping reads FASTA headers directly, so it needs no extra dependency.
Evidence
The updated project metadata no longer declares a transforms extra, while the separate Git
installation example still includes that exact extra name.

pyproject.toml[34-40]
README.md[84-90]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The optional `transforms` extra was removed, but the README's Git installation example still requests it.

## Fix Focus Areas
- README.md[84-90]
- pyproject.toml[34-40]

## Recommended Fix
Remove `transforms` from the README's optional-extras command, leaving only extras that remain declared in `pyproject.toml`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: ⚖️ Balanced: This changes core gene-mapping logic, CLI/API parameters, dependency packaging, FASTA parsing, and data-column preservation across multiple code paths, creating meaningful compatibility and correctness risk.

Grey Divider

Tip of the day
💡 Did you know, you can hide the parts of a finding you never read, like the evidence or the agent prompt

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread pyproject.toml
[project.optional-dependencies]
mzidentml = ["lxml>=4.9.0"]
pdc = ["pridepy>=0.0.15"]
transforms = ["biopython", "mygene>=1.0.0"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

1. Git install guidance names a dead extra 🐞 Bug ⚙ Maintainability

Removing the transforms entry from project.optional-dependencies leaves the README's Git
installation command requesting qpx[quantify,transforms,plotting]. Users following that command
request an undefined extra and are incorrectly told that transforms still require optional
installation.
Agent Prompt
## Issue description
The optional `transforms` extra was removed, but the README's Git installation example still requests it.

## Fix Focus Areas
- README.md[84-90]
- pyproject.toml[34-40]

## Recommended Fix
Remove `transforms` from the README's optional-extras command, leaving only extras that remain declared in `pyproject.toml`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

gene-map only took a single parquet, so annotating a converted dataset meant
calling it per file and left the .h5mu describing the genes the converter
wrote, not the ones just mapped.

--dataset annotates every quantification view that carries protein accessions
(pg and feature), preserving each file's identity recipe so pg_id / feature_id
do not change, then rebuilds the MuData view when the dataset has one. Writes
go through a staging directory, so --in-place never truncates a parquet that is
still being read.

The converters' best-effort h5mu writer moves to qpx.mudata.write_dataset_mudata
so both paths refresh the view the same way; BaseOrchestrator._write_mudata
delegates to it.
Codacy flagged two new issues: the dataset helper carried 13 branches (12 max)
and the new pg log used an f-string. Extract the copy, view-annotation and
mudata-refresh steps into their own functions, and pass log arguments lazily
here and in the three surrounding messages.

No behaviour change.
@ypriverol
ypriverol merged commit e66cce0 into dev Sep 12, 2026
9 checks passed
@ypriverol
ypriverol deleted the refactor/gene-map-fasta-only branch October 19, 2026 14:24
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