diff --git a/src/Edit.jl b/src/Edit.jl index 654b6d5..9ac2012 100644 --- a/src/Edit.jl +++ b/src/Edit.jl @@ -1,24 +1,6 @@ include("edits/Substitution.jl") include("edits/Deletion.jl") - -""" - Insertion{S <: BioSequence} - -Represents the insertion of a `S` into a sequence. The location of the insertion -is stored outside the struct. -""" -struct Insertion{S<:BioSequence} - seq::S - - function Insertion{S}(x::S) where {S<:BioSequence} - isempty(x) && error("Insertion must be at least 1 symbol") - return new(x) - end -end -Insertion(s::BioSequence) = Insertion{typeof(s)}(s) -Base.length(x::Insertion) = length(x.seq) -Base.:(==)(x::Insertion, y::Insertion) = x.seq == y.seq -Base.hash(x::Insertion, h::UInt) = hash(Insertion, hash(x.seq, h)) +include("edits/Insertion.jl") """ Edit{S <: BioSequence, T <: BioSymbol} @@ -77,15 +59,3 @@ function lendiff(edit::Edit) x = edit.x return x isa Substitution ? 0 : (x isa Deletion ? -length(x) : length(x.x)) end - -function _refbases(i::Insertion, reference::S, pos::UInt) where {S<:BioSequence} - return S([reference[pos]]) -end - -function _altbases(i::Insertion, reference::S, pos::UInt) where {S<:BioSequence} - if pos == 1 - return S([i.seq..., reference[pos]]) - else - return S([reference[pos], i.seq...]) - end -end diff --git a/src/edits/Insertion.jl b/src/edits/Insertion.jl new file mode 100644 index 0000000..bba1b25 --- /dev/null +++ b/src/edits/Insertion.jl @@ -0,0 +1,31 @@ +""" + Insertion{S <: BioSequence} + +Represents the insertion of a `S` into a sequence. The location of the insertion +is stored outside the struct. +""" +struct Insertion{S<:BioSequence} + seq::S + + function Insertion{S}(x::S) where {S<:BioSequence} + isempty(x) && error("Insertion must be at least 1 symbol") + return new(x) + end +end +Insertion(s::BioSequence) = Insertion{typeof(s)}(s) + +Base.length(x::Insertion) = length(x.seq) +Base.:(==)(x::Insertion, y::Insertion) = x.seq == y.seq +Base.hash(x::Insertion, h::UInt) = hash(Insertion, hash(x.seq, h)) + +function _refbases(i::Insertion, reference::S, pos::UInt) where {S<:BioSequence} + return S([reference[pos]]) +end + +function _altbases(i::Insertion, reference::S, pos::UInt) where {S<:BioSequence} + if pos == 1 + return S([i.seq..., reference[pos]]) + else + return S([reference[pos], i.seq...]) + end +end