diff --git a/src/Edit.jl b/src/Edit.jl index 35dc062..654b6d5 100644 --- a/src/Edit.jl +++ b/src/Edit.jl @@ -1,22 +1,5 @@ include("edits/Substitution.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)) +include("edits/Deletion.jl") """ Insertion{S <: BioSequence} @@ -95,22 +78,6 @@ function lendiff(edit::Edit) return x isa Substitution ? 0 : (x isa Deletion ? -length(x) : length(x.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))]) - 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} return S([reference[pos]]) end diff --git a/src/edits/Deletion.jl b/src/edits/Deletion.jl new file mode 100644 index 0000000..b4d4825 --- /dev/null +++ b/src/edits/Deletion.jl @@ -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