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:
Thomas A. Christensen II 2023-01-04 14:16:48 -06:00
parent 4e0d88039d
commit 8a71715cd9
2 changed files with 19 additions and 19 deletions

View file

@ -48,21 +48,21 @@ function Base.show(io::IO, x::Haplotype)
end 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. position is affected by multiple edits.
""" """
function _is_valid(v::Haplotype) function _is_valid(h::Haplotype)
isempty(v.ref) && return false isempty(h.ref) && return false
valid_positions = 1:length(v.ref) valid_positions = 1:length(h.ref)
last_was_insert = false last_was_insert = false
for edit in v.edits for edit in h.edits
pos = edit.pos pos = edit.pos
op = edit.x op = edit.x
# Sanity check: for this to be a valid variant, it must be comprised of valid # Sanity check: for this to be a valid variant, it must be comprised of valid
# variations # 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 # For substitutions we simply do not allow another modification of the same base
if op isa Substitution if op isa Substitution
@ -147,18 +147,18 @@ function Haplotype(
end 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 Base.:(==)(x::Haplotype, y::Haplotype) = x.ref == y.ref && x.edits == y.edits
""" """

View file

@ -171,14 +171,14 @@ function translate(var::Variation{S,T}, aln::PairwiseAlignment{S,S}) where {S,T}
end 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} function variations(h::Haplotype{S,T}) where {S,T}
vs = Vector{Variation{S,T}}(undef, length(_edits(v))) vs = Vector{Variation{S,T}}(undef, length(_edits(h)))
for (i, e) in enumerate(_edits(v)) for (i, e) in enumerate(_edits(h))
vs[i] = Variation{S,T}(reference(v), e) vs[i] = Variation{S,T}(reference(h), e)
end end
return vs return vs
end end