Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/longsequences/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ for alph in (DNAAlphabet, RNAAlphabet)
end
end

###
### Conversion
###
Base.convert(::Type{T}, seq::T) where {T <: LongSequence} = seq
Base.convert(::Type{T}, seq::T) where {T <: LongSequence{<:NucleicAcidAlphabet}} = seq

function Base.convert(::Type{T}, seq::LongSequence{<:NucleicAcidAlphabet}) where
{T<:LongSequence{<:NucleicAcidAlphabet}}
return T(seq)
end


@inline seq_data_len(s::LongSequence{A}) where A = seq_data_len(A, length(s))

@inline function seq_data_len(::Type{A}, len::Integer) where A <: Alphabet
Expand Down
38 changes: 7 additions & 31 deletions test/longsequences/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,6 @@ end
end
end

@testset "Construction from vectors" begin
function test_vector_construction(A, seq::AbstractString)
T = eltype(A)
xs = T[convert(T, c) for c in seq]
@test LongSequence{A}(xs) == LongSequence{A}(seq)
end

# Construct from abstract vector
LongDNA{4}(0x61:0x64) == LongDNA{4}("ABCD")
LongDNA{4}(0x61:0x64, 3:4) == LongDNA{4}("CD")
LongRNA{2}(0x61:0x61) == LongRNA{2}("A")
LongDNA{4}(Test.GenericString("AGCTMYWK")) == LongDNA{4}("AGCTMYWK")
LongAA(Test.GenericString("KMSPIYT")) == LongAA("KMSPIYT")

for len in [0, 1, 10, 32, 1000]
test_vector_construction(DNAAlphabet{4}, random_dna(len))
test_vector_construction(RNAAlphabet{4}, random_rna(len))
test_vector_construction(AminoAcidAlphabet, random_aa(len))

probs = [0.25, 0.25, 0.25, 0.25, 0.00]
test_vector_construction(DNAAlphabet{2}, random_dna(len, probs))
test_vector_construction(RNAAlphabet{2}, random_rna(len, probs))
end
end

@testset "Encode_copy!" begin
# Note: Other packages use this function, so we need to test it
# Even though this is NOT exported or part of the API in a normal sense
Expand Down Expand Up @@ -131,7 +106,7 @@ end

@testset "Convert to same type" begin
function test_same_conversion(seq)
@test convert(typeof(seq), seq) === seq
@test typeof(seq)(seq) === seq
end

test_same_conversion(random_dna(20))
Expand All @@ -141,7 +116,7 @@ end

@testset "Conversion between 2-bit and 4-bit encodings" begin
function test_conversion(A1, A2, seq)
@test convert(LongSequence{A1}, LongSequence{A2}(seq)) == LongSequence{A1}(seq)
@test LongSequence{A1}(LongSequence{A2}(seq)) == LongSequence{A1}(seq)
end

test_conversion(DNAAlphabet{2}, DNAAlphabet{4}, "")
Expand All @@ -161,8 +136,8 @@ end

# ambiguous nucleotides cannot be stored in 2-bit encoding
EncodeError = BioSequences.EncodeError
@test_throws EncodeError convert(LongSequence{DNAAlphabet{2}}, dna"AN")
@test_throws EncodeError convert(LongSequence{RNAAlphabet{2}}, rna"AN")
@test_throws EncodeError LongSequence{DNAAlphabet{2}}(dna"AN")
@test_throws EncodeError LongSequence{RNAAlphabet{2}}(rna"AN")

# test promotion
a = LongSequence{DNAAlphabet{2}}("ATCG")
Expand All @@ -177,8 +152,8 @@ end
end

@testset "Conversion between RNA and DNA" begin
@test convert(LongRNA{4}, LongDNA{4}("ACGTN")) == rna"ACGUN"
@test convert(LongDNA{4}, LongRNA{4}("ACGUN")) == dna"ACGTN"
@test LongRNA{4}(LongDNA{4}("ACGTN")) == rna"ACGUN"
@test LongDNA{4}(LongRNA{4}("ACGUN")) == dna"ACGTN"
end

@testset "Conversion to Matrices" begin
Expand Down Expand Up @@ -264,3 +239,4 @@ end
@test_throws ArgumentError seqmatrix(LongDNA{4}[], :seq)

end

Loading