Skip to content

Commit

Permalink
Fix iterator constructor and other failing tests (#32)
Browse files Browse the repository at this point in the history
* Fix iterator constructor and other failing tests

* Update test/access.jl

Co-authored-by: Kevin Bonham <[email protected]>

* Update test/access.jl

Co-authored-by: Kevin Bonham <[email protected]>

* Update the compat

* Update test/access.jl

Co-authored-by: Kevin Bonham <[email protected]>

---------

Co-authored-by: Kevin Bonham <[email protected]>
Co-authored-by: Sabrina J. Ward <[email protected]>
  • Loading branch information
3 people authored Apr 11, 2023
1 parent 5dd8f8f commit 0bdf3a8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "0.1.0"
BioSequences = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59"

[compat]
BioSequences = "3"
BioSequences = "3.1.3"
julia = "1.5"

[extras]
Expand Down
6 changes: 4 additions & 2 deletions src/kmer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ function Kmer{A,K,N}(itr) where {A,K,N}
# Construct the head.
head = zero(UInt64)
@inbounds for i in 1:n_head
sym = convert(eltype(Kmer{A,K,N}), itr[i])
(x, next_i) = iterate(itr, i)
sym = convert(eltype(Kmer{A,K,N}), x)
# Encode will throw if it cant encode an element.
head = (head << bits_per_sym) | UInt64(BioSequences.encode(A(), sym))
end
Expand All @@ -167,7 +168,8 @@ function Kmer{A,K,N}(itr) where {A,K,N}
Base.@_inline_meta
body = zero(UInt64)
@inbounds for i in 1:n_per_chunk
sym = convert(eltype(Kmer{A,K,N}), itr[idx[]])
(x, next_idx) = iterate(itr, idx[])
sym = convert(eltype(Kmer{A,K,N}), x)
# Encode will throw if it cant encode an element.
body = (body << bits_per_sym) | UInt64(BioSequences.encode(A(), sym))
idx[] += 1
Expand Down
2 changes: 0 additions & 2 deletions src/revtrans.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
struct Unsafe end

const N_AA = length(AminoAcidAlphabet())

"""
Expand Down
8 changes: 5 additions & 3 deletions test/access.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
@test iterate(DNAKmer("ACTG"), 1) !== nothing
@test iterate(DNAKmer("ACTG"), 4) !== nothing
@test iterate(DNAKmer("ACTG"), 5) === nothing
@test_throws BoundsError iterate(DNAKmer("ACTG"), -1)
@test isnothing(iterate(DNAKmer("ACTG"), -1))
@test iterate(DNAKmer("ACTG"), 0) === nothing

dna_vec = [DNA_A, DNA_C, DNA_T, DNA_G]
@test all([nt === dna_vec[i] for (i, nt) in enumerate(dna_kmer)])
Expand Down Expand Up @@ -64,10 +65,11 @@
@test iterate(RNAKmer("ACUG"), 4) == (RNA_G, 5)


@test iterate(RNAKmer("ACUG"), 1) !== nothing
@test iterate(RNAKmer("ACUG"), 1) !== nothing
@test iterate(RNAKmer("ACUG"), 4) !== nothing
@test iterate(RNAKmer("ACUG"), 5) === nothing
@test_throws BoundsError iterate(RNAKmer("ACUG"), -1)
@test iterate(RNAKmer("ACUG"), -1) === nothing
@test iterate(RNAKmer("ACUG"), 0) === nothing

rna_vec = [RNA_A, RNA_C, RNA_U, RNA_G]
@test all([nt === rna_vec[i] for (i, nt) in enumerate(rna_kmer)])
Expand Down
3 changes: 3 additions & 0 deletions test/conversion.jl → test/construction_and_conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ global reps = 10
@test DNAKmer(DNA_G, DNA_C, DNA_T) == Kmer("GCT")
@test RNAKmer(RNA_G, RNA_U, RNA_C, RNA_U) == Kmer("GUCU")

# creation from iterator
@test Kmers.kmertype(Kmer{DNAAlphabet{2},31})((i for i in rand(ACGT, 31))) isa Kmers.kmertype(Kmer{DNAAlphabet{2},31})

# Check that kmers in strings survive round trip conversion:
# String → Kmer → String
function check_string_construction(::Type{T}, seq::AbstractString) where {T<:Kmer}
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include("utils.jl")

if GROUP == "BioSequences" || GROUP == "All"
include("biosequences_interface.jl")
include("conversion.jl")
include("construction_and_conversion.jl")
include("comparisons.jl")
include("length.jl")
include("access.jl")
Expand Down

0 comments on commit 0bdf3a8

Please sign in to comment.