2020-01-17 18:24:09 +00:00
|
|
|
# BAI
|
|
|
|
# ===
|
|
|
|
#
|
|
|
|
# Index for BAM files.
|
|
|
|
|
|
|
|
|
|
|
|
# An index type for the BAM file format.
|
|
|
|
struct BAI
|
|
|
|
# BGZF file index
|
2020-02-20 10:19:07 +00:00
|
|
|
index::Indexes.BGZFIndex
|
2020-01-17 18:24:09 +00:00
|
|
|
|
|
|
|
# number of unmapped reads
|
|
|
|
n_no_coors::Union{Nothing, Int}
|
|
|
|
end
|
|
|
|
|
|
|
|
"""
|
|
|
|
BAI(filename::AbstractString)
|
|
|
|
|
|
|
|
Load a BAI index from `filename`.
|
|
|
|
"""
|
|
|
|
function BAI(filename::AbstractString)
|
|
|
|
return open(read_bai, filename)
|
|
|
|
end
|
|
|
|
|
|
|
|
"""
|
|
|
|
BAI(input::IO)
|
|
|
|
|
|
|
|
Load a BAI index from `input`.
|
|
|
|
"""
|
|
|
|
function BAI(input::IO)
|
|
|
|
return read_bai(input)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Read a BAI object from `input`.
|
|
|
|
function read_bai(input::IO)
|
|
|
|
# check magic bytes
|
|
|
|
B = read(input, UInt8)
|
|
|
|
A = read(input, UInt8)
|
|
|
|
I = read(input, UInt8)
|
|
|
|
x = read(input, UInt8)
|
|
|
|
if B != UInt8('B') || A != UInt8('A') || I != UInt8('I') || x != 0x01
|
|
|
|
error("input is not a valid BAI file")
|
|
|
|
end
|
|
|
|
|
|
|
|
# read contents
|
|
|
|
n_refs = read(input, Int32)
|
2020-02-20 10:19:07 +00:00
|
|
|
index = Indexes.read_bgzfindex(input, n_refs)
|
2020-01-17 18:24:09 +00:00
|
|
|
if !eof(input)
|
|
|
|
n_no_coors = read(input, UInt64)
|
|
|
|
else
|
|
|
|
n_no_coors = nothing
|
|
|
|
end
|
|
|
|
|
|
|
|
return BAI(index, n_no_coors)
|
|
|
|
end
|