diff --git a/Project.toml b/Project.toml index 6bb07ff..28dacf5 100644 --- a/Project.toml +++ b/Project.toml @@ -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] diff --git a/src/kmer.jl b/src/kmer.jl index 69d5a1d..b71a57a 100644 --- a/src/kmer.jl +++ b/src/kmer.jl @@ -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 @@ -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 diff --git a/src/revtrans.jl b/src/revtrans.jl index 4e8dc2e..e4ebedf 100644 --- a/src/revtrans.jl +++ b/src/revtrans.jl @@ -1,5 +1,3 @@ -struct Unsafe end - const N_AA = length(AminoAcidAlphabet()) """ diff --git a/test/access.jl b/test/access.jl index e5806c4..aa4a35e 100644 --- a/test/access.jl +++ b/test/access.jl @@ -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)]) @@ -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)]) diff --git a/test/conversion.jl b/test/construction_and_conversion.jl similarity index 98% rename from test/conversion.jl rename to test/construction_and_conversion.jl index b15109c..567042c 100644 --- a/test/conversion.jl +++ b/test/construction_and_conversion.jl @@ -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} diff --git a/test/runtests.jl b/test/runtests.jl index cb5fb05..4260278 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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")