Skip to content

Commit

Permalink
Fix bug in zero_offset! called when materializing seqview (#261)
Browse files Browse the repository at this point in the history
When materializing a seqview, a slice of the underlying buffer is copied
directly, for efficiency. Since the bytes may be placed in the buffer with a
nonzero offset, the optimised zero_offset! is called.
However, a bug in zero_offset! meant that it did not behave correctly when the
offset was already zero.
  • Loading branch information
jakobnissen authored Nov 28, 2022
1 parent db8a692 commit 1cfea08
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BioSequences"
uuid = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59"
authors = ["Sabrina Jaye Ward <[email protected]>", "Jakob Nissen <[email protected]>"]
version = "3.1.1"
version = "3.1.2"

[deps]
BioSymbols = "3c28c6f8-a34d-59c4-9654-267d177fcfa9"
Expand Down
1 change: 1 addition & 0 deletions src/longsequences/transformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ end

@inline function zero_offset!(seq::LongSequence{A}, offs::UInt) where A <: Alphabet
isempty(seq) && return seq
iszero(offs) && return seq
rshift = offs
lshift = 64 - rshift
len = length(seq.data)
Expand Down
19 changes: 19 additions & 0 deletions test/longsequences/seqview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ end
@test String(seq) == "ANKYH"
end

# Added after issue 260
@testset "Random construction" begin
for i in 1:100
seq = randdnaseq(rand(15:65))
begin_ = min(lastindex(seq), rand(10:30))
range = begin_:min(lastindex(seq), begin_ + rand(0:40))
seq2 = view(seq, range)
@test seq2 isa LongSubSeq{typeof(Alphabet(seq))}
seq3 = LongSequence(seq2)
@test typeof(seq) == typeof(seq3)
@test seq[range] == seq2 == seq3
end

# See issue 260
seq = dna"CATTTTTTTTTTTTTTT"
seq2 = LongSequence(LongSubSeq(seq, 1:17))
@test seq == seq2
end

@testset "Conversion" begin
seq = LongDNA{4}("TAGTATCGAAMYCGNA")
v = LongSubSeq(seq, 3:14)
Expand Down

2 comments on commit 1cfea08

@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/72990

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 v3.1.2 -m "<description of version>" 1cfea08e9f08ce8a2282a1e2abfebb1773a8fb77
git push origin v3.1.2

Please sign in to comment.