Browse Source

up alt cat

Thomas 9 months ago
parent
commit
8ff2dc0b66

+ 8 - 19
src/callers/clairs.rs

@@ -191,19 +191,15 @@ impl Variants for ClairS {
     fn variants(&self, annotations: &Annotations) -> anyhow::Result<VariantCollection> {
         let caller = self.caller_cat();
         let add = vec![caller.clone()];
-        info!(
-            "Loading variants from {}: {}",
-            caller, self.vcf_passed
-        );
-        let variants = read_vcf(&self.vcf_passed)?;
+        info!("Loading variants from {}: {}", caller, self.vcf_passed);
+        let variants = read_vcf(&self.vcf_passed).map_err(|e| {
+            anyhow::anyhow!("Failed to read ClairS VCF {}.\n{e}", self.vcf_passed)
+        })?;
+
         variants.par_iter().for_each(|v| {
             annotations.insert_update(v.hash(), &add);
         });
-        info!(
-            "{}, {} variants loaded.",
-            caller,
-            variants.len()
-        );
+        info!("{}, {} variants loaded.", caller, variants.len());
 
         Ok(VariantCollection {
             variants,
@@ -217,20 +213,13 @@ impl ClairS {
     pub fn germline(&self, annotations: &Annotations) -> anyhow::Result<VariantCollection> {
         let caller = Annotation::Callers(Caller::ClairS, Sample::Germline);
         let add = vec![caller.clone()];
-        info!(
-            "Loading variants from {}: {}",
-            caller, self.vcf_passed
-        );
+        info!("Loading variants from {}: {}", caller, self.vcf_passed);
 
         let variants = read_vcf(&self.clair3_germline_passed)?;
         variants.par_iter().for_each(|v| {
             annotations.insert_update(v.hash(), &add);
         });
-        info!(
-            "{}, {} variants loaded.",
-            caller,
-            variants.len()
-        );
+        info!("{}, {} variants loaded.", caller, variants.len());
 
         Ok(VariantCollection {
             variants,

+ 3 - 1
src/callers/deep_somatic.rs

@@ -147,7 +147,9 @@ impl Variants for DeepSomatic {
         let caller = self.caller_cat();
         let add = vec![caller.clone()];
         info!("Loading variants from {}: {}", caller, self.vcf_passed);
-        let variants = read_vcf(&self.vcf_passed)?;
+        let variants = read_vcf(&self.vcf_passed).map_err(|e| {
+            anyhow::anyhow!("Failed to read DeepSomatic VCF {}.\n{e}", self.vcf_passed)
+        })?;
         variants.par_iter().for_each(|v| {
             annotations.insert_update(v.hash(), &add);
         });

+ 1 - 1
src/callers/deep_variant.rs

@@ -146,7 +146,7 @@ impl Variants for DeepVariant {
         let caller = self.caller_cat();
         info!("Loading variants from {}: {}", caller, self.vcf_passed);
         let variants = read_vcf(&self.vcf_passed)
-            .map_err(|e| anyhow::anyhow!("Error while reading VFC {}.\n{e}", self.vcf_passed))?;
+            .map_err(|e| anyhow::anyhow!("Failed to read DeepVariant VCF {}.\n{e}", self.vcf_passed))?;
         variants.par_iter().for_each(|v| {
             annotations.insert_update(v.hash(), &[caller.clone()]);
         });

+ 4 - 2
src/callers/nanomonsv.rs

@@ -37,7 +37,7 @@ impl Initialize for NanomonSV {
     fn initialize(id: &str, config: Config) -> anyhow::Result<Self> {
         let id = id.to_string();
         info!("Initialize Nanomonsv for {id}.");
-        let log_dir = format!("{}/{}/log/clairs", config.result_dir, &id);
+        let log_dir = format!("{}/{}/log/nanomonsv", config.result_dir, &id);
 
         if !Path::new(&log_dir).exists() {
             fs::create_dir_all(&log_dir)
@@ -128,7 +128,9 @@ impl Variants for NanomonSV {
         let add = vec![caller.clone()];
         info!("Loading variants from {}: {}", caller, self.vcf_passed);
 
-        let variants = read_vcf(&self.vcf_passed)?;
+        let variants = read_vcf(&self.vcf_passed).map_err(|e| {
+            anyhow::anyhow!("Failed to read NanomonSV VCF {}.\n{e}", self.vcf_passed)
+        })?;
 
         variants.par_iter().for_each(|v| {
             annotations.insert_update(v.hash(), &add);

+ 7 - 4
src/callers/savana.rs

@@ -40,6 +40,7 @@ impl Initialize for Savana {
         }
 
         // Check for phased germline vcf
+        // no required anymore since >= 1.3.0
         let phased_germline_vcf = config.constit_phased_vcf(id);
         if !Path::new(&phased_germline_vcf).exists() {
             LongphasePhase::initialize(id, config.clone())?.run()?;
@@ -105,7 +106,7 @@ impl Run for Savana {
                 &self.config.savana_output_dir(id),
                 "--ref",
                 &self.config.reference,
-                "--phased_vcf",
+                "--snp_vcf",
                 &self.phased_germline_vcf,
                 "--no_blacklist",
                 "--threads",
@@ -197,7 +198,8 @@ impl Variants for Savana {
         let caller = self.caller_cat();
         let add = vec![caller.clone()];
         info!("Loading variants from {}: {}", caller, self.passed_vcf);
-        let variants = read_vcf(&self.passed_vcf)?;
+        let variants = read_vcf(&self.passed_vcf)
+            .map_err(|e| anyhow::anyhow!("Failed to read Savana VCF {}.\n{e}", self.passed_vcf))?;
         variants.par_iter().for_each(|v| {
             annotations.insert_update(v.hash(), &add);
         });
@@ -415,8 +417,9 @@ impl SavanaReadCounts {
                     .map(|c| c.tumour_read_count as usize)
                     .sum::<usize>();
 
-                let r = chr_counts as f64 / (( chr_n_bins as f64 * n_tum as f64) / n_bins as f64);
+                let r = chr_counts as f64 / ((chr_n_bins as f64 * n_tum as f64) / n_bins as f64);
                 (num_to_contig(contig_num), r)
-            }).collect()
+            })
+            .collect()
     }
 }

+ 3 - 1
src/callers/severus.rs

@@ -164,7 +164,9 @@ impl Variants for Severus {
             caller, vcf_passed
         );
 
-        let variants = read_vcf(&vcf_passed)?;
+        let variants = read_vcf(&vcf_passed).map_err(|e| {
+            anyhow::anyhow!("Failed to read Severus VCF {}.\n{e}", vcf_passed)
+        })?;
 
         variants.par_iter().for_each(|v| {
             annotations.insert_update(v.hash(), &add);

+ 5 - 3
src/config.rs

@@ -130,7 +130,7 @@ impl Default for Config {
             clairs_force: false,
 
             // Savana
-            savana_bin: "savana".to_string(),
+            savana_bin: "/home/prom/.local/bin/savana".to_string(),
             savana_threads: 150,
             savana_output_dir: "{result_dir}/{id}/diag/savana".to_string(),
             savana_passed_vcf: "{output_dir}/{id}_diag_savana_PASSED.vcf.gz".to_string(),
@@ -160,8 +160,10 @@ impl Default for Config {
             modkit_summary_file: "{result_dir}/{id}/{time}/{id}_{time}_5mC_5hmC_summary.txt"
                 .to_string(),
 
-            // Nanomonsv
-            nanomonsv_bin: "nanomonsv".to_string(),
+            /// Nanomonsv
+            /// tabix, bgzip, mafft in PATH
+            /// pip install pysam, parasail;  pip install nanomonsv
+            nanomonsv_bin: "/home/prom/.local/bin/nanomonsv".to_string(),
             nanomonsv_output_dir: "{result_dir}/{id}/{time}/nanomonsv".to_string(),
             nanomonsv_threads: 150,
             nanomonsv_force: false,

+ 1 - 1
src/lib.rs

@@ -677,7 +677,7 @@ mod tests {
     #[test]
     fn run_somatic_case() -> anyhow::Result<()> {
         init();
-        let id = "ADJAGBA";
+        let id = "COIFFET";
         let mut config = Config::default();
         config.somatic_pipe_force = true;
         match Somatic::initialize(id, config)?.run() {

+ 4 - 3
src/pipes/somatic.rs

@@ -507,6 +507,9 @@ impl Run for Somatic {
         let vep_stats = annotations.vep_stats()?;
         vep_stats.save_to_json(&format!("{stats_dir}/{id}_annotations_10_vep.json"))?;
 
+        VariantsStats::new(&variants)
+            .save_to_json(&format!("{stats_dir}/{id}_variants_stats_final.json"))?;
+
         info!("Final unique variants: {}", variants.data.len());
         variants.save_to_json(&result_json)?;
 
@@ -514,12 +517,10 @@ impl Run for Somatic {
     }
 }
 
-
 pub fn const_stats(id: String, config: Config) -> anyhow::Result<()> {
     info!("Loading Germline");
     let annotations = Annotations::default();
-        let clairs_germline =
-            ClairS::initialize(&id, config)?.germline(&annotations)?;
+    let clairs_germline = ClairS::initialize(&id, config)?.germline(&annotations)?;
 
     info!("Annotation with Cosmic and GnomAD.");
     let ext_annot = ExternalAnnotation::init()?;

+ 13 - 5
src/variant/variant.rs

@@ -6,6 +6,7 @@ use crate::{
     variant::variant_collection::VariantCollection,
 };
 use anyhow::{anyhow, Context};
+use log::warn;
 use rayon::prelude::*;
 use serde::{Deserialize, Serialize};
 use std::{cmp::Ordering, collections::HashSet, fmt, hash::Hash, str::FromStr};
@@ -251,12 +252,12 @@ impl VcfVariant {
                         if bnd_desc.a_contig != bnd_desc.b_contig {
                             AlterationCategory::TRL
                         } else {
-                            AlterationCategory::DEL
+                            AlterationCategory::BND
                         }
                     } else {
-                        AlterationCategory::from(sv_type) 
+                        AlterationCategory::from(sv_type)
                     }
-                },
+                }
                 None => AlterationCategory::Other,
             },
         }
@@ -1033,9 +1034,16 @@ pub fn load_variants(
 ) -> anyhow::Result<Vec<VariantCollection>> {
     iterable
         .par_iter()
-        .map(|runner| runner.variants(annotations))
+        .map(|runner| {
+            let r = runner.variants(annotations);
+            if let Err(ref e) = r {
+                warn!("{e}");
+            };
+            r
+        })
+        .filter(|r| r.is_ok())
         .collect::<anyhow::Result<Vec<_>>>()
-        .map_err(|e| anyhow::anyhow!("Error while running load_variants.\n{e}"))
+        .map_err(|e| anyhow::anyhow!("Failed to load variants.\n{e}"))
 }
 
 pub fn parallel_intersection<T: Hash + Eq + Clone + Send + Sync>(