Skip to content

Commit

Permalink
Pluralise flag
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed Jan 20, 2024
1 parent 671f522 commit 8ce16c0
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 54 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved Slack link.
- Updated to use [Automa](https://github.com/BioJulia/Automa.jl) v1 ([#65](https://github.com/BioJulia/XAM.jl/pull/65)).
- Pointed the Unit Tests badge at the develop branch.
- Pluralised flag.

### Fixed
- Updated hts-files.md ([#62](https://github.com/BioJulia/XAM.jl/pull/62)).
Expand Down
4 changes: 2 additions & 2 deletions docs/src/man/hts-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ In the above we can see there were 7 sequences in the reference: 5 chromosomes,
The `XAM` package supports the following accessors for `SAM.Record` types.

```@docs
XAM.SAM.flag
XAM.SAM.flags
XAM.SAM.ismapped
XAM.SAM.isprimary
XAM.SAM.refname
Expand All @@ -135,7 +135,7 @@ XAM.SAM.auxdata
The `XAM` package supports the following accessors for `BAM.Record` types.

```@docs
XAM.BAM.flag
XAM.BAM.flags
XAM.BAM.ismapped
XAM.BAM.isprimary
XAM.BAM.refid
Expand Down
2 changes: 1 addition & 1 deletion src/bam/bam.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module BAM
using BioGenerics
using GenomicFeatures
using XAM.SAM
import ..XAM: flag, XAMRecord, XAMReader, XAMWriter,
import ..XAM: flags, XAMRecord, XAMReader, XAMWriter,
ismapped, isprimary, ispositivestrand, isnextmapped #TODO: Deprecate import of flag queries. These were imported to preseve existing API.

import BGZFStreams
Expand Down
14 changes: 7 additions & 7 deletions src/bam/record.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mutable struct Record <: XAMRecord
mapq::UInt8
bin::UInt16
n_cigar_op::UInt16
flag::UInt16
flags::UInt16
l_seq::Int32
next_refid::Int32
next_pos::Int32
Expand Down Expand Up @@ -56,7 +56,7 @@ function Base.:(==)(a::Record, b::Record)
a.mapq == b.mapq &&
a.bin == b.bin &&
a.n_cigar_op == b.n_cigar_op &&
a.flag == b.flag &&
a.flags == b.flags &&
a.l_seq == b.l_seq &&
a.next_refid == b.next_refid &&
a.next_pos == b.next_pos &&
Expand All @@ -83,7 +83,7 @@ function Base.empty!(record::Record)
record.l_read_name = 0
record.mapq = 0
record.bin = 0
record.flag = 0
record.flags = 0
record.n_cigar_op = 0
record.l_seq = 0
record.next_refid = 0
Expand All @@ -100,7 +100,7 @@ function Base.show(io::IO, record::Record)
if isfilled(record)
println(io)
println(io, " template name: ", tempname(record))
println(io, " flag: ", flag(record))
println(io, " flags: ", flags(record))

Check warning on line 103 in src/bam/record.jl

View check run for this annotation

Codecov / codecov/patch

src/bam/record.jl#L103

Added line #L103 was not covered by tests
println(io, " reference ID: ", refid(record))
println(io, " position: ", position(record))
println(io, " mapping quality: ", mappingquality(record))
Expand Down Expand Up @@ -128,12 +128,12 @@ end
# Accessor Fuctions
# -----------------

function flag(record::Record)::UInt16
function flags(record::Record)::UInt16
checkfilled(record)
return record.flag
return record.flags
end

function hasflag(record::Record)
function hasflags(record::Record)

Check warning on line 136 in src/bam/record.jl

View check run for this annotation

Codecov / codecov/patch

src/bam/record.jl#L136

Added line #L136 was not covered by tests
return isfilled(record)
end

Expand Down
46 changes: 23 additions & 23 deletions src/flags.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

"""
flag(record::XAMRecord})::UInt16
flags(record::XAMRecord})::UInt16
Get the bitwise flags of `record`.
The returned value is a `UInt16` of each flag being OR'd together.
Expand All @@ -23,9 +23,9 @@ The possible flags are:
0x0800 supplementary alignment
"""

function flag end
function flags end

# Bitwise flags (or FLAG).
# Bitwise flag (or FLAG).
for (name, bits, doc) in [
(:PAIRED, UInt16(0x001), "the read is paired in sequencing, no matter whether it is mapped in a pair"),
(:PROPER_PAIR, UInt16(0x002), "the read is mapped in a proper pair" ),
Expand All @@ -44,7 +44,7 @@ for (name, bits, doc) in [
docstring = """ $sym
SAM/BAM flag: $doc
See also: [`flag`](@ref)
See also: [`flags`](@ref)
"""
@eval begin
@doc $(docstring) const $(sym) = $(bits)
Expand All @@ -57,7 +57,7 @@ end
Query whether the `record`'s template has multiple segments in sequencing.
"""
function ispaired(record::XAMRecord)::Bool
return flag(record) & FLAG_PAIRED == FLAG_PAIRED
return flags(record) & FLAG_PAIRED == FLAG_PAIRED

Check warning on line 60 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L59-L60

Added lines #L59 - L60 were not covered by tests
end

"""
Expand All @@ -66,7 +66,7 @@ end
Query whether each segment of the `record`'s template properly aligned according to the aligner.
"""
function isproperpair(record::XAMRecord)::Bool
return flag(record) & PROPER_PAIR == PROPER_PAIR
return flags(record) & PROPER_PAIR == PROPER_PAIR

Check warning on line 69 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L68-L69

Added lines #L68 - L69 were not covered by tests
end

"""
Expand All @@ -75,7 +75,7 @@ end
Query whether the `record` is unmapped.
"""
function isunmapped(record::XAMRecord)::Bool
return flag(record) & FLAG_UNMAP == FLAG_UNMAP
return flags(record) & FLAG_UNMAP == FLAG_UNMAP

Check warning on line 78 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L77-L78

Added lines #L77 - L78 were not covered by tests
end

"""
Expand All @@ -84,8 +84,8 @@ end
Query whether the `record` is mapped.
"""
function ismapped(record::XAMRecord)::Bool
# return flag(record) & FLAG_UNMAP == 0
return isfilled(record) && (flag(record) & FLAG_UNMAP == 0)
# return flags(record) & FLAG_UNMAP == 0
return isfilled(record) && (flags(record) & FLAG_UNMAP == 0)
end

"""
Expand All @@ -94,7 +94,7 @@ end
Query whether the `record`'s mate is unmapped.
"""
function ismateunmapped(record::XAMRecord)::Bool
return flag(record) & FLAG_MUNMAP == FLAG_MUNMAP
return flags(record) & FLAG_MUNMAP == FLAG_MUNMAP

Check warning on line 97 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L96-L97

Added lines #L96 - L97 were not covered by tests
end

"""
Expand All @@ -103,7 +103,7 @@ end
Test if the mate/next read of `record` is mapped.
"""
function isnextmapped(record::XAMRecord)::Bool
return flag(record) & FLAG_MUNMAP == 0
return flags(record) & FLAG_MUNMAP == 0

Check warning on line 106 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L105-L106

Added lines #L105 - L106 were not covered by tests
end

"""
Expand All @@ -112,7 +112,7 @@ end
Query whether the `record` is mapped to the reverse strand.
"""
function isreverse(record::XAMRecord)::Bool
return flag(record) & FLAG_REVERSE == FLAG_REVERSE
return flags(record) & FLAG_REVERSE == FLAG_REVERSE

Check warning on line 115 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L114-L115

Added lines #L114 - L115 were not covered by tests
end

"""
Expand All @@ -121,7 +121,7 @@ end
Query whether the `record` is mapped to the forward strand.
"""
function isforward(record::XAMRecord)::Bool
return flag(record) & FLAG_REVERSE == 0
return flags(record) & FLAG_REVERSE == 0
end

"""
Expand All @@ -148,7 +148,7 @@ end
Query whether the `record`'s mate is mapped to the reverse strand.
"""
function ismatereverse(record::XAMRecord)::Bool
return flag(record) & FLAG_MREVERSE == FLAG_MREVERSE
return flags(record) & FLAG_MREVERSE == FLAG_MREVERSE

Check warning on line 151 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L150-L151

Added lines #L150 - L151 were not covered by tests
end

"""
Expand All @@ -157,7 +157,7 @@ end
Query whether the `record` is read1.
"""
function isread1(record::XAMRecord)::Bool
return flag(record) & FLAG_READ1 == FLAG_READ1
return flags(record) & FLAG_READ1 == FLAG_READ1

Check warning on line 160 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L159-L160

Added lines #L159 - L160 were not covered by tests
end

"""
Expand All @@ -166,7 +166,7 @@ end
Query whether the `record` is read2.
"""
function isread2(record::XAMRecord)::Bool
return flag(record) & FLAG_READ2 == FLAG_READ2
return flags(record) & FLAG_READ2 == FLAG_READ2

Check warning on line 169 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L168-L169

Added lines #L168 - L169 were not covered by tests
end

"""
Expand All @@ -175,7 +175,7 @@ end
Query whether the `record` is a secondary alignment.
"""
function issecondaryalignment(record::XAMRecord)::Bool
return flag(record) & FLAG_SECONDARY == FLAG_SECONDARY
return flags(record) & FLAG_SECONDARY == FLAG_SECONDARY

Check warning on line 178 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L177-L178

Added lines #L177 - L178 were not covered by tests
end

"""
Expand All @@ -184,7 +184,7 @@ end
Query whether the `record` is the primary alignment.
"""
function isprimaryalignment(record::XAMRecord)::Bool
return flag(record) & FLAG_SECONDARY == 0
return flags(record) & FLAG_SECONDARY == 0

Check warning on line 187 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L186-L187

Added lines #L186 - L187 were not covered by tests
end

"""
Expand All @@ -193,7 +193,7 @@ end
Query whether the `record` did not pass filters, such as platform/vendor quality controls.
"""
function isqcfail(record::XAMRecord)::Bool
return flag(record) & FLAG_QCFAIL == FLAG_QCFAIL
return flags(record) & FLAG_QCFAIL == FLAG_QCFAIL

Check warning on line 196 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L195-L196

Added lines #L195 - L196 were not covered by tests
end

"""
Expand All @@ -202,7 +202,7 @@ end
Query whether the `record` is a PCR or optical duplicate.
"""
function isduplicate(record::XAMRecord)::Bool
return flag(record) & FLAG_DUP == FLAG_DUP
return flags(record) & FLAG_DUP == FLAG_DUP

Check warning on line 205 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L204-L205

Added lines #L204 - L205 were not covered by tests
end

"""
Expand All @@ -211,16 +211,16 @@ end
Query whether the `record` is a supplementary alignment.
"""
function issupplementaryalignment(record::XAMRecord)::Bool
return flag(record) & FLAG_SUPPLEMENTARY == FLAG_SUPPLEMENTARY
return flags(record) & FLAG_SUPPLEMENTARY == FLAG_SUPPLEMENTARY

Check warning on line 214 in src/flags.jl

View check run for this annotation

Codecov / codecov/patch

src/flags.jl#L213-L214

Added lines #L213 - L214 were not covered by tests
end

"""
isprimary(record::XAMRecord)::Bool
Query whether `record` is a primary line of the read.
This is equivalent to `flag(record) & 0x900 == 0`.
This is equivalent to `flags(record) & 0x900 == 0`.
"""
function isprimary(record::XAMRecord)::Bool
return flag(record) & 0x900 == 0
return flags(record) & 0x900 == 0
end
6 changes: 3 additions & 3 deletions src/sam/readrecord.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const sam_machine_metainfo, sam_machine_record, sam_machine_header, sam_machine_

record = let
qname = onexit!(onenter!(re"[!-?A-~]+", :pos), :record_qname)
flag = onexit!(onenter!(re"[0-9]+", :pos), :record_flag)
flags = onexit!(onenter!(re"[0-9]+", :pos), :record_flags)
rname = onexit!(onenter!(re"\*|[!-()+-<>-~][!-~]*", :pos), :record_rname)
pos = onexit!(onenter!(re"[0-9]+", :pos), :record_pos)
mapq = onexit!(onenter!(re"[0-9]+", :pos), :record_mapq)
Expand All @@ -54,7 +54,7 @@ const sam_machine_metainfo, sam_machine_record, sam_machine_header, sam_machine_
onexit!(onenter!(field, :pos), :record_field)

qname * '\t' *
flag * '\t' *
flags * '\t' *
rname * '\t' *
pos * '\t' *
mapq * '\t' *
Expand Down Expand Up @@ -129,7 +129,7 @@ const sam_actions_record = Dict(
:mark => :(@mark),
:pos => :(pos = @relpos(p)),
:record_qname => :(record.qname = pos:@relpos(p-1)),
:record_flag => :(record.flag = pos:@relpos(p-1)),
:record_flags => :(record.flags = pos:@relpos(p-1)),
:record_rname => :(record.rname = pos:@relpos(p-1)),
:record_pos => :(record.pos = pos:@relpos(p-1)),
:record_mapq => :(record.mapq = pos:@relpos(p-1)),
Expand Down
16 changes: 8 additions & 8 deletions src/sam/record.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mutable struct Record <: XAMRecord

# Mandatory fields.
qname::UnitRange{Int}
flag::UnitRange{Int}
flags::UnitRange{Int}
rname::UnitRange{Int}
pos::UnitRange{Int}
mapq::UnitRange{Int}
Expand Down Expand Up @@ -80,7 +80,7 @@ end
function Base.:(==)(a::Record, b::Record)
return a.filled == b.filled &&
a.qname == b.qname &&
a.flag == b.flag &&
a.flags == b.flags &&
a.rname == b.rname &&
a.pos == b.pos &&
a.mapq == b.mapq &&
Expand All @@ -99,7 +99,7 @@ function Base.show(io::IO, record::Record)
if isfilled(record)
println(io)
println(io, " template name: ", hastempname(record) ? tempname(record) : "<missing>")
println(io, " flag: ", hasflag(record) ? flag(record) : "<missing>")
println(io, " flags: ", hasflags(record) ? flags(record) : "<missing>")
println(io, " reference: ", hasrefname(record) ? refname(record) : "<missing>")
println(io, " position: ", hasposition(record) ? position(record) : "<missing>")
println(io, " mapping quality: ", hasmappingquality(record) ? mappingquality(record) : "<missing>")
Expand Down Expand Up @@ -133,7 +133,7 @@ function Base.copy(record::Record)
copy(record.data),
record.filled,
record.qname,
record.flag,
record.flags,
record.rname,
record.pos,
record.mapq,
Expand All @@ -150,12 +150,12 @@ end
# Accessor Functions
# ------------------

function flag(record::Record)::UInt16
function flags(record::Record)::UInt16
checkfilled(record)
return unsafe_parse_decimal(UInt16, record.data, record.flag)
return unsafe_parse_decimal(UInt16, record.data, record.flags)
end

function hasflag(record::Record)
function hasflags(record::Record)
return isfilled(record)
end

Expand Down Expand Up @@ -545,7 +545,7 @@ end
function Base.empty!(record::Record)
record.filled = 1:0
record.qname = 1:0
record.flag = 1:0
record.flags = 1:0
record.rname = 1:0
record.pos = 1:0
record.mapq = 1:0
Expand Down
2 changes: 1 addition & 1 deletion src/sam/sam.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import BioGenerics.Exceptions: missingerror
import BioGenerics.Automa: State
import BioSequences
import TranscodingStreams: TranscodingStreams, TranscodingStream
import ..XAM: flag, XAMRecord, XAMReader, XAMWriter,
import ..XAM: flags, XAMRecord, XAMReader, XAMWriter,
ismapped, isprimary, ispositivestrand, isnextmapped #TODO: Deprecate import of flag queries. These were imported to preseve existing API.

using Printf: @sprintf
Expand Down
Loading

0 comments on commit 8ce16c0

Please sign in to comment.