Package org.snpsift.annotate.mem
Class SortedVariantsVcfIterator
java.lang.Object
org.snpsift.annotate.mem.SortedVariantsVcfIterator
- All Implemented Interfaces:
Iterable<org.snpeff.vcf.VariantVcfEntry>,Iterator<org.snpeff.vcf.VariantVcfEntry>
public class SortedVariantsVcfIterator
extends Object
implements Iterator<org.snpeff.vcf.VariantVcfEntry>, Iterable<org.snpeff.vcf.VariantVcfEntry>
This is a class that reads a VCF file and returns the variants in sorted order.
The SortedVariantsVcfIterator class provides an iterator to traverse through
VCF (Variant Call Format) entries in a sorted manner. It implements both
Iterator and Iterable interfaces for VariantVcfEntry objects.
This class reads VCF entries from a file or a string containing VCF lines,
and ensures that the variants are returned in a sorted order based on their
positions. It uses a priority queue (min-heap) to keep track of the next
variant to be returned.
How it works:
It uses a min heap to keep track of the next variant to be returned.
The min heap is populated with the first variant from each chromosome.
The next variant to be returned is the one with the smallest position.
When a variant is returned, the min heap is updated with the next variant from the same chromosome.
The process continues until all variants have been returned.
The class handles edge cases such as:
- Variants from different chromosomes.
- Ensuring that the VCF file is sorted.
- Handling pending VcfEntries that belong to a different chromosome.
Limitations:
- The VCF file must be sorted by chromosome and position. If the file is not
sorted, a RuntimeException will be thrown.
- The class assumes that the input VCF lines or file are in a valid format.
- The class does not handle multi-threaded access and should be used in a
single-threaded context.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PriorityQueue<org.snpeff.vcf.VariantVcfEntry> protected Stringprotected org.snpeff.vcf.VcfEntryprotected org.snpeff.fileIterator.VcfFileIteratorprotected Stringprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanhasNext()Iterator<org.snpeff.vcf.VariantVcfEntry> iterator()static SortedVariantsVcfIteratorlines2SortedVariantsVcfIterator(String vcfLines) Create a VcfFileIterator from a string containig VCF linesorg.snpeff.vcf.VariantVcfEntrynext()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Field Details
-
vcfFileName
-
vcfFileIterator
protected org.snpeff.fileIterator.VcfFileIterator vcfFileIterator -
variantsMinHeap
-
vcfChr
-
vcfPos
protected int vcfPos -
vcfEntryPending
protected org.snpeff.vcf.VcfEntry vcfEntryPending
-
-
Constructor Details
-
SortedVariantsVcfIterator
-
SortedVariantsVcfIterator
-
-
Method Details
-
lines2SortedVariantsVcfIterator
Create a VcfFileIterator from a string containig VCF lines -
close
public void close() -
iterator
-
hasNext
public boolean hasNext() -
next
public org.snpeff.vcf.VariantVcfEntry next()
-