Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 6 additions & 6 deletions src/longsequences/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ end
###
### Conversion
###
Base.convert(::Type{T}, seq::T) where {T <: LongSequence} = seq
Base.convert(::Type{T}, seq::T) where {T <: LongSequence{<:NucleicAcidAlphabet}} = seq
#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
#function Base.convert(::Type{T}, seq::LongSequence{<:NucleicAcidAlphabet}) where
# {T<:LongSequence{<:NucleicAcidAlphabet}}
# return T(seq)
#end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think things need to be commented out, they can just be removed. The diff shows what was there/



@inline seq_data_len(s::LongSequence{A}) where A = seq_data_len(A, length(s))
Expand Down
73 changes: 45 additions & 28 deletions test/longsequences/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,32 @@ 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")
#@testset "Construction from vectors" begin
# function test_vector_construction(A, seq::AbstractString)
# T = eltype(A)
# xs = T[(T, c) for c in seq]
# xs = T[convert(T, c) for c in seq]

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))
# @test LongSequence{A}(xs) == LongSequence{A}(seq)
#end

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
# 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
Expand Down Expand Up @@ -131,7 +133,9 @@ end

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

end

test_same_conversion(random_dna(20))
Expand All @@ -141,7 +145,9 @@ 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)
# @test convert(LongSequence{A1}, LongSequence{A2}(seq)) == LongSequence{A1}(seq)

end

test_conversion(DNAAlphabet{2}, DNAAlphabet{4}, "")
Expand All @@ -161,8 +167,10 @@ 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 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 +185,11 @@ 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 convert(LongRNA{4}, LongDNA{4}("ACGTN")) == rna"ACGUN"
@test LongRNA{4}(LongDNA{4}("ACGTN")) == rna"ACGUN"
@test LongDNA{4}(LongRNA{4}("ACGUN")) == dna"ACGTN"

# @test convert(LongDNA{4}, LongRNA{4}("ACGUN")) == dna"ACGTN"
end

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

end
@testset "Object identity" begin
x = dna"TAG"
y = LongDNA{4}[]
push!(y, x)
@test y[1] === x
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we actually need this?

Loading