mirror of
https://github.com/MillironX/SequenceVariation.jl.git
synced 2024-11-22 05:19:55 +00:00
Add more informative errors to _is_valid
This commit is contained in:
parent
4e6c781c60
commit
2fa5782719
1 changed files with 8 additions and 6 deletions
|
@ -29,7 +29,8 @@ function Haplotype{S,T}(
|
||||||
) where {S<:BioSequence,T<:BioSymbol}
|
) where {S<:BioSequence,T<:BioSymbol}
|
||||||
sort!(edits; by=x -> x.pos)
|
sort!(edits; by=x -> x.pos)
|
||||||
result = Haplotype{S,T}(ref, edits, Unsafe())
|
result = Haplotype{S,T}(ref, edits, Unsafe())
|
||||||
_is_valid(result) || error("TODO") # report what kind of error message?
|
valid, message = _is_valid(result)
|
||||||
|
valid || error(message)
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -62,11 +63,12 @@ function _is_valid(h::Haplotype)
|
||||||
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(h.ref, edit)) || return false
|
_is_valid(Variation(h.ref, edit)) || return (false, "Invalid Variation")
|
||||||
|
|
||||||
# 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
|
||||||
pos in valid_positions || return false
|
pos in valid_positions ||
|
||||||
|
return (false, "Multiple modifications at same position")
|
||||||
valid_positions = (first(valid_positions) + 1):last(valid_positions)
|
valid_positions = (first(valid_positions) + 1):last(valid_positions)
|
||||||
last_was_insert = false
|
last_was_insert = false
|
||||||
# Insertions affect 0 reference bases, so it does not modify the valid positions
|
# Insertions affect 0 reference bases, so it does not modify the valid positions
|
||||||
|
@ -75,18 +77,18 @@ function _is_valid(h::Haplotype)
|
||||||
elseif op isa Insertion
|
elseif op isa Insertion
|
||||||
pos in
|
pos in
|
||||||
((first(valid_positions) - 1 + last_was_insert):(last(valid_positions) + 1)) ||
|
((first(valid_positions) - 1 + last_was_insert):(last(valid_positions) + 1)) ||
|
||||||
return false
|
return (false, "Multiple insertions at same position")
|
||||||
last_was_insert = true
|
last_was_insert = true
|
||||||
# Deletions obviously invalidate the reference bases that are deleted.
|
# Deletions obviously invalidate the reference bases that are deleted.
|
||||||
elseif op isa Deletion
|
elseif op isa Deletion
|
||||||
len = length(op)
|
len = length(op)
|
||||||
pos in (first(valid_positions):(last(valid_positions) - len + 1)) ||
|
pos in (first(valid_positions):(last(valid_positions) - len + 1)) ||
|
||||||
return false
|
return (false, "Deletion out of range")
|
||||||
valid_positions = (first(valid_positions) + len):last(valid_positions)
|
valid_positions = (first(valid_positions) + len):last(valid_positions)
|
||||||
last_was_insert = false
|
last_was_insert = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return (true, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
function Haplotype(
|
function Haplotype(
|
||||||
|
|
Loading…
Reference in a new issue