/** * Gets a SAMRecord if one is available after marking. This enforces that we return records in the original * coordinate sort order in a stable fashion. * * @return record representing the head of the alignment-start sorted buffer, or null if the head record has not yet been duplicate marked */ private SAMRecord flush() { // Check that there is at least one record in the coordinate-sorted buffer, and that the head record has been through duplicate-marking while (!outputBuffer.isEmpty() && outputBuffer.canEmit()) { // the buffer contains wrapped SAMRecords, which we want to unwrap final SAMRecord record = outputBuffer.next().getRecord(); // If this read is a duplicate, do we want to remove it (continue the loop) or return it for emission? if (!removeDuplicates || !record.getDuplicateReadFlag()) { return record; } } return null; }
@Override public void close() { // close the input and output backingIterator.close(); outputBuffer.close(); isClosed = true; }
/** Returns true if this buffer contains the record at the given index, false otherwise */ public boolean contains(final SamRecordWithOrdinal samRecordWithOrdinal) { return (null != getBlock(samRecordWithOrdinal)); }
@Override public boolean hasNext() { // fast succeed if (null != nextRecord) return true; // We would need to get another record, so check if we can either a record read from the input to the mark queue, or we have more that we should return. // There should be at no time records in the mark queue that are not tracked in the output buffer. return (backingIterator.hasNext() || !outputBuffer.isEmpty()); }
if (outputBuffer.isEmpty()) { return null; outputBuffer.setResultState(samRecordWithOrdinal, false); if(record.isSecondaryOrSupplementary()){ ++metrics.SECONDARY_OR_SUPPLEMENTARY_RDS;
/** Removes the next record from this buffer */ public void remove() { this.next(); }
outputBuffer.setResultState(pair.getSamRecordIndex(), false); // you are not a duplicate! this.otherEndOfNonDuplicateReadEndsSet.remove(current); outputBuffer.setResultState(duplicate.getSamRecordIndex(), true); outputBuffer.setResultState(current.getSamRecordIndex(), false);
public void logMemoryStats(final Log log) { System.gc(); final Runtime runtime = Runtime.getRuntime(); log.info("freeMemory: " + runtime.freeMemory() + "; totalMemory: " + runtime.totalMemory() + "; maxMemory: " + runtime.maxMemory() + "; output buffer size: " + outputBuffer.size() + "; duplicate queue size: " + toMarkQueue.size() ); }
/** * Adds a samRecordWithOrdinal to the output buffer. This does not mean that it is ready to be emitted, since it may need to be * duplicate marked. * * @param samRecordWithOrdinal the index of the record of which to track. * @throws PicardException if the records are added out of order */ private void addRecordToTheOutputBuffer(final SamRecordWithOrdinal samRecordWithOrdinal) throws PicardException { final int recordReferenceIndex = samRecordWithOrdinal.getRecord().getReferenceIndex(); if (recordReferenceIndex < referenceIndex) { throw new PicardException("Records out of order: " + recordReferenceIndex + " < " + referenceIndex); } else if (referenceIndex < recordReferenceIndex) { // new reference, so we need to mark duplicates on the current ones // NB: we will not miss inter-chromosomal alignments since presumably one end will have been mapped to this chromosome and processed, and we do not need the other end to do so. tryPollingTheToMarkQueue(true, null); // update genomic coordinate to the next reference index referenceIndex = recordReferenceIndex; } // add the samRecordWithOrdinal to the output buffer so that it can be tracked outputBuffer.add(samRecordWithOrdinal); }
outputBuffer = new SamRecordTrackingBuffer<SamRecordWithOrdinalAndSetDuplicateReadFlag>(maxRecordsInRam, blockSize, tmpDirs, header, SamRecordWithOrdinalAndSetDuplicateReadFlag.class);
@Override public boolean hasNext() { // fast succeed if (null != nextRecord) return true; // We would need to get another record, so check if we can either a record read from the input to the mark queue, or we have more that we should return. // There should be at no time records in the mark queue that are not tracked in the output buffer. return (backingIterator.hasNext() || !outputBuffer.isEmpty()); }
if (outputBuffer.isEmpty()) { return null; outputBuffer.setResultState(samRecordWithOrdinal, false); if(record.isSecondaryOrSupplementary()){ ++metrics.SECONDARY_OR_SUPPLEMENTARY_RDS;
/** Removes the next record from this buffer */ public void remove() { this.next(); }
outputBuffer.setResultState(pair.getSamRecordIndex(), false); // you are not a duplicate! this.otherEndOfNonDuplicateReadEndsSet.remove(current); outputBuffer.setResultState(duplicate.getSamRecordIndex(), true); outputBuffer.setResultState(current.getSamRecordIndex(), false);
public void logMemoryStats(final Log log) { System.gc(); final Runtime runtime = Runtime.getRuntime(); log.info("freeMemory: " + runtime.freeMemory() + "; totalMemory: " + runtime.totalMemory() + "; maxMemory: " + runtime.maxMemory() + "; output buffer size: " + outputBuffer.size() + "; duplicate queue size: " + toMarkQueue.size() ); }
/** * Adds a samRecordWithOrdinal to the output buffer. This does not mean that it is ready to be emitted, since it may need to be * duplicate marked. * * @param samRecordWithOrdinal the index of the record of which to track. * @throws PicardException if the records are added out of order */ private void addRecordToTheOutputBuffer(final SamRecordWithOrdinal samRecordWithOrdinal) throws PicardException { final int recordReferenceIndex = samRecordWithOrdinal.getRecord().getReferenceIndex(); if (recordReferenceIndex < referenceIndex) { throw new PicardException("Records out of order: " + recordReferenceIndex + " < " + referenceIndex); } else if (referenceIndex < recordReferenceIndex) { // new reference, so we need to mark duplicates on the current ones // NB: we will not miss inter-chromosomal alignments since presumably one end will have been mapped to this chromosome and processed, and we do not need the other end to do so. tryPollingTheToMarkQueue(true, null); // update genomic coordinate to the next reference index referenceIndex = recordReferenceIndex; } // add the samRecordWithOrdinal to the output buffer so that it can be tracked outputBuffer.add(samRecordWithOrdinal); }
outputBuffer = new SamRecordTrackingBuffer<SamRecordWithOrdinalAndSetDuplicateReadFlag>(maxRecordsInRam, blockSize, tmpDirs, header, SamRecordWithOrdinalAndSetDuplicateReadFlag.class);
/** * Gets a SAMRecord if one is available after marking. This enforces that we return records in the original * coordinate sort order in a stable fashion. * * @return record representing the head of the alignment-start sorted buffer, or null if the head record has not yet been duplicate marked */ private SAMRecord flush() { // Check that there is at least one record in the coordinate-sorted buffer, and that the head record has been through duplicate-marking while (!outputBuffer.isEmpty() && outputBuffer.canEmit()) { // the buffer contains wrapped SAMRecords, which we want to unwrap final SAMRecord record = outputBuffer.next().getRecord(); // If this read is a duplicate, do we want to remove it (continue the loop) or return it for emission? if (!removeDuplicates || !record.getDuplicateReadFlag()) { return record; } } return null; }
/** * Add the given SAMRecordIndex to the buffer. The records must be added in order. * @param samRecordWithOrdinal The samRecordWithOrdinal to be added */ public void add(final SamRecordWithOrdinal samRecordWithOrdinal) { if (this.isEmpty()) { this.queueHeadRecordIndex = samRecordWithOrdinal.getRecordOrdinal(); this.queueTailRecordIndex = samRecordWithOrdinal.getRecordOrdinal() - 1; } this.queueTailRecordIndex++; if (samRecordWithOrdinal.getRecordOrdinal() != this.queueTailRecordIndex) { throw new SAMException("The records were added out of order"); } // If necessary, create a new block, using as much ram as available up to its total size if (this.blocks.isEmpty() || !this.blocks.getLast().canAdd()) { // once ram is given to a block, we can't give it to another block (until some is recovered from the head of the queue) final int blockRam = Math.min(this.blockSize, this.availableRecordsInMemory); this.availableRecordsInMemory = this.availableRecordsInMemory - blockRam; final BufferBlock block = new BufferBlock(this.blockSize, blockRam, this.tmpDirs, this.header, samRecordWithOrdinal.getRecordOrdinal()); this.blocks.addLast(block); } this.blocks.getLast().add(samRecordWithOrdinal); }
final ReadEndsForMateCigar pair = this.otherEndOfNonDuplicateReadEndsSet.subSet(current, true, current, true).first(); this.otherEndOfNonDuplicateReadEndsSet.remove(current); outputBuffer.setResultState(pair.getSamRecordIndex(), true); // track that this samRecordWithOrdinal has been through duplicate marking updateDuplicationMetrics(pair, metrics); outputBuffer.setResultState(duplicate.getSamRecordIndex(), true);