Search in sources :

Example 1 with AbstractIterator

use of htsjdk.samtools.util.AbstractIterator in project jvarkit by lindenb.

the class VcfIterator method filter.

/**
 * wrap as a filtering iterator
 */
public static VcfIterator filter(final VcfIterator delegate, final Predicate<VariantContext> predicate) {
    class FilteringVcfIterator extends AbstractIterator<VariantContext> implements VcfIterator {

        private final VcfIterator delegate;

        private final Predicate<VariantContext> predicate;

        FilteringVcfIterator(final VcfIterator delegate, final Predicate<VariantContext> predicate) {
            this.delegate = delegate;
            this.predicate = predicate;
        }

        @Override
        public AbstractVCFCodec getCodec() {
            return this.delegate.getCodec();
        }

        @Override
        public VCFHeader getHeader() {
            return this.delegate.getHeader();
        }

        @Override
        public void close() throws IOException {
            this.delegate.close();
        }

        @Override
        protected VariantContext advance() {
            while (this.delegate.hasNext()) {
                final VariantContext ctx = this.delegate.next();
                if (this.predicate.test(ctx))
                    return ctx;
                ;
            }
            return null;
        }
    }
    return new FilteringVcfIterator(delegate, predicate);
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) AbstractIterator(htsjdk.samtools.util.AbstractIterator) Predicate(java.util.function.Predicate)

Aggregations

AbstractIterator (htsjdk.samtools.util.AbstractIterator)1 VariantContext (htsjdk.variant.variantcontext.VariantContext)1 Predicate (java.util.function.Predicate)1