From 3eab4263982f0af6ba43b23dcdd8f0fa0dfc762c Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:54:43 -0500 Subject: [PATCH] feat: Add SubstitutionEdit type --- src/Edit.jl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Edit.jl b/src/Edit.jl index 1c55dab..62040a6 100644 --- a/src/Edit.jl +++ b/src/Edit.jl @@ -62,6 +62,28 @@ Base.hash(x::InsertionEdit, h::UInt) = hash(InsertionEdit, hash((x.position, x.s BioGenerics.leftposition(i::InsertionEdit) = i.position BioGenerics.rightposition(i::InsertionEdit) = leftposition(i) + 1 +struct SubstitutionEdit{S<:BioSequence,T<:BioSymbol} <: Edit{S,T} + position::UInt + base::T + + function SubstitutionEdit{T}(position::UInt, base::T) where {T<:BioSymbol} + iszero(position) && + function SubstitutionEdit{S,T}( + position::UInt, base::T + ) where {S<:BioSequence,T<:BioSymbol} + return new(position, base) + end +end +Base.length(s::SubstitutionEdit) = 1 +function Base.:(==)(x::SubstitutionEdit, y::SubstitutionEdit) + return x.position == y.position && x.base == y.base +end +function Base.hash(x::SubstitutionEdit, h::UInt) + return hash(SubstitutionEdit, hash((x.position, x.base), h)) +end +BioGenerics.leftposition(s::SubstitutionEdit) = s.position +BioGenerics.rightposition(s::SubstitutionEdit) = leftposition(s) + function Base.parse(::Type{T}, s::AbstractString) where {T<:Edit{Se,Sy}} where {Se,Sy} return parse(T, String(s)) end