Browse Source

deletions_len

Thomas 8 months ago
parent
commit
8448c00e0d
4 changed files with 50 additions and 2 deletions
  1. 1 1
      src/annotation/mod.rs
  2. 1 1
      src/lib.rs
  3. 37 0
      src/variant/variant_collection.rs
  4. 11 0
      src/variant/variants_stats.rs

+ 1 - 1
src/annotation/mod.rs

@@ -210,7 +210,7 @@ impl fmt::Display for Annotation {
                 ReplicationClass::Early => "ReplicationEarly".into(),
                 ReplicationClass::Late => "ReplicationLate".into(),
             },
-            Annotation::HighDepth => "HighDepths".into(),
+            Annotation::HighDepth => "HighDepth".into(),
             Annotation::Panel(name) => format!("Panel_{name}"),
         };
         write!(f, "{}", s)

+ 1 - 1
src/lib.rs

@@ -681,7 +681,7 @@ mod tests {
         //     }
         // }
         // Ok(())
-        let id = "ACHITE";
+        let id = "CHAMPION";
         SomaticPipe::initialize(id, Config::default())?.run()
     }
 

+ 37 - 0
src/variant/variant_collection.rs

@@ -505,6 +505,9 @@ impl Variant {
     /// }
     /// ```
     pub fn insertion_length(&self) -> Option<u32> {
+        if !self.alteration_category().contains(&AlterationCategory::INS) {
+            return None;
+        }
         self.vcf_variants
             .iter()
             .filter_map(|v| {
@@ -514,6 +517,8 @@ impl Variant {
                     .find_map(|i| {
                         if let Info::SVINSLEN(len) = i {
                             Some(*len)
+                        } else if let Info::SVLEN(len) = i {
+                            Some(*len as u32)
                         } else {
                             None
                         }
@@ -533,6 +538,38 @@ impl Variant {
             .max()
     }
 
+     pub fn deletion_length(&self) -> Option<u32> {
+        if !self.alteration_category().contains(&AlterationCategory::DEL) {
+            return None;
+        }
+        self.vcf_variants
+            .iter()
+            .filter_map(|v| {
+                v.infos
+                    .0
+                    .iter()
+                    .find_map(|i| {
+                        if let Info::SVLEN(len) = i {
+                            Some(*len as u32)
+                        } else {
+                            None
+                        }
+                    })
+                    .or_else(|| {
+                        if let (
+                            ReferenceAlternative::Nucleotides(nt),
+                            ReferenceAlternative::Nucleotide(_),
+                        ) = (&v.reference, &self.alternative)
+                        {
+                            Some(nt.len().saturating_sub(1) as u32)
+                        } else {
+                            None
+                        }
+                    })
+            })
+            .max()
+    }
+
     pub fn n_alt_depth(&self) -> (f64, f64) {
         let (n_alts, depths): (Vec<u32>, Vec<u32>) = self
             .vcf_variants

+ 11 - 0
src/variant/variants_stats.rs

@@ -59,6 +59,10 @@ pub struct VariantsStats {
 
     #[serde(serialize_with = "serialize_dashmap_sort")]
     pub insertions_len: DashMap<u32, u32>,
+
+    #[serde(serialize_with = "serialize_dashmap_sort")]
+    pub deletions_len: DashMap<u32, u32>,
+
 }
 
 pub fn serialize_dashmap_sort<S, T>(
@@ -92,6 +96,7 @@ impl VariantsStats {
         let gnomads: DashMap<String, Vec<f64>> = DashMap::new();
         let context: DashMap<String, Vec<String>> = DashMap::new();
         let insertions_len: DashMap<u32, u32> = DashMap::new();
+        let deletions_len: DashMap<u32, u32> = DashMap::new();
 
         variants.data.par_iter().for_each(|v| {
             // VEP
@@ -164,6 +169,11 @@ impl VariantsStats {
             if let Some(len) = v.insertion_length() {
                 *insertions_len.entry(len).or_default() += 1;
             }
+
+            if let Some(len) = v.deletion_length() {
+                *deletions_len.entry(len).or_default() += 1;
+            }
+
         });
 
         let mut n_gnomad = 0;
@@ -362,6 +372,7 @@ impl VariantsStats {
             high_depth_somatic_rates: high_depth,
             mutation_rates,
             insertions_len,
+            deletions_len,
         })
     }