From 1bbb85153c176ff1fb4c909136b0e8ea8369de9e Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Wed, 20 Jul 2022 17:13:06 -0500 Subject: [PATCH] Add constructor for Variant based on Variations A Variant is a collection of Variations, right? Unfortunately there was no way to convert a collection of Variations into a Variant, so I added one. --- src/SequenceVariation.jl | 7 +++++++ test/runtests.jl | 7 +++++++ 2 files changed, 14 insertions(+) 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"