From ade9b7e41d2f28bc36850ed4c1e72d7e913e8937 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Fri, 6 May 2022 05:26:49 -0500 Subject: [PATCH] Fix inconsistent Variation positions (#4) * Change Variant constructor to use alignment positions Signed-off-by: Thomas A. Christensen II <25492070+MillironX@users.noreply.github.com> * Add test for positions of Variations Signed-off-by: Thomas A. Christensen II <25492070+MillironX@users.noreply.github.com> --- src/SequenceVariation.jl | 3 ++- test/runtests.jl | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/SequenceVariation.jl b/src/SequenceVariation.jl index 8b4ea6e..b8a630a 100644 --- a/src/SequenceVariation.jl +++ b/src/SequenceVariation.jl @@ -242,7 +242,8 @@ function Variant(aln::PairwiseAlignment{T, T}) where {T <: LongSequence{<:Union{ E = eltype(typeof(ref)) edits = Edit{T, E}[] result = Variant(ref, edits) - refpos = seqpos = 0 + refpos = first(aln.a.aln.anchors).refpos + seqpos = first(aln.a.aln.anchors).seqpos markpos = 0 n_gaps = n_ins = 0 insertion_buffer = E[] diff --git a/test/runtests.jl b/test/runtests.jl index 89947cd..78e4d0b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -32,4 +32,15 @@ const DNA_MODEL = BioAlignments.AffineGapScoreModel(EDNAFULL, gap_open=-25, gap_ align(a::BioSequence, b::BioSequence) = pairalign(GlobalAlignment(), a, b, DNA_MODEL).aln seq1 = ungap!(dna"--ATGCGTGTTAGCAAC--TTATCGCG") seq2 = ungap!(dna"TGATGCGTGT-AGCAACACTTATAGCG") -var = Variant(align(seq1, seq2)) \ No newline at end of file +var = Variant(align(seq1, seq2)) + +@testset "VariationPosition" begin + refseq = dna"ACAACTTTATCT" + mutseq = dna"ACATCTTTATCT" + + read01 = AlignedSequence(mutseq[1:10], Alignment("10M", 1, 1)) + read02 = AlignedSequence(mutseq[3:12], Alignment("10M", 1, 3)) + aln01 = PairwiseAlignment(read01, refseq) + aln02 = PairwiseAlignment(read02, refseq) + @test Variant(aln01).edits == Variant(aln02).edits +end