mirror of
https://github.com/MillironX/SequenceVariation.jl.git
synced 2024-11-22 05:19:55 +00:00
Change v::Haplotype
function arguments to h::Haplotype
`v` made sense for a `Variant`, but doesn't for a `Haplotype`, so pretty things up.
This commit is contained in:
parent
4e0d88039d
commit
8a71715cd9
2 changed files with 19 additions and 19 deletions
|
@ -48,21 +48,21 @@ function Base.show(io::IO, x::Haplotype)
|
|||
end
|
||||
|
||||
"""
|
||||
is_valid(v::Haplotype)
|
||||
is_valid(h::Haplotype)
|
||||
|
||||
Validate `v`. `v` is invalid if any of its operations are out of bounds, or the same
|
||||
Validate `h`. `h` is invalid if any of its operations are out of bounds, or the same
|
||||
position is affected by multiple edits.
|
||||
"""
|
||||
function _is_valid(v::Haplotype)
|
||||
isempty(v.ref) && return false
|
||||
valid_positions = 1:length(v.ref)
|
||||
function _is_valid(h::Haplotype)
|
||||
isempty(h.ref) && return false
|
||||
valid_positions = 1:length(h.ref)
|
||||
last_was_insert = false
|
||||
for edit in v.edits
|
||||
for edit in h.edits
|
||||
pos = edit.pos
|
||||
op = edit.x
|
||||
# Sanity check: for this to be a valid variant, it must be comprised of valid
|
||||
# variations
|
||||
_is_valid(Variation(v.ref, edit)) || return false
|
||||
_is_valid(Variation(h.ref, edit)) || return false
|
||||
|
||||
# For substitutions we simply do not allow another modification of the same base
|
||||
if op isa Substitution
|
||||
|
@ -147,18 +147,18 @@ function Haplotype(
|
|||
end
|
||||
|
||||
"""
|
||||
_edits(v::Haplotype)
|
||||
_edits(h::Haplotype)
|
||||
|
||||
Gets the [`Edit`](@ref)s that comprise `v`
|
||||
Gets the [`Edit`](@ref)s that comprise `h`
|
||||
"""
|
||||
_edits(v::Haplotype) = v.edits
|
||||
_edits(h::Haplotype) = h.edits
|
||||
|
||||
"""
|
||||
reference(v::Haplotype)
|
||||
reference(h::Haplotype)
|
||||
|
||||
Gets the reference sequence of `v`.
|
||||
Gets the reference sequence of `h`.
|
||||
"""
|
||||
reference(v::Haplotype) = v.ref
|
||||
reference(h::Haplotype) = h.ref
|
||||
Base.:(==)(x::Haplotype, y::Haplotype) = x.ref == y.ref && x.edits == y.edits
|
||||
|
||||
"""
|
||||
|
|
|
@ -171,14 +171,14 @@ function translate(var::Variation{S,T}, aln::PairwiseAlignment{S,S}) where {S,T}
|
|||
end
|
||||
|
||||
"""
|
||||
variations(v::Haplotype{S,T}) where {S,T}
|
||||
variations(h::Haplotype{S,T}) where {S,T}
|
||||
|
||||
Converts the [`Edit`](@ref)s of `v` into a vector of [`Variation`](@ref)s.
|
||||
Converts the [`Edit`](@ref)s of `h` into a vector of [`Variation`](@ref)s.
|
||||
"""
|
||||
function variations(v::Haplotype{S,T}) where {S,T}
|
||||
vs = Vector{Variation{S,T}}(undef, length(_edits(v)))
|
||||
for (i, e) in enumerate(_edits(v))
|
||||
vs[i] = Variation{S,T}(reference(v), e)
|
||||
function variations(h::Haplotype{S,T}) where {S,T}
|
||||
vs = Vector{Variation{S,T}}(undef, length(_edits(h)))
|
||||
for (i, e) in enumerate(_edits(h))
|
||||
vs[i] = Variation{S,T}(reference(h), e)
|
||||
end
|
||||
return vs
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue