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] 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)