I believe $GeneticVariation.DEFAULT_TRANS
should be $(GeneticVariation.DEFAULT_TRANS)
. You’re interpolating the module, but not the constant. This makes the allocations go away in both functions.
My test code:
using BioSequences
using BioSequences.GeneticCode
using GeneticVariation
using BenchmarkTools
const CDN = Union{BioSequences.DNACodon, BioSequences.RNACodon}
const DEFAULT_TRANS = BioSequences.ncbi_trans_table[1]
const CDN_POS_MASKS = (0xFFFFFFFFFFFFFFFC, 0xFFFFFFFFFFFFFFF3, 0xFFFFFFFFFFFFFFCF)
function expected_NG86_min(codon::C, k::Float64, code::GeneticCode) where {C <: CDN}
cdn_bits = UInt64(codon)
S = N = 0.0
for (pos, msk) in enumerate(CDN_POS_MASKS)
@inbounds for base in 0:3
# Create the neighbor codon.
ins = base << (2 * (pos - 1))
neighbor = C((cdn_bits & msk) | ins)
S += 1.0
N += 1.0
end
end
normalization = (N + S) / 3
return (S / normalization), (N / normalization)
end
cdn = DNACodon(0x000000000000000) # a test codon to benchmark and look at allocation.
@benchmark expected_NG86_min($cdn, 1.0, $(GeneticVariation.DEFAULT_TRANS))