Skip to content

Commit bf4aac5

Browse files
authored
Fix ambiguity errors (#235)
Fix ambiguity errors Julia 1.8 introduces LazyString, which is useful in error throwing code. However, due to a blanket implementation BioSequence(::AbstractString) in BioSequences, and a blanket implementation LazyString(::Any) in Base, LazyString(::BioSequence) is ambiguous. Fix that Also fix ambiguity with findall(::Function, ::BioSequence), which was not properly tested. Add tests
1 parent f12d64b commit bf4aac5

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

src/BioSequences.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ function Base.findall(pat, seq::BioSequence; overlap::Bool = DEFAULT_OVERLAP)
256256
return collect(search(pat, seq; overlap))
257257
end
258258

259+
# Fix ambiguity with Base's findall
260+
Base.findall(f::Function, seq::BioSequence) = collect(search(f, seq; overlap=DEFAULT_OVERLAP))
261+
259262
function Base.findall(pat, seq::BioSequence, rng::UnitRange{Int}; overlap::Bool = DEFAULT_OVERLAP)
260263
v = view(seq, rng)
261264
itr = search(pat, v; overlap)

src/biosequence/conversion.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ function (::Type{S})(seq::BioSequence) where {S <: AbstractString}
1111
_string(S, seq, codetype(Alphabet(seq)))
1212
end
1313

14+
@static if VERSION >= v"1.8"
15+
Base.LazyString(seq::BioSequence) = LazyString(string(seq))
16+
end
17+
1418
function _string(::Type{S}, seq::BioSequence, ::AlphabetCode) where {S<:AbstractString}
1519
return S([Char(x) for x in seq])
1620
end

test/longsequences/conversion.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ end
6767
@test_throws Exception LongDNA{4}("ACCNNCATTTTTTAGATXATAG")
6868
@test_throws Exception LongRNA{4}("ACCNNCATTTTTTAGATXATAG")
6969
@test_throws Exception LongAA("ATGHLMY@ZACAGNM")
70+
71+
# LazyString from BioSequence
72+
@static if VERSION >= v"1.8"
73+
@test string(LazyString(aa"MQLLCP")) == "MQLLCP"
74+
end
7075
end
7176

7277
@testset "Construction from vectors" begin

test/longsequences/find.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@
5050
@test findall(DNA_A, dna"GGGG") |> typeof == Vector{Int}
5151
@test findall(ExactSearchQuery(dna"A"), dna"GGGG") |> typeof == Vector{UnitRange{Int}}
5252

53+
@test findall(isequal(DNA_A), dna"ACGTAC") == [1, 5]
54+
@test findall(i -> true, aa"ACGTA") == collect(1:5)
55+
@test findall(i -> true, aa"") == Int[]
56+
@test findall(i -> i == AA_A, rna"AGCA") == Int[]
5357
end

0 commit comments

Comments
 (0)