Skip to content

Commit

Permalink
sam/alignment/record/flags: Rename PROPERLY_ALIGNED to PROPERLY_SEGME…
Browse files Browse the repository at this point in the history
…NTED

Closes #236.
  • Loading branch information
zaeleus committed Feb 29, 2024
1 parent 71c8de5 commit 43da5c5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion noodles-bam/examples/bam_flagstat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn count(counts: &mut Counts, record: &bam::Record) -> io::Result<()> {
}

if !flags.is_unmapped() {
if flags.is_properly_aligned() {
if flags.is_properly_segmented() {
counts.proper_pair += 1;
}

Expand Down
9 changes: 9 additions & 0 deletions noodles-sam/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Unreleased

### Deprecated

* sam/alignment/record/flags: Rename `PROPERLY_ALIGNED` to
`PROPERLY_SEGMENTED` ([#236]).

[#236]: https://github.com/zaeleus/noodles/issues/236

## 0.53.0 - 2024-02-15

### Changed
Expand Down
22 changes: 21 additions & 1 deletion noodles-sam/src/alignment/record/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ bitflags::bitflags! {
/// Read is segmented (`0x01`).
const SEGMENTED = 0x01;
/// Each segment in the read is properly aligned (`0x02`).
#[deprecated(since = "0.54.0", note = "Use `PROPERLY_SEGMENTED` instead.")]
const PROPERLY_ALIGNED = 0x02;
/// Each segment in the read is properly aligned (`0x02`).
const PROPERLY_SEGMENTED = 0x02;
/// Read is unmapped (`Ox04`).
const UNMAPPED = 0x04;
/// The mate is unmapped (`0x08`).
Expand Down Expand Up @@ -52,10 +55,25 @@ impl Flags {
/// assert!(Flags::PROPERLY_ALIGNED.is_properly_aligned());
/// assert!(!Flags::UNMAPPED.is_properly_aligned());
/// ```
#[allow(deprecated)]
#[deprecated(since = "0.54.0", note = "Use `Flags::is_properly_segmented` instead.")]
pub fn is_properly_aligned(self) -> bool {
self.contains(Self::PROPERLY_ALIGNED)
}

/// Returns whether the `PROPERLY_SEGMENTED` flag is set.
///
/// # Examples
///
/// ```
/// use noodles_sam::alignment::record::Flags;
/// assert!(Flags::PROPERLY_SEGMENTED.is_properly_segmented());
/// assert!(!Flags::UNMAPPED.is_properly_segmented());
/// ```
pub fn is_properly_segmented(self) -> bool {
self.contains(Self::PROPERLY_SEGMENTED)
}

/// Returns whether the `UNMAPPED` flag is set.
///
/// # Examples
Expand Down Expand Up @@ -199,6 +217,7 @@ impl From<Flags> for u16 {
}
}

#[allow(deprecated)]
#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -208,9 +227,9 @@ mod tests {
let flags = Flags::default();

assert!(flags.is_empty());

assert!(!flags.is_segmented());
assert!(!flags.is_properly_aligned());
assert!(!flags.is_properly_segmented());
assert!(!flags.is_unmapped());
assert!(!flags.is_mate_unmapped());
assert!(!flags.is_reverse_complemented());
Expand All @@ -227,6 +246,7 @@ mod tests {
fn test_contains() {
assert!(Flags::SEGMENTED.is_segmented());
assert!(Flags::PROPERLY_ALIGNED.is_properly_aligned());
assert!(Flags::PROPERLY_SEGMENTED.is_properly_segmented());
assert!(Flags::UNMAPPED.is_unmapped());
assert!(Flags::MATE_UNMAPPED.is_mate_unmapped());
assert!(Flags::REVERSE_COMPLEMENTED.is_reverse_complemented());
Expand Down

0 comments on commit 43da5c5

Please sign in to comment.