pub mod gc_content_distribution;
use anyhow::Context;
use std::path::PathBuf;
use tracing::debug;
use tracing::info;
use clap::Args;
use crate::plot::command::get_all_cohort_plots;
use crate::plot::command::FilepathResults;
use crate::qc::results::Results;
#[derive(Args)]
pub struct PlotCohortArgs {
#[arg(required = true, value_name = "JSON")] pub src: Vec<PathBuf>,
#[arg(short, long, value_name = "PATH")]
pub output_directory: Option<PathBuf>,
#[arg(long = "only")]
pub only_graph: Option<String>,
}
pub fn plot(args: PlotCohortArgs) -> anyhow::Result<()> {
let mut filepath_results = Vec::new();
for src in args.src {
let results = Results::read(&src)
.with_context(|| format!("invalid input file: {}", src.display()))?;
filepath_results.push(FilepathResults(src.clone(), results));
debug!(" [*] Source: {}", src.display());
}
let output_directory = if let Some(o) = args.output_directory {
o
} else {
std::env::current_dir().expect("could not retrieve the current working directory.")
};
debug!(" [*] Output directory: {}", output_directory.display());
let plots = get_all_cohort_plots(args.only_graph)?;
for p in plots {
let plot = p.generate(&filepath_results)?;
let mut filename = output_directory.clone();
filename.push(String::from(p.filename()) + ".cohort.html");
info!(" [*] Writing {} to {}", p.name(), filename.display());
plot.write_html(filename);
}
Ok(())
}