diff --git a/src/SequenceVariation.jl b/src/SequenceVariation.jl index 0237a15..fb752c8 100644 --- a/src/SequenceVariation.jl +++ b/src/SequenceVariation.jl @@ -211,6 +211,8 @@ function Variant(ref::S, edits::Vector{Edit{S, T}}) where {S<:BioSequence, T<:Bi Variant{S, T}(ref, edits) end + + function Base.show(io::IO, x::Variant) n = length(x.edits) print(io, summary(x), " with $n edit$(n > 1 ? "s" : ""):") @@ -367,6 +369,11 @@ function Variation(ref::S, edit::AbstractString) where {S<:BioSequence} return Variation{S,T}(ref, e) end +function Variant(ref::S, vars::Vector{Variation{S,T}}) where {S<:BioSequence, T<:BioSymbol} + edits = edit.(vars) + return Variant{S, T}(ref, edits) +end + reference(v::Variation) = v.ref edit(v::Variation) = v.edit mutation(v::Variation) = mutation(edit(v)) diff --git a/test/runtests.jl b/test/runtests.jl index 9982a55..c1eeb37 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -35,6 +35,13 @@ seq1 = ungap!(dna"--ATGCGTGTTAGCAAC--TTATCGCG") seq2 = ungap!(dna"TGATGCGTGT-AGCAACACTTATAGCG") var = Variant(align(seq1, seq2)) +@testset "VariantRoundtrip" begin + for v in variations(var) + @test v in var + @test v in Variant(seq2, [v]) + end +end + @testset "VariationPosition" begin refseq = dna"ACAACTTTATCT" mutseq = dna"ACATCTTTATCT"