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
23 changes: 23 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,26 @@ jobs:
# (lib + tests + benches) with no default features to surface
# regressions at PR time.
run: cargo check --workspace --no-default-features --all-targets

msrv-lockstep:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: rust-version matches the pinned toolchain
# We support exactly the Rust we develop and test on: `rust-version`
# (the published MSRV) is kept identical to the `channel` in
# rust-toolchain.toml. This fails if the two drift, so neither can be
# bumped without the other. Because every other job builds on the
# rust-toolchain.toml channel, keeping them equal means all of CI
# already verifies the MSRV builds -- no separate MSRV build job needed.
run: |
set -euo pipefail
msrv=$(grep -m1 -E '^rust-version' Cargo.toml | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
chan=$(grep -m1 -E '^channel' rust-toolchain.toml | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
echo "Cargo.toml rust-version = $msrv"
echo "rust-toolchain.toml channel = $chan"
if [ "$msrv" != "$chan" ]; then
echo "::error::MSRV ($msrv) and pinned toolchain ($chan) have drifted; keep them in lockstep." >&2
exit 1
fi
9 changes: 8 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ Types: `feat`, `fix`, `build`, `chore`, `ci`, `config`, `docs`, `example`, `perf

## Rust Version

Minimum: 1.87.0 (uses edition 2024)
Minimum supported and pinned build version: 1.93.0 (edition 2024).

fgumi supports exactly the Rust it is developed and tested on: `rust-version`
in `Cargo.toml` (the published MSRV) is kept identical to the `channel` in
`rust-toolchain.toml`, and CI's `msrv-lockstep` job fails if they drift. When
raising the toolchain, bump `rust-version` in the same change and adopt any
idioms the newer compiler unlocks (e.g. let-chains) rather than suppressing the
clippy lints that flag them.

## Allocator

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
[workspace.package]
version = "0.4.0"
edition = "2024"
rust-version = "1.87.0"
rust-version = "1.93.0"
repository = "https://github.com/fulcrumgenomics/fgumi"
license = "MIT"

Expand Down
8 changes: 4 additions & 4 deletions crates/fgumi-bam-io/src/prefetch_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ impl Drop for PrefetchReader {
// guarantee no leak.
self.rx = None;
self.current = None;
if let Some(handle) = self.handle.take() {
if handle.join().is_err() {
log::debug!("fgumi-prefetch producer thread panicked during shutdown");
}
if let Some(handle) = self.handle.take()
&& handle.join().is_err()
{
log::debug!("fgumi-prefetch producer thread panicked during shutdown");
}
}
}
Expand Down
46 changes: 23 additions & 23 deletions crates/fgumi-consensus/src/codec_caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,24 +681,24 @@ impl CodecConsensusCaller {
}

// Downsample if needed
if let Some(max_reads) = self.options.max_reads_per_strand {
if r1_infos.len() > max_reads {
let mut indices: Vec<usize> = (0..r1_infos.len()).collect();
indices.shuffle(&mut self.rng);
indices.truncate(max_reads);
indices.sort_unstable();

let new_r1: Vec<_> = indices
.iter()
.map(|&i| std::mem::replace(&mut r1_infos[i], Self::dummy_info()))
.collect();
let new_r2: Vec<_> = indices
.iter()
.map(|&i| std::mem::replace(&mut r2_infos[i], Self::dummy_info()))
.collect();
r1_infos = new_r1;
r2_infos = new_r2;
}
if let Some(max_reads) = self.options.max_reads_per_strand
&& r1_infos.len() > max_reads
{
let mut indices: Vec<usize> = (0..r1_infos.len()).collect();
indices.shuffle(&mut self.rng);
indices.truncate(max_reads);
indices.sort_unstable();

let new_r1: Vec<_> = indices
.iter()
.map(|&i| std::mem::replace(&mut r1_infos[i], Self::dummy_info()))
.collect();
let new_r2: Vec<_> = indices
.iter()
.map(|&i| std::mem::replace(&mut r2_infos[i], Self::dummy_info()))
.collect();
r1_infos = new_r1;
r2_infos = new_r2;
}

// Phase 3: Filter to most common alignment on ClippedRecordInfo
Expand Down Expand Up @@ -1395,11 +1395,11 @@ impl CodecConsensusCaller {
if let Some(cell_tag) = &self.options.cell_tag {
let cell_tag_bytes: [u8; 2] = [cell_tag.as_ref()[0], cell_tag.as_ref()[1]];
for raw in source_raws {
if let Some(cell_bc) = RawRecordView::new(raw).tags().find_string(cell_tag_bytes) {
if !cell_bc.is_empty() {
self.bam_builder.append_string_tag(cell_tag_bytes, cell_bc);
break;
}
if let Some(cell_bc) = RawRecordView::new(raw).tags().find_string(cell_tag_bytes)
&& !cell_bc.is_empty()
{
self.bam_builder.append_string_tag(cell_tag_bytes, cell_bc);
break;
}
}
}
Expand Down
48 changes: 23 additions & 25 deletions crates/fgumi-consensus/src/duplex_caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,20 +1149,18 @@ impl DuplexConsensusCaller {
builder.append_int_tag(SamTag::BM, ba_depth_min);

// 7. Per-base BA tags if requested and BA strand exists
if produce_per_base_tags {
if let Some(ba) = ba_opt {
builder.append_string_tag(SamTag::BC_BASES, &ba.bases);
if produce_per_base_tags && let Some(ba) = ba_opt {
builder.append_string_tag(SamTag::BC_BASES, &ba.bases);

let ba_depths_i16: Vec<i16> =
ba.depths.iter().map(|&d| i16::try_from(d).unwrap_or(i16::MAX)).collect();
builder.append_i16_array_tag(SamTag::BD_BASES, &ba_depths_i16);
let ba_depths_i16: Vec<i16> =
ba.depths.iter().map(|&d| i16::try_from(d).unwrap_or(i16::MAX)).collect();
builder.append_i16_array_tag(SamTag::BD_BASES, &ba_depths_i16);

let ba_errors_i16: Vec<i16> =
ba.errors.iter().map(|&e| i16::try_from(e).unwrap_or(i16::MAX)).collect();
builder.append_i16_array_tag(SamTag::BE_BASES, &ba_errors_i16);
let ba_errors_i16: Vec<i16> =
ba.errors.iter().map(|&e| i16::try_from(e).unwrap_or(i16::MAX)).collect();
builder.append_i16_array_tag(SamTag::BE_BASES, &ba_errors_i16);

builder.append_phred33_string_tag(SamTag::BQ, &ba.quals);
}
builder.append_phred33_string_tag(SamTag::BQ, &ba.quals);
}

// 8. Duplex consensus tags (cD, cM, cE)
Expand Down Expand Up @@ -1248,21 +1246,21 @@ impl DuplexConsensusCaller {
builder.append_i16_array_tag(t_tag, &t_counts);
}

if let Some(ba) = &consensus.ba_consensus {
if let Some(ba_annot) = &ba.methylation {
if let Some(bm) = crate::methylation::build_mm_tag_no_ml(
&ba.bases,
ba_annot,
false,
methylation_mode,
) {
builder.append_string_tag(SamTag::BM_BASES, bm.as_bytes());
}
let bu = ba_annot.unconverted_counts();
let bt = ba_annot.converted_counts();
builder.append_i16_array_tag(SamTag::BU, &bu);
builder.append_i16_array_tag(SamTag::BT, &bt);
if let Some(ba) = &consensus.ba_consensus
&& let Some(ba_annot) = &ba.methylation
{
if let Some(bm) = crate::methylation::build_mm_tag_no_ml(
&ba.bases,
ba_annot,
false,
methylation_mode,
) {
builder.append_string_tag(SamTag::BM_BASES, bm.as_bytes());
}
let bu = ba_annot.unconverted_counts();
let bt = ba_annot.converted_counts();
builder.append_i16_array_tag(SamTag::BU, &bu);
builder.append_i16_array_tag(SamTag::BT, &bt);
}

// Combined duplex methylation tags (MM/ML/cu/ct)
Expand Down
8 changes: 4 additions & 4 deletions crates/fgumi-consensus/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,10 @@ pub fn filter_read(aux_data: &[u8], thresholds: &FilterThresholds) -> Result<Fil
}

// Check maximum error rate (cE tag — Float)
if let Some(error_rate) = error_rate {
if f64::from(error_rate) > thresholds.max_read_error_rate {
return Ok(FilterResult::ExcessiveErrorRate);
}
if let Some(error_rate) = error_rate
&& f64::from(error_rate) > thresholds.max_read_error_rate
{
return Ok(FilterResult::ExcessiveErrorRate);
}

Ok(FilterResult::Pass)
Expand Down
32 changes: 16 additions & 16 deletions crates/fgumi-consensus/src/vanilla_caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,11 @@ impl VanillaUmiConsensusCaller {

/// Downsamples reads if there are more than `max_reads`
fn downsample_reads(&mut self, mut reads: Vec<RawRecord>) -> Vec<RawRecord> {
if let Some(max_reads) = self.options.max_reads {
if reads.len() > max_reads {
reads.shuffle(&mut self.rng);
reads.truncate(max_reads);
}
if let Some(max_reads) = self.options.max_reads
&& reads.len() > max_reads
{
reads.shuffle(&mut self.rng);
reads.truncate(max_reads);
}
reads
}
Expand Down Expand Up @@ -1423,12 +1423,12 @@ impl VanillaUmiConsensusCaller {
self.bam_builder.append_string_tag(SamTag::MI, umi.as_bytes());

// Cell barcode tag (if configured and present in original reads)
if let Some(cell_tag) = self.options.cell_tag {
if let Some(first_raw) = original_raws.first() {
let tag_bytes = [cell_tag.as_ref()[0], cell_tag.as_ref()[1]];
if let Some(value) = RawRecordView::new(first_raw).tags().find_string(tag_bytes) {
self.bam_builder.append_string_tag(tag_bytes, value);
}
if let Some(cell_tag) = self.options.cell_tag
&& let Some(first_raw) = original_raws.first()
{
let tag_bytes = [cell_tag.as_ref()[0], cell_tag.as_ref()[1]];
if let Some(value) = RawRecordView::new(first_raw).tags().find_string(tag_bytes) {
self.bam_builder.append_string_tag(tag_bytes, value);
}
}

Expand Down Expand Up @@ -2705,11 +2705,11 @@ mod tests {
};

// Merge with previous if same kind
if let Some((prev_kind, prev_len)) = ops.last_mut() {
if *prev_kind == kind {
*prev_len += len;
continue;
}
if let Some((prev_kind, prev_len)) = ops.last_mut()
&& *prev_kind == kind
{
*prev_len += len;
continue;
}
ops.push((kind, len));
}
Expand Down
10 changes: 5 additions & 5 deletions crates/fgumi-raw-bam/src/noodles_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ pub fn simplify_cigar_from_raw(
};

// Coalesce adjacent operations of the same type
if let Some((last_kind, last_len)) = simplified.last_mut() {
if *last_kind == new_kind {
*last_len += op_len;
continue;
}
if let Some((last_kind, last_len)) = simplified.last_mut()
&& *last_kind == new_kind
{
*last_len += op_len;
continue;
}

simplified.push((new_kind, op_len));
Expand Down
66 changes: 33 additions & 33 deletions crates/fgumi-raw-bam/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,27 +769,27 @@ pub fn remove_tag(record: &mut Vec<u8>, tag: impl AsTagBytes) {
pub fn update_string_tag(record: &mut Vec<u8>, tag: impl AsTagBytes, new_value: &[u8]) {
let tag = tag.as_tag_bytes();
let aux_start = aux_data_offset_from_record(record).unwrap_or(record.len());
if aux_start < record.len() {
if let Some((start, end)) = find_tag_bounds(&record[aux_start..], tag) {
let abs_start = aux_start + start;
let abs_end = aux_start + end;
let old_value_len = end - start - 4; // subtract tag(2) + type(1) + NUL(1)
if old_value_len == new_value.len() {
// Same length: overwrite value bytes in-place (no memmove)
let value_start = abs_start + 3; // skip tag(2) + type(1)
record[value_start..value_start + new_value.len()].copy_from_slice(new_value);
} else {
// Different length: splice replacement
let mut replacement = Vec::with_capacity(3 + new_value.len() + 1);
replacement.push(tag[0]);
replacement.push(tag[1]);
replacement.push(b'Z');
replacement.extend_from_slice(new_value);
replacement.push(0);
record.splice(abs_start..abs_end, replacement);
}
return;
if aux_start < record.len()
&& let Some((start, end)) = find_tag_bounds(&record[aux_start..], tag)
{
let abs_start = aux_start + start;
let abs_end = aux_start + end;
let old_value_len = end - start - 4; // subtract tag(2) + type(1) + NUL(1)
if old_value_len == new_value.len() {
// Same length: overwrite value bytes in-place (no memmove)
let value_start = abs_start + 3; // skip tag(2) + type(1)
record[value_start..value_start + new_value.len()].copy_from_slice(new_value);
} else {
// Different length: splice replacement
let mut replacement = Vec::with_capacity(3 + new_value.len() + 1);
replacement.push(tag[0]);
replacement.push(tag[1]);
replacement.push(b'Z');
replacement.extend_from_slice(new_value);
replacement.push(0);
record.splice(abs_start..abs_end, replacement);
}
return;
}
// Tag not found — append
append_string_tag(record, tag, new_value);
Expand All @@ -804,21 +804,21 @@ pub fn update_string_tag(record: &mut Vec<u8>, tag: impl AsTagBytes, new_value:
pub fn update_int_tag(record: &mut Vec<u8>, tag: impl AsTagBytes, value: i32) {
let tag = tag.as_tag_bytes();
let aux_start = aux_data_offset_from_record(record).unwrap_or(record.len());
if aux_start < record.len() {
if let Some((start, end)) = find_tag_bounds(&record[aux_start..], tag) {
let abs_start = aux_start + start;
let abs_end = aux_start + end;
let val_type = record[abs_start + 2];
// If 4-byte integer type, overwrite in-place
if matches!(val_type, b'i' | b'I') && (abs_end - abs_start) == 7 {
record[abs_start + 3..abs_start + 7].copy_from_slice(&value.to_le_bytes());
return;
}
// Different size — remove and re-append
record.drain(abs_start..abs_end);
append_int_tag(record, tag, value);
if aux_start < record.len()
&& let Some((start, end)) = find_tag_bounds(&record[aux_start..], tag)
{
let abs_start = aux_start + start;
let abs_end = aux_start + end;
let val_type = record[abs_start + 2];
// If 4-byte integer type, overwrite in-place
if matches!(val_type, b'i' | b'I') && (abs_end - abs_start) == 7 {
record[abs_start + 3..abs_start + 7].copy_from_slice(&value.to_le_bytes());
return;
}
// Different size — remove and re-append
record.drain(abs_start..abs_end);
append_int_tag(record, tag, value);
return;
}
// Tag not found — append
append_int_tag(record, tag, value);
Expand Down
21 changes: 10 additions & 11 deletions crates/fgumi-sam/src/clipper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,11 @@ impl SamRecordClipper {
*record.cigar_mut() = CigarBuf::from(final_ops);

// Update alignment start position
if ref_bases_clipped > 0 {
if let Some(start_pos) = record.alignment_start() {
if let Some(new_start) = Position::new(usize::from(start_pos) + ref_bases_clipped) {
*record.alignment_start_mut() = Some(new_start);
}
}
if ref_bases_clipped > 0
&& let Some(start_pos) = record.alignment_start()
&& let Some(new_start) = Position::new(usize::from(start_pos) + ref_bases_clipped)
{
*record.alignment_start_mut() = Some(new_start);
}

// Handle sequence and quality updates based on mode
Expand Down Expand Up @@ -2585,11 +2584,11 @@ pub mod cigar_utils {
};

// Coalesce adjacent operations of the same type
if let Some((last_kind, last_len)) = simplified.last_mut() {
if *last_kind == new_kind {
*last_len += len;
continue;
}
if let Some((last_kind, last_len)) = simplified.last_mut()
&& *last_kind == new_kind
{
*last_len += len;
continue;
}

simplified.push((new_kind, len));
Expand Down
Loading
Loading