I would like to update the sequence of a list of records in a BAM file. Looking at the code of record.jl, data is stored as Vector{UInt64} and some dark magic is used to convert to a DNA sequence.
As it looks very low level, how can I change the sequence ?
Following your suggestion, I managed to make it work with:
function updateRecord(seq::BioSequences.LongDNA{4}, record::BAM.Record)
seqlen = BAM.seqlength(record)
src::Ptr{UInt64} = pointer(record.data, BAM.seqname_length(record) + BAM.n_cigar_op(record, false) * 4 + 1)
for i in 1:length(seq.data)
# Flip high and low nibble
x = (seq.data[i] & 0x0f0f0f0f0f0f0f0f) << 4 | (seq.data[i] & 0xf0f0f0f0f0f0f0f0) >> 4
unsafe_store!(src, x, i)
end
end
Performances are good ! However, this only works for sequence substitution and not deletion/insertion.