From ba9f0e8fb155b810771ea6261b6526145d8e6215 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:35:55 -0600 Subject: [PATCH] Move Substitution-related code to edits/Substitution.jl --- src/Edit.jl | 20 +------------------- src/edits/Substitution.jl | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 src/edits/Substitution.jl diff --git a/src/Edit.jl b/src/Edit.jl index ecf2094..35dc062 100644 --- a/src/Edit.jl +++ b/src/Edit.jl @@ -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))]) diff --git a/src/edits/Substitution.jl b/src/edits/Substitution.jl new file mode 100644 index 0000000..e8101da --- /dev/null +++ b/src/edits/Substitution.jl @@ -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