@Override public void prepareToNormalize(BaseInformationRecords.BaseInformationOrBuilder record, int indexOfRecord) { Arrays.fill(propCounts, 0); Arrays.fill(propFractions, 0); List<BaseInformationRecords.NumberWithFrequency> bamFlagFreqs = function.apply(record); int overallSum = 0; for (BaseInformationRecords.NumberWithFrequency bamFlagFreq : bamFlagFreqs) { int flags = bamFlagFreq.getNumber(); int frequency = bamFlagFreq.getFrequency(); // reverser order here so bits and histogram are in the same order: for (int i = BOOL_NUM; i >= 0; i--) { if (getBit(flags, i) == 1) { propCounts[i] += frequency; overallSum += frequency; } } // alignmentCount += frequency; } for (int i = 0; i < BOOL_NUM; i++) { if (overallSum != 0) { propFractions[i] = propCounts[i] / (double) (overallSum); } else { propFractions[i] = 0; } } }