Search in sources :

Example 1 with FilteringVariantContextIterator

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);
    }
}
Also used : VCFFileReader(htsjdk.variant.vcf.VCFFileReader) IOException(java.io.IOException) VCFHeader(htsjdk.variant.vcf.VCFHeader) ItemStreamException(org.springframework.batch.item.ItemStreamException) File(java.io.File) FilteringVariantContextIterator(htsjdk.variant.variantcontext.filter.FilteringVariantContextIterator)

Aggregations

FilteringVariantContextIterator (htsjdk.variant.variantcontext.filter.FilteringVariantContextIterator)1 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)1 VCFHeader (htsjdk.variant.vcf.VCFHeader)1 File (java.io.File)1 IOException (java.io.IOException)1 ItemStreamException (org.springframework.batch.item.ItemStreamException)1