Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make error message in mmseqs run prettier #115

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions packages/pangraph/src/align/mmseqs/align_with_mmseqs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::io::file::open_file_or_stdin;
use crate::io::fs::path_to_str;
use crate::pangraph::pangraph_block::{BlockId, PangraphBlock};
use crate::utils::subprocess::create_arg_optional;
use crate::{make_error, vec_of_owned};
use color_eyre::{Section, SectionExt};
use eyre::{Report, WrapErr};
use itertools::Itertools;
use std::collections::BTreeMap;
use std::io::Read;
use std::process::Command;
Expand All @@ -32,33 +35,32 @@ pub fn align_with_mmseqs(
}

let output_column_names = PafTsvRecord::fields_names().join(",");
let k = create_arg_optional("-k", &params.kmer_length);

let cmd_outcome = Command::new("mmseqs")
.arg("easy-search")
.arg(&input_path)
.arg(&input_path)
.arg(&output_path)
.arg(&tmp_path)
.arg("--threads")
.arg("1")
.arg("--max-seq-len")
.arg("10000")
.arg("-a")
.arg("--search-type")
.arg("3")
.arg("--format-output")
.arg(&output_column_names)
.args(&k)
.output()
.wrap_err("When trying to align sequences using mmseqs")?;
let mut args = vec_of_owned![
"easy-search",
&input_path,
&input_path,
&output_path,
&tmp_path,
"--thread",
"1",
"--max-seq-len",
"10000",
"-a",
"--search-type",
"3",
"--format-output",
&output_column_names,
];

if !cmd_outcome.status.success() {
return Err(Report::msg(format!(
"mmseqs command {}\nfailed with stderr:\n{}",
cmd_outcome.status,
String::from_utf8_lossy(&cmd_outcome.stderr).trim()
)));
args.extend(create_arg_optional("-k", &params.kmer_length));

let cmd = Command::new("mmseqs").args(&args).output()?;

if !cmd.status.success() {
return make_error!("{}", String::from_utf8(cmd.stderr)?.trim())
.wrap_err_with(|| format!("mmseqs failed with exit code {}", cmd.status.code().unwrap()))
.with_section(|| format!("mmseqs {}", args.join(" ")).header("Full command line was:"));
}

let mut paf_str = String::new();
Expand Down
1 change: 1 addition & 0 deletions packages/pangraph/src/pangraph/graph_merging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pub fn find_matches(
AlignmentBackend::Minimap2 => align_with_minimap2_lib(blocks, &args.aln_args),
AlignmentBackend::Mmseqs => align_with_mmseqs(blocks, &args.aln_args),
}
.wrap_err_with(|| format!("When trying to align sequences using {}", &args.alignment_kernel))
}

pub fn filter_matches(alns: &[Alignment], args: &AlignmentArgs) -> Vec<Alignment> {
Expand Down
2 changes: 1 addition & 1 deletion packages/pangraph/src/utils/subprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ where
pub fn create_arg_optional(name: impl AsRef<str>, value: &Option<impl ToString>) -> Vec<String> {
value
.as_ref()
.map(|kmer_len| vec![name.as_ref().to_owned(), kmer_len.to_string()])
.map(|value| vec![name.as_ref().to_owned(), value.to_string()])
.unwrap_or_default()
}