|
|
@@ -1,5 +1,6 @@
|
|
|
use std::{fs, path::Path, thread};
|
|
|
|
|
|
+use anyhow::Context;
|
|
|
use log::info;
|
|
|
|
|
|
use crate::{
|
|
|
@@ -56,16 +57,18 @@ impl NanomonSV {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub fn run(&mut self) {
|
|
|
+ pub fn run(&mut self) -> anyhow::Result<()> {
|
|
|
// Create direcories
|
|
|
if !Path::new(&self.diag_out_dir).exists() {
|
|
|
- fs::create_dir_all(&self.diag_out_dir).unwrap();
|
|
|
+ fs::create_dir_all(&self.diag_out_dir)
|
|
|
+ .context(format!("Can't create {}", &self.diag_out_dir))?;
|
|
|
}
|
|
|
if !Path::new(&self.mrd_out_dir).exists() {
|
|
|
- fs::create_dir_all(&self.mrd_out_dir).unwrap();
|
|
|
+ fs::create_dir_all(&self.mrd_out_dir)
|
|
|
+ .context(format!("Can't create {}", &self.mrd_out_dir))?;
|
|
|
}
|
|
|
if !Path::new(&self.log_dir).exists() {
|
|
|
- fs::create_dir_all(&self.log_dir).unwrap();
|
|
|
+ fs::create_dir_all(&self.log_dir).context(format!("Can't create {}", &self.log_dir))?;
|
|
|
}
|
|
|
|
|
|
// Parse
|
|
|
@@ -123,7 +126,9 @@ impl NanomonSV {
|
|
|
None,
|
|
|
self.config.clone(),
|
|
|
)
|
|
|
- .unwrap();
|
|
|
+ .context(format!(
|
|
|
+ "Error while running NanomonSV get for {mrd_result_vcf}"
|
|
|
+ ))?;
|
|
|
report
|
|
|
.save_to_file(&format!("{}/nanomonsv_get_mrd_", self.log_dir))
|
|
|
.unwrap();
|
|
|
@@ -137,7 +142,9 @@ impl NanomonSV {
|
|
|
Some(&mrd_out_prefix),
|
|
|
self.config.clone(),
|
|
|
)
|
|
|
- .unwrap();
|
|
|
+ .context(format!(
|
|
|
+ "Error while running NanomonSV get for {diag_result_vcf}"
|
|
|
+ ))?;
|
|
|
report
|
|
|
.save_to_file(&format!("{}/nanomonsv_get_diag_", self.log_dir,))
|
|
|
.unwrap();
|
|
|
@@ -152,6 +159,89 @@ impl NanomonSV {
|
|
|
.save_to_file(&format!("{}/bcftools_pass_", self.log_dir,))
|
|
|
.unwrap();
|
|
|
}
|
|
|
+ Ok(())
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#[derive(Debug)]
|
|
|
+pub struct NanomonSVSolo {
|
|
|
+ pub id: String,
|
|
|
+ pub bam: String,
|
|
|
+ pub time_point: String,
|
|
|
+ pub out_dir: String,
|
|
|
+ pub log: String,
|
|
|
+ pub log_dir: String,
|
|
|
+ pub config: NanomonSVConfig,
|
|
|
+}
|
|
|
+
|
|
|
+impl NanomonSVSolo {
|
|
|
+ pub fn new(id: &str, bam: &str, time_point: &str, config: NanomonSVConfig) -> Self {
|
|
|
+ let out_dir = format!("{}/{id}/{time_point}/nanomonsv", &config.result_dir);
|
|
|
+ let log_dir = format!("{}/{id}/log/nanomonsv", &config.result_dir);
|
|
|
+ NanomonSVSolo {
|
|
|
+ id: id.to_string(),
|
|
|
+ bam: bam.to_string(),
|
|
|
+ out_dir,
|
|
|
+ time_point: time_point.to_string(),
|
|
|
+ log: String::default(),
|
|
|
+ log_dir,
|
|
|
+ config,
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn run(&mut self) -> anyhow::Result<()> {
|
|
|
+ // Create direcories
|
|
|
+ if !Path::new(&self.out_dir).exists() {
|
|
|
+ fs::create_dir_all(&self.out_dir).context(format!("Can't create {}", &self.out_dir))?;
|
|
|
+ }
|
|
|
+
|
|
|
+ if !Path::new(&self.log_dir).exists() {
|
|
|
+ fs::create_dir_all(&self.log_dir).context(format!("Can't create {}", &self.log_dir))?;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Parse
|
|
|
+ info!("Nanomonsv Parse");
|
|
|
+ let out_prefix = format!("{}/{}_{}", self.out_dir, self.id, self.time_point);
|
|
|
+
|
|
|
+ let info_vcf = format!("{out_prefix}.bp_info.sorted.bed.gz");
|
|
|
+ if !Path::new(&info_vcf).exists() {
|
|
|
+ let report = nanomonsv_parse(&self.bam, &out_prefix, self.config.clone()).context(
|
|
|
+ format!("Error while running NanomonSV parse for {}", self.bam),
|
|
|
+ )?;
|
|
|
+ let log_file = format!("{}/nanomonsv_parse_{}_", self.log_dir, self.time_point);
|
|
|
+ report
|
|
|
+ .save_to_file(&log_file)
|
|
|
+ .context(format!("Can't write logs into {log_file}"))?;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Get
|
|
|
+ info!("Nanomonsv Get");
|
|
|
+ let result_vcf = format!("{out_prefix}.nanomonsv.result.vcf");
|
|
|
+
|
|
|
+ if !Path::new(&result_vcf).exists() {
|
|
|
+ let report = nanomonsv_get(&self.bam, &out_prefix, None, None, self.config.clone())
|
|
|
+ .context(format!(
|
|
|
+ "Error while running NanomonSV get for {result_vcf}"
|
|
|
+ ))?;
|
|
|
+ let log_file = format!("{}/nanomonsv_get_{}_", self.log_dir, self.time_point);
|
|
|
+ report
|
|
|
+ .save_to_file(&log_file)
|
|
|
+ .context(format!("Error while writing log into {log_file}"))?;
|
|
|
+ }
|
|
|
+
|
|
|
+ let vcf_passed = format!("{out_prefix}_nanomonsv_PASSED.vcf.gz");
|
|
|
+ if !Path::new(&vcf_passed).exists() {
|
|
|
+ let report = bcftools_keep_pass(&result_vcf, &vcf_passed, BcftoolsConfig::default())
|
|
|
+ .context(format!(
|
|
|
+ "Error while running bcftools keep PASS for {result_vcf}"
|
|
|
+ ))?;
|
|
|
+
|
|
|
+ let log_file = format!("{}/bcftools_pass_", self.log_dir);
|
|
|
+ report
|
|
|
+ .save_to_file(&log_file)
|
|
|
+ .context(format!("Error while writing log into {log_file}"))?;
|
|
|
+ }
|
|
|
+ Ok(())
|
|
|
}
|
|
|
}
|
|
|
|