def index(self, persist=True): """(re)builds the interval tree index into the interval list you have stored. .. note: interval tree performance will not be obtained unless the user *explicitly* calls this method. This is typically called after a set of intervals has been added. :param persist: permanently store the index on disk :type persist: bool """ refcountdict = None tbl = self.hdf_group._f_getChild(INTERVAL_TABLE) tree_group = self.hdf_group._f_getChild(INTERVAL_INDEX_GROUP) for rname, idx in self.indexes.iteritems(): # see if index needs to be generated if (idx.tree is None) or idx.dirty: # count number of items for each reference if refcountdict is None: refcountdict = self._get_ref_count_dict() # iterate and insert all intervals tree = IntervalTree(refcountdict[rname]) cur_id = 1 for row in tbl.where('ref == rname'): start = row[START_COL_NAME] end = row[END_COL_NAME] tree.insert(cur_id, start, end, row.nrow) cur_id += 1 # update index idx.tree = tree idx.dirty = False # save for future use if persist: tree.tohdf(tree_group, rname)