|
|
@@ -14,6 +14,7 @@ use crate::{
|
|
|
},
|
|
|
config::Config,
|
|
|
in_out::{
|
|
|
+ self,
|
|
|
dict_reader::read_dict,
|
|
|
get_reader,
|
|
|
vcf_reader::{read_vcf, read_vcf_progress, VCFRow},
|
|
|
@@ -55,11 +56,11 @@ use std::{
|
|
|
pub struct Variants {
|
|
|
pub name: String,
|
|
|
pub data: Vec<Variant>,
|
|
|
- constit: DashMap<String, Variant>,
|
|
|
- stats_vcf: StatsVCF,
|
|
|
- stats_bam: StatsBAM,
|
|
|
- cfg: Config,
|
|
|
- mp: MultiProgress,
|
|
|
+ pub constit: DashMap<String, Variant>,
|
|
|
+ pub stats_vcf: StatsVCF,
|
|
|
+ pub stats_bam: StatsBAM,
|
|
|
+ pub cfg: Config,
|
|
|
+ pub mp: MultiProgress,
|
|
|
}
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
|
@@ -119,6 +120,7 @@ impl Variants {
|
|
|
mp: mp.clone(),
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
pub fn from_vcfs(
|
|
|
name: String,
|
|
|
v: Vec<(&str, &VCFSource, &VariantType)>,
|
|
|
@@ -426,6 +428,7 @@ impl Variants {
|
|
|
pg.finish();
|
|
|
info!("{}. Executed in {}s", self.stats_vcf, elapsed.as_secs());
|
|
|
}
|
|
|
+
|
|
|
pub fn get_cat(&mut self, cat: &VariantCategory) -> Vec<Variant> {
|
|
|
let pg = self.mp.add(new_pg_speed(self.data.len() as u64));
|
|
|
pg.set_message(format!("Get cat {:?}", cat));
|
|
|
@@ -465,6 +468,7 @@ impl Variants {
|
|
|
w.write_index_finish()?;
|
|
|
Ok(())
|
|
|
}
|
|
|
+
|
|
|
pub fn keep_somatics_un(&mut self) {
|
|
|
let pg = self.mp.add(new_pg_speed(self.data.len() as u64));
|
|
|
pg.set_message("Filtering Variants");
|
|
|
@@ -640,19 +644,22 @@ impl Variants {
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
+ 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>>()
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ .collect::<Vec<&Variant>>()
|
|
|
}
|
|
|
|
|
|
pub fn filter_snp(&mut self) -> Result<i32> {
|
|
|
@@ -840,6 +847,28 @@ impl Variants {
|
|
|
)?;
|
|
|
Ok(())
|
|
|
}
|
|
|
+
|
|
|
+ pub fn save_bytes(&self, path: &str) -> Result<()> {
|
|
|
+ let serialized = pot::to_vec(&self.data)?;
|
|
|
+ let mut w =
|
|
|
+ noodles_bgzf::writer::Builder::default().build_with_writer(File::create(path)?);
|
|
|
+ w.write_all(&serialized)?;
|
|
|
+ Ok(())
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn new_from_bytes(name: &str, path: &str, mp: MultiProgress) -> Result<Self> {
|
|
|
+ let r = in_out::get_reader(path)?;
|
|
|
+ let data: Vec<Variant> = pot::from_reader(r)?;
|
|
|
+ Ok(Self {
|
|
|
+ name: name.to_string(),
|
|
|
+ data,
|
|
|
+ constit: DashMap::new(),
|
|
|
+ stats_vcf: StatsVCF::default(),
|
|
|
+ stats_bam: StatsBAM::default(),
|
|
|
+ cfg: Config::get()?,
|
|
|
+ mp,
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|