class_docstr: Class for "reading" Variant protos from an in-memory cache of variants.
  
  ```python
  from third_party.nucleus.io import vcf
  from third_party.nucleus.protos import variants_pb2
  
  variants = [... Variant protos ...]
  header = variants_pb2.VcfHeader()
  
  with vcf.InMemoryVcfReader(variants, header) as reader:
    for variant in reader:
      print(variant)
  ```
  
  This class accepts a collection of variants and optionally a header and
  provides all of the standard API functions of VcfReader but instead of
  fetching variants from a file the variants are queried from an in-memory cache
  of variant protos.
  
  Note that the input variants provided to this class aren't checked in any way,
  and their ordering determines the order of variants emitted by this class for
  the iterate() and query() operations. This is intentional, to make this class
  easy to use for testing where you often want to use less-than-perfectly formed
  inputs. In order to fully meet the contract of a standard VcfReader, variants
  should be sorted by their contig ordering and then by their start and finally
  by their ends.
  
  Implementation note:
    The current implementation will be very slow for query() if the provided
    cache of variants is large, as we do a O(n) search to collect all of the
    overlapping variants for each query. There are several straightforward
    optimizations to do if we need/want to scale this up. (a) sort the variants
    and use a binary search to find overlapping variants (b) partition the
    variants by contig, so we have dict[contig] => [variants on contig], which
    allows us to completely avoid considering any variants on any other contigs.
    Neither of these optimizations are worth it if len(variants) is small, but
    it may be worth considering if we want to use this functionality with a
    large number of variants.
class_docstr_tok: ["Class","for","``","reading","''","Variant","protos","from","an","in-memory","cache","of","variants",".","``","`","python","from","third_party.nucleus.io","import","vcf","from","third_party.nucleus.protos","import","variants_pb2","variants","=","[","...","Variant","protos","...","]","header","=","variants_pb2.VcfHeader","(",")","with","vcf.InMemoryVcfReader","(","variants",",","header",")","as","reader",":","for","variant","in","reader",":","print","(","variant",")","``","`","This","class","accepts","a","collection","of","variants","and","optionally","a","header","and","provides","all","of","the","standard","API","functions","of","VcfReader","but","instead","of","fetching","variants","from","a","file","the","variants","are","queried","from","an","in-memory","cache","of","variant","protos",".","Note","that","the","input","variants","provided","to","this","class","are","n't","checked","in","any","way",",","and","their","ordering","determines","the","order","of","variants","emitted","by","this","class","for","the","iterate","(",")","and","query","(",")","operations",".","This","is","intentional",",","to","make","this","class","easy","to","use","for","testing","where","you","often","want","to","use","less-than-perfectly","formed","inputs",".","In","order","to","fully","meet","the","contract","of","a","standard","VcfReader",",","variants","should","be","sorted","by","their","contig","ordering","and","then","by","their","start","and","finally","by","their","ends",".","Implementation","note",":","The","current","implementation","will","be","very","slow","for","query","(",")","if","the","provided","cache","of","variants","is","large",",","as","we","do","a","O","(","n",")","search","to","collect","all","of","the","overlapping","variants","for","each","query",".","There","are","several","straightforward","optimizations","to","do","if","we","need\/want","to","scale","this","up",".","(","a",")","sort","the","variants","and","use","a","binary","search","to","find","overlapping","variants","(","b",")","partition","the","variants","by","contig",",","so","we","have","dict","[","contig","]","=",">","[","variants","on","contig","]",",","which","allows","us","to","completely","avoid","considering","any","variants","on","any","other","contigs",".","Neither","of","these","optimizations","are","worth","it","if","len","(","variants",")","is","small",",","but","it","may","be","worth","considering","if","we","want","to","use","this","functionality","with","a","large","number","of","variants","."]
docstr: Creates a VCFReader backed by a collection of variants.
  
  Args:
    variants: list of nucleus.genomics.v1.Variant protos we will "read"
      from.
    header: a VCFHeader object to provide as a result to calls to self.header,
      or None, indicating that we don't have a header associated with this
      reader.
docstr_tok: ["Creates","a","VCFReader","backed","by","a","collection","of","variants",".","Args",":","variants",":","list","of","nucleus.genomics.v1.Variant","protos","we","will","``","read","''","from",".","header",":","a","VCFHeader","object","to","provide","as","a","result","to","calls","to","self.header",",","or","None",",","indicating","that","we","do","n't","have","a","header","associated","with","this","reader","."]
code: def __init__(self, variants, header=None):
      """Creates a VCFReader backed by a collection of variants.
  
      Args:
        variants: list of nucleus.genomics.v1.Variant protos we will "read"
          from.
        header: a VCFHeader object to provide as a result to calls to self.header,
          or None, indicating that we don't have a header associated with this
          reader.
      """
      super(InMemoryVcfReader, self).__init__()
      self.variants = list(variants)
      self.header = header
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from third_party.nucleus.io import genomics_reader
  from third_party.nucleus.io import genomics_writer
  from third_party.nucleus.io.python import vcf_reader
  from third_party.nucleus.io.python import vcf_writer
  from third_party.nucleus.protos import variants_pb2
  from third_party.nucleus.util import ranges
  from third_party.nucleus.util import variant_utils
  from third_party.nucleus.util import vcf_constants
label_desc: Use image node_id 1 to create a new InMemoryVcfReader object from inherited base classes: genomics_reader with example: obj = InMemoryVcfReader(variants, header)