From 9f9d0899bdff26f936bc90e2b99ec2b395bf5071 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:43:55 -0600 Subject: [PATCH] Move Insertion-related code to edits/Insertion.jl --- src/Edit.jl | 32 +------------------------------- src/edits/Insertion.jl | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 31 deletions(-) create mode 100644 src/edits/Insertion.jl 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