Skip to content

Commit

Permalink
Fix Base.read!(::Reader, ::Record) and add tests
Browse files Browse the repository at this point in the history
These functions were not tested directly, and indeed did not work for FASTQ,
due to a typo.
  • Loading branch information
jakobnissen committed Feb 16, 2023
1 parent 14a26ef commit 26a43dd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FASTX"
uuid = "c2308a5c-f048-11e8-3e8a-31650f418d12"
authors = ["Sabrina J. Ward <[email protected]>", "Jakob N. Nissen <[email protected]>"]
version = "2.0.0"
version = "2.0.1"

[weakdeps]
BioSequences = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59"
Expand Down
2 changes: 1 addition & 1 deletion src/fastq/reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
10 changes: 10 additions & 0 deletions test/fasta/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions test/fastq/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

2 comments on commit 26a43dd

@jakobnissen
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/77772

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.0.1 -m "<description of version>" 26a43dda77ee19a5fc2824deaea311aa2ff22ae8
git push origin v2.0.1

Please sign in to comment.