From e84f765357f4ff4fed39260d063f366395561af9 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Tue, 4 Apr 2023 11:32:21 -0500 Subject: [PATCH] feat: Add _cigar_between(::Variation, ::Variation) function Add a function that can calculate the matching bases between two (non-matching) Variations and return a matching (M) CIGAR operation --- src/Variation.jl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Variation.jl b/src/Variation.jl index af9f4df..851650a 100644 --- a/src/Variation.jl +++ b/src/Variation.jl @@ -135,6 +135,26 @@ function _cigar(var::Variation{S,T}) where {S,T} return string(length(mut), cigar_letter) end +""" + _cigar_between(x::Variation{S,T}, y::Variation{S,T}) where {S,T} + +Returns a CIGAR operation for the (assumed) matching bases between `x` and `y`. + +See also [`_cigar`](@ref) +""" +function _cigar_between(x::Variation{S,T}, y::Variation{S,T}) where {S,T} + x == y && return "" + match_length = leftposition(y) - rightposition(x) + if mutation(y) isa Insertion + match_length -= 1 + end + if mutation(y) isa Deletion + match_length += 1 + end + match_length > 0 || return "" + return "$(match_length)M" +end + """ translate(var::Variation{S,T}, aln::PairwiseAlignment{S,S}) where {S,T}