f.captureUnmappedBases = true;
f.captureUnmappedScores = true;
List<CramRecord> cramRecords = new ArrayList<CramRecord>(maxRecords);
int prevAlStart = samRecords.get(0).getAlignmentStart();
int index = 0;
QualityScorePreservation preservation = new QualityScorePreservation(
"R8X10-R40X5-N40-U40");
for (SAMRecord samRecord : samRecords) {
CramRecord cramRecord = f.createCramRecord(samRecord);
cramRecord.index = index++;
cramRecord.alignmentStartOffsetFromPreviousRecord = samRecord
.getAlignmentStart() - prevAlStart;
prevAlStart = samRecord.getAlignmentStart();
cramRecords.add(cramRecord);
int refPos = samRecord.getAlignmentStart();
int readPos = 0;
for (CigarElement ce : samRecord.getCigar().getCigarElements()) {
if (ce.getOperator().consumesReferenceBases()) {
for (int i = 0; i < ce.getLength(); i++)
tracks.addCoverage(refPos + i, 1);
}
switch (ce.getOperator()) {
case M:
case X:
case EQ:
for (int i = readPos; i < ce.getLength(); i++) {
byte readBase = samRecord.getReadBases()[readPos + i];
byte refBase = tracks.baseAt(refPos + i);
if (readBase != refBase)
tracks.addMismatches(refPos + i, 1);
}
break;
default:
break;
}
readPos += ce.getOperator().consumesReadBases() ? ce
.getLength() : 0;
refPos += ce.getOperator().consumesReferenceBases() ? ce
.getLength() : 0;
}
preservation.addQualityScores(samRecord, cramRecord, tracks);
}
// mating:
Map<String, CramRecord> mateMap = new TreeMap<String, CramRecord>();
for (CramRecord r : cramRecords) {