Skip to content

Commit

Permalink
feat: try gfa crate for gfa output
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov committed Oct 25, 2024
1 parent 871503b commit 6b20a4a
Show file tree
Hide file tree
Showing 9 changed files with 357 additions and 34 deletions.
93 changes: 91 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ eyre = "=0.6.12"
flate2 = "=1.0.33"
gcollections = "=1.5.0"
getset = "0.1.3"
gfa = { version = "=0.10.1", features = ["serde", "serde_json"] }
indoc = "=2.0.5"
intervallum = "=1.4.1"
itertools = "=0.13.0"
lazy_static = "=1.5.0"
Expand Down
2 changes: 2 additions & 0 deletions packages/pangraph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ eyre = { workspace = true }
flate2 = { workspace = true }
gcollections = { workspace = true }
getset = { workspace = true }
gfa = { workspace = true }
indoc = { workspace = true }
intervallum = { workspace = true }
itertools = { workspace = true }
lazy_static = { workspace = true }
Expand Down
30 changes: 9 additions & 21 deletions packages/pangraph/src/commands/export/export_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,17 @@ pub struct PangraphExportArgs {
#[clap(value_hint = ValueHint::Other)]
pub maximum_depth: usize,

/// Path to directory where output will be stored
#[clap(long, short = 'o', default_value = "export")]
#[clap(value_hint = ValueHint::DirPath)]
pub output_directory: PathBuf,

/// Basename of files
#[clap(long, short = 'p', default_value = "pangraph")]
#[clap(value_hint = ValueHint::DirPath)]
pub prefix: String,

/// Do not emit GFA file
#[clap(long, alias = "ng")]
pub no_export_gfa: bool,

/// Emit vis directory to input to panX-visualization
#[clap(long, alias = "px")]
pub export_panx: bool,

/// Do not export any block that contains at least one strain more than once
#[clap(long, alias = "nd")]
pub no_duplications: bool,

/// Random seed
#[clap(long)]
pub seed: Option<u64>,
/// Path to output GFA file
#[clap(long, alias = "gfa")]
#[clap(value_hint = ValueHint::Other)]
pub output_gfa: Option<PathBuf>,

/// Path to output directory where PanX visualization files will be written
#[clap(long, alias = "panx")]
#[clap(value_hint = ValueHint::DirPath)]
pub output_panx: Option<PathBuf>,
}
29 changes: 19 additions & 10 deletions packages/pangraph/src/commands/export/export_run.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::commands::export::export_args::PangraphExportArgs;
use crate::io::gfa::gfa_write_file;
use crate::make_error;
use crate::pangraph::pangraph::Pangraph;
use crate::utils::random::get_random_number_generator;
use eyre::Report;

pub fn export_run(args: &PangraphExportArgs) -> Result<(), Report> {
pub fn export_run(args: PangraphExportArgs) -> Result<(), Report> {
let PangraphExportArgs {
input_json,
edge_minimum_length,
Expand All @@ -14,17 +15,25 @@ pub fn export_run(args: &PangraphExportArgs) -> Result<(), Report> {
maximum_length,
minimum_depth,
maximum_depth,
output_directory,
prefix,
no_export_gfa,
export_panx,
no_duplications,
seed,
} = &args;
output_gfa,
output_panx,
} = args;

let rng = get_random_number_generator(seed);
if [&output_gfa, &output_panx].iter().all(|o| o.is_none()) {
return make_error!("No output formats specified. Specify at least one output path.");
}

let pangraph_json = Pangraph::from_path(input_json)?;
let graph = Pangraph::from_path(&input_json)?;

if let Some(output_gfa) = output_gfa {
gfa_write_file(output_gfa, &graph)?;
}

if let Some(output_panx) = output_panx {
// TODO
// panx_write(output_panx, &graph)?;
}

Ok(())
}
2 changes: 1 addition & 1 deletion packages/pangraph/src/commands/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn pangraph_main() -> Result<(), Report> {

match args.command {
PangraphCommands::Build(args) => build_run(&args),
PangraphCommands::Export(args) => export_run(&args),
PangraphCommands::Export(args) => export_run(args),
PangraphCommands::Simplify(args) => simplify_run(args),
PangraphCommands::Reconstruct(args) => reconstruct_run(&args),
PangraphCommands::Schema(args) => generate_schema(&args),
Expand Down
Loading

0 comments on commit 6b20a4a

Please sign in to comment.