private String getIdentifier(SAMRecord read) { String id = read.getReadName(); if (read.getReadPairedFlag() && read.getSecondOfPairFlag()) { id += "_2"; } return id; }
@Override public boolean nextKeyValue() { long virtPos; while ((virtPos = bci.getFilePointer()) < virtualEnd || (keepReadPairsTogether && readPair && !lastOfPair)) { final SAMRecord r = codec.decode(); if (r == null) return false; // Since we're reading from a BAMRecordCodec directly we have to set the // validation stringency ourselves. if (this.stringency != null) r.setValidationStringency(this.stringency); readPair = r.getReadPairedFlag(); if (readPair) { boolean first = r.getFirstOfPairFlag(), second = r.getSecondOfPairFlag(); // According to the SAM spec (section 1.4) it is possible for pairs to have // multiple segments (i.e. more than two), in which case both `first` and // `second` will be true. boolean firstOfPair = first && !second; lastOfPair = !first && second; // ignore any template that is not first in a pair right at the start of a split // since it will have been returned in the previous split if (virtPos == virtualStart && keepReadPairsTogether && !firstOfPair) { continue; } } if (!overlaps(r)) { continue; } key.set(getKey(r)); record.set(r); return true; } return false; }