Compare commits

..

4 commits

3 changed files with 14 additions and 8 deletions

View file

@ -7,9 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.2.1] - 2023-01-11
### Added ### Added
- `translate` functionality for `Haplotype`s ([#31](https://github.com/BioJulia/SequenceVariation.jl/pull/31)) - `translate` functionality for `Haplotype`s ([#31](https://github.com/BioJulia/SequenceVariation.jl/pull/31))
- More informative errors when constructing invalid `Haplotype`s ([#34](https://github.com/BioJulia/SequenceVariation.jl/pull/34))
## [0.2.0] - 2023-01-10 ## [0.2.0] - 2023-01-10
@ -67,7 +70,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Variant` constructor to automatically detect mutations from a `BioAlignments.PairwiseAlignment` - `Variant` constructor to automatically detect mutations from a `BioAlignments.PairwiseAlignment`
- Methods to get reference and alternate bases from a `Variation` - Methods to get reference and alternate bases from a `Variation`
[unreleased]: https://github.com/BioJulia/SequenceVariation.jl/compare/v0.2.0...HEAD [unreleased]: https://github.com/BioJulia/SequenceVariation.jl/compare/v0.2.1...HEAD
[0.2.1]: https://github.com/BioJulia/SequenceVariation.jl/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/BioJulia/SequenceVariation.jl/compare/v0.1.4...v0.2.0 [0.2.0]: https://github.com/BioJulia/SequenceVariation.jl/compare/v0.1.4...v0.2.0
[0.1.4]: https://github.com/BioJulia/SequenceVariation.jl/compare/v0.1.3...v0.1.4 [0.1.4]: https://github.com/BioJulia/SequenceVariation.jl/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/BioJulia/SequenceVariation.jl/compare/v0.1.2...v0.1.3 [0.1.3]: https://github.com/BioJulia/SequenceVariation.jl/compare/v0.1.2...v0.1.3

View file

@ -1,7 +1,7 @@
name = "SequenceVariation" name = "SequenceVariation"
uuid = "eef6e190-9969-4f06-a38f-35a110a8fdc8" uuid = "eef6e190-9969-4f06-a38f-35a110a8fdc8"
authors = ["Jakob Nybo Nissen <jakobnybonissen@gmail.com>", "Thomas A. Christensen II <25492070+MillironX@users.noreply.github.com>"] authors = ["Jakob Nybo Nissen <jakobnybonissen@gmail.com>", "Thomas A. Christensen II <25492070+MillironX@users.noreply.github.com>"]
version = "0.2.0" version = "0.2.1"
[deps] [deps]
BioAlignments = "00701ae9-d1dc-5365-b64a-a3a3ebf5695e" BioAlignments = "00701ae9-d1dc-5365-b64a-a3a3ebf5695e"

View file

@ -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(