use of htsjdk.variant.variantcontext.filter.FilteringVariantContextIterator in project jvarkit by lindenb.
the class VariantContextBatchReader method open.
@Override
public void open(final ExecutionContext executionContext) throws ItemStreamException {
if (this.rsrc == null)
throw new ItemStreamException("resource is not defined");
final File vcfFile;
try {
if (LOG.isInfoEnabled())
LOG.info("Opening " + this.rsrc);
vcfFile = this.rsrc.getFile();
IOUtil.assertFileIsReadable(vcfFile);
this.vcfFileReader = new VCFFileReader(vcfFile, this.interval != null);
final VCFHeader header = this.vcfFileReader.getFileHeader();
executionContext.put(SpringBatchUtils.VCF_HEADER_KEY, header);
if (this.interval == null) {
this.iter = this.vcfFileReader.iterator();
} else {
this.iter = this.vcfFileReader.query(this.interval.getContig(), this.interval.getStart(), this.interval.getEnd());
}
if (this.filter != null) {
this.iter = new FilteringVariantContextIterator(this.iter, this.filter);
}
if (!executionContext.containsKey(CURRENT_INDEX)) {
this.currentIndex = 0L;
} else {
this.currentIndex = executionContext.getLong(CURRENT_INDEX);
if (LOG.isInfoEnabled())
LOG.info("skipping " + this.currentIndex + " variants");
for (long n = 0L; n < this.currentIndex; n++) {
if (!this.iter.hasNext()) {
throw new IllegalStateException("no more variants");
}
this.iter.next();
}
}
} catch (final IOException err) {
if (LOG.isErrorEnabled())
LOG.error("Cannot open Vcf", err);
priv_close();
throw new ItemStreamException(err);
}
}
Aggregations