Skip to content

Commit bb2dcd7

Browse files
committed
fix: skipped cycle handling (temporary)
1 parent 93339df commit bb2dcd7

7 files changed

Lines changed: 56 additions & 28 deletions

File tree

rust/timscentroid/src/indexing.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ use timsrust::{
1414
FramePeaks,
1515
Metadata,
1616
};
17-
use tracing::instrument;
17+
use tracing::{
18+
instrument,
19+
warn,
20+
};
1821

1922
use crate::rt_mapping::{
2023
CycleToRTMapping,
@@ -669,14 +672,29 @@ impl<T: RTIndex> IndexedPeakGroup<T> {
669672
) -> Vec<(usize, u32, u32)> {
670673
let mut out = Vec::new();
671674
let mut cycle_index = 0;
675+
let mut last_pushed_cycle = None;
672676

673677
for (i, meta) in frame_reader.frame_metas.iter().enumerate() {
674678
if matches!(meta.ms_level, timsrust::MSLevel::MS1) {
675679
cycle_index += 1;
676680
}
677681
if filter(meta) {
682+
if let Some(last_cycle) = last_pushed_cycle
683+
&& last_cycle == cycle_index
684+
{
685+
warn!(
686+
"Found multiple frames in the same cycle,
687+
skipping the non-first ones (cycle: {}, rt: {})
688+
this might point to an error when collecting the data
689+
(missing ms1 frame)
690+
",
691+
last_cycle, meta.rt_in_seconds,
692+
);
693+
continue;
694+
}
678695
let rt_ms = (meta.rt_in_seconds * 1000.0).round() as u32;
679696
out.push((i, cycle_index, rt_ms));
697+
last_pushed_cycle = Some(cycle_index);
680698
}
681699
}
682700
// TODO: check that cycle indices are continuous AND without replicates
@@ -685,11 +703,21 @@ impl<T: RTIndex> IndexedPeakGroup<T> {
685703
// Note: These are assertions instead of errors because
686704
// they are invariants I am checking, not recoverable errors, none of the logic
687705
// after this point would make sense if this is not true.
706+
//
707+
// This checks that whatever filter is used returns only a single frame within each
708+
// cycle ...
688709
assert!(
689710
w[0].1 < w[1].1,
690-
"Cycle indices should be strictly increasing"
711+
"Cycle indices should be strictly increasing, {:?} vs {:?}",
712+
w[0],
713+
w[1],
714+
);
715+
assert!(
716+
w[0].2 <= w[1].2,
717+
"Retention times should be non-decreasing, {:?} vs {:?}",
718+
w[0],
719+
w[1],
691720
);
692-
assert!(w[0].2 <= w[1].2, "Retention times should be non-decreasing");
693721
assert!(
694722
w[1].1 - w[0].1 == 1,
695723
"Cycle indices should be continuous without gaps, found gap between {} and {}",

rust/timsquery/src/models/aggregators/spectrum_agg.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,3 @@ impl Add for MzMobilityStatsCollector {
167167
}
168168
}
169169
}
170-

rust/timsquery/src/models/indexed_data.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,9 @@ impl<FH: KeyLike> QueriableData<ChromatogramCollector<FH, f32>> for IndexedPeaks
455455
}
456456
}
457457

458-
impl<FH: KeyLike> QueriableData<SpectralCollector<FH, MzMobilityStatsCollector>> for IndexedPeaksHandle {
458+
impl<FH: KeyLike> QueriableData<SpectralCollector<FH, MzMobilityStatsCollector>>
459+
for IndexedPeaksHandle
460+
{
459461
fn add_query(
460462
&self,
461463
aggregator: &mut SpectralCollector<FH, MzMobilityStatsCollector>,

rust/timsquery_viewer/src/app.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,7 @@ impl ViewerApp {
310310
for &pane in ALL_PANES {
311311
if dock_state.find_tab(&pane).is_none() {
312312
tracing::info!("Adding missing pane {:?} to saved layout", pane);
313-
dock_state
314-
.main_surface_mut()
315-
.push_to_first_leaf(pane);
313+
dock_state.main_surface_mut().push_to_first_leaf(pane);
316314
}
317315
}
318316

@@ -603,7 +601,13 @@ impl ViewerApp {
603601
return Err("Computation cancelled".to_string());
604602
}
605603

606-
Ok((output, collector, expected_intensities, selected_idx as u64, elution_group))
604+
Ok((
605+
output,
606+
collector,
607+
expected_intensities,
608+
selected_idx as u64,
609+
elution_group,
610+
))
607611
}
608612

609613
/// Check if background chromatogram computation completed
@@ -1296,10 +1300,7 @@ impl ViewerApp {
12961300
}
12971301

12981302
/// Encode an egui ColorImage as PNG and write to disk
1299-
fn save_color_image_as_png(
1300-
image: &egui::ColorImage,
1301-
path: &std::path::Path,
1302-
) -> Result<(), String> {
1303+
fn save_color_image_as_png(image: &egui::ColorImage, path: &std::path::Path) -> Result<(), String> {
13031304
let width = image.width() as u32;
13041305
let height = image.height() as u32;
13051306
let pixels: Vec<u8> = image
@@ -1442,7 +1443,7 @@ impl<'a> AppTabViewer<'a> {
14421443
let action = ConfigPanel::render_export_section(
14431444
ui,
14441445
self.screenshot_delay_secs,
1445-
&self.screenshot_state,
1446+
self.screenshot_state,
14461447
);
14471448
match action {
14481449
ScreenshotAction::None => {}

rust/timsquery_viewer/src/computed_state.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,10 @@ impl ComputedState {
544544
return false;
545545
};
546546
(
547-
result.elution_group.clone().with_rt_seconds(rt_seconds as f32),
547+
result
548+
.elution_group
549+
.clone()
550+
.with_rt_seconds(rt_seconds as f32),
548551
result.output.mobility_ook0 as f64,
549552
)
550553
};
@@ -567,9 +570,7 @@ impl ComputedState {
567570

568571
let to_range = |r: OptionallyRestricted<TupleRange<f32>>| -> (f64, f64) {
569572
match r {
570-
OptionallyRestricted::Restricted(tr) => {
571-
(tr.start() as f64, tr.end() as f64)
572-
}
573+
OptionallyRestricted::Restricted(tr) => (tr.start() as f64, tr.end() as f64),
573574
OptionallyRestricted::Unrestricted => (0.0, 2.0),
574575
}
575576
};

rust/timsquery_viewer/src/ui/panels/config_panel.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ const SECTION_SPACING: f32 = 12.0;
1313
const INTERNAL_SPACING: f32 = 8.0;
1414

1515
/// Screenshot capture lifecycle
16+
#[derive(Default)]
1617
pub enum ScreenshotState {
1718
/// Nothing happening
19+
#[default]
1820
Idle,
1921
/// Timer running, show remaining seconds overlay
2022
Countdown { deadline: Instant },
@@ -24,12 +26,6 @@ pub enum ScreenshotState {
2426
Saving(Arc<egui::ColorImage>),
2527
}
2628

27-
impl Default for ScreenshotState {
28-
fn default() -> Self {
29-
Self::Idle
30-
}
31-
}
32-
3329
/// Actions the export UI can request
3430
pub enum ScreenshotAction {
3531
None,
@@ -243,9 +239,10 @@ impl ConfigPanel {
243239
.as_secs_f32()
244240
.ceil() as u32;
245241
ui.horizontal(|ui| {
246-
ui.add_enabled(false, egui::Button::new(
247-
format!("Capturing in {}s...", remaining),
248-
));
242+
ui.add_enabled(
243+
false,
244+
egui::Button::new(format!("Capturing in {}s...", remaining)),
245+
);
249246
if ui.button("Cancel").clicked() {
250247
action = ScreenshotAction::Cancel;
251248
}

rust/timsquery_viewer/src/ui/panels/mobility_panel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct MobilityPanel;
2020

2121
impl MobilityPanel {
2222
pub fn new() -> Self {
23-
Self::default()
23+
Self
2424
}
2525

2626
pub fn title(&self) -> &str {

0 commit comments

Comments
 (0)