mirror of
https://github.com/MillironX/XAM.jl.git
synced 2024-11-27 03:49:54 +00:00
Merge branch 'hotfix/header'
This commit is contained in:
commit
6ae1180cfa
5 changed files with 60 additions and 23 deletions
|
@ -1,7 +1,7 @@
|
||||||
name = "XAM"
|
name = "XAM"
|
||||||
uuid = "d759349c-bcba-11e9-07c2-5b90f8f05f7c"
|
uuid = "d759349c-bcba-11e9-07c2-5b90f8f05f7c"
|
||||||
authors = ["Kenta Sato <bicycle1885@gmail.com>", "Ben J. Ward <ward9250@gmail.com>", "Ciarán O'Mara <Ciaran.OMara@utas.edu.au>"]
|
authors = ["Kenta Sato <bicycle1885@gmail.com>", "Ben J. Ward <ward9250@gmail.com>", "Ciarán O'Mara <Ciaran.OMara@utas.edu.au>"]
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
Automa = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b"
|
Automa = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b"
|
||||||
|
|
|
@ -14,6 +14,10 @@ function Header()
|
||||||
return Header(MetaInfo[])
|
return Header(MetaInfo[])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Base.:(==)(a::Header, b::Header)
|
||||||
|
return a.metainfo == b.metainfo
|
||||||
|
end
|
||||||
|
|
||||||
function Base.copy(header::Header)
|
function Base.copy(header::Header)
|
||||||
return Header(header.metainfo)
|
return Header(header.metainfo)
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,15 @@ mutable struct MetaInfo
|
||||||
dictval::Vector{UnitRange{Int}}
|
dictval::Vector{UnitRange{Int}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Base.:(==)(a::MetaInfo, b::MetaInfo)
|
||||||
|
return a.data == b.data &&
|
||||||
|
a.filled == b.filled &&
|
||||||
|
a.tag == b.tag &&
|
||||||
|
a.val == b.val &&
|
||||||
|
a.dictkey == b.dictkey &&
|
||||||
|
a.dictval == b.dictval
|
||||||
|
end
|
||||||
|
|
||||||
function MetaInfo(data::Vector{UInt8}=UInt8[])
|
function MetaInfo(data::Vector{UInt8}=UInt8[])
|
||||||
metainfo = MetaInfo(data, 1:0, 1:0, 1:0, UnitRange{Int}[], UnitRange{Int}[])
|
metainfo = MetaInfo(data, 1:0, 1:0, 1:0, UnitRange{Int}[], UnitRange{Int}[])
|
||||||
if !isempty(data)
|
if !isempty(data)
|
||||||
|
|
|
@ -165,6 +165,19 @@ function appendfrom!(dst, dpos, src, spos, n)
|
||||||
return dst
|
return dst
|
||||||
end
|
end
|
||||||
|
|
||||||
|
const action_metainfo = quote
|
||||||
|
|
||||||
|
let markpos = @markpos()
|
||||||
|
|
||||||
|
appendfrom!(metainfo.data, 1, data, markpos, length(markpos:p-1))
|
||||||
|
|
||||||
|
metainfo.filled = @relpos(markpos):@relpos(p-1)
|
||||||
|
|
||||||
|
found_metainfo = true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
const sam_actions_metainfo = Dict(
|
const sam_actions_metainfo = Dict(
|
||||||
:mark => :(@mark),
|
:mark => :(@mark),
|
||||||
:pos1 => :(pos1 = @relpos(p)),
|
:pos1 => :(pos1 = @relpos(p)),
|
||||||
|
@ -173,22 +186,18 @@ const sam_actions_metainfo = Dict(
|
||||||
:metainfo_val => :(metainfo.val = pos1:@relpos(p-1)),
|
:metainfo_val => :(metainfo.val = pos1:@relpos(p-1)),
|
||||||
:metainfo_dict_key => :(push!(metainfo.dictkey, pos2:@relpos(p-1))),
|
:metainfo_dict_key => :(push!(metainfo.dictkey, pos2:@relpos(p-1))),
|
||||||
:metainfo_dict_val => :(push!(metainfo.dictval, pos2:@relpos(p-1))),
|
:metainfo_dict_val => :(push!(metainfo.dictval, pos2:@relpos(p-1))),
|
||||||
:metainfo => quote
|
:metainfo => action_metainfo
|
||||||
let markpos = @markpos()
|
|
||||||
|
|
||||||
appendfrom!(metainfo.data, 1, data, markpos, length(markpos:p-1))
|
|
||||||
|
|
||||||
metainfo.filled = @relpos(markpos):@relpos(p-1)
|
|
||||||
|
|
||||||
found_metainfo = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const sam_actions_header = merge(
|
const sam_actions_header = merge(
|
||||||
sam_actions_metainfo,
|
sam_actions_metainfo,
|
||||||
Dict(
|
Dict(
|
||||||
:countline => :(linenum += 1),
|
:countline => :(linenum += 1),
|
||||||
|
:metainfo => quote
|
||||||
|
$(action_metainfo)
|
||||||
|
push!(header, metainfo)
|
||||||
|
metainfo = MetaInfo()
|
||||||
|
end,
|
||||||
:header => quote
|
:header => quote
|
||||||
|
|
||||||
finish_header = true
|
finish_header = true
|
||||||
|
@ -309,13 +318,6 @@ const sam_loopcode_header = quote
|
||||||
throw(ArgumentError("malformed metainfo at line $(linenum)"))
|
throw(ArgumentError("malformed metainfo at line $(linenum)"))
|
||||||
end
|
end
|
||||||
|
|
||||||
if found_metainfo
|
|
||||||
push!(header, metainfo)
|
|
||||||
found_metainfo = false
|
|
||||||
end
|
|
||||||
|
|
||||||
metainfo = MetaInfo()
|
|
||||||
|
|
||||||
if finish_header
|
if finish_header
|
||||||
@goto __return__
|
@goto __return__
|
||||||
end
|
end
|
||||||
|
|
|
@ -172,15 +172,27 @@ end
|
||||||
mktemp() do path, io
|
mktemp() do path, io
|
||||||
# copy
|
# copy
|
||||||
reader = open(SAM.Reader, filepath)
|
reader = open(SAM.Reader, filepath)
|
||||||
writer = SAM.Writer(io, header(reader))
|
|
||||||
|
header_original = header(reader)
|
||||||
|
|
||||||
|
writer = SAM.Writer(io, header_original)
|
||||||
|
|
||||||
records = SAM.Record[]
|
records = SAM.Record[]
|
||||||
for record in reader
|
for record in reader
|
||||||
push!(records, record)
|
push!(records, record)
|
||||||
write(writer, record)
|
write(writer, record)
|
||||||
end
|
end
|
||||||
|
|
||||||
close(reader)
|
close(reader)
|
||||||
close(writer)
|
close(writer)
|
||||||
@test compare_records(open(collect, SAM.Reader, path), records)
|
|
||||||
|
reader = open(SAM.Reader, path)
|
||||||
|
|
||||||
|
@test header(reader) == header_original
|
||||||
|
@test compare_records(collect(reader), records)
|
||||||
|
|
||||||
|
close(reader)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -378,8 +390,11 @@ end
|
||||||
else
|
else
|
||||||
reader = open(BAM.Reader, filepath)
|
reader = open(BAM.Reader, filepath)
|
||||||
end
|
end
|
||||||
writer = BAM.Writer(
|
|
||||||
BGZFStream(path, "w"), BAM.header(reader, fillSQ=isempty(findall(header(reader), "SQ"))))
|
header_original = header(reader)
|
||||||
|
|
||||||
|
writer = BAM.Writer(BGZFStream(path, "w"), BAM.header(reader, fillSQ=isempty(findall(header(reader), "SQ"))))
|
||||||
|
|
||||||
records = BAM.Record[]
|
records = BAM.Record[]
|
||||||
for record in reader
|
for record in reader
|
||||||
push!(records, record)
|
push!(records, record)
|
||||||
|
@ -387,7 +402,14 @@ end
|
||||||
end
|
end
|
||||||
close(reader)
|
close(reader)
|
||||||
close(writer)
|
close(writer)
|
||||||
@test compare_records(open(collect, BAM.Reader, path), records)
|
|
||||||
|
reader = open(BAM.Reader, path)
|
||||||
|
|
||||||
|
@test header(reader) == header_original
|
||||||
|
@test compare_records(collect(reader), records)
|
||||||
|
|
||||||
|
close(reader)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue