Move Deletion-related code to edits/Deletion.jl

This commit is contained in:
Thomas A. Christensen II 2022-12-30 14:38:59 -06:00
parent ba9f0e8fb1
commit b36ab69c72
2 changed files with 35 additions and 34 deletions

View file

@ -1,22 +1,5 @@
include("edits/Substitution.jl") include("edits/Substitution.jl")
include("edits/Deletion.jl")
"""
Deletion
Represents the deletion of N symbols. The location of the deletion is stored
outside this struct
"""
struct Deletion
len::UInt
function Deletion(len::UInt)
iszero(len) && error("Deletion must be at least 1 symbol")
return new(len)
end
end
Deletion(x::Integer) = Deletion(convert(UInt, x))
Base.length(x::Deletion) = Int(x.len)
Base.hash(x::Deletion, h::UInt) = hash(Deletion, hash(x.len, h))
""" """
Insertion{S <: BioSequence} Insertion{S <: BioSequence}
@ -95,22 +78,6 @@ function lendiff(edit::Edit)
return x isa Substitution ? 0 : (x isa Deletion ? -length(x) : length(x.x)) return x isa Substitution ? 0 : (x isa Deletion ? -length(x) : length(x.x))
end end
function _refbases(d::Deletion, reference::S, pos::UInt) where {S<:BioSequence}
if pos == 1
return S(reference[UnitRange{Int}(pos, pos + length(d))])
else
return S(reference[UnitRange{Int}(pos - 1, pos + length(d) - 1)])
end
end
function _altbases(d::Deletion, reference::S, pos::UInt) where {S<:BioSequence}
if pos == 1
return S([reference[pos + 1]])
else
return S([reference[pos - 1]])
end
end
function _refbases(i::Insertion, reference::S, pos::UInt) where {S<:BioSequence} function _refbases(i::Insertion, reference::S, pos::UInt) where {S<:BioSequence}
return S([reference[pos]]) return S([reference[pos]])
end end

34
src/edits/Deletion.jl Normal file
View file

@ -0,0 +1,34 @@
"""
Deletion
Represents the deletion of N symbols. The location of the deletion is stored
outside this struct
"""
struct Deletion
len::UInt
function Deletion(len::UInt)
iszero(len) && error("Deletion must be at least 1 symbol")
return new(len)
end
end
Deletion(x::Integer) = Deletion(convert(UInt, x))
Base.length(x::Deletion) = Int(x.len)
Base.hash(x::Deletion, h::UInt) = hash(Deletion, hash(x.len, h))
function _refbases(d::Deletion, reference::S, pos::UInt) where {S<:BioSequence}
if pos == 1
return S(reference[UnitRange{Int}(pos, pos + length(d))])
else
return S(reference[UnitRange{Int}(pos - 1, pos + length(d) - 1)])
end
end
function _altbases(d::Deletion, reference::S, pos::UInt) where {S<:BioSequence}
if pos == 1
return S([reference[pos + 1]])
else
return S([reference[pos - 1]])
end
end