diff --git a/src/Variant.jl b/src/Variant.jl index 0b38153..2ce2aeb 100644 --- a/src/Variant.jl +++ b/src/Variant.jl @@ -45,9 +45,12 @@ function Base.show(io::IO, x::Variant) end end -# Validate: -# A sequence is invalid if any of its operations are out of bounds, or the same position -# is affected by multiple edits. +""" + is_valid(v::Variant) + +Validate `v`. `v` is invalid if any of its operations are out of bounds, or the same +position is affected by multiple edits. +""" function _is_valid(v::Variant) isempty(v.ref) && return false valid_positions = 1:length(v.ref) @@ -141,10 +144,26 @@ function Variant( return Variant(ref, edits) end +""" + _edits(v::Variant) + +Gets the [`Edit`](@ref)s that comprise `v` +""" _edits(v::Variant) = v.edits + +""" + reference(v::Variant) + +Gets the reference sequence of `v`. +""" reference(v::Variant) = v.ref Base.:(==)(x::Variant, y::Variant) = x.ref == y.ref && x.edits == y.edits +""" + reconstruct!(seq::S, x::Variant{S}) where {S} + +Apply the edits in `x` to `seq` and return the mutated sequence +""" function reconstruct!(seq::S, x::Variant{S}) where {S} len = length(x.ref) + sum(edit -> _lendiff(edit), _edits(x)) resize!(seq, len % UInt) diff --git a/src/Variation.jl b/src/Variation.jl index ed25633..9ee1eba 100644 --- a/src/Variation.jl +++ b/src/Variation.jl @@ -118,6 +118,11 @@ function translate(var::Variation{S,T}, aln::PairwiseAlignment{S,S}) where {S,T} end end +""" + variations(v::Variant{S,T}) where {S,T} + +Converts the [`Edit`](@ref)s of `v` into a vector of [`Variation`](@ref)s. +""" function variations(v::Variant{S,T}) where {S,T} vs = Vector{Variation{S,T}}(undef, length(_edits(v))) for (i, e) in enumerate(_edits(v))