Thomas 1 year ago
parent
commit
bc7592003b
3 changed files with 37 additions and 5 deletions
  1. 1 0
      Cargo.toml
  2. 12 0
      src/collection/bam.rs
  3. 24 5
      src/collection/mod.rs

+ 1 - 0
Cargo.toml

@@ -11,6 +11,7 @@ glob = "0.3.1"
 pandora_lib_pod5 = { git = "https://git.t0m4.fr/Thomas/pandora_lib_pod5.git" }
 pandora_lib_pileup = { git = "https://git.t0m4.fr/Thomas/pandora_lib_pileup.git" }
 pandora_lib_bindings = { git = "https://git.t0m4.fr/Thomas/pandora_lib_bindings.git" }
+pandora_lib_scan = { git = "https://git.t0m4.fr/Thomas/pandora_lib_scan.git" }
 regex = "1.10.5"
 chrono = { version = "0.4.38", features = ["serde"] }
 csv = "1.3.0"

+ 12 - 0
src/collection/bam.rs

@@ -7,12 +7,14 @@ use std::{
 
 use anyhow::{anyhow, Context};
 use glob::glob;
+use hashbrown::HashMap;
 use log::warn;
 use pandora_lib_bindings::{
     progs::cramino::{Cramino, CraminoRes},
     utils::RunBin,
 };
 use rayon::prelude::*;
+use tracing::warn;
 
 #[derive(Debug)]
 pub struct Bam {
@@ -140,6 +142,16 @@ impl BamCollection {
             .filter(|b| b.id == id && b.time_point == time_point)
             .collect()
     }
+
+    pub fn by_id_completed(&self) -> Vec<Bam> {
+        self.bams
+            .iter()
+            .filter(|b| matches!(b.bam_type, BamType::WGS))
+            .filter(|b| match b.cramino {
+                Some(cramino) => cramino.mean_length >= 15.0,
+                _ => false,
+            }).collect()
+    }
 }
 
 pub fn load_bam_collection(result_dir: &str) -> BamCollection {

+ 24 - 5
src/collection/mod.rs

@@ -1,4 +1,8 @@
-use std::{collections::HashMap, fmt, fs, path::Path};
+use std::{
+    collections::HashMap,
+    fmt, fs,
+    path::{Path, PathBuf},
+};
 
 use log::{info, warn};
 
@@ -41,6 +45,7 @@ impl Default for CollectionsConfig {
 }
 #[derive(Debug)]
 pub struct Collections {
+    pub result_dir: String,
     pub pod5: Pod5Collection,
     pub bam: BamCollection,
     pub vcf: VcfCollection,
@@ -58,6 +63,7 @@ impl Collections {
             bam,
             vcf,
             tasks: Vec::new(),
+            result_dir: result_dir.to_string(),
         })
     }
 
@@ -103,6 +109,22 @@ impl Collections {
         //     .into_values()
         //     .for_each(|data| tasks.push(CollectionsTasks::DemuxAlign(data)));
 
+        // Whole scan
+        for bam in self.bam.by_id_completed() {
+            let id = bam.id;
+            let scan_dir = format!("{}/{}/{}/scan", self.result_dir, bam.id, bam.time_point);
+            if PathBuf::from(scan_dir).exists() {
+                let dir_mod = fs::metadata(scan_dir)?.modified()?;
+                if bam.file_metadata.modified() > dir_mod {
+                    fs::remove_dir_all(scan_dir)?;
+                }
+            }
+
+            if !PathBuf::from(scan_dir).exists() {
+                par_whole_scan();
+            }
+        }
+
         // Remove VCF anterior to BAM
         let vcf_by_id = self.vcf.group_by_id();
         vcf_by_id.iter().for_each(|(id, vcfs)| {
@@ -209,14 +231,11 @@ impl Collections {
             }
         });
 
-
-        // 
-
+        // Tasks sorting and dedup
         let mut hs = HashMap::new();
         tasks.into_iter().for_each(|t| {
             hs.insert(t.to_string(), t);
         });
-
         self.tasks = hs.into_values().collect();
     }