|
|
@@ -1,7 +1,10 @@
|
|
|
use crate::{
|
|
|
annotation::{Annotation, Annotations, Caller, CallerCat},
|
|
|
collection::{vcf::Vcf, HasOutputs, Initialize, InitializeSolo, Version},
|
|
|
- commands::bcftools::{bcftools_keep_pass, BcftoolsConfig},
|
|
|
+ commands::{
|
|
|
+ bcftools::{bcftools_keep_pass_precise, BcftoolsConfig},
|
|
|
+ longphase::LongphasePhase,
|
|
|
+ },
|
|
|
config::Config,
|
|
|
io::vcf::read_vcf,
|
|
|
runners::{run_wait, CommandRun, Run},
|
|
|
@@ -11,8 +14,8 @@ use crate::{
|
|
|
},
|
|
|
};
|
|
|
use anyhow::Context;
|
|
|
-use rayon::prelude::*;
|
|
|
use log::{debug, info};
|
|
|
+use rayon::prelude::*;
|
|
|
use std::{fs, path::Path};
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
@@ -24,14 +27,10 @@ pub struct Severus {
|
|
|
|
|
|
impl Initialize for Severus {
|
|
|
fn initialize(id: &str, config: Config) -> anyhow::Result<Self> {
|
|
|
- let mut output_vcf_exists = Path::new(&config.severus_output_vcf(id)).exists();
|
|
|
+ info!("Initialize Severus for {id}.");
|
|
|
+ let output_vcf_exists = Path::new(&config.severus_output_vcf(id)).exists();
|
|
|
if config.severus_force && output_vcf_exists {
|
|
|
fs::remove_dir_all(config.severus_output_dir(id))?;
|
|
|
- output_vcf_exists = false;
|
|
|
- }
|
|
|
-
|
|
|
- if output_vcf_exists {
|
|
|
- anyhow::bail!("{} already exists.", config.severus_output_vcf(id))
|
|
|
}
|
|
|
|
|
|
let log_dir = format!("{}/{}/log/severus", config.result_dir, id);
|
|
|
@@ -42,8 +41,10 @@ impl Initialize for Severus {
|
|
|
|
|
|
let phased_germline_vcf = &config.constit_phased_vcf(id);
|
|
|
if !Path::new(phased_germline_vcf).exists() {
|
|
|
- anyhow::bail!("Could not find required phased VCF: {phased_germline_vcf}")
|
|
|
+ LongphasePhase::initialize(id, config.clone())?.run()?;
|
|
|
+ // anyhow::bail!("Could not find required phased VCF: {phased_germline_vcf}")
|
|
|
}
|
|
|
+ fs::create_dir_all(config.severus_output_dir(id))?;
|
|
|
|
|
|
Ok(Self {
|
|
|
id: id.to_string(),
|
|
|
@@ -55,54 +56,59 @@ impl Initialize for Severus {
|
|
|
|
|
|
impl Run for Severus {
|
|
|
fn run(&mut self) -> anyhow::Result<()> {
|
|
|
+ // TODO make that work
|
|
|
info!("Running Severus v{}", Severus::version(&self.config)?);
|
|
|
|
|
|
let id = &self.id;
|
|
|
let output_vcf = &self.config.severus_output_vcf(id);
|
|
|
let passed_vcf = &self.config.severus_passed_vcf(id);
|
|
|
|
|
|
- // Run command if output VCF doesn't exist
|
|
|
- let severus_args = [
|
|
|
- "--target-bam",
|
|
|
- &self.config.tumoral_bam(id),
|
|
|
- "--control-bam",
|
|
|
- &self.config.normal_bam(id),
|
|
|
- "--phasing-vcf",
|
|
|
- &self.config.germline_phased_vcf(id),
|
|
|
- "--out-dir",
|
|
|
- &self.config.severus_output_dir(id),
|
|
|
- "-t",
|
|
|
- &self.config.severus_threads.to_string(),
|
|
|
- "--write-alignments",
|
|
|
- "--use-supplementary-tag",
|
|
|
- "--resolve-overlaps",
|
|
|
- "--between-junction-ins",
|
|
|
- "--vntr-bed",
|
|
|
- &self.config.vntrs_bed,
|
|
|
- ];
|
|
|
- let args = [
|
|
|
- "-c",
|
|
|
- &format!(
|
|
|
- "source {} && conda activate severus_env && {} {}",
|
|
|
- self.config.conda_sh,
|
|
|
- self.config.severus_bin,
|
|
|
- severus_args.join(" ")
|
|
|
- ),
|
|
|
- ];
|
|
|
- let mut cmd_run = CommandRun::new("bash", &args);
|
|
|
- let report = run_wait(&mut cmd_run).context(format!(
|
|
|
- "Error while running `severus.py {}`",
|
|
|
- args.join(" ")
|
|
|
- ))?;
|
|
|
+ if !Path::new(output_vcf).exists() {
|
|
|
+ // Run command if output VCF doesn't exist
|
|
|
+ let severus_args = [
|
|
|
+ "--target-bam",
|
|
|
+ &self.config.tumoral_bam(id),
|
|
|
+ "--control-bam",
|
|
|
+ &self.config.normal_bam(id),
|
|
|
+ "--phasing-vcf",
|
|
|
+ &self.config.constit_phased_vcf(id),
|
|
|
+ "--out-dir",
|
|
|
+ &self.config.severus_output_dir(id),
|
|
|
+ "-t",
|
|
|
+ &self.config.severus_threads.to_string(),
|
|
|
+ "--write-alignments",
|
|
|
+ "--use-supplementary-tag",
|
|
|
+ "--resolve-overlaps",
|
|
|
+ "--between-junction-ins",
|
|
|
+ "--vntr-bed",
|
|
|
+ &self.config.vntrs_bed,
|
|
|
+ ];
|
|
|
+ let args = [
|
|
|
+ "-c",
|
|
|
+ &format!(
|
|
|
+ "source {} && conda activate severus_env && {} {}",
|
|
|
+ self.config.conda_sh,
|
|
|
+ self.config.severus_bin,
|
|
|
+ severus_args.join(" ")
|
|
|
+ ),
|
|
|
+ ];
|
|
|
+ let mut cmd_run = CommandRun::new("bash", &args);
|
|
|
+ let report = run_wait(&mut cmd_run).context(format!(
|
|
|
+ "Error while running `severus.py {}`",
|
|
|
+ args.join(" ")
|
|
|
+ ))?;
|
|
|
|
|
|
- let log_file = format!("{}/severus_", self.log_dir);
|
|
|
- report
|
|
|
- .save_to_file(&log_file)
|
|
|
- .context(format!("Error while writing logs into {log_file}"))?;
|
|
|
+ let log_file = format!("{}/severus_", self.log_dir);
|
|
|
+ report
|
|
|
+ .save_to_file(&log_file)
|
|
|
+ .context(format!("Error while writing logs into {log_file}"))?;
|
|
|
+ } else {
|
|
|
+ debug!("")
|
|
|
+ }
|
|
|
|
|
|
// Keep PASS
|
|
|
if !Path::new(passed_vcf).exists() && Path::new(output_vcf).exists() {
|
|
|
- let report = bcftools_keep_pass(output_vcf, passed_vcf, BcftoolsConfig::default())
|
|
|
+ let report = bcftools_keep_pass_precise(output_vcf, passed_vcf, BcftoolsConfig::default())
|
|
|
.context(format!(
|
|
|
"Error while running bcftools keep PASS for {output_vcf}"
|
|
|
))?;
|
|
|
@@ -155,14 +161,21 @@ impl Variants for Severus {
|
|
|
let (caller, category) = self.caller_cat();
|
|
|
let add = vec![Annotation::Callers(caller.clone()), category.clone()];
|
|
|
info!(
|
|
|
- "Loading variants from Severus {}: {vcf_passed} with annotations: {:?}",
|
|
|
- self.id, add
|
|
|
+ "Loading variants from {} {}: {}",
|
|
|
+ caller, category, vcf_passed
|
|
|
);
|
|
|
+
|
|
|
let variants = read_vcf(&vcf_passed)?;
|
|
|
|
|
|
variants.par_iter().for_each(|v| {
|
|
|
annotations.insert_update(v.hash(), &add);
|
|
|
});
|
|
|
+ info!(
|
|
|
+ "{} {}, {} variants loaded.",
|
|
|
+ caller,
|
|
|
+ category,
|
|
|
+ variants.len()
|
|
|
+ );
|
|
|
Ok(VariantCollection {
|
|
|
variants,
|
|
|
vcf: Vcf::new(vcf_passed.into())?,
|
|
|
@@ -206,7 +219,7 @@ impl Run for SeverusSolo {
|
|
|
|
|
|
let output_vcf = &self.config.severus_solo_output_vcf(id, time);
|
|
|
let passed_vcf = &self.config.severus_solo_passed_vcf(id, time);
|
|
|
-
|
|
|
+
|
|
|
if !Path::new(output_vcf).exists() {
|
|
|
// Run command if output VCF doesn't exist
|
|
|
let severus_args = [
|
|
|
@@ -242,15 +255,13 @@ impl Run for SeverusSolo {
|
|
|
report
|
|
|
.save_to_file(&log_file)
|
|
|
.context(format!("Error while writing logs into {log_file}"))?;
|
|
|
-
|
|
|
} else {
|
|
|
debug!("Severus output vcf already exists.");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// Keep PASS
|
|
|
if !Path::new(passed_vcf).exists() && Path::new(output_vcf).exists() {
|
|
|
- let report = bcftools_keep_pass(output_vcf, passed_vcf, BcftoolsConfig::default())
|
|
|
+ let report = bcftools_keep_pass_precise(output_vcf, passed_vcf, BcftoolsConfig::default())
|
|
|
.context(format!(
|
|
|
"Error while running bcftools keep PASS for {output_vcf}"
|
|
|
))?;
|