* Get the next value in the sequence.
* @return Next value in the sequence. By convention, a NoSuchElementException should be thrown if
* no next exists.
*/
public SAMRecord next() {
SAMRecord rec = wrappedIterator.next();
// Always consolidate the cigar string into canonical form, collapsing zero-length / repeated cigar elements.
// Downstream code (like LocusIteratorByState) cannot necessarily handle non-consolidated cigar strings.
rec.setCigar(AlignmentUtils.consolidateCigar(rec.getCigar()));
// if we are using default quals, check if we need them, and add if necessary.
// 1. we need if reads are lacking or have incomplete quality scores
// 2. we add if defaultBaseQualities has a positive value
if (defaultBaseQualities >= 0) {
byte reads [] = rec.getReadBases();
byte quals [] = rec.getBaseQualities();
if (quals == null || quals.length < reads.length) {
byte new_quals [] = new byte [reads.length];
for (int i=0; i<reads.length; i++)
new_quals[i] = defaultBaseQualities;
rec.setBaseQualities(new_quals);
}
}
// if we are using original quals, set them now if they are present in the record
if ( useOriginalBaseQualities ) {
byte[] originalQuals = rec.getOriginalBaseQualities();
if ( originalQuals != null )
rec.setBaseQualities(originalQuals);
}
return rec;
}