mirror of
https://github.com/MillironX/SequenceVariation.jl.git
synced 2024-11-22 05:19:55 +00:00
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.
This commit is contained in:
parent
6a77d6d589
commit
1bbb85153c
2 changed files with 14 additions and 0 deletions
|
@ -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))
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue