code: def tupletree(table, start='start', stop='stop', value=None):
      
  
      import intervaltree
      tree = intervaltree.IntervalTree()
      it = iter(table)
      hdr = next(it)
      flds = list(map(text_type, hdr))
      assert start in flds, 'start field not recognised'
      assert stop in flds, 'stop field not recognised'
      getstart = itemgetter(flds.index(start))
      getstop = itemgetter(flds.index(stop))
      if value is None:
          getvalue = tuple
      else:
          valueindices = asindices(hdr, value)
          assert len(valueindices) > 0, 'invalid value field specification'
          getvalue = itemgetter(*valueindices)
      for row in it:
          tree.addi(getstart(row), getstop(row), getvalue(row))
      return tree
docs: Construct an interval tree for the given table, where each node in the tree
      is a row of the table.