Browse Source

Flowcells

Thomas 8 months ago
parent
commit
e74a453c8c
1 changed files with 25 additions and 16 deletions
  1. 25 16
      src/collection/flowcells.rs

+ 25 - 16
src/collection/flowcells.rs

@@ -156,8 +156,10 @@ impl FlowCells {
 
         // Load Vec<FlowCell> from archive if present
         if Path::new(archive_store_path).exists() {
-            let file = File::open(archive_store_path)?;
-            let archived: Vec<FlowCell> = serde_json::from_reader(BufReader::new(file))?;
+            let file = File::open(archive_store_path)
+                .with_context(|| format!("Failed to open File: {archive_store_path}"))?;
+            let archived: Vec<FlowCell> = serde_json::from_reader(BufReader::new(file))
+                .with_context(|| format!("Failed to parse FlowCells from: {archive_store_path}"))?;
 
             for fc in archived {
                 merged_map.insert(fc.sample_sheet.flow_cell_id.clone(), fc);
@@ -176,14 +178,16 @@ impl FlowCells {
 
             let dir_str = dir.to_string_lossy().to_string();
 
-            let (sample_sheet, pore_activity, throughput, files) = scan_local(&dir_str)?;
+            let (sample_sheet, pore_activity, throughput, files) = scan_local(&dir_str)
+                .with_context(|| format!("Failed to scan local run dir: {dir_str}"))?;
             let fc = FlowCell::new(
                 sample_sheet,
                 pore_activity,
                 throughput,
-                FlowCellLocation::Local(dir_str),
+                FlowCellLocation::Local(dir_str.clone()),
                 files,
-            )?;
+            )
+            .with_context(|| format!("Failed to load FlowCell from dir: {dir_str}"))?;
 
             // Dedup by flowcell_id, retain most recently modified
             merged_map
@@ -197,14 +201,19 @@ impl FlowCells {
         }
 
         // Load IdsInput and annotate flowcells
-        let inputs = IdsInput::load_json(inputs_path)?;
-        for fc in merged_map.values_mut() {
-            fc.cases = inputs
-                .data
-                .iter()
-                .filter(|info| info.flow_cell_id == fc.sample_sheet.flow_cell_id)
-                .cloned()
-                .collect();
+        if Path::new(inputs_path).exists() {
+            let inputs = IdsInput::load_json(inputs_path)
+                .with_context(|| format!("Failed to load json from: {inputs_path}"))?;
+            for fc in merged_map.values_mut() {
+                fc.cases = inputs
+                    .data
+                    .iter()
+                    .filter(|info| info.flow_cell_id == fc.sample_sheet.flow_cell_id)
+                    .cloned()
+                    .collect();
+            }
+        } else {
+            warn!("No inputs json...");
         }
 
         Ok(Self {
@@ -369,7 +378,7 @@ impl fmt::Display for FlowCellLocation {
 }
 
 impl FlowCell {
-    /// Constructs a new `FlowCel` from a sample sheet and associated file list.
+    /// Constructs a new `FlowCell` from a sample sheet and associated file list.
     ///
     /// This method aggregates information from a parsed `MinKnowSampleSheet` and the
     /// corresponding `.pod5` file metadata, and infers the experiment type from
@@ -384,7 +393,7 @@ impl FlowCell {
     ///   - `DateTime<Utc>`: modification time
     ///
     /// # Returns
-    /// - `Ok(FlowCel)` if experiment type and file metadata are successfully resolved.
+    /// - `Ok(FlowCell)` if experiment type and file metadata are successfully resolved.
     /// - `Err` if the experiment type cannot be determined.
     ///
     /// # Errors
@@ -392,7 +401,7 @@ impl FlowCell {
     ///
     /// # Example
     /// ```
-    /// let fc = FlowCel::new(sample_sheet, FlowCellLocation::Local(dir), files)?;
+    /// let fc = FlowCell::new(sample_sheet, FlowCellLocation::Local(dir), files)?;
     /// println!("Flowcell ID: {}", fc.flowcell_id);
     /// ```
     pub fn new(