Skip to content

Commit

Permalink
more CRAMIterator cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthibault79 committed Jan 16, 2019
1 parent 814da07 commit b24ac12
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/main/java/htsjdk/samtools/CRAMIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import htsjdk.samtools.cram.structure.CramHeader;
import htsjdk.samtools.cram.structure.Slice;
import htsjdk.samtools.seekablestream.SeekableStream;
import htsjdk.samtools.util.Log;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -39,7 +38,6 @@
import htsjdk.samtools.cram.CRAMException;

public class CRAMIterator implements SAMRecordIterator {
private static final Log log = Log.getInstance(CRAMIterator.class);
private final CountingInputStream countingInputStream;
private final CramHeader cramHeader;
private final ArrayList<SAMRecord> records;
Expand All @@ -63,8 +61,7 @@ public ValidationStringency getValidationStringency() {
return validationStringency;
}

public void setValidationStringency(
final ValidationStringency validationStringency) {
public void setValidationStringency(final ValidationStringency validationStringency) {
this.validationStringency = validationStringency;
}

Expand All @@ -75,11 +72,13 @@ public void setValidationStringency(
private long samRecordIndex;
private ArrayList<CramCompressionRecord> cramRecords;

public CRAMIterator(final InputStream inputStream, final CRAMReferenceSource referenceSource, final ValidationStringency validationStringency)
throws IOException {
public CRAMIterator(final InputStream inputStream,
final CRAMReferenceSource referenceSource,
final ValidationStringency validationStringency) {
if (null == referenceSource) {
throw new CRAMException("A reference source is required for CRAM files");
}

this.countingInputStream = new CountingInputStream(inputStream);
this.referenceSource = referenceSource;
this.validationStringency = validationStringency;
Expand All @@ -88,17 +87,20 @@ public CRAMIterator(final InputStream inputStream, final CRAMReferenceSource ref
this.containerIterator = containerIterator;

firstContainerOffset = this.countingInputStream.getCount();
records = new ArrayList<SAMRecord>(CRAMContainerStreamWriter.DEFAULT_RECORDS_PER_SLICE);
records = new ArrayList<>(CRAMContainerStreamWriter.DEFAULT_RECORDS_PER_SLICE);
normalizer = new CramNormalizer(cramHeader.getSamFileHeader(),
referenceSource);
parser = new ContainerParser(cramHeader.getSamFileHeader());
}

public CRAMIterator(final SeekableStream seekableStream, final CRAMReferenceSource referenceSource, final long[] coordinates, final ValidationStringency validationStringency)
throws IOException {
public CRAMIterator(final SeekableStream seekableStream,
final CRAMReferenceSource referenceSource,
final long[] coordinates,
final ValidationStringency validationStringency) {
if (null == referenceSource) {
throw new CRAMException("A reference source is required for CRAM files");
}

this.countingInputStream = new CountingInputStream(seekableStream);
this.referenceSource = referenceSource;
this.validationStringency = validationStringency;
Expand All @@ -107,24 +109,24 @@ public CRAMIterator(final SeekableStream seekableStream, final CRAMReferenceSour
this.containerIterator = containerIterator;

firstContainerOffset = containerIterator.getFirstContainerOffset();
records = new ArrayList<SAMRecord>(CRAMContainerStreamWriter.DEFAULT_RECORDS_PER_SLICE);
records = new ArrayList<>(CRAMContainerStreamWriter.DEFAULT_RECORDS_PER_SLICE);
normalizer = new CramNormalizer(cramHeader.getSamFileHeader(),
referenceSource);
parser = new ContainerParser(cramHeader.getSamFileHeader());
}

@Deprecated
public CRAMIterator(final SeekableStream seekableStream, final CRAMReferenceSource referenceSource, final long[] coordinates)
throws IOException {
public CRAMIterator(final SeekableStream seekableStream,
final CRAMReferenceSource referenceSource,
final long[] coordinates) {
this(seekableStream, referenceSource, coordinates, ValidationStringency.DEFAULT_STRINGENCY);
}

public CramHeader getCramHeader() {
return cramHeader;
}

void nextContainer() throws IOException, IllegalArgumentException,
IllegalAccessException, CRAMException {
void nextContainer() throws IllegalArgumentException, CRAMException {

if (containerIterator != null) {
if (!containerIterator.hasNext()) {
Expand All @@ -149,7 +151,7 @@ void nextContainer() throws IOException, IllegalArgumentException,

records.clear();
if (cramRecords == null)
cramRecords = new ArrayList<CramCompressionRecord>(container.nofRecords);
cramRecords = new ArrayList<>(container.nofRecords);
else
cramRecords.clear();

Expand Down Expand Up @@ -250,11 +252,7 @@ public boolean advanceToAlignmentInContainer(final int refIndex, final int pos)
public boolean hasNext() {
if (container != null && container.isEOF()) return false;
if (!iterator.hasNext()) {
try {
nextContainer();
} catch (IOException | IllegalAccessException e) {
throw new SAMException(e);
}
nextContainer();
}

return !records.isEmpty();
Expand Down

0 comments on commit b24ac12

Please sign in to comment.