class_docstr: Fast overlap detection of a genomic position against a database of Ranges.
  
  Enables O(log n) computation of whether a point chr:pos falls within one of a
  large number of genomic ranges.
  
  This class does not supports overlapping or adjacent intervals. Any such
  intervals will be automatically merged together in the constructor.
  
  This class is immutable. No methods should be added that directly modify the
  ranges held by the class.
class_docstr_tok: ["Fast","overlap","detection","of","a","genomic","position","against","a","database","of","Ranges",".","Enables","O","(","log","n",")","computation","of","whether","a","point","chr",":","pos","falls","within","one","of","a","large","number","of","genomic","ranges",".","This","class","does","not","supports","overlapping","or","adjacent","intervals",".","Any","such","intervals","will","be","automatically","merged","together","in","the","constructor",".","This","class","is","immutable",".","No","methods","should","be","added","that","directly","modify","the","ranges","held","by","the","class","."]
docstr: Creates a RangeSet backed by ranges.
  
  Note that the Range objects in ranges are *not* stored directly here, so
  they can safely be modified after they are passed to this RangeSet.
  
  Args:
    ranges: list(nucleus.genomics.v1.Range) protos (or anything with
      reference_name, start, and end properties following the Range
      convention). If None, no ranges will be used, and overlaps() will always
      return False.
    contigs: list(nucleus.genomics.v1.ContigInfo) protos. Used to define the
      iteration order over contigs (i.e., by contig.pos_in_fasta).  If this
      list is not provided, the iteration order will be determined by the
      alphabetical order of the contig names.
    quiet: bool; defaults to False: If False, we will emit a logging message
      every _LOG_EVERY_N_RANGES_IN_RANGESET_INIT records processed while
      building this intervaltree. Set to True to stop all of the logging.
  
  Raises:
    ValueError: if any range's reference_name does not correspond to any
      contig in `contigs`.
docstr_tok: ["Creates","a","RangeSet","backed","by","ranges",".","Note","that","the","Range","objects","in","ranges","are","*","not","*","stored","directly","here",",","so","they","can","safely","be","modified","after","they","are","passed","to","this","RangeSet",".","Args",":","ranges",":","list","(","nucleus.genomics.v1.Range",")","protos","(","or","anything","with","reference_name",",","start",",","and","end","properties","following","the","Range","convention",")",".","If","None",",","no","ranges","will","be","used",",","and","overlaps","(",")","will","always","return","False",".","contigs",":","list","(","nucleus.genomics.v1.ContigInfo",")","protos",".","Used","to","define","the","iteration","order","over","contigs","(","i.e.",",","by","contig.pos_in_fasta",")",".","If","this","list","is","not","provided",",","the","iteration","order","will","be","determined","by","the","alphabetical","order","of","the","contig","names",".","quiet",":","bool",";","defaults","to","False",":","If","False",",","we","will","emit","a","logging","message","every","_LOG_EVERY_N_RANGES_IN_RANGESET_INIT","records","processed","while","building","this","intervaltree",".","Set","to","True","to","stop","all","of","the","logging",".","Raises",":","ValueError",":","if","any","range","'s","reference_name","does","not","correspond","to","any","contig","in","`","contigs","`","."]
code: def __init__(self, ranges=None, contigs=None, quiet=False):
      """Creates a RangeSet backed by ranges.
  
      Note that the Range objects in ranges are *not* stored directly here, so
      they can safely be modified after they are passed to this RangeSet.
  
      Args:
        ranges: list(nucleus.genomics.v1.Range) protos (or anything with
          reference_name, start, and end properties following the Range
          convention). If None, no ranges will be used, and overlaps() will always
          return False.
        contigs: list(nucleus.genomics.v1.ContigInfo) protos. Used to define the
          iteration order over contigs (i.e., by contig.pos_in_fasta).  If this
          list is not provided, the iteration order will be determined by the
          alphabetical order of the contig names.
        quiet: bool; defaults to False: If False, we will emit a logging message
          every _LOG_EVERY_N_RANGES_IN_RANGESET_INIT records processed while
          building this intervaltree. Set to True to stop all of the logging.
  
      Raises:
        ValueError: if any range's reference_name does not correspond to any
          contig in `contigs`.
      """
      if contigs is not None:
          self._contigs = contigs
          self._contig_map = contigs_dict(contigs)
          self._contig_sort_key_fn = lambda name: self._contig_map[
              name
          ].pos_in_fasta
          self._is_valid_contig = lambda name: name in self._contig_map
      else:
          self._contigs = None
          self._contig_map = None
          self._contig_sort_key_fn = lambda name: name
          self._is_valid_contig = lambda name: True
  
      if ranges is None:
          ranges = []
  
      # Add each range to our contig-specific intervaltrees.
      self._by_chr = collections.defaultdict(intervaltree.IntervalTree)
      for i, range_ in enumerate(ranges):
          if not self._is_valid_contig(range_.reference_name):
              raise ValueError(
                  "Range {} is on an unrecognized contig.".format(
                      range_
                  )
              )
          self._by_chr[range_.reference_name].addi(
              range_.start, range_.end, None
          )
          if (
              not quiet
              and i > 0
              and i % _LOG_EVERY_N_RANGES_IN_RANGESET_INIT == 0
          ):
              # We do our test directly here on i > 0 so we only see the log messages
              # if we add at least _LOG_EVERY_N_RANGES_IN_RANGESET_INIT records.
              logging.info(
                  "Adding interval %s to intervaltree",
                  to_literal(range_),
              )
  
      # Merge overlapping / adjacent intervals in each tree.
      for tree in six.itervalues(self._by_chr):
          tree.merge_overlaps(strict=False)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import re
  from typing import Dict, Iterable, Optional, Sequence
  from absl import logging
  from etils import epath
  import intervaltree
  import six
  from third_party.nucleus.io import bed
  from third_party.nucleus.protos import position_pb2
  from third_party.nucleus.protos import range_pb2
  from third_party.nucleus.protos import reference_pb2
  from third_party.nucleus.protos import variants_pb2
label_desc: Use image node_id 1 to create a new RangeSet object from inherited base classes: object with example: obj = RangeSet(ranges, contigs, quiet)