Skip to content

XAM.isproperpair() fix#78

Merged
CiaranOMara merged 1 commit intoBioJulia:developfrom
hanningk:patch-1
Apr 1, 2025
Merged

XAM.isproperpair() fix#78
CiaranOMara merged 1 commit intoBioJulia:developfrom
hanningk:patch-1

Conversation

@hanningk
Copy link
Contributor

Use of XAM.isproperpair(record) returns:

UndefVarError: `PROPER_PAIR` not defined in `XAM`

I think the function should be using FLAG_PROPER_PAIR instead.

This PR implements the following changes:

  • 🐛 Bug fix (A non-breaking change, which fixes an issue).

PROPER_PAIR is not defined - naming mistake?
"""
function isproperpair(record::XAMRecord)::Bool
return flags(record) & PROPER_PAIR == PROPER_PAIR
return flags(record) & FLAG_PROPER_PAIR == FLAG_PROPER_PAIR
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't really make any sense (the previous version didn't either to be clear). The right hand expression will always return true or throw an error. Is it supposed to be FLAG_PROPER_PAIR == PROPER_PAIR or something? That wouldn't fix the error you're seeing but would at least be sensible.

What am I missing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies in advance - I'm new to this.

I figured this was a simple oversight as the other FLAG query functions contain the FLAG_ prefix for their constants. They are defined in the loop starting at line 33 in src/flags.jl

An example for a different FLAG:

function ispaired(record::XAMRecord)::Bool
    return flags(record) & FLAG_PAIRED == FLAG_PAIRED
end

Shouldn't the logic be:

const FLAG_A = UInt8(0x01)      # 00000001
const FLAG_B = UInt8(0x02)      # 00000010
const FLAG_C = UInt8(0x04)      # 00000100

flag_record = FLAG_A | FLAG_C   # 00000101

flag_record & FLAG_A == FLAG_A  # true
flag_record & FLAG_B == FLAG_B  # false 
flag_record & FLAG_C == FLAG_C  # true

I'll look more into how XAM records handle the flag field.

Copy link
Member

Choose a reason for hiding this comment

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

@kescobo The expression breaks down into

return (
    flags(record)    # The integer with the set flags of this record
    &                # bitwise AND
    FLAG_PROPER_PAIR # the constant of the PROPER_PAIR flag (0x002)
    )                # Will be equal to PROPER_PAIR (0x002) if the flag was set in the
    ==               #     record, otherwise won't be
    FLAG_PROPER_PAIR

I think you were mistaking the bitwise AND for logical AND ALSO.

Page 7 of the SAM specification has a pretty detailed explanation and plenty of examples.

@hanningk Thanks for this patch! Good catch! lgtm. Tho I am wondering why we didn't have a test for this in hindsight. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, I see - you're right I didn't realize the precedence was different.

@kescobo kescobo added bug Something isn't working question Further information is requested labels Mar 18, 2025
"""
function isproperpair(record::XAMRecord)::Bool
return flags(record) & PROPER_PAIR == PROPER_PAIR
return flags(record) & FLAG_PROPER_PAIR == FLAG_PROPER_PAIR
Copy link
Member

Choose a reason for hiding this comment

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

@kescobo The expression breaks down into

return (
    flags(record)    # The integer with the set flags of this record
    &                # bitwise AND
    FLAG_PROPER_PAIR # the constant of the PROPER_PAIR flag (0x002)
    )                # Will be equal to PROPER_PAIR (0x002) if the flag was set in the
    ==               #     record, otherwise won't be
    FLAG_PROPER_PAIR

I think you were mistaking the bitwise AND for logical AND ALSO.

Page 7 of the SAM specification has a pretty detailed explanation and plenty of examples.

@hanningk Thanks for this patch! Good catch! lgtm. Tho I am wondering why we didn't have a test for this in hindsight. 🤔

@kescobo
Copy link
Member

kescobo commented Mar 19, 2025

Tho I am wondering why we didn't have a test for this in hindsight. 🤔

Should we add one now?

@CiaranOMara CiaranOMara merged commit 564ecea into BioJulia:develop Apr 1, 2025
31 of 34 checks passed
@CiaranOMara
Copy link
Member

Thank you @hanningk. Your fix was release in v0.4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants