mirror of
https://github.com/MillironX/SequenceVariation.jl.git
synced 2024-11-25 22:59:56 +00:00
Move Insertion-related code to edits/Insertion.jl
This commit is contained in:
parent
b36ab69c72
commit
9f9d0899bd
2 changed files with 32 additions and 31 deletions
32
src/Edit.jl
32
src/Edit.jl
|
@ -1,24 +1,6 @@
|
||||||
include("edits/Substitution.jl")
|
include("edits/Substitution.jl")
|
||||||
include("edits/Deletion.jl")
|
include("edits/Deletion.jl")
|
||||||
|
include("edits/Insertion.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))
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Edit{S <: BioSequence, T <: BioSymbol}
|
Edit{S <: BioSequence, T <: BioSymbol}
|
||||||
|
@ -77,15 +59,3 @@ function lendiff(edit::Edit)
|
||||||
x = edit.x
|
x = edit.x
|
||||||
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(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
|
|
||||||
|
|
31
src/edits/Insertion.jl
Normal file
31
src/edits/Insertion.jl
Normal file
|
@ -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
|
Loading…
Reference in a new issue