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: Computes the intersection among this RangeSet and *others RangeSets.
  
  This function computes the intersection of all of the intervals in self and
  *others, returning a RangeSet containing only intervals common to all. The
  intersection here is an ranged intersection, not an identity intersection,
  so the resulting set of intervals may not contain any of the original
  intervals in any of the sets.
  
  To be concrete, suppose we have three sets to intersect, each having two
  intervals:
  
    self   : chr1:1-10, chr2:20-30
    other1 : chr1:5-8, chr3:10-40
    other2 : chr1:3-7, chr3:10-30
  
  self.intersection(other1, other2) produces a RangeSet with one interval
  chr1:5-7, the common bases on chr1 in self, other1, and other2. No intervals
  on chr2 or chr3 are included since the chr2 only occurs in self and the two
  intervals on chr3, despite having some shared bases, don't have an
  overlapping interval in self.
  
  Args:
    *others: A list of RangeSet objects to intersect with the intervals in
      this RangeSet.
  
  Returns:
    A RangeSet. If *others is empty, this function returns self rather than
    making an unnecessary copy. In all other cases, the returned value will be
    a freshly allocated RangeSet.
docstr_tok: ["Computes","the","intersection","among","this","RangeSet","and","*","others","RangeSets",".","This","function","computes","the","intersection","of","all","of","the","intervals","in","self","and","*","others",",","returning","a","RangeSet","containing","only","intervals","common","to","all",".","The","intersection","here","is","an","ranged","intersection",",","not","an","identity","intersection",",","so","the","resulting","set","of","intervals","may","not","contain","any","of","the","original","intervals","in","any","of","the","sets",".","To","be","concrete",",","suppose","we","have","three","sets","to","intersect",",","each","having","two","intervals",":","self",":","chr1:1-10",",","chr2:20-30","other1",":","chr1:5-8",",","chr3:10-40","other2",":","chr1:3-7",",","chr3:10-30","self.intersection","(","other1",",","other2",")","produces","a","RangeSet","with","one","interval","chr1:5-7",",","the","common","bases","on","chr1","in","self",",","other1",",","and","other2",".","No","intervals","on","chr2","or","chr3","are","included","since","the","chr2","only","occurs","in","self","and","the","two","intervals","on","chr3",",","despite","having","some","shared","bases",",","do","n't","have","an","overlapping","interval","in","self",".","Args",":","*","others",":","A","list","of","RangeSet","objects","to","intersect","with","the","intervals","in","this","RangeSet",".","Returns",":","A","RangeSet",".","If","*","others","is","empty",",","this","function","returns","self","rather","than","making","an","unnecessary","copy",".","In","all","other","cases",",","the","returned","value","will","be","a","freshly","allocated","RangeSet","."]
code: def intersection(self, *others: "RangeSet") -> "RangeSet":
      """Computes the intersection among this RangeSet and *others RangeSets.
  
      This function computes the intersection of all of the intervals in self and
      *others, returning a RangeSet containing only intervals common to all. The
      intersection here is an ranged intersection, not an identity intersection,
      so the resulting set of intervals may not contain any of the original
      intervals in any of the sets.
  
      To be concrete, suppose we have three sets to intersect, each having two
      intervals:
  
        self   : chr1:1-10, chr2:20-30
        other1 : chr1:5-8, chr3:10-40
        other2 : chr1:3-7, chr3:10-30
  
      self.intersection(other1, other2) produces a RangeSet with one interval
      chr1:5-7, the common bases on chr1 in self, other1, and other2. No intervals
      on chr2 or chr3 are included since the chr2 only occurs in self and the two
      intervals on chr3, despite having some shared bases, don't have an
      overlapping interval in self.
  
      Args:
        *others: A list of RangeSet objects to intersect with the intervals in
          this RangeSet.
  
      Returns:
        A RangeSet. If *others is empty, this function returns self rather than
        making an unnecessary copy. In all other cases, the returned value will be
        a freshly allocated RangeSet.
      """
  
      def _intersect2(refname, tree1, tree2):
          """Intersects the intervals of two IntervalTrees."""
          # Yields all of the overlapping intervals from each interval of tree1
          # found in tree2. Since each tree has only non-adjacent, non-overlapping,
          # intervals this calculation is straightforward and safe and produces only
          # non-adjacent, non-overlapping intervals.
          if len(tree1) > len(tree2):
              (bigtree, smalltree) = (tree1, tree2)
          else:
              (bigtree, smalltree) = (tree2, tree1)
          return (
              make_range(
                  refname,
                  max(interval1.begin, overlapping.begin),
                  min(interval1.end, overlapping.end),
              )
              for interval1 in bigtree
              for overlapping in smalltree.overlap(interval1)
          )
  
      # Iteratively intersect each of our *other RangeSets with this RangeSet.
      # Sort by size so we do the smallest number of element merge first.
      # TODO: Note we could optimize this code by computing the set of
      # common contigs upfront across all others and only looping over those.
      intersected = self
      for other in sorted(others, key=len):
          intersected_intervals = []
          # pylint: disable=protected-access
          # So we can intersect intervals within each contig separately.
          for refname, intervals in six.iteritems(intersected._by_chr):
              # If refname is present in other, intersect those two IntervalTrees
              # directly and add those contigs to our growing list of intersected
              # intervals. If refname isn't present, all of the intervals on refname
              # should be dropped as there are no intervals to overlap.
              other_chr = other._by_chr.get(refname, None)
              if other_chr:
                  intersected_intervals.extend(
                      _intersect2(refname, intervals, other_chr)
                  )
  
          # Update our intersected RangeSet with the new intervals.
          intersected = RangeSet(intersected_intervals, self._contigs)
  
      return intersected
  
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 6 for calling the RangeSet obj's underlying member method code with example usage: obj.intersection() and returns: intersected, unknown