Skip to main content

IntensityMatrix

Struct IntensityMatrix 

Source
pub struct IntensityMatrix {
Show 19 fields pub search_guidance: Option<SearchGuidance>, pub consensus: Vec<ConsensusFeature>, pub n_features: usize, pub n_runs: usize, pub run_names: Vec<String>, pub reference_run: String, pub feature_mz: Vec<f64>, pub feature_mass: Vec<f64>, pub feature_charge: Vec<u8>, pub feature_rt: Vec<f64>, pub feature_im: Vec<f64>, pub feature_combined_score: Vec<f64>, pub feature_seed_run: Vec<String>, pub feature_n_contributing_runs: Vec<usize>, pub hills_per_run: Vec<usize>, pub intensities: Vec<f64>, pub q_values: Vec<f64>, pub decoy_intensities: Vec<f64>, pub entries: Vec<LfqEntry>,
}
Expand description

Final intensity matrix: features (rows) × runs (columns).

Fields§

§search_guidance: Option<SearchGuidance>

Peptide identities and donor evidence, present only in search-guided mode.

§consensus: Vec<ConsensusFeature>

Original consensus membership retained for long-format evidence export.

§n_features: usize§n_runs: usize§run_names: Vec<String>§reference_run: String§feature_mz: Vec<f64>§feature_mass: Vec<f64>§feature_charge: Vec<u8>§feature_rt: Vec<f64>§feature_im: Vec<f64>§feature_combined_score: Vec<f64>

Seed feature’s combined_score (isotope × chromato cosine) per consensus row.

§feature_seed_run: Vec<String>

Name of the run that provided the seed feature for each consensus row.

§feature_n_contributing_runs: Vec<usize>

Number of runs that contributed at least one detection to each consensus group.

§hills_per_run: Vec<usize>

Hill count per run (recorded as each run’s hills were streamed in).

§intensities: Vec<f64>§q_values: Vec<f64>§decoy_intensities: Vec<f64>

Decoy intensities, same flat layout as intensities. All zeros when run_tdc = false.

§entries: Vec<LfqEntry>

Full per-(feature, run) target + decoy entries with detail stats. Empty when run_tdc = false and details are not requested.

Implementations§

Source§

impl IntensityMatrix

Source

pub fn intensity(&self, feat: usize, run: usize) -> f64

Examples found in repository?
examples/support/lfq_matrices.rs (line 52)
4pub fn matrices(m: &IntensityMatrix, folder: &Path) -> anyhow::Result<()> {
5    let meta = [
6        "massCalib",
7        "mz",
8        "charge",
9        "rtApex",
10        "im",
11        "combined_score",
12        "seed_run",
13        "n_contributing_runs",
14    ];
15    for (kind, name) in [
16        "consensus_features.tsv",
17        "intensity_matrix.tsv",
18        "qvalue_matrix.tsv",
19        "decoy_intensity_matrix.tsv",
20    ]
21    .iter()
22    .enumerate()
23    {
24        let mut out = csv::WriterBuilder::new()
25            .delimiter(b'\t')
26            .from_path(folder.join(name))?;
27        let mut header: Vec<String> = meta.iter().map(|s| s.to_string()).collect();
28        if kind == 0 {
29            header.extend(["n_runs_detected", "group_score", "group_qvalue"].map(String::from));
30        } else {
31            header.extend(m.run_names.clone());
32        }
33        out.write_record(header)?;
34        for (i, g) in m.consensus.iter().enumerate() {
35            let mut row = vec![
36                format!("{:.6}", g.neutral_mass),
37                format!("{:.6}", g.ref_mz),
38                g.charge.to_string(),
39                format!("{:.6}", g.ref_rt),
40                if g.ref_im == 0.0 {
41                    String::new()
42                } else {
43                    format!("{:.6}", g.ref_im)
44                },
45                format!("{:.6}", g.seed_combined_score),
46                m.run_names[g.seed_run_idx].clone(),
47                g.n_contributing_runs.to_string(),
48            ];
49            if kind == 0 {
50                row.extend([
51                    (0..m.n_runs)
52                        .filter(|&r| m.intensity(i, r) > 0.0)
53                        .count()
54                        .to_string(),
55                    format!("{:.6}", g.group_score),
56                    format!("{:.6}", g.group_qvalue),
57                ]);
58            } else {
59                for r in 0..m.n_runs {
60                    let v = match kind {
61                        1 => m.intensity(i, r),
62                        2 => m.q_value(i, r),
63                        _ => m.decoy_intensity(i, r),
64                    };
65                    row.push(if kind == 2 {
66                        format!("{v:.4}")
67                    } else if v > 0.0 {
68                        format!("{v:.5e}")
69                    } else {
70                        "0".into()
71                    });
72                }
73            }
74            out.write_record(row)?;
75        }
76        out.flush()?;
77    }
78    let mut audit = csv::WriterBuilder::new()
79        .delimiter(b'\t')
80        .from_path(folder.join("ownership.tsv"))?;
81    audit.write_record([
82        "feature_idx",
83        "run_idx",
84        "is_decoy",
85        "intensity",
86        "ownership_status",
87        "owned_samples",
88        "excluded_samples",
89        "competing_feature",
90        "apex_rt",
91        "bhattacharyya",
92        "coelution",
93        "preceding_signal_fraction",
94    ])?;
95    for e in &m.entries {
96        audit.write_record([
97            e.feature_idx.to_string(),
98            e.run_idx.to_string(),
99            e.is_decoy.to_string(),
100            e.intensity.to_string(),
101            e.ownership_status.to_string(),
102            e.owned_samples.to_string(),
103            e.excluded_samples.to_string(),
104            e.competing_feature
105                .map(|i| i.to_string())
106                .unwrap_or_default(),
107            e.apex_rt.to_string(),
108            e.spectral_bhattacharyya.to_string(),
109            e.coelution.to_string(),
110            e.preceding_signal_fraction.to_string(),
111        ])?;
112    }
113    audit.flush()?;
114    Ok(())
115}
Source

pub fn q_value(&self, feat: usize, run: usize) -> f64

Examples found in repository?
examples/support/lfq_matrices.rs (line 62)
4pub fn matrices(m: &IntensityMatrix, folder: &Path) -> anyhow::Result<()> {
5    let meta = [
6        "massCalib",
7        "mz",
8        "charge",
9        "rtApex",
10        "im",
11        "combined_score",
12        "seed_run",
13        "n_contributing_runs",
14    ];
15    for (kind, name) in [
16        "consensus_features.tsv",
17        "intensity_matrix.tsv",
18        "qvalue_matrix.tsv",
19        "decoy_intensity_matrix.tsv",
20    ]
21    .iter()
22    .enumerate()
23    {
24        let mut out = csv::WriterBuilder::new()
25            .delimiter(b'\t')
26            .from_path(folder.join(name))?;
27        let mut header: Vec<String> = meta.iter().map(|s| s.to_string()).collect();
28        if kind == 0 {
29            header.extend(["n_runs_detected", "group_score", "group_qvalue"].map(String::from));
30        } else {
31            header.extend(m.run_names.clone());
32        }
33        out.write_record(header)?;
34        for (i, g) in m.consensus.iter().enumerate() {
35            let mut row = vec![
36                format!("{:.6}", g.neutral_mass),
37                format!("{:.6}", g.ref_mz),
38                g.charge.to_string(),
39                format!("{:.6}", g.ref_rt),
40                if g.ref_im == 0.0 {
41                    String::new()
42                } else {
43                    format!("{:.6}", g.ref_im)
44                },
45                format!("{:.6}", g.seed_combined_score),
46                m.run_names[g.seed_run_idx].clone(),
47                g.n_contributing_runs.to_string(),
48            ];
49            if kind == 0 {
50                row.extend([
51                    (0..m.n_runs)
52                        .filter(|&r| m.intensity(i, r) > 0.0)
53                        .count()
54                        .to_string(),
55                    format!("{:.6}", g.group_score),
56                    format!("{:.6}", g.group_qvalue),
57                ]);
58            } else {
59                for r in 0..m.n_runs {
60                    let v = match kind {
61                        1 => m.intensity(i, r),
62                        2 => m.q_value(i, r),
63                        _ => m.decoy_intensity(i, r),
64                    };
65                    row.push(if kind == 2 {
66                        format!("{v:.4}")
67                    } else if v > 0.0 {
68                        format!("{v:.5e}")
69                    } else {
70                        "0".into()
71                    });
72                }
73            }
74            out.write_record(row)?;
75        }
76        out.flush()?;
77    }
78    let mut audit = csv::WriterBuilder::new()
79        .delimiter(b'\t')
80        .from_path(folder.join("ownership.tsv"))?;
81    audit.write_record([
82        "feature_idx",
83        "run_idx",
84        "is_decoy",
85        "intensity",
86        "ownership_status",
87        "owned_samples",
88        "excluded_samples",
89        "competing_feature",
90        "apex_rt",
91        "bhattacharyya",
92        "coelution",
93        "preceding_signal_fraction",
94    ])?;
95    for e in &m.entries {
96        audit.write_record([
97            e.feature_idx.to_string(),
98            e.run_idx.to_string(),
99            e.is_decoy.to_string(),
100            e.intensity.to_string(),
101            e.ownership_status.to_string(),
102            e.owned_samples.to_string(),
103            e.excluded_samples.to_string(),
104            e.competing_feature
105                .map(|i| i.to_string())
106                .unwrap_or_default(),
107            e.apex_rt.to_string(),
108            e.spectral_bhattacharyya.to_string(),
109            e.coelution.to_string(),
110            e.preceding_signal_fraction.to_string(),
111        ])?;
112    }
113    audit.flush()?;
114    Ok(())
115}
Source

pub fn decoy_intensity(&self, feat: usize, run: usize) -> f64

Examples found in repository?
examples/support/lfq_matrices.rs (line 63)
4pub fn matrices(m: &IntensityMatrix, folder: &Path) -> anyhow::Result<()> {
5    let meta = [
6        "massCalib",
7        "mz",
8        "charge",
9        "rtApex",
10        "im",
11        "combined_score",
12        "seed_run",
13        "n_contributing_runs",
14    ];
15    for (kind, name) in [
16        "consensus_features.tsv",
17        "intensity_matrix.tsv",
18        "qvalue_matrix.tsv",
19        "decoy_intensity_matrix.tsv",
20    ]
21    .iter()
22    .enumerate()
23    {
24        let mut out = csv::WriterBuilder::new()
25            .delimiter(b'\t')
26            .from_path(folder.join(name))?;
27        let mut header: Vec<String> = meta.iter().map(|s| s.to_string()).collect();
28        if kind == 0 {
29            header.extend(["n_runs_detected", "group_score", "group_qvalue"].map(String::from));
30        } else {
31            header.extend(m.run_names.clone());
32        }
33        out.write_record(header)?;
34        for (i, g) in m.consensus.iter().enumerate() {
35            let mut row = vec![
36                format!("{:.6}", g.neutral_mass),
37                format!("{:.6}", g.ref_mz),
38                g.charge.to_string(),
39                format!("{:.6}", g.ref_rt),
40                if g.ref_im == 0.0 {
41                    String::new()
42                } else {
43                    format!("{:.6}", g.ref_im)
44                },
45                format!("{:.6}", g.seed_combined_score),
46                m.run_names[g.seed_run_idx].clone(),
47                g.n_contributing_runs.to_string(),
48            ];
49            if kind == 0 {
50                row.extend([
51                    (0..m.n_runs)
52                        .filter(|&r| m.intensity(i, r) > 0.0)
53                        .count()
54                        .to_string(),
55                    format!("{:.6}", g.group_score),
56                    format!("{:.6}", g.group_qvalue),
57                ]);
58            } else {
59                for r in 0..m.n_runs {
60                    let v = match kind {
61                        1 => m.intensity(i, r),
62                        2 => m.q_value(i, r),
63                        _ => m.decoy_intensity(i, r),
64                    };
65                    row.push(if kind == 2 {
66                        format!("{v:.4}")
67                    } else if v > 0.0 {
68                        format!("{v:.5e}")
69                    } else {
70                        "0".into()
71                    });
72                }
73            }
74            out.write_record(row)?;
75        }
76        out.flush()?;
77    }
78    let mut audit = csv::WriterBuilder::new()
79        .delimiter(b'\t')
80        .from_path(folder.join("ownership.tsv"))?;
81    audit.write_record([
82        "feature_idx",
83        "run_idx",
84        "is_decoy",
85        "intensity",
86        "ownership_status",
87        "owned_samples",
88        "excluded_samples",
89        "competing_feature",
90        "apex_rt",
91        "bhattacharyya",
92        "coelution",
93        "preceding_signal_fraction",
94    ])?;
95    for e in &m.entries {
96        audit.write_record([
97            e.feature_idx.to_string(),
98            e.run_idx.to_string(),
99            e.is_decoy.to_string(),
100            e.intensity.to_string(),
101            e.ownership_status.to_string(),
102            e.owned_samples.to_string(),
103            e.excluded_samples.to_string(),
104            e.competing_feature
105                .map(|i| i.to_string())
106                .unwrap_or_default(),
107            e.apex_rt.to_string(),
108            e.spectral_bhattacharyya.to_string(),
109            e.coelution.to_string(),
110            e.preceding_signal_fraction.to_string(),
111        ])?;
112    }
113    audit.flush()?;
114    Ok(())
115}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more