Skip to main content

Crate koth_core

Crate koth_core 

Source
Expand description

koth-core: the in-memory LC-MS feature detection stages of koth.

This crate reads and writes no files and has no native dependencies. A caller brings its own spectra (for example from its own mzML, Thermo or Bruker reader) as Spectrum values and runs:

  1. Hill detection – groups MS1 peaks across scans into chromatographic hills
  2. Feature finding – groups hills into isotope envelopes with charge state assignment
  3. Scoring – scores isotope pattern quality using the averagine model

either stage by stage (run_hills, run_features, run_scoring) or in one call (run_pipeline_from_spectra, or the streaming run_pipeline_streaming_from_spectra with a PipelineSink).

The koth-ms crate (the koth_ff and koth_align executables) adds the file readers and writers and cross-run LFQ, and runs exactly these stages; it re-exports this crate’s modules at their original koth_ms:: paths.

§Example

use koth_core::{run_pipeline_from_spectra, KothConfig, Peak, PipelineOptions, Spectrum};

let spectra: Vec<Spectrum> = (0..20)
    .map(|i| Spectrum {
        scan_index: i,
        retention_time: i as f64 * 0.05,
        peaks: vec![Peak { mz: 500.0, intensity: 1.0e5, ion_mobility: 0.0 }],
        ms_level: 1,
        isolation_window: None,
        faims_cv: None,
    })
    .collect();

let out = run_pipeline_from_spectra(
    spectra.into_iter(),
    &KothConfig::default(),
    &PipelineOptions::default(),
)?;
println!("{} hills, {} features", out.hills.len(), out.features.len());

Re-exports§

pub use config::KothConfig;
pub use error::Error;
pub use error::Result;
pub use models::Feature;
pub use models::Hill;
pub use models::IsolationWindow;
pub use models::Peak;
pub use models::Polarity;
pub use models::ScoredFeature;
pub use models::Spectrum;
pub use pipeline::group_ms2_hills_by_window;
pub use pipeline::run_pipeline_from_hills;
pub use pipeline::run_pipeline_from_spectra;
pub use pipeline::run_pipeline_streaming_from_spectra;
pub use pipeline::FeatureFindingOutput;
pub use pipeline::PipelineOptions;
pub use pipeline::PipelineSink;

Modules§

config
error
The error type of the in-memory stages and the detection configuration.
features
hills
mem
models
pipeline
In-process / streaming feature-finding API over in-memory spectra.
scoring
stats
Small shared numeric helpers.

Functions§

run_features
Stage 2: Detect isotope features from hills.
run_hills
Stage 1: Detect chromatographic hills from MS1 spectra.
run_scoring
Stage 3: Score isotope features using the averagine model.
shuffle_if_decoy
Apply the decoy construction to a full spectrum set: when file.decoy_mode is set, shuffle the entire set (Fisher–Yates over rand::thread_rng) before hill detection; otherwise return it untouched.