From 031751f6b375cad59fc02c8550bbb599ce390666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Sat, 21 Mar 2020 00:41:24 +1100 Subject: [PATCH 1/4] Increment version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 2acfbc3..11649a7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "XAM" uuid = "d759349c-bcba-11e9-07c2-5b90f8f05f7c" authors = ["Kenta Sato ", "Ben J. Ward ", "CiarĂ¡n O'Mara "] -version = "0.2.0" +version = "0.2.1" [deps] Automa = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b" From f6846edfb1eb4da1346756a7a73cd36b4fb2b4a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Sat, 21 Mar 2020 17:16:14 +1100 Subject: [PATCH 2/4] Check header in roundtrip --- test/runtests.jl | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 10ca2d0..30f6914 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -172,15 +172,27 @@ end mktemp() do path, io # copy reader = open(SAM.Reader, filepath) - writer = SAM.Writer(io, header(reader)) + + header_original = header(reader) + + writer = SAM.Writer(io, header_original) + records = SAM.Record[] for record in reader push!(records, record) write(writer, record) end + close(reader) 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 @@ -378,8 +390,11 @@ end else reader = open(BAM.Reader, filepath) 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[] for record in reader push!(records, record) @@ -387,7 +402,14 @@ end end close(reader) 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 From e69c6de5867c94f9a2af5e1df2bdf064896eecdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Sat, 21 Mar 2020 17:18:34 +1100 Subject: [PATCH 3/4] Equality comparators --- src/sam/header.jl | 4 ++++ src/sam/metainfo.jl | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/sam/header.jl b/src/sam/header.jl index 1369e37..668cb59 100644 --- a/src/sam/header.jl +++ b/src/sam/header.jl @@ -14,6 +14,10 @@ function Header() return Header(MetaInfo[]) end +function Base.:(==)(a::Header, b::Header) + return a.metainfo == b.metainfo +end + function Base.copy(header::Header) return Header(header.metainfo) end diff --git a/src/sam/metainfo.jl b/src/sam/metainfo.jl index f40e6ae..f99c952 100644 --- a/src/sam/metainfo.jl +++ b/src/sam/metainfo.jl @@ -12,6 +12,15 @@ mutable struct MetaInfo dictval::Vector{UnitRange{Int}} 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[]) metainfo = MetaInfo(data, 1:0, 1:0, 1:0, UnitRange{Int}[], UnitRange{Int}[]) if !isempty(data) From d0e2560ec4ba5f86aee9f3285304a9f9c16ec3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Sat, 21 Mar 2020 16:49:15 +1100 Subject: [PATCH 4/4] Correct header parsing --- src/sam/readrecord.jl | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/sam/readrecord.jl b/src/sam/readrecord.jl index e7ea75f..b5b3373 100644 --- a/src/sam/readrecord.jl +++ b/src/sam/readrecord.jl @@ -165,6 +165,19 @@ function appendfrom!(dst, dpos, src, spos, n) return dst 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( :mark => :(@mark), :pos1 => :(pos1 = @relpos(p)), @@ -173,22 +186,18 @@ const sam_actions_metainfo = Dict( :metainfo_val => :(metainfo.val = pos1:@relpos(p-1)), :metainfo_dict_key => :(push!(metainfo.dictkey, pos2:@relpos(p-1))), :metainfo_dict_val => :(push!(metainfo.dictval, pos2:@relpos(p-1))), - :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 + :metainfo => action_metainfo ) const sam_actions_header = merge( sam_actions_metainfo, Dict( :countline => :(linenum += 1), + :metainfo => quote + $(action_metainfo) + push!(header, metainfo) + metainfo = MetaInfo() + end, :header => quote finish_header = true @@ -309,13 +318,6 @@ const sam_loopcode_header = quote throw(ArgumentError("malformed metainfo at line $(linenum)")) end - if found_metainfo - push!(header, metainfo) - found_metainfo = false - end - - metainfo = MetaInfo() - if finish_header @goto __return__ end