Commit de91a40
Adding remaining Koina models (#1073)
* Refactor Koina models: neutral loss support, output extraction by name, unrestricted CE
- Add ParsedFragmentAnnotation record with neutral loss parsing
- Extract API outputs by name instead of positional index
- Fix intensity variable bug (was using m/z instead of intensities)
- Support neutral loss mass calculation in fragment ion matching
- Add CreateUnimodConverterAcceptAll for models accepting any modification
- Make KoinaModelBase members protected for subclass extensibility
- Remove collision energy restrictions on Prosit2020IntensityHCD
- Move DetectabilityModel to AbstractClasses namespace
* Refactor Koina model layer: deduplicate batching, add switch exhaustiveness, fix validation
- Add BuildBatchedRequest helper + InputField record to KoinaModelBase,
eliminating ~770 lines of duplicated dictionary construction across 37 models
- Remove Guid.NewGuid() from batch IDs (simpler counter-based IDs);
server ignores the id field for deduplication
- Add 'default: throw' to all ParameterHandlingMode switches for
future-proofing against new enum values
- Replace positional Outputs[0] lookup in CollisionalCrossSectionModel
with name-based "ccs" output resolution
- Move crosslink beta-null check from AsyncThrottledPredictor loop into
ValidateModelSpecificInputs for consistent validation
- Remove stale Outputs.Count != 3 guards (ExtractOutputs validates by name)
- Add virtual NumberOfPredictedFragmentIons to FragmentIntensityModel base;
override in 19 concrete models for polymorphic access
* Fix BaseFragmentIdentifier string arithmetic, PFly2024 null-forgiving, thread-safety docs, RT ToArray
- Fix BaseFragmentIdentifier computed property: use IndexOf('-') instead of
string-length arithmetic that broke for multi-character neutral loss formulas
(e.g. H3PO4 would include the trailing dash in the base identifier)
- Add missing null-forgiving operator on ValidatedFullSequence in
PFly2024FineTuned.ToBatchedRequests (consistent with all other models)
- Document thread-safety caveat on FragmentIntensityModel,
CollisionalCrossSectionModel, CrosslinkFragmentIntensityModel,
and DetectabilityModel (previously only on RetentionTimeModel)
- Remove unnecessary .ToArray() in RetentionTimeModel.ResponseToPredictions
(List<string> already implements IReadOnlyList<string>)
* Fix Contains('+') filter, TryGetValue indexer, CCS realignment + revert charge guard
- Remove Contains('+') pre-filter in GenerateLibrarySpectraFromPredictions
that silently dropped Altimeter (^ delimiter) and UniSpec annotations.
Parse failures are now caught by try/catch around ParseFragmentAnnotation
in the second loop, matching the ResponseToPredictions pattern.
- Replace tpLookup indexer (KeyNotFoundException risk) with TryGetValue
+ continue, consistent with ResponseToPredictions at line 458.
- Add ParameterWarning fallback in CollisionalCrossSectionModel realignment
(was SequenceWarning-only, unlike the other two model types).
- Change BaseFragmentIdentifier LastIndexOf('-') to IndexOf('-') to match
the dash-finding logic in ParseFragmentAnnotation.
- Revert the charge <= 0 guard in CollisionalCrossSectionModel.ValidateModelSpecificInputs
and add a TODO to revisit what empty AllowedPrecursorCharges means.
* Implement null/empty semantics for allowed parameter collections
Phase 1 — Validation logic change:
- Change AllowedCollisionEnergies, AllowedInstrumentTypes, AllowedFragmentationTypes
base property types from HashSet<T> to HashSet<T>? with default null
- null = parameter not applicable to this model (skip validation entirely)
- empty HashSet = parameter IS required but any value accepted
- populated HashSet = parameter IS required AND value must be in set
- Split the combined 'missing required params' check into per-parameter checks
with individual error messages
Phase 2 — Model migration:
- Models that send collision_energies to Koina keep empty HashSet (required, any value):
All Prosit fragment models (except CID), UniSpec, AlphaPeptDeep, XLCMS2, XLNMS2
- Models that don't send collision_energies change to null (not applicable):
Prosit2020IntensityCID, all 7 Ms2Pip models, Prosit2023IntensityXLCMS3
- Altimeter keeps its populated range (already correct)
- XLCMS2 and XLNMS2 add explicit AllowedCollisionEnergies = {} override
(previously inherited now-changed base default)
* Phase 4: Document null/empty/populated semantics on Allowed* properties
- Add XML doc comments to AllowedPrecursorCharges, AllowedCollisionEnergies,
AllowedInstrumentTypes, and AllowedFragmentationTypes in
FragmentIntensityModel documenting the three-tier convention
- Add same docs to AllowedPrecursorCharges and AllowedCollisionEnergies
in CrosslinkFragmentIntensityModel
- Update AllowedUnimodIds doc in KoinaModelBase to clarify it belongs to
the converter layer (not parameter validation) with empty = accept none
- Update TODO in CollisionalCrossSectionModel to reference the new
null/empty convention and note AllowedPrecursorCharges isn't yet migrated
* Fix review feedback
- Fix MapToInputFullSequence desynchronization bug in FragmentIntensityModel.cs
- Correct Prosit2024IntensityXLNMS2 fragment ion count from 174 to 348
- Fix Prosit2020IntensityTMT TryCleanSequence return value
* Fix Koina model validation, MS2PIP Immuno HCD length, CMS3 null CE, and batch type mismatches
- FragmentIntensityModel: require non-empty constraint sets before rejecting null params
- CrosslinkModelTests: handle null AllowedCollisionEnergies for CMS3
- Ms2PipImmunoHCD: correct MaxPeptideLength from 15 to 30
- CollisionalCrossSectionModel: add non-physical charge guard
- CrosslinkFragmentIntensityModel: fix sequence validation warning propagation
- CollisionEnergy: cast to float across all model impls (int? -> float)
- UniSpec: case-insensitive instrument type matching
- Ms2PipCIDTMT: N-terminal TMT/iTRAQ label validation
- Crosslink benchmark: generate independent beta peptides
- Prosit2024IntensityXLNMS2: correct fragment ion count to 348
* Review updates: fix parameter validation, neutral loss parsing, benchmark/test bugs
* Fix FragmentIntensityModel validation tests defaulting untested constraints to empty sets
The TestFragmentIntensityModel constructor defaulted unspecified constraints
(AllowedCollisionEnergies, AllowedInstrumentTypes, AllowedFragmentationTypes)
to empty HashSets. Per the validation logic in FragmentIntensityModel.cs:
- null = skip validation (not applicable)
- empty set = parameter IS required but any value accepted
This caused 4 tests to fail because empty sets made untested constraints
required, while the test inputs provided null for those fields.
Fix: default to null instead of empty sets, so only explicitly-passed
constraints are validated.
* Koina: fix annotation/instrument/detectability handling, share HttpClient, add coverage
Audit follow-ups for the Koina prediction client:
- FragmentIntensityModel: route the MapToInputFullSequence branch through the
overridable ParseFragmentAnnotation and compute neutral-loss-aware m/z, matching
GenerateLibrarySpectraFromPredictions. Fixes a crash on non-'+' annotations
(Altimeter '^', UniSpec internal ions) and wrong m/z for neutral-loss ions.
- HTTP: back with a single process-wide HttpClient; per-request CancellationToken
timeout replaces the per-session client to avoid socket exhaustion under repeated
Predict() calls. Updated the five AsyncThrottledPredictor call sites.
- CollisionalCrossSectionModel: make AllowedPrecursorCharges nullable to follow the
null/empty/populated constraint convention; the charge >= 1 physical guard still
applies. Removes the standing TODO.
- DetectabilityModel: map ValidatedFullSequence from requestInputs rather than the
full ModelInputs list, so the reported sequence is correct when inputs are filtered.
- Prosit_2025_intensity_lac: send instrument types uppercased and accept them
case-insensitively. Koina's Prosit_Preprocess_instrument_types matches uppercase
and silently defaults unknown casing to LUMOS, so lowercase astral/eclipse were
silently mispredicted.
Tests (no network; run on every PR build):
- New unit fixtures for crosslink, CCS, detectability, fragment-intensity, and HTTP
covering TryCleanSequence, ValidateModelSpecificInputs, ResponseToPredictions,
the all-invalid realignment path, GenerateLibrarySpectraFromPredictions, and the
MapToInputFullSequence/neutral-loss parsing.
- Moved crosslink client-side validation tests out of the [Category("Koina")] fixture
so they count toward coverage.
PredictionClients line coverage ~49% -> ~66%; HTTP 0 -> 100%,
CrosslinkFragmentIntensityModel ~5% -> ~89%.
* minor previous test fix (one line)
* codecov
* more codecov
* Address Koina model review feedback
- Remove unused FragmentIonMappingMode from the crosslink model hierarchy
- Guard equal annotation/mz/intensity output array lengths in ResponseToPredictions
- Label library spectra with the sequence the masses were built from
- Add offline tests for XLNMS2 and TMT validation, TMT fragmentation type, and library labeling
* Address automated review: deadlock-safe Predict, bounded HTTP, model name discovery test
- Wrap CCS/Crosslink/RetentionTime/Detectability Predict in lock + Task.Run to avoid the documented single-threaded SynchronizationContext deadlock
- Require a CancellationToken on HTTP requests and add a coarse backstop client timeout
- Add deadlock regression tests and a live ModelName-resolves-to-Koina-endpoint test
* Koina: carry neutral loss on generated library spectrum fragments
* Koina: drop unused baseId out-param from Altimeter neutral-loss parser
---------
Co-authored-by: Nic Bollis <nbollis@comcast.net>1 parent 15f2b41 commit de91a40
71 files changed
Lines changed: 8091 additions & 223 deletions
File tree
- mzLib
- PredictionClients/Koina
- AbstractClasses
- Client
- SupportedModels
- CCSModels
- CrosslinkIntensityModels
- FlyabilityModels
- FragmentIntensityModels
- RetentionTimeModels
- Test
- KoinaTests
- BenchmarkTests
- CCSModelTests
- CrosslinkIntensityPrediction
- DetectabilityPrediction
- FlyabilityPrediction
- FragmentIntensityPrediction
- RetentionTimePrediction
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 237 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
0 commit comments