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 Details

    • vcfFileName

      protected String vcfFileName
    • vcfFileIterator

      protected org.snpeff.fileIterator.VcfFileIterator vcfFileIterator
    • variantsMinHeap

      protected PriorityQueue<org.snpeff.vcf.VariantVcfEntry> variantsMinHeap
    • vcfChr

      protected String vcfChr
    • vcfPos

      protected int vcfPos
    • vcfEntryPending

      protected org.snpeff.vcf.VcfEntry vcfEntryPending
  • Constructor Details

    • SortedVariantsVcfIterator

      public SortedVariantsVcfIterator(String vcfFileName)
    • SortedVariantsVcfIterator

      public SortedVariantsVcfIterator(BufferedReader reader)
  • Method Details

    • lines2SortedVariantsVcfIterator

      public static SortedVariantsVcfIterator lines2SortedVariantsVcfIterator(String vcfLines)
      Create a VcfFileIterator from a string containig VCF lines
    • close

      public void close()
    • iterator

      public Iterator<org.snpeff.vcf.VariantVcfEntry> iterator()
      Specified by:
      iterator in interface Iterable<org.snpeff.vcf.VariantVcfEntry>
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<org.snpeff.vcf.VariantVcfEntry>
    • next

      public org.snpeff.vcf.VariantVcfEntry next()
      Specified by:
      next in interface Iterator<org.snpeff.vcf.VariantVcfEntry>