From aaf3710fbed304f7c8bb843ca6151bcdf8d12b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciara=CC=81n=20O=E2=80=99Mara?= Date: Sat, 27 Mar 2021 00:28:44 +1100 Subject: [PATCH 1/3] Increment version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index beb4170..0c21bf9 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.6" +version = "0.2.7" [deps] Automa = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b" From 64f371e1e479b07d7d14621b0bd23ad040087842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciara=CC=81n=20O=E2=80=99Mara?= Date: Thu, 1 Apr 2021 12:31:44 +1100 Subject: [PATCH 2/3] Adjust for Automa 0.8.1 Defines an unambiguous state machine. https://github.com/BioJulia/Automa.jl/pull/49. --- src/sam/readrecord.jl | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/sam/readrecord.jl b/src/sam/readrecord.jl index 4bc0761..e2d6669 100644 --- a/src/sam/readrecord.jl +++ b/src/sam/readrecord.jl @@ -134,11 +134,10 @@ const sam_machine_metainfo, sam_machine_record, sam_machine_header, sam_machine_ cat(re"\r?", lf) end - header′ = rep(cat(metainfo, newline)) - header′.actions[:exit] = [:header] - header = cat(header′, opt(any() \ cat('@'))) # look ahead + header = rep(cat(metainfo, newline)) + header.actions[:exit] = [:header] - body = rep(cat(record, newline)) + body = record * rep(newline * record) * opt(newline) body.actions[:exit] = [:body] sam = cat(header, body) @@ -200,10 +199,6 @@ const sam_actions_header = merge( finish_header = true - if !eof(stream) - p -= 1 # cancel look-ahead - end - @escape end ) @@ -308,10 +303,6 @@ Automa.Stream.generate_reader( const sam_loopcode_header = quote - if cs < 0 - throw(ArgumentError("malformed metainfo at line $(linenum)")) - end - if finish_header @goto __return__ end From c423694f296075e11317f961561744bb60ec664a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciara=CC=81n=20O=E2=80=99Mara?= Date: Thu, 1 Apr 2021 11:48:02 +1100 Subject: [PATCH 3/3] Cater for blank sam files --- src/sam/reader.jl | 18 +++++++++++------- test/test_sam.jl | 6 ++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/sam/reader.jl b/src/sam/reader.jl index a20fd4c..aa5546e 100644 --- a/src/sam/reader.jl +++ b/src/sam/reader.jl @@ -94,17 +94,21 @@ end Read a `Record` into `rec`; overwriting or adding to existing field values. It is assumed that `rec` is already initialized or empty. """ -function Base.read!(rdr::Reader, rec::Record) +function Base.read!(rdr::Reader, record::Record) - cs, ln, f = readrecord!(rdr.state.stream, rec, (rdr.state.state, rdr.state.linenum)) + cs, ln, found = readrecord!(rdr.state.stream, record, (rdr.state.state, rdr.state.linenum)) rdr.state.state = cs rdr.state.linenum = ln - rdr.state.filled = f + rdr.state.filled = found - if !f - cs == 0 && throw(EOFError()) - throw(ArgumentError("malformed SAM file")) + if found + return record end - return rec + + if cs == 0 || eof(rdr.state.stream) + throw(EOFError()) + end + + throw(ArgumentError("malformed SAM file")) end diff --git a/test/test_sam.jl b/test/test_sam.jl index e669757..c6fadc1 100644 --- a/test/test_sam.jl +++ b/test/test_sam.jl @@ -194,5 +194,11 @@ close(reader) + # Test blank file. + file_sam = joinpath(samdir, "xx#blank.sam") + + records = open(collect, SAM.Reader, file_sam) + @test records == [] + end end