From e6f542a368c368e85c3cc411fb4fb84fa694d441 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Mon, 10 Oct 2022 08:51:20 -0500 Subject: [PATCH 1/4] Change alignment getter for BAM.Record to use existing cigar constructor Rather than keep a copy of the BioAlignments cigar constructor embedded in this function, have it call the existing constructor. There may be performance implications for using `cigar` instead of `cigar_rle`, but having a second copy of the constructor here is an antipattern if I've ever seen one, so prioritise stable code over performant code. --- src/bam/record.jl | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/bam/record.jl b/src/bam/record.jl index 6de18a5..bd092e8 100644 --- a/src/bam/record.jl +++ b/src/bam/record.jl @@ -430,27 +430,11 @@ end Get the alignment of `record`. """ function alignment(record::Record)::BioAlignments.Alignment - checkfilled(record) - if !ismapped(record) - return BioAlignments.Alignment(BioAlignments.AlignmentAnchor[]) + if ismapped(record) + return BioAlignments.Alignment(cigar(record), 1, position(record)) end - seqpos = 0 - refpos = position(record) - 1 - anchors = [BioAlignments.AlignmentAnchor(seqpos, refpos, BioAlignments.OP_START)] - for (op, len) in zip(cigar_rle(record)...) - if BioAlignments.ismatchop(op) - seqpos += len - refpos += len - elseif BioAlignments.isinsertop(op) - seqpos += len - elseif BioAlignments.isdeleteop(op) - refpos += len - else - error("operation $(op) is not supported") - end - push!(anchors, BioAlignments.AlignmentAnchor(seqpos, refpos, op)) - end - return BioAlignments.Alignment(anchors) + + return BioAlignments.Alignment(BioAlignments.AlignmentAnchor[]) end function hasalignment(record::Record) From 9720fd0fcd342c10791c7e1b620653d2362845ee Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Mon, 10 Oct 2022 08:45:26 -0500 Subject: [PATCH 2/4] Bump BioAlignments version compat to 3 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 4ff9efb..66cf408 100644 --- a/Project.toml +++ b/Project.toml @@ -17,7 +17,7 @@ TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" [compat] Automa = "0.7, 0.8" BGZFStreams = "0.3.1" -BioAlignments = "2.2" +BioAlignments = "3" BioGenerics = "0.1" BioSequences = "3" FormatSpecimens = "1.1" From f7b9d9fa75ca686c6412fdecd6a012f1dfaa7fcc Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Mon, 10 Oct 2022 08:51:36 -0500 Subject: [PATCH 3/4] Update tests to use new AlignmentAnchor structure --- test/test_bam.jl | 8 ++++---- test/test_sam.jl | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/test_bam.jl b/test/test_bam.jl index beb6d03..1f2e8ac 100644 --- a/test/test_bam.jl +++ b/test/test_bam.jl @@ -79,10 +79,10 @@ @test BAM.flag(record) === UInt16(16) @test BAM.cigar(record) == "27M1D73M" @test BAM.alignment(record) == Alignment([ - AlignmentAnchor( 0, 1, OP_START), - AlignmentAnchor( 27, 28, OP_MATCH), - AlignmentAnchor( 27, 29, OP_DELETE), - AlignmentAnchor(100, 102, OP_MATCH)]) + AlignmentAnchor( 0, 1, 0, OP_START), + AlignmentAnchor( 27, 28, 27, OP_MATCH), + AlignmentAnchor( 27, 29, 28, OP_DELETE), + AlignmentAnchor(100, 102, 101, OP_MATCH)]) @test record["XG"] == 1 @test record["XM"] == 5 @test record["XN"] == 0 diff --git a/test/test_sam.jl b/test/test_sam.jl index 195288d..5496d8d 100644 --- a/test/test_sam.jl +++ b/test/test_sam.jl @@ -104,10 +104,10 @@ @test SAM.flag(record) == 16 @test SAM.cigar(record) == "27M1D73M" @test SAM.alignment(record) == Alignment([ - AlignmentAnchor( 0, 1, OP_START), - AlignmentAnchor( 27, 28, OP_MATCH), - AlignmentAnchor( 27, 29, OP_DELETE), - AlignmentAnchor(100, 102, OP_MATCH)]) + AlignmentAnchor( 0, 1, 0, OP_START), + AlignmentAnchor( 27, 28, 27, OP_MATCH), + AlignmentAnchor( 27, 29, 28, OP_DELETE), + AlignmentAnchor(100, 102, 101, OP_MATCH)]) @test record["XG"] == 1 @test record["XM"] == 5 @test record["XN"] == 0 From 32e3213ee8dc008084e0e3b60a51e3993f8a71dc Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Mon, 10 Oct 2022 16:48:49 -0500 Subject: [PATCH 4/4] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4ef97d..a14f7f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Upgraded to BioAlignments v3 ([#53](https://github.com/BioJulia/XAM.jl/pull/53)) + ## [0.3.0] ## Added