Skip to content

[translate 3/3] Fix correctness and naming in the spectral library exports - #446

Draft
mo-sameh wants to merge 4 commits into
translate-refactor/2-restructurefrom
translate-refactor/3-fixes
Draft

[translate 3/3] Fix correctness and naming in the spectral library exports#446
mo-sameh wants to merge 4 commits into
translate-refactor/2-restructurefrom
translate-refactor/3-fixes

Conversation

@mo-sameh

@mo-sameh mo-sameh commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Goal

Fix the remaining defects the characterization tests exposed, now that the structure makes them one-line changes, and give the exports names that say what they produce.

What's here

  • rt_norm_pred is accepted as a retention time. peptdeep writes it alongside rt_pred, so a library whose rt_pred was dropped was rejected outright.
  • DIA-NN Flags marks one base peak per precursor row. It grouped on Precursor.Id, which is not unique — SpecLibBase.append produces libraries holding the same precursor twice, and those shared a single flag. Two appended libraries: 8 flags for 16 precursor rows, now 16.
  • The SWATH fragment columns are typed. They were object, and FragmentCharge held strings, so arithmetic on it concatenated. The written tsv and parquet are byte-identical; only the in-memory frames change.
  • translate_to_tsv notices a dead writer. multiprocessing=True is the default, and that process dies before writing anything if the calling script has no if __name__ == "__main__": guard — the norm on macOS and Windows. The export printed its success message and returned over a 0-byte file.
  • speclib_to_single_df is now speclib_to_swath_df. The good name already existed as a wrapper that has been missing its return since the module arrived from AlphaPeptDeep in 2022, so it only ever returned None. The real function takes the name; the old one stays as a deprecated alias. Nothing breaks — the wrapper's arguments are a subset, under the same names and defaults.

The module now reads speclib_to_*_df to build a frame, translate_to_* to write a file.

mo-sameh and others added 4 commits September 3, 2026 00:13
`Flags` marked the base peak by grouping on `Precursor.Id`, which is not unique:
`SpecLibBase.append` produces libraries holding the same precursor twice, and
those shared a single flag between them.
`fragment_table` built a frame of lists and exploded it, and `explode` yields
object columns. The DIA-NN export casts them against its schema; the SWATH one
does not, so it returned `FragmentMz`, `RelativeIntensity`, `FragmentCharge` and
`FragmentNumber` as objects of boxed scalars -- and the charge as strings, since
it is sliced out of a fragment column name and was never converted.

Concatenate the columns instead of exploding them: m/z and intensity keep the
dtype of the frame they came from, the charge and series number become int64.
That also removes the all-NaN row the explode needed dropped.

`translate_to_tsv` never checked its writer process. `multiprocessing=True` is
the default, and that process dies before writing anything if the calling script
has no `if __name__ == "__main__":` guard, so the export printed its success
message and returned over a 0-byte tsv. Raise on a non-zero exit code.

The written tsv and parquet are byte-identical; only the in-memory frames change,
and only in dtype -- plus `FragmentCharge` "1" -> 1.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mo-sameh mo-sameh changed the title translate refactor/3 fixes fix: correctness and naming in the spectral library exports Sep 2, 2026
@mo-sameh mo-sameh changed the title fix: correctness and naming in the spectral library exports [translate 3/3] Fix correctness and naming in the spectral library exports Sep 3, 2026
FragmentTableCols.SERIES_NUMBER: frag_numbers,
FragmentTableCols.MZ: np.concatenate(frag_masses),
FragmentTableCols.INTENSITY: np.concatenate(frag_intensities),
FragmentTableCols.CHARGE: np.array(frag_charges, dtype=np.int64),

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.

is int64 required for charges?

frag_types.append(types)
frag_losses.append(losses)
frag_charges.append(charges)
frag_types.extend(types)

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.

we change from append to extend, is this intended?

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