Skip to content

Commit

Permalink
Start implementing consistent command and subcommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
hhandika committed Sep 2, 2024
1 parent 5ce7882 commit cc7c6eb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/cli/args/genomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub(crate) enum ContigSubcommand {
}

#[derive(Subcommand)]
pub(crate) enum MafSubcommand {
#[command(about = "Convert MAF to other formats", name = "convert")]
MafConvert(MafConvertArgs),
pub(crate) enum GenomicSubcommand {
#[command(about = "Convert genomic files to other formats", name = "convert")]
Genomic(GenomicConvertArgs),
}


Expand Down Expand Up @@ -78,11 +78,11 @@ pub(crate) struct ContigSummaryArgs {
}

#[derive(Args)]
pub(crate) struct MafConvertArgs {
pub(crate) struct GenomicConvertArgs {
#[command(flatten)]
pub(crate) io: IOArgs,
#[arg(long, help = "Source of reference names")]
pub(crate) reference_path: PathBuf,
#[arg(long, help = "Path to the source of reference names")]
pub(crate) reference: PathBuf,
#[arg(long, help = "Source of names is a bed file")]
pub(crate) from_bed: bool,
#[arg(
Expand Down
6 changes: 3 additions & 3 deletions src/cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use clap::Args;
use clap::Parser;
use clap::Subcommand;
use genomics::ContigSubcommand;
use genomics::MafSubcommand;
use genomics::GenomicSubcommand;
use genomics::SeqReadSubcommand;

use super::args::sequence::SequenceSubcommand;
Expand Down Expand Up @@ -41,8 +41,8 @@ pub(crate) enum MainSubcommand {
RawRead(SeqReadSubcommand),
#[command(subcommand, about = "Contiguous sequence analyses", name = "contig")]
Contig(ContigSubcommand),
#[command(subcommand, about = "Multiple alignment format analyses", name = "maf")]
Maf(MafSubcommand),
#[command(subcommand, about = "Genomic specific analyses", name = "genomic")]
Genomic(GenomicSubcommand),
#[command(subcommand, about = "Alignment analyses", name = "align")]
Alignment(AlignmentSubcommand),
#[command(
Expand Down
8 changes: 4 additions & 4 deletions src/cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::align::concat::ConcatParser;
use super::align::trim::AlignTrimParser;
use super::align::unalign::UnalignParser;
use super::args::align::{AlignmentSubcommand, PartitionSubcommand};
use super::args::genomics::{ContigSubcommand, MafSubcommand, SeqReadSubcommand};
use super::args::genomics::{ContigSubcommand, GenomicSubcommand, SeqReadSubcommand};
use super::args::sequence::SequenceSubcommand;
use super::args::MainSubcommand;
use super::contig::summarize::ContigCliParser;
Expand All @@ -26,7 +26,7 @@ pub(crate) fn match_cli_subcommand(subcommand: &MainSubcommand) {
match subcommand {
MainSubcommand::RawRead(subcommand) => match_raw_read_subcommand(subcommand),
MainSubcommand::Contig(subcommand) => match_contig_subcommand(subcommand),
MainSubcommand::Maf(subcommand) => match_maf_subcommand(subcommand),
MainSubcommand::Genomic(subcommand) => match_genomic_subcommand(subcommand),
MainSubcommand::Alignment(subcommand) => match_alignment_subcommand(subcommand),
MainSubcommand::Partition(subcommand) => match_partition_subcommand(subcommand),
MainSubcommand::Sequence(subcommand) => match_sequence_subcommand(subcommand),
Expand All @@ -45,9 +45,9 @@ fn match_raw_read_subcommand(subcommand: &SeqReadSubcommand) {
};
}

fn match_maf_subcommand(subcommand: &MafSubcommand) {
fn match_genomic_subcommand(subcommand: &GenomicSubcommand) {
match subcommand {
MafSubcommand::MafConvert(maf_args) => {
GenomicSubcommand::Genomic(maf_args) => {
MafConvertParser::new(maf_args).convert();
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/cli/maf/convert.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use std::path::Path;

use crate::{
cli::{args::genomics::MafConvertArgs, InputCli, OutputCli},
cli::{args::genomics::GenomicConvertArgs, InputCli, OutputCli},
core::maf::convert::MafConverter,
helper::{finder::MafFileFinder, utils},
};

pub(in crate::cli) struct MafConvertParser<'a> {
args: &'a MafConvertArgs,
args: &'a GenomicConvertArgs,
}

impl InputCli for MafConvertParser<'_> {}

impl OutputCli for MafConvertParser<'_> {}

impl<'a> MafConvertParser<'a> {
pub(in crate::cli) fn new(args: &'a MafConvertArgs) -> Self {
pub(in crate::cli) fn new(args: &'a GenomicConvertArgs) -> Self {
Self { args }
}

Expand All @@ -38,7 +38,7 @@ impl<'a> MafConvertParser<'a> {
self.check_output_dir_exist(&self.args.output, self.args.io.force);
let convert = MafConverter::new(
&files,
&self.args.reference_path,
&self.args.reference,
self.args.from_bed,
&self.args.output,
&output_fmt,
Expand Down
5 changes: 5 additions & 0 deletions src/core/maf/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ impl<'a> MafConverter<'a> {
pub fn convert(&self) {
if self.name_from_bed {
self.parse_maf_from_bed();
} else {
unreachable!(
"Name source is not supported. \
Use BED file instead and set the flag --from-bed"
);
}
self.print_output_info();
}
Expand Down

0 comments on commit cc7c6eb

Please sign in to comment.