Skip to content

Commit 4ffb3dc

Browse files
Merge pull request #115 from neherlab/suggestion-2
2 parents bdb2f54 + c0db982 commit 4ffb3dc

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

packages/pangraph/src/align/mmseqs/align_with_mmseqs.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use crate::io::file::open_file_or_stdin;
66
use crate::io::fs::path_to_str;
77
use crate::pangraph::pangraph_block::{BlockId, PangraphBlock};
88
use crate::utils::subprocess::create_arg_optional;
9+
use crate::{make_error, vec_of_owned};
10+
use color_eyre::{Section, SectionExt};
911
use eyre::{Report, WrapErr};
12+
use itertools::Itertools;
1013
use std::collections::BTreeMap;
1114
use std::io::Read;
1215
use std::process::Command;
@@ -32,33 +35,32 @@ pub fn align_with_mmseqs(
3235
}
3336

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

37-
let cmd_outcome = Command::new("mmseqs")
38-
.arg("easy-search")
39-
.arg(&input_path)
40-
.arg(&input_path)
41-
.arg(&output_path)
42-
.arg(&tmp_path)
43-
.arg("--threads")
44-
.arg("1")
45-
.arg("--max-seq-len")
46-
.arg("10000")
47-
.arg("-a")
48-
.arg("--search-type")
49-
.arg("3")
50-
.arg("--format-output")
51-
.arg(&output_column_names)
52-
.args(&k)
53-
.output()
54-
.wrap_err("When trying to align sequences using mmseqs")?;
39+
let mut args = vec_of_owned![
40+
"easy-search",
41+
&input_path,
42+
&input_path,
43+
&output_path,
44+
&tmp_path,
45+
"--thread",
46+
"1",
47+
"--max-seq-len",
48+
"10000",
49+
"-a",
50+
"--search-type",
51+
"3",
52+
"--format-output",
53+
&output_column_names,
54+
];
5555

56-
if !cmd_outcome.status.success() {
57-
return Err(Report::msg(format!(
58-
"mmseqs command {}\nfailed with stderr:\n{}",
59-
cmd_outcome.status,
60-
String::from_utf8_lossy(&cmd_outcome.stderr).trim()
61-
)));
56+
args.extend(create_arg_optional("-k", &params.kmer_length));
57+
58+
let cmd = Command::new("mmseqs").args(&args).output()?;
59+
60+
if !cmd.status.success() {
61+
return make_error!("{}", String::from_utf8(cmd.stderr)?.trim())
62+
.wrap_err_with(|| format!("mmseqs failed with exit code {}", cmd.status.code().unwrap()))
63+
.with_section(|| format!("mmseqs {}", args.join(" ")).header("Full command line was:"));
6264
}
6365

6466
let mut paf_str = String::new();

packages/pangraph/src/pangraph/graph_merging.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pub fn find_matches(
176176
AlignmentBackend::Minimap2 => align_with_minimap2_lib(blocks, &args.aln_args),
177177
AlignmentBackend::Mmseqs => align_with_mmseqs(blocks, &args.aln_args),
178178
}
179+
.wrap_err_with(|| format!("When trying to align sequences using {}", &args.alignment_kernel))
179180
}
180181

181182
pub fn filter_matches(alns: &[Alignment], args: &AlignmentArgs) -> Vec<Alignment> {

packages/pangraph/src/utils/subprocess.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ where
6464
pub fn create_arg_optional(name: impl AsRef<str>, value: &Option<impl ToString>) -> Vec<String> {
6565
value
6666
.as_ref()
67-
.map(|kmer_len| vec![name.as_ref().to_owned(), kmer_len.to_string()])
67+
.map(|value| vec![name.as_ref().to_owned(), value.to_string()])
6868
.unwrap_or_default()
6969
}

0 commit comments

Comments
 (0)