|
@@ -1,16 +1,11 @@
|
|
|
use std::{
|
|
use std::{
|
|
|
fs,
|
|
fs,
|
|
|
- io::{BufRead, BufReader},
|
|
|
|
|
path::Path,
|
|
path::Path,
|
|
|
- process::{Child, Command, Stdio},
|
|
|
|
|
- sync::{Arc, Mutex},
|
|
|
|
|
- thread,
|
|
|
|
|
|
|
+ process::{Command, Stdio},
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
-use duct::cmd;
|
|
|
|
|
use log::{info, warn};
|
|
use log::{info, warn};
|
|
|
|
|
|
|
|
-use crate::runners::{self, DockerRun};
|
|
|
|
|
|
|
+use crate::runners::DockerRun;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
#[derive(Debug)]
|
|
|
pub struct DeepVariantConfig {
|
|
pub struct DeepVariantConfig {
|
|
@@ -40,42 +35,55 @@ pub struct DeepVariant {
|
|
|
pub id: String,
|
|
pub id: String,
|
|
|
pub time_point: String,
|
|
pub time_point: String,
|
|
|
pub bam: String,
|
|
pub bam: String,
|
|
|
|
|
+ pub output_dir: String,
|
|
|
|
|
+ pub output_vcf: String,
|
|
|
|
|
+ pub vcf_passed: String,
|
|
|
|
|
+ pub log: String,
|
|
|
pub config: DeepVariantConfig,
|
|
pub config: DeepVariantConfig,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
impl DeepVariant {
|
|
impl DeepVariant {
|
|
|
pub fn new(id: &str, time_point: &str, bam: &str, config: DeepVariantConfig) -> Self {
|
|
pub fn new(id: &str, time_point: &str, bam: &str, config: DeepVariantConfig) -> Self {
|
|
|
|
|
+ let output_dir = format!(
|
|
|
|
|
+ "{}/{}/{}/DeepVariant",
|
|
|
|
|
+ config.result_dir, id, time_point
|
|
|
|
|
+ );
|
|
|
|
|
+ let output_vcf = format!(
|
|
|
|
|
+ "{output_dir}/{}_{}_DeepVariant.vcf.gz",
|
|
|
|
|
+ id, time_point
|
|
|
|
|
+ );
|
|
|
|
|
+ let vcf_passed = format!(
|
|
|
|
|
+ "{}/{}_{}_DeepVariant_PASSED.vcf.gz",
|
|
|
|
|
+ output_dir, id,time_point
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
Self {
|
|
Self {
|
|
|
id: id.to_string(),
|
|
id: id.to_string(),
|
|
|
time_point: time_point.to_string(),
|
|
time_point: time_point.to_string(),
|
|
|
bam: bam.to_string(),
|
|
bam: bam.to_string(),
|
|
|
config,
|
|
config,
|
|
|
|
|
+ log: String::default(),
|
|
|
|
|
+ output_dir,
|
|
|
|
|
+ output_vcf,
|
|
|
|
|
+ vcf_passed,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pub fn run(self) -> Self {
|
|
|
|
|
|
|
+ pub fn run(mut self) -> Self {
|
|
|
// Create out dir
|
|
// Create out dir
|
|
|
- let output_dir = format!(
|
|
|
|
|
- "{}/{}/{}/DeepVariant",
|
|
|
|
|
- self.config.result_dir, self.id, self.time_point
|
|
|
|
|
- );
|
|
|
|
|
- if !Path::new(&output_dir).exists() {
|
|
|
|
|
- fs::create_dir_all(&output_dir).expect("Failed to create output directory");
|
|
|
|
|
|
|
+ if !Path::new(&self.output_dir).exists() {
|
|
|
|
|
+ fs::create_dir_all(&self.output_dir).expect("Failed to create output directory");
|
|
|
}
|
|
}
|
|
|
- let output_vcf = format!(
|
|
|
|
|
- "{output_dir}/{}_{}_DeepVariant.vcf.gz",
|
|
|
|
|
- self.id, self.time_point
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Run Docker command if output VCF doesn't exist
|
|
// Run Docker command if output VCF doesn't exist
|
|
|
- if !Path::new(&output_vcf).exists() {
|
|
|
|
|
|
|
+ if !Path::new(&self.output_vcf).exists() {
|
|
|
let docker_run = DockerRun::run(&[
|
|
let docker_run = DockerRun::run(&[
|
|
|
"run",
|
|
"run",
|
|
|
"-d",
|
|
"-d",
|
|
|
"-v",
|
|
"-v",
|
|
|
"/data:/data", // <---
|
|
"/data:/data", // <---
|
|
|
"-v",
|
|
"-v",
|
|
|
- &format!("{}:/output", output_dir),
|
|
|
|
|
|
|
+ &format!("{}:/output", self.output_dir),
|
|
|
&format!("google/deepvariant:{}", self.config.bin_version),
|
|
&format!("google/deepvariant:{}", self.config.bin_version),
|
|
|
"/opt/deepvariant/bin/run_deepvariant",
|
|
"/opt/deepvariant/bin/run_deepvariant",
|
|
|
"--model_type=ONT_R104",
|
|
"--model_type=ONT_R104",
|
|
@@ -98,16 +106,12 @@ impl DeepVariant {
|
|
|
&format!("{}_{}", self.id, self.time_point),
|
|
&format!("{}_{}", self.id, self.time_point),
|
|
|
]);
|
|
]);
|
|
|
docker_run.wait();
|
|
docker_run.wait();
|
|
|
- let log = docker_run.log();
|
|
|
|
|
- println!("{log}");
|
|
|
|
|
|
|
+ self.log = docker_run.log();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Keep PASS
|
|
// Keep PASS
|
|
|
- let vcf_passed = format!(
|
|
|
|
|
- "{}/{}_{}_DeepVariant_PASSED.vcf.gz",
|
|
|
|
|
- output_dir, self.id, self.time_point
|
|
|
|
|
- );
|
|
|
|
|
- if !Path::new(&vcf_passed).exists() {
|
|
|
|
|
|
|
+ if !Path::new(&self.vcf_passed).exists() {
|
|
|
|
|
+ info!("Filtering PASS variants");
|
|
|
let status = Command::new(&self.config.bcftools)
|
|
let status = Command::new(&self.config.bcftools)
|
|
|
.args([
|
|
.args([
|
|
|
"view",
|
|
"view",
|
|
@@ -116,9 +120,9 @@ impl DeepVariant {
|
|
|
"20",
|
|
"20",
|
|
|
"-i",
|
|
"-i",
|
|
|
"FILTER='PASS'",
|
|
"FILTER='PASS'",
|
|
|
- &output_vcf,
|
|
|
|
|
|
|
+ &self.output_vcf,
|
|
|
"-o",
|
|
"-o",
|
|
|
- &vcf_passed,
|
|
|
|
|
|
|
+ &self.vcf_passed,
|
|
|
])
|
|
])
|
|
|
.stdout(Stdio::inherit())
|
|
.stdout(Stdio::inherit())
|
|
|
.stderr(Stdio::inherit())
|
|
.stderr(Stdio::inherit())
|