From ee92aad18fa969ecfad604a104ecc4b0c4b697f0 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Tue, 29 Aug 2023 11:15:00 +0200 Subject: [PATCH] Small fixes * Remove the erroneous method Base.:*() with empty Varargs, and make sure that there is at least one `BioSequence`. * Fixup inner constructor for the test type `SimpleSequence` --- src/biosequence/biosequence.jl | 6 +++--- test/biosequences/biosequence.jl | 10 +++++++--- test/biosequences/indexing.jl | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/biosequence/biosequence.jl b/src/biosequence/biosequence.jl index 94217364..f71ea95f 100644 --- a/src/biosequence/biosequence.jl +++ b/src/biosequence/biosequence.jl @@ -170,9 +170,9 @@ Base.repeat(chunk::BioSequence, n::Integer) = join(typeof(chunk), (chunk for i i Base.:^(x::BioSequence, n::Integer) = repeat(x, n) # Concatenation and Base.repeat operators -function Base.:*(chunks::BioSequence...) - T = typeof(first(chunks)) - join(T, chunks) +function Base.:*(fst::BioSequence, rest::BioSequence...) + T = typeof(fst) + join(T, (fst, rest...)) end """ diff --git a/test/biosequences/biosequence.jl b/test/biosequences/biosequence.jl index 48d1dfd9..834c94d9 100644 --- a/test/biosequences/biosequence.jl +++ b/test/biosequences/biosequence.jl @@ -1,18 +1,22 @@ +struct Unsafe end + # Create new biosequence for testing struct SimpleSeq <: BioSequence{RNAAlphabet{2}} x::Vector{UInt} + + SimpleSeq(::Unsafe, x::Vector{UInt}) = new(x) end function SimpleSeq(it) - SimpleSeq([BioSequences.encode(Alphabet(SimpleSeq), convert(RNA, i)) for i in it]) + SimpleSeq(Unsafe(), [BioSequences.encode(Alphabet(SimpleSeq), convert(RNA, i)) for i in it]) end -Base.copy(x::SimpleSeq) = SimpleSeq(copy(x.x)) +Base.copy(x::SimpleSeq) = SimpleSeq(Unsafe(), copy(x.x)) Base.length(x::SimpleSeq) = length(x.x) BioSequences.encoded_data_eltype(::Type{SimpleSeq}) = UInt BioSequences.extract_encoded_element(x::SimpleSeq, i::Integer) = x.x[i] BioSequences.encoded_setindex!(x::SimpleSeq, e::UInt, i::Integer) = x.x[i] = e -SimpleSeq(::UndefInitializer, x::Integer) = SimpleSeq(zeros(UInt, x)) +SimpleSeq(::UndefInitializer, x::Integer) = SimpleSeq(Unsafe(), zeros(UInt, x)) Base.resize!(x::SimpleSeq, len::Int) = (resize!(x.x, len); x) # Not part of the API, just used for testing purposes diff --git a/test/biosequences/indexing.jl b/test/biosequences/indexing.jl index c7d1470c..4cbbee4f 100644 --- a/test/biosequences/indexing.jl +++ b/test/biosequences/indexing.jl @@ -68,7 +68,7 @@ @test_throws BoundsError seq[[5, 3, 13]] seq[[5, 2, 1]] == SimpleSeq([RNA_U, RNA_C, RNA_A]) - seq[1:2:11] == SimpleSeq(seq.x[1:2:11]) + seq[1:2:11] == SimpleSeq(collect(seq)[1:2:11]) end end @@ -99,7 +99,7 @@ end n = count(mask) seq2 = random_simple(n) cp = copy(s) - @test s[mask] == SimpleSeq(cp.x[mask]) + @test s[mask] == SimpleSeq(collect(cp)[mask]) end random_simple(len::Integer) = SimpleSeq(rand([RNA_A, RNA_C, RNA_G, RNA_U], len))