1
0
Fork 0
mirror of https://github.com/MillironX/XAM.jl.git synced 2024-11-23 02:09:55 +00:00

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.
This commit is contained in:
Thomas A. Christensen II 2022-10-10 08:51:20 -05:00
parent 946e77a734
commit e6f542a368
Signed by: millironx
GPG key ID: 139C07724802BC5D

View file

@ -430,27 +430,11 @@ end
Get the alignment of `record`.
"""
function alignment(record::Record)::BioAlignments.Alignment
checkfilled(record)
if !ismapped(record)
if ismapped(record)
return BioAlignments.Alignment(cigar(record), 1, position(record))
end
return BioAlignments.Alignment(BioAlignments.AlignmentAnchor[])
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)
end
function hasalignment(record::Record)