Skip to content

Fix/user mod unimod id dtype - #455

Open
mo-sameh wants to merge 4 commits into
mainfrom
fix/user-mod-unimod-id-dtype
Open

mo-sameh wants to merge 4 commits into
mainfrom
fix/user-mod-unimod-id-dtype

Conversation

@mo-sameh

@mo-sameh mo-sameh commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes exporting libraries that contain modifications added with
add_new_modifications:

  • unimod_id stayed float after adding a modification, so TSV/parquet export
    wrote UniMod:4.0 instead of UniMod:4 for every modification.
  • add_new_modifications now accepts an optional unimod_id.
  • The export lookup (mod_to_unimod_dict) now includes modifications added
    after import. It is rebuilt in update_all_by_MOD_DF() together with the
    other modification dicts. A custom modification without an id is left out
    (so it raises a KeyError) instead of being exported as UniMod:0.

To-do list (outside contributers only)

mo-sameh and others added 2 commits October 9, 2026 14:21
Adding a row to MOD_DF upcast unimod_id to float64, so translated
libraries wrote every modification as e.g. [UniMod:4.0].

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…for exports

add_new_modifications accepts an optional unimod_id. Added modifications
default to -1 (no UniMod id) instead of 0, which was exported as the
invalid accession UniMod:0.

mod_to_unimod_dict was built once at import, so modifications added later
were missing from TSV/parquet exports, and whether a user mod was exported
depended on import order. It is now a read-only mapping over the current
MOD_DF (cached until the table changes) that pickles to a plain dict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mo-sameh
mo-sameh requested review from GeorgWa and mschwoer and removed request for mschwoer October 11, 2026 23:41
Comment thread alphabase/spectral_library/translate.py Outdated
# MOD_DF is replaced by load_mod_df() and grown by add_new_modifications(),
# so rebuild whenever the table object or its length changes.
mod_df = modification.MOD_DF
cache_key = (id(mod_df), len(mod_df))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isn't len a bit of a weak hash? If I remove a mod, and add one, it stays the same

@mo-sameh mo-sameh Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

True, good catch! Instead of a better hash on every lookup, I dropped building a cache and went with rebuilding the dict in update_all_by_MOD_DF(), which should be called after every change to MOD_DF anyway.

mo-sameh and others added 2 commits October 25, 2026 13:53
The cached lookup keyed on (id, len) of MOD_DF and missed changes that
keep the row count, e.g. removing one mod and adding another. Build
MOD_TO_UNIMOD alongside the other mod dicts instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
load_mod_df() in other tests rebinds MOD_DF, so a module-level import
pointed the tests at a stale table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
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