diff --git a/src/ext_tools.rs b/src/ext_tools.rs index ff71d4b..49e4a6b 100644 --- a/src/ext_tools.rs +++ b/src/ext_tools.rs @@ -7,7 +7,7 @@ use std::path::{Path, PathBuf}; use tempfile::{Builder, NamedTempFile, TempDir}; use crate::edam; -use crate::run::ModuleResult; +use crate::module::ModuleResult; const CWL_INSPECTOR_DOCKER_IMAGE: &str = "ghcr.io/tom-tan/cwl-inspector:v0.1.1"; const LABEL_KEY: &str = "label"; @@ -29,10 +29,10 @@ pub fn invoke( // make sure that the both paths are canonicalized. let target_file_path = target_file_path .canonicalize() - .with_context(|| format!("Failed to canonicalize {}", target_file_path.display()))?; + .with_context(|| format!("The specified path of CWL document '{}' does not exist. Please check the path for typos and try again.", target_file_path.display()))?; let cwl_file_path = cwl_file_path .canonicalize() - .with_context(|| format!("Failed to canonicalize {}", cwl_file_path.display()))?; + .with_context(|| format!("The specified path of CWL document '{}' does not exist. Please check the path for typos and try again.", cwl_file_path.display()))?; // get the EDAM_ID and LABEL from the comment lines in the CWL file. let mut cwl_metadatas = get_metadata_fields_from_cwl_file(&cwl_file_path)?; @@ -77,7 +77,7 @@ pub fn invoke( // remove the "-v" options and split the docker command on the "-v" option. let mut parts_iter = tmp_cwl_docker_command_split.into_iter().peekable(); - let cwl_docker_commandname = parts_iter.next().unwrap(); + let cwl_docker_command_name = parts_iter.next().unwrap(); let mut cwl_docker_args_before_v: Vec = Vec::new(); let mut cwl_docker_args_after_v: Vec = Vec::new(); let mut encountered_v = false; @@ -110,12 +110,12 @@ pub fn invoke( // run the docker command created by cwl-inspector. debug!( "Running the docker command: '{} {} {}'", - cwl_docker_commandname, + cwl_docker_command_name, cwl_docker_args_before_v.join(" "), cwl_docker_args_after_v.join(" ") ); - let cwl_docker_process = std::process::Command::new(cwl_docker_commandname) + let cwl_docker_process = std::process::Command::new(cwl_docker_command_name) .args(cwl_docker_args_before_v) .args(cwl_docker_args_after_v) .stdout(std::process::Stdio::piped()) diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..7ad3eac --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,7 @@ +pub mod args; +mod edam; +mod ext_tools; +mod fetch; +mod logger; +pub mod module; +mod parser; diff --git a/src/logger.rs b/src/logger.rs index 896a334..bfa2188 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,5 +1,3 @@ -use std::io::Write; - pub fn init_logger(verbose: bool, quiet: bool) { let env = env_logger::Env::default().filter_or( env_logger::DEFAULT_FILTER_ENV, @@ -12,8 +10,5 @@ pub fn init_logger(verbose: bool, quiet: bool) { }, ); let mut builder = env_logger::Builder::from_env(env); - if !verbose { - builder.format(|buf, record| writeln!(buf, "{}", record.args())); - } builder.init(); } diff --git a/src/main.rs b/src/main.rs index 36a825a..b194d24 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,26 +1,13 @@ -mod args; -mod edam; -mod ext_tools; -mod fetch; -mod logger; -mod parser; -mod run; - use anyhow::{Context, Result}; use clap::Parser; -use log::{debug, info}; use std::fs::File; use std::io::BufReader; -use crate::args::OutputFormat; -use crate::run::Config; - fn main() -> Result<()> { // parse arguments and options with clap - let args = args::Args::parse(); - logger::init_logger(args.verbose, args.quiet); + let args = tataki::args::Args::parse(); - let config: Config = match &args.conf { + let config: tataki::module::Config = match &args.conf { None => { let config_str = include_str!("./tataki.conf"); serde_yaml::from_str(config_str)? @@ -38,12 +25,9 @@ fn main() -> Result<()> { }; if args.dry_run { - run::dry_run(config)?; + tataki::module::dry_run(config)?; } else { - info!("tataki started"); - debug!("Args: {:?}", args); - debug!("Output format: {:?}", args.get_output_format()); - run::run(config, args)?; + tataki::module::run(config, args)?; } Ok(()) diff --git a/src/run.rs b/src/module.rs similarity index 95% rename from src/run.rs rename to src/module.rs index dae84f8..81d91f7 100644 --- a/src/run.rs +++ b/src/module.rs @@ -6,11 +6,7 @@ use std::path::{Path, PathBuf}; use tempfile::{NamedTempFile, TempDir}; use url::Url; -use crate::args::Args; -use crate::ext_tools; -use crate::fetch; -use crate::parser; -use crate::OutputFormat; +use crate::args::{Args, OutputFormat}; // Struct to store the result of Parser invocation and ExtTools invocation. #[derive(Debug)] @@ -117,7 +113,12 @@ pub struct Config { } pub fn run(config: Config, args: Args) -> Result<()> { - let temp_dir = fetch::create_temporary_dir(&args.cache_dir)?; + crate::logger::init_logger(args.verbose, args.quiet); + info!("tataki started"); + debug!("Args: {:?}", args); + debug!("Output format: {:?}", args.get_output_format()); + + let temp_dir = crate::fetch::create_temporary_dir(&args.cache_dir)?; info!("Created temporary directory: {}", temp_dir.path().display()); let mut module_results: Vec = Vec::new(); @@ -193,7 +194,7 @@ fn run_modules( ) -> Result { // create an input file for CWL modules if there is any CWL module in the config file. let cwl_input_file_path: Option = if cwl_module_exists(config)? { - Some(ext_tools::make_cwl_input_file( + Some(crate::ext_tools::make_cwl_input_file( target_file_path.clone(), temp_dir, )?) @@ -212,8 +213,8 @@ fn run_modules( .unwrap_or(""); let result = match module_extension { - "" => parser::invoke(module, &target_file_path), - "cwl" => ext_tools::invoke( + "" => crate::parser::invoke(module, &target_file_path), + "cwl" => crate::ext_tools::invoke( module_path, &target_file_path, cwl_input_file_path.as_ref().unwrap(), diff --git a/src/parser.rs b/src/parser.rs index 3a9f160..e8799a5 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -14,7 +14,7 @@ use anyhow::{bail, Result}; use log::info; use std::path::Path; -use crate::run::ModuleResult; +use crate::module::ModuleResult; pub trait Parser { /// Determine if the provided file is in a format that this parser can interpret. diff --git a/src/parser/bam.rs b/src/parser/bam.rs index a95cc88..55dafe3 100644 --- a/src/parser/bam.rs +++ b/src/parser/bam.rs @@ -1,7 +1,7 @@ use std::path::Path; +use crate::module::ModuleResult; use crate::parser::Parser; -use crate::run::ModuleResult; pub struct Bam; diff --git a/src/parser/bcf.rs b/src/parser/bcf.rs index f308ede..fe5b78f 100644 --- a/src/parser/bcf.rs +++ b/src/parser/bcf.rs @@ -1,7 +1,7 @@ use std::path::Path; +use crate::module::ModuleResult; use crate::parser::Parser; -use crate::run::ModuleResult; pub struct Bcf; diff --git a/src/parser/bed.rs b/src/parser/bed.rs index 6a38917..4fa37a4 100644 --- a/src/parser/bed.rs +++ b/src/parser/bed.rs @@ -2,8 +2,8 @@ use std::fs::File; use std::io::BufReader; use std::path::Path; +use crate::module::ModuleResult; use crate::parser::Parser; -use crate::run::ModuleResult; pub struct Bed; diff --git a/src/parser/cram.rs b/src/parser/cram.rs index e531d3e..cf2b2cf 100644 --- a/src/parser/cram.rs +++ b/src/parser/cram.rs @@ -1,7 +1,7 @@ use std::path::Path; +use crate::module::ModuleResult; use crate::parser::Parser; -use crate::run::ModuleResult; pub struct Cram; diff --git a/src/parser/empty.rs b/src/parser/empty.rs index a93aacb..fb6b634 100644 --- a/src/parser/empty.rs +++ b/src/parser/empty.rs @@ -1,8 +1,8 @@ use std::fs; use std::path::Path; +use crate::module::ModuleResult; use crate::parser::Parser; -use crate::run::ModuleResult; pub struct Empty; diff --git a/src/parser/fasta.rs b/src/parser/fasta.rs index 3f3fa51..c22b2bc 100644 --- a/src/parser/fasta.rs +++ b/src/parser/fasta.rs @@ -1,7 +1,7 @@ use std::path::Path; +use crate::module::ModuleResult; use crate::parser::Parser; -use crate::run::ModuleResult; pub struct Fasta; diff --git a/src/parser/fastq.rs b/src/parser/fastq.rs index 9402e08..65480d0 100644 --- a/src/parser/fastq.rs +++ b/src/parser/fastq.rs @@ -2,8 +2,8 @@ use std::fs::File; use std::io::BufReader; use std::path::Path; +use crate::module::ModuleResult; use crate::parser::Parser; -use crate::run::ModuleResult; pub struct Fastq; diff --git a/src/parser/gff3.rs b/src/parser/gff3.rs index 0d34274..d9a8b3f 100644 --- a/src/parser/gff3.rs +++ b/src/parser/gff3.rs @@ -2,8 +2,8 @@ use std::fs::File; use std::io::BufReader; use std::path::Path; +use crate::module::ModuleResult; use crate::parser::Parser; -use crate::run::ModuleResult; pub struct Gff3; diff --git a/src/parser/gtf.rs b/src/parser/gtf.rs index 156bb5a..63c084e 100644 --- a/src/parser/gtf.rs +++ b/src/parser/gtf.rs @@ -2,8 +2,8 @@ use std::fs::File; use std::io::BufReader; use std::path::Path; +use crate::module::ModuleResult; use crate::parser::Parser; -use crate::run::ModuleResult; pub struct Gtf; diff --git a/src/parser/sam.rs b/src/parser/sam.rs index 75bc1ee..0c64128 100644 --- a/src/parser/sam.rs +++ b/src/parser/sam.rs @@ -1,7 +1,7 @@ use std::path::Path; +use crate::module::ModuleResult; use crate::parser::Parser; -use crate::run::ModuleResult; pub struct Sam; diff --git a/src/parser/vcf.rs b/src/parser/vcf.rs index 23abbce..adec5bd 100644 --- a/src/parser/vcf.rs +++ b/src/parser/vcf.rs @@ -1,7 +1,7 @@ use std::path::Path; +use crate::module::ModuleResult; use crate::parser::Parser; -use crate::run::ModuleResult; pub struct Vcf;