From 26a43dda77ee19a5fc2824deaea311aa2ff22ae8 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Thu, 16 Feb 2023 09:43:00 +0100 Subject: [PATCH] Fix Base.read!(::Reader, ::Record) and add tests These functions were not tested directly, and indeed did not work for FASTQ, due to a typo. --- CHANGELOG.md | 4 ++++ Project.toml | 2 +- src/fastq/reader.jl | 2 +- test/fasta/io.jl | 10 ++++++++++ test/fastq/io.jl | 11 +++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ce31c4..b4e2c60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [2.0.1] +### Bugfix +* Fix `Base.read!(::FASTQReader, ::FASTQRecord)` (issue #95) + ## [2.0.0] Version 2 is a near-complete rewrite of FASTX. It brings strives to provide an easier and more consistent API, while also being diff --git a/Project.toml b/Project.toml index 281d304..73f9fd6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "FASTX" uuid = "c2308a5c-f048-11e8-3e8a-31650f418d12" authors = ["Sabrina J. Ward ", "Jakob N. Nissen "] -version = "2.0.0" +version = "2.0.1" [weakdeps] BioSequences = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59" diff --git a/src/fastq/reader.jl b/src/fastq/reader.jl index 92b1be1..2c7a473 100644 --- a/src/fastq/reader.jl +++ b/src/fastq/reader.jl @@ -67,7 +67,7 @@ function Base.iterate(rdr::Reader, state=nothing) end function Base.read!(rdr::Reader, rec::Record) - (cs, f) = _read!(rdr, rdr.record) + (cs, f) = _read!(rdr, rec) if !f cs == 0 && throw(EOFError()) throw(ArgumentError("malformed FASTQ file")) diff --git a/test/fasta/io.jl b/test/fasta/io.jl index 810bb7d..718a1d7 100644 --- a/test/fasta/io.jl +++ b/test/fasta/io.jl @@ -27,6 +27,16 @@ @test records[1] != records[3] close(reader) + # Test Base.read! works + reader = Reader(IOBuffer(">header string\r\nYWBL\nKKL\r\n>another\nAAGTC")) + record = Record() + read!(reader, record) + @test identifier(record) == "header" + @test description(record) == "header string" + @test sequence(record) == "YWBLKKL" + (record, _) = iterate(reader) + @test (description(record), sequence(record)) == ("another", "AAGTC") + # Does not copy on iteration if copy=false # in this case it will iterate the same object which # will just be overwritten. diff --git a/test/fastq/io.jl b/test/fastq/io.jl index 039329d..15ce2e9 100644 --- a/test/fastq/io.jl +++ b/test/fastq/io.jl @@ -29,6 +29,17 @@ @test records[1] != records[3] close(reader) + # Test Base.read! works + reader = Reader(IOBuffer("@HWI:HDR TEXT\nTAGGCTAG\n+\nKM@BCAAC\n@A\nTAG\n+\nJJK\n")) + record = Record() + read!(reader, record) + @test identifier(record) == "HWI:HDR" + @test description(record) == "HWI:HDR TEXT" + @test sequence(record) == "TAGGCTAG" + @test quality(record) == "KM@BCAAC" + (record, _) = iterate(reader) + @test (description(record), sequence(record), quality(record)) == ("A", "TAG", "JJK") + # Does not copy on iteration if copy=false # See comments in equivalent FASTA tests reader = Reader(IOBuffer(copy_str); copy=false)