diff --git a/src/cli.rs b/src/cli.rs index 0ee03469..cead1fea 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -394,31 +394,31 @@ pub(crate) enum Command { /// Reconstruct a phylogenetic tree given a Phylip distance matrix input file. #[structopt(author = "Ragnar Groot Koerkamp ")] Phylogeny { - /// The reconstruction method to use. `UPGMA` and `NeighborJoining`. - #[structopt(long = "method")] + #[structopt( + long = "method", + help = "The reconstruction method to use. `UPGMA` or `NeighborJoining`" + )] method: PhylogenyMethod, - - /// Path of Phylip distance matrix file. - #[structopt(parse(from_os_str))] + #[structopt(parse(from_os_str), help = "Input Phylip distance matrix file.")] input: PathBuf, - - /// Path to store the phylogeny in Newick format, or stdout otherwise. - #[structopt(parse(from_os_str))] + #[structopt( + parse(from_os_str), + help = "Optional output Newick file. Stdout by default." + )] output: Option, }, /// Compute the Robinson-Foulds distance between two phylogenetic trees. #[structopt(author = "Ragnar Groot Koerkamp ")] RobinsonFoulds { - /// The path of the first phylogeny in Newick format. - #[structopt(parse(from_os_str))] + #[structopt(parse(from_os_str), help = "First input Newick file.")] newick_1: PathBuf, - /// The path of the second phylogeny in Newick format. - #[structopt(parse(from_os_str))] + #[structopt(parse(from_os_str), help = "Second input Newick file.")] newick_2: PathBuf, - - /// The path to write the distance to, or stdout otherwise. - #[structopt(parse(from_os_str))] + #[structopt( + parse(from_os_str), + help = "Optional file to write distance to. Stdout by default." + )] output: Option, }, } diff --git a/src/main.rs b/src/main.rs index 9a662fe9..52e79a7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ mod cli; pub mod common; pub mod csv; pub mod fastq; +pub mod phylogeny; pub mod sequences_stats; fn main() -> Result<()> { @@ -284,43 +285,12 @@ fn main() -> Result<()> { method, input, output, - } => { - let dm = bio_types::distancematrix::DistanceMatrix::from_file(&input)?; - let phylogeny = (match method { - cli::PhylogenyMethod::UPGMA => bio::phylogeny::upgma, - cli::PhylogenyMethod::NeighborJoining => bio::phylogeny::neighbor_joining, - })(&dm); - match output { - Some(path) => { - let mut f = fs::File::create(path)?; - f.write_all(phylogeny.to_string().as_bytes())?; - f.write(b"\n")?; - } - None => { - println!("{}", phylogeny.to_string()); - } - } - } + } => phylogeny::phylogeny(input, method, output)?, RobinsonFoulds { - ref newick_1, - ref newick_2, + newick_1, + newick_2, output, - } => { - let dist = bio::phylogeny::robinson_foulds_distance( - &bio::io::newick::from_file(newick_1)?, - &bio::io::newick::from_file(newick_2)?, - ); - match output { - Some(path) => { - let mut f = fs::File::create(path)?; - f.write_all(dist.to_string().as_bytes())?; - f.write(b"\n")?; - } - None => { - println!("{}", dist.to_string()); - } - } - } + } => phylogeny::robinson_foulds_distance(&newick_1, &newick_2, output)?, } Ok(()) }