Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/test-coverm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:

- name: Run tests with Pixi
run: |
pixi run --frozen cargo test -- --skip bwa_mem2 --skip strobealign
pixi run --frozen cargo test -- --skip bwa_mem2 --skip strobealign --skip rammap

# Run after removing lock file so dependences are unlocked
pixi_test_dependencies_optimistic_osx:
Expand Down Expand Up @@ -117,4 +117,4 @@ jobs:

- name: Run tests with Pixi
run: |
pixi run cargo test -- --skip bwa_mem2 --skip strobealign
pixi run cargo test -- --skip bwa_mem2 --skip strobealign --skip rammap
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ and one of these for mapping:
* [strobealign](https://github.com/ksahlin/StrobeAlign) v0.14.0
* [minimap2](https://github.com/lh3/minimap2) v2.21
* [bwa-mem2](https://github.com/bwa-mem2/bwa-mem2) v2.0
* [rammap](https://github.com/jwanglab/rammap) v1.1.1

and one of these for genome dereplication:
* [skani](https://github.com/bluenote-1577/skani) v0.1.1
Expand Down
13 changes: 13 additions & 0 deletions pixi.lock

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

1 change: 1 addition & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern = "*"
bwa-mem2 = "*"
dashing = ">=0.4.0,<1.0" # dashing 1.0 build gives illegal instruction errors
strobealign = ">=0.14.0" # tests generate the strobealign index at runtime
rammap = ">=1.1.1"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Commit rammap into the frozen Pixi lockfile

Line 31 adds the new dependency, but pixi.lock still has no rammap entry (rg rammap pixi.lock). The locked Linux workflow runs pixi run --frozen cargo test in .github/workflows/test-coverm.yml line 28, and Pixi documents --frozen as installing from the lockfile without updating it, so the new test_make_rammap runs in an environment without the binary and check_for_rammap fails. Please regenerate and commit pixi.lock with rammap included.

Useful? React with 👍 / 👎.


[package]
name = "coverm"
Expand Down
22 changes: 19 additions & 3 deletions src/bam_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub enum MappingProgram {
MINIMAP2_LR_HQ,
MINIMAP2_NO_PRESET,
STROBEALIGN,
RAMMAP,
}

pub struct BamFileNamedReader {
Expand Down Expand Up @@ -416,7 +417,10 @@ pub fn generate_named_bam_readers_from_reads(

// Required because of https://github.com/wwood/CoverM/issues/58
let minimap2_log_file_index = match mapping_program {
MappingProgram::BWA_MEM | MappingProgram::BWA_MEM2 | MappingProgram::STROBEALIGN => None,
MappingProgram::BWA_MEM
| MappingProgram::BWA_MEM2
| MappingProgram::STROBEALIGN
| MappingProgram::RAMMAP => None,
// Required because of https://github.com/lh3/minimap2/issues/527
MappingProgram::MINIMAP2_SR
| MappingProgram::MINIMAP2_ONT
Expand Down Expand Up @@ -867,13 +871,21 @@ pub fn build_mapping_command(
mapping_options: Option<&str>,
) -> String {
let read_params1 = match mapping_program {
// minimap2 auto-detects interleaved based on read names
// minimap2 auto-detects interleaved input based on read names
MappingProgram::MINIMAP2_SR
| MappingProgram::MINIMAP2_ONT
| MappingProgram::MINIMAP2_HIFI
| MappingProgram::MINIMAP2_PB
| MappingProgram::MINIMAP2_LR_HQ
| MappingProgram::MINIMAP2_NO_PRESET => "",
MappingProgram::RAMMAP => match read_format {
// rammap's `sr` preset turns on fragment mode, which pulls read
// pairs from a single input file (this is how it maps interleaved
// reads). For genuinely single-end reads that would incorrectly
// consume the file as interleaved pairs, so disable fragment mode.
ReadFormat::Single => "--frag no",
ReadFormat::Coupled | ReadFormat::Interleaved => "",
},
MappingProgram::BWA_MEM | MappingProgram::BWA_MEM2 => match read_format {
ReadFormat::Interleaved => "-p",
ReadFormat::Coupled | ReadFormat::Single => "",
Expand All @@ -896,6 +908,9 @@ pub fn build_mapping_command(
MappingProgram::BWA_MEM => "bwa mem".to_string(),
MappingProgram::BWA_MEM2 => "bwa-mem2 mem".to_string(),
MappingProgram::STROBEALIGN => "strobealign".to_string(),
// rammap is a minimap2-compatible aligner; map short reads with
// the 'sr' preset and emit SAM with -a.
MappingProgram::RAMMAP => "rammap -x sr -a".to_string(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Disable rammap fragment mode for single-end reads

When CoverM users choose --single with --mapper rammap, this command still forces -x sr; in the upstream rammap CLI source, the sr preset sets FRAG_MODE, and the CLI derives pe_mode = two_file_pe || frag_mode, then reads the second mate from the same iterator when only one query file is supplied. That makes a single-end FASTQ get consumed as interleaved pairs, with an odd final read dropped, instead of being mapped as single-end reads. Please add --frag no/--pairing no for ReadFormat::Single or otherwise vary the rammap options by read format.

Useful? React with 👍 / 👎.

_ => {
let split_prefix = tempfile::Builder::new()
.prefix("coverm-minimap2-split-index")
Expand All @@ -915,7 +930,8 @@ pub fn build_mapping_command(
match mapping_program {
MappingProgram::BWA_MEM
| MappingProgram::BWA_MEM2
| MappingProgram::STROBEALIGN => unreachable!(),
| MappingProgram::STROBEALIGN
| MappingProgram::RAMMAP => unreachable!(),
MappingProgram::MINIMAP2_SR => "-x sr",
MappingProgram::MINIMAP2_ONT => "-x map-ont",
MappingProgram::MINIMAP2_HIFI => "-x map-hifi",
Expand Down
11 changes: 11 additions & 0 deletions src/bin/coverm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,13 @@ fn setup_mapping_index(
)
}
}
MappingProgram::RAMMAP => {
// Pre-generating an index for a batch of readsets is not supported for rammap
info!("Not pre-generating rammap index");
Box::new(coverm::mapping_index_maintenance::VanillaIndexStruct::new(
reference_wise_params.reference,
))
}
MappingProgram::STROBEALIGN => {
// Indexing once for a batch of readsets is not yet supported for strobealign
info!("Not pre-generating strobealign index");
Expand Down Expand Up @@ -881,6 +888,7 @@ fn parse_mapping_program(m: &clap::ArgMatches) -> MappingProgram {
Some("minimap2-lr-hq") => MappingProgram::MINIMAP2_LR_HQ,
Some("minimap2-no-preset") => MappingProgram::MINIMAP2_NO_PRESET,
Some("strobealign") => MappingProgram::STROBEALIGN,
Some("rammap") => MappingProgram::RAMMAP,
None => DEFAULT_MAPPING_SOFTWARE_ENUM,
_ => panic!(
"Unexpected definition for --mapper: {:?}",
Expand All @@ -905,6 +913,9 @@ fn parse_mapping_program(m: &clap::ArgMatches) -> MappingProgram {
MappingProgram::STROBEALIGN => {
external_command_checker::check_for_strobealign();
}
MappingProgram::RAMMAP => {
external_command_checker::check_for_rammap();
}
}
mapping_program
}
Expand Down
33 changes: 33 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const MAPPING_SOFTWARE_LIST: &[&str] = &[
"minimap2-lr-hq",
"minimap2-no-preset",
"strobealign",
"rammap",
];
const DEFAULT_MAPPING_SOFTWARE: &str = "strobealign";

Expand Down Expand Up @@ -94,6 +95,10 @@ fn add_mapping_options(manual: Manual) -> Manual {
&monospace_roff("minimap2-no-preset"),
&format!("minimap2 with no '{}' option", &monospace_roff("-x"))
],
&[
&monospace_roff("rammap"),
&format!("rammap (a minimap2-compatible aligner) with '{}' option", &monospace_roff("-x sr"))
],
])
)))
.option(Opt::new("PARAMS").long("--minimap2-params").help(&format!(
Expand All @@ -120,6 +125,13 @@ fn add_mapping_options(manual: Manual) -> Manual {
implications if untrusted input is specified. \
[default: none]",
))
.option(Opt::new("PARAMS").long("--rammap-params").help(&format!(
"Extra parameters to provide to rammap. Note \
that usage of this parameter has security \
implications if untrusted input is specified. '{}' \
is always specified to rammap. [default: none]",
&monospace_roff("-x sr -a")
)))
.flag(Flag::new().long("--strobealign-use-index").help(
"Use a pregenerated index (one that has been created with 'strobealign --create-index'). The --reference option should be specified as the original FASTA file i.e. 'ref.fna' not 'ref.fna.r100.sti' [default: not set]",
)),
Expand Down Expand Up @@ -1244,6 +1256,13 @@ Ben J. Woodcroft <benjwoodcroft near gmail.com>
.requires("reference")
.action(clap::ArgAction::SetTrue),
)
.arg(
Arg::new("rammap-params")
.long("rammap-params")
.long("rammap-parameters")
.allow_hyphen_values(true)
.requires("reference"),
)
// TODO: Relax this for autoconcatenation
.arg(
Arg::new("discard-unmapped")
Expand Down Expand Up @@ -1779,6 +1798,13 @@ Ben J. Woodcroft <benjwoodcroft near gmail.com>
.requires("reference")
.action(clap::ArgAction::SetTrue),
)
.arg(
Arg::new("rammap-params")
.long("rammap-params")
.long("rammap-parameters")
.allow_hyphen_values(true)
.requires("reference"),
)
.arg(
Arg::new("discard-unmapped")
.long("discard-unmapped")
Expand Down Expand Up @@ -2156,6 +2182,13 @@ Ben J. Woodcroft <benjwoodcroft near gmail.com>
.long("strobealign-use-index")
.requires("reference")
.action(clap::ArgAction::SetTrue),
)
.arg(
Arg::new("rammap-params")
.long("rammap-params")
.long("rammap-parameters")
.allow_hyphen_values(true)
.requires("reference"),
),
)
.subcommand(
Expand Down
7 changes: 7 additions & 0 deletions src/external_command_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ pub fn check_for_strobealign() {
default_version_check("strobealign", "0.11.0", false, None)
.expect("Failed to find sufficient version of strobealign");
}

pub fn check_for_rammap() {
check_for_external_command_presence_with_which("rammap")
.expect("Failed to find installed rammap");
default_version_check("rammap", "1.1.1", false, None)
.expect("Failed to find sufficient version of rammap");
}
10 changes: 8 additions & 2 deletions src/mapping_index_maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl TemporaryIndexStruct {
| MappingProgram::MINIMAP2_LR_HQ
| MappingProgram::MINIMAP2_NO_PRESET => std::process::Command::new("minimap2"),
MappingProgram::STROBEALIGN => std::process::Command::new("strobealign"),
MappingProgram::RAMMAP => std::process::Command::new("rammap"),
};
match &mapping_program {
MappingProgram::BWA_MEM | MappingProgram::BWA_MEM2 => {
Expand Down Expand Up @@ -101,7 +102,8 @@ impl TemporaryIndexStruct {
MappingProgram::MINIMAP2_NO_PRESET
| MappingProgram::BWA_MEM
| MappingProgram::BWA_MEM2
| MappingProgram::STROBEALIGN => {}
| MappingProgram::STROBEALIGN
| MappingProgram::RAMMAP => {}
};
if let Some(t) = num_threads {
cmd.arg("-t").arg(format!("{t}"));
Expand All @@ -111,6 +113,9 @@ impl TemporaryIndexStruct {
MappingProgram::STROBEALIGN => {
warn!("STROBEALIGN pre-indexing is not supported currently, so skipping index generation.");
}
MappingProgram::RAMMAP => {
warn!("RAMMAP pre-indexing is not supported currently, so skipping index generation.");
}
};
if let Some(params) = index_creation_options {
for s in params.split_whitespace() {
Expand Down Expand Up @@ -207,7 +212,8 @@ pub fn check_reference_existence(reference_path: &str, mapping_program: &Mapping
| MappingProgram::MINIMAP2_PB
| MappingProgram::MINIMAP2_LR_HQ
| MappingProgram::MINIMAP2_NO_PRESET
| MappingProgram::STROBEALIGN => {}
| MappingProgram::STROBEALIGN
| MappingProgram::RAMMAP => {}
};

if !ref_path.exists() {
Expand Down
1 change: 1 addition & 0 deletions src/mapping_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl<'a> MappingParameters<'a> {
| MappingProgram::MINIMAP2_LR_HQ
| MappingProgram::MINIMAP2_NO_PRESET => "minimap2-params",
MappingProgram::STROBEALIGN => "strobealign-params",
MappingProgram::RAMMAP => "rammap-params",
};
let mapping_options = match m.contains_id(mapping_parameters_arg) {
true => {
Expand Down
49 changes: 49 additions & 0 deletions tests/test_cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3239,6 +3239,55 @@ genome6~random_sequence_length_11003 0 0 0
.is_file());
}

#[test]
fn test_make_rammap() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Skip the rammap test where rammap is unavailable

This test is unconditional, but the macOS workflows still run cargo test -- --skip bwa_mem2 --skip strobealign in .github/workflows/test-coverm.yml lines 87 and 120, while rammap was added only under [target.linux-64.dependencies]. In those jobs, selecting --mapper rammap reaches parse_mapping_program and check_for_rammap, so the test fails before mapping because the binary is absent. Please either add a macOS rammap dependency or skip/gate this test on platforms without rammap.

Useful? React with 👍 / 👎.

let td = tempfile::TempDir::new().unwrap();
Assert::main_binary()
.with_args(&[
"make",
"--coupled",
"tests/data/reads_for_seq1_and_seq2.1.fq.gz",
"tests/data/reads_for_seq1_and_seq2.2.fq.gz",
"--reference",
"tests/data/7seqs.fna",
"--mapper",
"rammap",
"--output-directory",
td.path().to_str().unwrap(),
])
.succeeds()
.unwrap();
assert!(td
.path()
.join("7seqs.fna.reads_for_seq1_and_seq2.1.fq.gz.bam")
.is_file());
}

#[test]
fn test_make_rammap_single() {
// Single-end reads must not be consumed as interleaved pairs by
// rammap's fragment mode; exercise the single-end path end to end.
let td = tempfile::TempDir::new().unwrap();
Assert::main_binary()
.with_args(&[
"make",
"--single",
"tests/data/reads_for_seq1_and_seq2.1.fq.gz",
"--reference",
"tests/data/7seqs.fna",
"--mapper",
"rammap",
"--output-directory",
td.path().to_str().unwrap(),
])
.succeeds()
.unwrap();
assert!(td
.path()
.join("7seqs.fna.reads_for_seq1_and_seq2.1.fq.gz.bam")
.is_file());
}

#[test]
fn test_strobealign_pregenerated_index() {
// Generate the index at runtime so the format always matches the installed strobealign version
Expand Down
Loading