Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent BAM flag accessor functions #16

Open
jakobnissen opened this issue Dec 16, 2018 · 2 comments
Open

Inconsistent BAM flag accessor functions #16

jakobnissen opened this issue Dec 16, 2018 · 2 comments

Comments

@jakobnissen
Copy link
Member

Inconsistent BAM flag accessor functions

Currently, it's possible to create a spec-compliant BAM record with the following behaviour:

julia> BAM.hasrefname(record)
true

julia> BAM.refname(record)
ERROR: ArgumentError: record is not mapped
Stacktrace:
 [1] checked_refid at /home/jakni/.julia/packages/BioAlignments/AGQde/src/bam/record.jl:162 [inlined]
 [2] refname(::BioAlignments.BAM.Record) at /home/jakni/.julia/packages/BioAlignments/AGQde/src/bam/record.jl:178
 [3] top-level scope at none:0

(on a related note, the function BAM.hasnextrefname simply doesn't work.)

What's going on?

Well, for a subset (which subset, I'm not quite sure) of the flags, there is a corresponding flag accessor isX function and a function hasX. I'm not entirely sure what the purpose of the hasX function are - some of them seem to be exported to BioCore. It might be I'm simply confused as to what the purpose of these functions are, if so, please tell me.
Anyway, the behaviour of these functions are inconsistent and highly unintuitive. For example, ismapped, isprimary and ispositivestrand all raise an error if the record is unfilled, else return a boolean. However isnextmapped returns false with an unfilled record.

Furthermore, hasrefid, hasrefname, hasnextrefid returns whether the record is filled, NOT whether the record is aligned (i.e. actually has a refid etc.). So a valid, unmapped record can have an ID of -1 and still return true when asked if hasrefid. The similar function hasnextrefname, however, actually does check whether it has a valid next reference name.

Also, refname and nextrefname checks for the validity of the corresponding IDs before fetching the name, whereas hasrefname does not (hence the error at the beginning of this issue).

hasposition returns true if the Record is unmapped (i.e. has an invalid position), but hasrightposition returns false in that case.

hasflag seem to me to be meaningless. All BAM records by definition has flags. Currently, it simply returns isfilled(record), and is not used in any other code.

This seems very unsystematic. I propose changing all these functions to follow the following rules:

  • If an existing function hasX returns true, then isX will always return a boolean which is guaranteed to be correct.
  • If an existing function hasX returns false, then isX will always throw an error
  • The functions hasrefid, hasrefname, hasnextrefid and hasnextrefname will return false if the record is unfilled, or if the record/mate is unmapped, else true
  • The functions hasposition, hasnextposition and hasrightposition returns false is the record is unfilled or the record/mate is unmapped, else true
@TransGirlCodes
Copy link
Member

@jakobnissen Did this get fixed to your satisfaction in your PR? I'm trying to figure if this can be closed or if it's still troubling you?

@jakobnissen
Copy link
Member Author

So it turns out it's an operation a little larger than I expected - and I've been short on time due to work the past month or so. Feel free to close this issue or not; I'll create a PR some time when I have the time either way :)

@CiaranOMara CiaranOMara transferred this issue from BioJulia/BioAlignments.jl Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants