Move Substitution-related code to edits/Substitution.jl

This commit is contained in:
Thomas A. Christensen II 2022-12-30 14:35:55 -06:00
parent 8c2dd271f3
commit ba9f0e8fb1
2 changed files with 21 additions and 19 deletions

View file

@ -1,14 +1,4 @@
"""
Substitution
Represents the presence of a `T` at a given position. The position is stored
outside this struct.
"""
struct Substitution{T<:BioSymbol}
x::T
end
Base.:(==)(x::Substitution, y::Substitution) = x.x == y.x
Base.hash(x::Substitution, h::UInt) = hash(Substitution, hash(x.x, h))
include("edits/Substitution.jl")
"""
Deletion
@ -105,14 +95,6 @@ function lendiff(edit::Edit)
return x isa Substitution ? 0 : (x isa Deletion ? -length(x) : length(x.x))
end
function _refbases(s::Substitution, reference::S, pos::UInt) where {S<:BioSequence}
return S([reference[pos]])
end
function _altbases(s::Substitution, reference::S, pos::UInt) where {S<:BioSequence}
return S([s.x])
end
function _refbases(d::Deletion, reference::S, pos::UInt) where {S<:BioSequence}
if pos == 1
return S(reference[UnitRange{Int}(pos, pos + length(d))])

20
src/edits/Substitution.jl Normal file
View file

@ -0,0 +1,20 @@
"""
Substitution
Represents the presence of a `T` at a given position. The position is stored
outside this struct.
"""
struct Substitution{T<:BioSymbol}
x::T
end
Base.:(==)(x::Substitution, y::Substitution) = x.x == y.x
Base.hash(x::Substitution, h::UInt) = hash(Substitution, hash(x.x, h))
function _refbases(s::Substitution, reference::S, pos::UInt) where {S<:BioSequence}
return S([reference[pos]])
end
function _altbases(s::Substitution, reference::S, pos::UInt) where {S<:BioSequence}
return S([s.x])
end