소스 검색

category iter

Thomas 1 년 전
부모
커밋
6437dac5e1
1개의 변경된 파일29개의 추가작업 그리고 44개의 파일을 삭제
  1. 29 44
      src/variants.rs

+ 29 - 44
src/variants.rs

@@ -12,6 +12,7 @@ use crate::{
         nanomonsv::{NanomonsvFormat, NanomonsvInfo},
         sniffles::{SnifflesFormat, SnifflesInfo},
     },
+    config::Config,
     in_out::{
         dict_reader::read_dict,
         get_reader,
@@ -23,9 +24,8 @@ use crate::{
         chi_square_test_for_proportions, estimate_shannon_entropy, get_hts_nt_pileup, new_pg,
         new_pg_speed, print_stat_cat,
     },
-    config::Config,
 };
-use anyhow::{anyhow, Context, Ok, Result, Error};
+use anyhow::{anyhow, Context, Error, Ok, Result};
 use csv::ReaderBuilder;
 use dashmap::DashMap;
 use hashbrown::HashMap;
@@ -109,7 +109,15 @@ impl fmt::Display for StatsBAM {
 
 impl Variants {
     pub fn from_vec(name: String, mp: &MultiProgress, data: Vec<Variant>) -> Self {
-        Self { name, data, constit: DashMap::new(), stats_vcf: StatsVCF::default(), stats_bam: StatsBAM::default(), cfg: Config::get().unwrap(), mp: mp.clone() }
+        Self {
+            name,
+            data,
+            constit: DashMap::new(),
+            stats_vcf: StatsVCF::default(),
+            stats_bam: StatsBAM::default(),
+            cfg: Config::get().unwrap(),
+            mp: mp.clone(),
+        }
     }
     pub fn from_vcfs(
         name: String,
@@ -519,7 +527,6 @@ impl Variants {
                 e.callers_data.iter().for_each(|cd| {
                     v.callers_data.push(cd.clone());
                     v.callers_data.dedup();
-                    
                 });
                 v.source.extend(e.source.clone());
                 v.source.dedup();
@@ -631,6 +638,23 @@ impl Variants {
             });
         Ok(())
     }
+
+    pub fn category_iter(&self, category: &VariantCategory) -> Vec<&Variant> {
+        self.data.par_iter().filter(|v| {
+            for annotation in v.annotations.iter() {
+                match annotation {
+                    AnnotationType::VariantCategory(cat) => {
+                        if cat == category {
+                            return true;
+                        }
+                    }
+                    _ => (),
+                }
+            }
+            return false;
+        }).collect::<Vec<&Variant>>()
+    }
+
     pub fn filter_snp(&mut self) -> Result<i32> {
         let n_snp = AtomicI32::new(0);
         self.data = self
@@ -866,6 +890,7 @@ impl CallerData {
             Format::Nanomonsv(v) => v.tr - v.vr,
         }
     }
+
     /// Variants filter rules
     pub fn should_filter(&self) -> bool {
         if let Info::Sniffles(info) = &self.info {
@@ -954,21 +979,6 @@ impl Variant {
         })
     }
 
-    // fn get_vaf(&mut self) -> f32 {
-    //     if let Some(vaf) = self.vaf {
-    //         return vaf;
-    //     } else {
-    //         let vaf = match &self.format {
-    //             Format::DeepVariant(v) => v.vaf as f32,
-    //             Format::ClairS(v) => v.af as f32,
-    //             Format::Sniffles(v) => v.dv as f32 / self.get_depth() as f32,
-    //             Format::Nanomonsv(v) => v.vr as f32 / self.get_depth() as f32,
-    //         };
-    //         self.vaf = Some(vaf);
-    //         return vaf;
-    //     }
-    // }
-
     pub fn get_depth(&mut self) -> u32 {
         if let Some(depth) = self.depth {
             return depth;
@@ -1057,20 +1067,6 @@ impl Variant {
         )
     }
 
-    // fn get_n_ref(&mut self) -> u32 {
-    //     if let Some(n_ref) = self.n_ref {
-    //         return n_ref;
-    //     } else {
-    //         let n_ref = match &self.format {
-    //             Format::DeepVariant(v) => v.ad.get(0).unwrap().to_owned(),
-    //             Format::ClairS(v) => v.ad.get(0).unwrap().to_owned(),
-    //             Format::Sniffles(v) => v.dr,
-    //             Format::Nanomonsv(v) => v.tr,
-    //         };
-    //         self.n_ref = Some(n_ref);
-    //         return n_ref;
-    //     }
-    // }
     pub fn get_veps(&self) -> Vec<VEP> {
         self.annotations
             .iter()
@@ -1210,14 +1206,6 @@ impl fmt::Display for Base {
     }
 }
 
-// #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
-// enum VCFSource {
-//     DeepVariant,
-//     ClairS,
-//     Sniffles,
-//     Nanomonsv,
-// }
-
 #[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
 pub enum Format {
     DeepVariant(DeepVariantFormat),
@@ -1234,9 +1222,6 @@ pub enum Info {
     Nanomonsv(NanomonsvInfo),
 }
 
-// type DeepVariantInfo = String;
-// type ClairSInfo = String;
-
 fn parse_info(s: &str, source: &VCFSource) -> Result<Info> {
     match source {
         VCFSource::DeepVariant => Ok(Info::DeepVariant(s.parse()?)),