Compare commits

..

No commits in common. "9776d5a31e042845f5a812d4f67b72177603ad90" and "4e6c781c602e4ad944802f37854122080b25c8df" have entirely different histories.

3 changed files with 8 additions and 14 deletions

View file

@ -7,12 +7,9 @@ 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
@ -70,8 +67,7 @@ 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.1...HEAD [unreleased]: https://github.com/BioJulia/SequenceVariation.jl/compare/v0.2.0...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.1" version = "0.2.0"
[deps] [deps]
BioAlignments = "00701ae9-d1dc-5365-b64a-a3a3ebf5695e" BioAlignments = "00701ae9-d1dc-5365-b64a-a3a3ebf5695e"

View file

@ -29,8 +29,7 @@ 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())
valid, message = _is_valid(result) _is_valid(result) || error("TODO") # report what kind of error message?
valid || error(message)
return result return result
end end
@ -63,12 +62,11 @@ 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, "Invalid Variation") _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
pos in valid_positions || pos in valid_positions || return false
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
@ -77,18 +75,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, "Multiple insertions at same position") return false
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, "Deletion out of range") return false
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(