mirror of
https://github.com/MillironX/SequenceVariation.jl.git
synced 2024-11-21 21:16:05 +00:00
feat: Add DeletionEdit type
This commit is contained in:
parent
1c80158d5b
commit
7afeede80c
1 changed files with 23 additions and 0 deletions
23
src/Edit.jl
23
src/Edit.jl
|
@ -23,6 +23,29 @@ function Base.isless(x::Edit, y::Edit)
|
|||
return leftposition(x) < leftposition(y)
|
||||
end
|
||||
|
||||
struct DeletionEdit{S<:BioSequence,T<:BioSymbol} <: Edit{S,T}
|
||||
position::UInt
|
||||
length::UInt
|
||||
|
||||
function DeletionEdit{S,T}(
|
||||
position::UInt, length::UInt
|
||||
) where {S<:BioSequence,T<:BioSymbol}
|
||||
iszero(position) && error("Deletion cannot be at a position outside the sequence")
|
||||
iszero(length) && error("Deletion must be at least 1 symbol")
|
||||
return new(position, length)
|
||||
end
|
||||
end
|
||||
|
||||
DeletionEdit(x::Integer, y::Integer) = DeletionEdit(convert(UInt, x), convert(UInt, y))
|
||||
|
||||
Base.length(d::DeletionEdit) = Int(d.length)
|
||||
function Base.:(==)(d1::DeletionEdit, d2::DeletionEdit)
|
||||
return d1.position == d2.position && d1.length == d2.length
|
||||
end
|
||||
Base.hash(x::DeletionEdit, h::UInt) = hash(DeletionEdit, hash((x.position, x.length), h))
|
||||
BioGenerics.leftposition(d::DeletionEdit) = d.position
|
||||
BioGenerics.rightposition(d::DeletionEdit) = leftposition(d) + length(d) - 1
|
||||
|
||||
function Base.parse(::Type{T}, s::AbstractString) where {T<:Edit{Se,Sy}} where {Se,Sy}
|
||||
return parse(T, String(s))
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue