Thomas 6 сар өмнө
parent
commit
052e4c59b1
1 өөрчлөгдсөн 48 нэмэгдсэн , 22 устгасан
  1. 48 22
      src/commands/dorado.rs

+ 48 - 22
src/commands/dorado.rs

@@ -447,40 +447,66 @@ impl Dorado {
     }
 
     pub fn from_flowcell(flowcell: &FlowCell, config: &Config) -> anyhow::Result<()> {
-        let pod_dir = match &flowcell.location {
-            crate::collection::flowcells::FlowCellLocation::Local(pod_dir) => pod_dir,
+        let base_pod_dir = match &flowcell.location {
+            crate::collection::flowcells::FlowCellLocation::Local(pod_dir) => None,
             crate::collection::flowcells::FlowCellLocation::Archived(pod_tar) => {
                 let file = File::open(pod_tar)
                     .map_err(|e| anyhow::anyhow!("Failed to open tar file: {pod_tar}\n\t{e}"))?;
                 let mut archive = tar::Archive::new(file);
+                info!("Un-tar of archived {pod_tar}");
                 archive
                     .unpack(&config.unarchive_tmp_dir)
                     .map_err(|e| anyhow::anyhow!("Failed to un-tar: {pod_tar}\n\t{e}"))?;
-                // find
-                ""
+                info!("Un-tar of archived {pod_tar} Done.");
+
+                Some(config.unarchive_tmp_dir.to_string())
             }
         };
 
-        // detect demuxed
-        let mut demuxed_pods = Vec::new();
-        for entry in fs::read_dir(pod_dir)? {
-            let entry = entry?;
-            let ft = entry.file_type()?;
-            if ft.is_dir() {
-                let fname = entry.file_name().into_string().unwrap();
-                if fname.contains("barcode") {
-                    if let Some(case) = flowcell.cases.iter().find_map(|c| {
-                        if c.barcode.replace("NB", "") == fname.replace("barcode", "") {
-                            Some(c.clone())
-                        } else {
-                            None
-                        }
-                    }) {
-                        demuxed_pods.push((entry.path(), case));
-                    }
+        match &flowcell.experiment {
+            crate::collection::flowcells::FlowCellExperiment::WGSPod5Mux(pod_dir) => {
+                let pod_dir = if let Some(base_pod_dir) = base_pod_dir {
+                    format!("{base_pod_dir}/{pod_dir}")
+                } else {
+                    pod_dir.clone()
+                };
+
+                let cases = flowcell
+                    .cases
+                    .iter()
+                    .map(|c| FlowCellCase {
+                        id: c.case_id.clone(),
+                        time_point: c.sample_type.clone(),
+                        barcode: c.barcode.clone(),
+                        pod_dir: pod_dir.clone().into(),
+                    })
+                    .collect();
+                info!("Starting basecaller for muxed pod5: {cases:#?}");
+
+                Dorado::from_mux(cases, config.clone())?;
+            }
+            crate::collection::flowcells::FlowCellExperiment::WGSPod5Demux(pod_dir) => {
+                let pod_dir = if let Some(base_pod_dir) = base_pod_dir {
+                    format!("{base_pod_dir}/{pod_dir}")
+                } else {
+                    pod_dir.clone()
+                };
+
+                for c in flowcell.cases.iter() {
+                    let pod_dir = format!("{pod_dir}/barcode{}", c.barcode.replace("NB", ""));
+                    info!("Starting basecaller for demuxed pod5: {pod_dir}");
+                    let mut d = Dorado::init(
+                        FlowCellCase {
+                            id: c.case_id.clone(),
+                            time_point: c.sample_type.clone(),
+                            barcode: c.barcode.clone(),
+                            pod_dir: pod_dir.into(),
+                        },
+                        config.clone(),
+                    )?;
+                    d.run_pipe()?;
                 }
             }
-            todo!();
         }
 
         Ok(())