当前位置: 首页>>代码示例>>Python>>正文


Python intervaltree.IntervalTree方法代码示例

本文整理汇总了Python中intervaltree.IntervalTree方法的典型用法代码示例。如果您正苦于以下问题:Python intervaltree.IntervalTree方法的具体用法?Python intervaltree.IntervalTree怎么用?Python intervaltree.IntervalTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在intervaltree的用法示例。


在下文中一共展示了intervaltree.IntervalTree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_blacklist

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def read_blacklist(blacklist_bed, black_buffer=20):
  """Construct interval trees of blacklist
     regions for each chromosome."""
  black_chr_trees = {}

  if blacklist_bed is not None and os.path.isfile(blacklist_bed):
    for line in open(blacklist_bed):
      a = line.split()
      chrm = a[0]
      start = max(0, int(a[1]) - black_buffer)
      end = int(a[2]) + black_buffer

      if chrm not in black_chr_trees:
        black_chr_trees[chrm] = intervaltree.IntervalTree()

      black_chr_trees[chrm][start:end] = True

  return black_chr_trees 
开发者ID:calico,项目名称:basenji,代码行数:20,代码来源:basenji_data_read.py

示例2: read_blacklist

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def read_blacklist(blacklist_bed, black_buffer=20):
  """Construct interval trees of blacklist
     regions for each chromosome."""
  black_chr_trees = {}

  if blacklist_bed is not None and os.path.isfile(blacklist_bed):
    for line in open(blacklist_bed):
      a = line.split()
      chrm = a[0]
      start = max(0, int(a[1]) - black_buffer)
      end = int(a[2]) + black_buffer

      if chrm not in black_chr_trees:
        black_chr_trees[chrm] = intervaltree.IntervalTree()

      black_chr_trees[chrm][start:end] = True

  return black_chr_trees



################################################################################
# __main__
################################################################################ 
开发者ID:calico,项目名称:basenji,代码行数:26,代码来源:basenji_data_hic_read.py

示例3: __init__

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def __init__(self, zkquorum, pool_size):
        # Location of the ZooKeeper quorum (csv)
        self.zkquorum = zkquorum
        # Connection pool size per region server (and master!)
        self.pool_size = pool_size
        # Persistent connection to the master server.
        self.master_client = None
        # IntervalTree data structure that allows me to create ranges
        # representing known row keys that fall within a specific region. Any
        # 'region look up' is then O(logn)
        self.region_cache = IntervalTree()
        # Takes a client's host:port as key and maps it to a client instance.
        self.reverse_client_cache = {}
        # Mutex used for all caching operations.
        self._cache_lock = Lock()
        # Mutex used so only one thread can request meta information from
        # the master at a time.
        self._master_lookup_lock = Lock() 
开发者ID:CurleySamuel,项目名称:PyBase,代码行数:20,代码来源:client.py

示例4: intervalListToIntervalTree

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def intervalListToIntervalTree(interval_list):
    r"""
    given a dictionary containing tuples of chrom, start, end,
    this is transformed to an interval trees. To each
    interval an id is assigned, this id corresponds to the
    position of the interval in the given array of tuples
    and if needed can be used to identify
    the index of a row/colum in the hic matrix.

    >>> bin_list = [('chrX', 0, 50000), ('chrX', 50000, 100000)]
    >>> res = intervalListToIntervalTree(bin_list)
    >>> sorted(res['chrX'])
    [Interval(0, 50000, 0), Interval(50000, 100000, 1)]
    """
    bin_int_tree = {}

    for intval_id, intval in enumerate(interval_list):
        chrom, start, end = intval[0:3]
        if chrom not in bin_int_tree:
            bin_int_tree[chrom] = IntervalTree()
        bin_int_tree[chrom].add(Interval(start, end, intval_id))

    return bin_int_tree 
开发者ID:deeptools,项目名称:HiCExplorer,代码行数:25,代码来源:hicBuildMatrix.py

示例5: __init__

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def __init__(self, stream):
        """Init the bit-wrapped stream

        :stream: The normal byte stream
        """
        self._stream = stream
        self._bits = collections.deque()

        self.closed = False

        # assume that bitfields end on an even boundary,
        # otherwise the entire stream will be treated as
        # a bit stream with no padding
        self.padded = True

        self.range_set = IntervalTree() 
开发者ID:d0c-s4vage,项目名称:pfp,代码行数:18,代码来源:bitwrap.py

示例6: __init__

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def __init__(self, interval_tuples):
        '''intervals is like [('22', 12321, 12345, 'APOL1'), ...]'''
        self._its = {}
        self._gene_starts = {}
        self._gene_ends = {}
        for interval_tuple in interval_tuples:
            chrom, pos_start, pos_end, gene_name = interval_tuple
            assert isinstance(pos_start, int)
            assert isinstance(pos_end, int)
            if chrom not in self._its:
                self._its[chrom] = intervaltree.IntervalTree()
                self._gene_starts[chrom] = []
                self._gene_ends[chrom] = []
            self._its[chrom].add(intervaltree.Interval(pos_start, pos_end, gene_name))
            self._gene_starts[chrom].append((pos_start, gene_name))
            self._gene_ends[chrom].append((pos_end, gene_name))
        for chrom in self._its:
            self._gene_starts[chrom] = BisectFinder(self._gene_starts[chrom])
            self._gene_ends[chrom] = BisectFinder(self._gene_ends[chrom]) 
开发者ID:statgen,项目名称:pheweb,代码行数:21,代码来源:add_genes.py

示例7: __init__

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def __init__(self, data, row_sentence_bounds, window=5, process_all=False):
        """
        Class for managing windowed input data (like TIMIT).

        :param data: Numpy matrix. Each row should be an example data
        :param row_sentence_bounds:  Numpy matrix with bounds for padding. TODO add default NONE
        :param window: half-window size
        :param process_all: (default False) if True adds context to all data at object initialization.
                            Otherwise the windowed data is created in runtime.
        """
        self.window = window
        self.data = data
        base_shape = self.data.shape
        self.shape = (base_shape[0], (2 * self.window + 1) * base_shape[1])
        self.tree = it.IntervalTree([it.Interval(int(e[0]), int(e[1]) + 1) for e in row_sentence_bounds])
        if process_all:
            print('adding context to all the dataset', end='- ')
            self.data = self.generate_all()
            print('DONE')
        self.process_all = process_all 
开发者ID:lucfra,项目名称:RFHO,代码行数:22,代码来源:datasets.py

示例8: intervaltree_prep

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def intervaltree_prep(h1, h2, ref_seq):
        """Mock up trees as would be done by the `VCFReader` class so we can test medaka.vcf._merge_variants

        :param h1, h2: iterable of variants in first and second haplotype, respectively.
        :param ref_seq: str, reference sequence

        :returns: (`intervaltree.Interval` containing interable of all variants,
                   [`intervaltree.IntervalTree` for each haplotype])
        """
        trees = []
        for variants in h1, h2:
            trees.append(intervaltree.IntervalTree())
            for v in variants:
                trees[-1].add(intervaltree.Interval(v.pos, v.pos + len(v.ref), data=v))
        only_overlapping=True
        comb_tree = intervaltree.IntervalTree(trees[0].all_intervals.union(trees[1].all_intervals))
        # if strict, merge only overlapping intervals (not adjacent ones)
        comb_tree.merge_overlaps(strict=only_overlapping, data_initializer=list(), data_reducer=lambda x,y: x + [y])
        comb_interval = list(comb_tree.all_intervals)[0]
        return comb_interval, trees 
开发者ID:nanoporetech,项目名称:medaka,代码行数:22,代码来源:test_vcf.py

示例9: _build_symbol_search_tree

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def _build_symbol_search_tree(self):
        self.symbol_tree = IntervalTree()
        symbols = self.symtab.iter_symbols()
        for symbol in symbols:
            # Only look for functions and objects.
            sym_type = symbol.entry['st_info']['type']
            if sym_type not in ['STT_FUNC', 'STT_OBJECT']:
                continue

            sym_value = symbol.entry['st_value']
            sym_size = symbol.entry['st_size']

            # Cannot put an empty interval into the tree, so ensure symbols have
            # at least a size of 1.
            real_sym_size = sym_size
            if sym_size == 0:
                sym_size = 1

            syminfo = SymbolInfo(name=symbol.name, address=sym_value, size=real_sym_size, type=sym_type)

            # Add to symbol dict.
            self.symbol_dict[symbol.name] = syminfo
            
            # Add to symbol tree.
            self.symbol_tree.addi(sym_value, sym_value+sym_size, syminfo) 
开发者ID:XIVN1987,项目名称:DMCUProg,代码行数:27,代码来源:decoder.py

示例10: _build_function_search_tree

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def _build_function_search_tree(self):
        self.function_tree = IntervalTree()
        for prog in self.subprograms:
            try:
                name = prog.attributes['DW_AT_name'].value
                low_pc = prog.attributes['DW_AT_low_pc'].value
                high_pc = prog.attributes['DW_AT_high_pc'].value

                # Skip subprograms excluded from the link.
                if low_pc == 0:
                    continue

                # If high_pc is not explicitly an address, then it's an offset from the
                # low_pc value.
                if prog.attributes['DW_AT_high_pc'].form != 'DW_FORM_addr':
                    high_pc = low_pc + high_pc

                fninfo = FunctionInfo(name=name, subprogram=prog, low_pc=low_pc, high_pc=high_pc)

                self.function_tree.addi(low_pc, high_pc, fninfo)
            except KeyError:
                pass 
开发者ID:XIVN1987,项目名称:DMCUProg,代码行数:24,代码来源:decoder.py

示例11: __intervaltree_from_list

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def __intervaltree_from_list(self, vlines_list):
        from intervaltree import IntervalTree
        itree = {}
        for v in vlines_list:
            if isinstance(v, str):
                grange = GenomeRange(v)
            elif isinstance(v, tuple):
                grange = GenomeRange(v[0], v[1], v[1])
            elif isinstance(v, GenomeRange):
                grange = v
            else:
                raise ValueError("position must be a tuple or string.")
            chr_ = grange.chrom
            itree.setdefault(chr_, IntervalTree())
            itree[chr_][grange.start:grange.end+1] = grange
        return itree 
开发者ID:GangCaoLab,项目名称:CoolBox,代码行数:18,代码来源:vlines.py

示例12: remove_gff_breaks

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def remove_gff_breaks(gff_ins, breaks):
    """
    Given a list of candidate breakpoints proposed by misassembly correction, remove any such break points that
    fall within the interval of a gff feature. This should be called once per contig.
    :param gff_ins: List of GFFLines
    :param breaks: candidate break points
    :return:
    """
    # Make an interval tree from the intervals of the gff lines
    t = IntervalTree()
    for line in gff_ins:
        # If the interval is one bp long, skip
        if line.start == line.end:
            continue
        t[line.start:line.end] = (line.start, line.end)

    return [i for i in breaks if not t[i]] 
开发者ID:malonge,项目名称:RaGOO,代码行数:19,代码来源:ragoo.py

示例13: translate

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def translate(self, chromosome, strand, pos):
        """translates a chromosome, position, and strand into a gene identifier

        Uses the IntervalTree data structure to rapidly search for the corresponding
        identifier.

        :param bytes chromosome: chromosome for this alignment
        :param bytes strand: strand for this alignment (one of ['+', '-'])
        :param int pos: position of the alignment within the chromosome
        :return int|None: Returns either an integer gene_id if a unique gene was found
          at the specified position, or None otherwise
        """
        # todo remove duplicate exons during construction to save time
        try:
            result = set(x.data for x in
                         self._chromosomes_to_genes[chromosome][strand][pos])
            if len(result) == 1:
                return first(result)  # just right
            else:
                return None  # too many genes
        except KeyError:
            return None  # no gene 
开发者ID:ambrosejcarr,项目名称:seqc,代码行数:24,代码来源:gtf.py

示例14: __init__

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def __init__(self, match_type, equal=False):
        super(ScoreFunction, self).__init__()
        self.logger = logging.getLogger(__name__)
        self.logger.debug("Initializing match_type to:{0}".format(match_type))
        self.match_type = match_type #['integer','float','flag','character','string']
        self.logger.debug("Initializing string_dict to:{}")
        self._string_dict = {}
        self.logger.debug("Initializing interval_tree")
        self._interval_tree = IntervalTree()
        self.logger.debug("Initializing value_dict")
        self._value_dict = {}
        self.logger.debug("Initializing not_reported_score to 0")
        self._not_reported_score = 0
        self.logger.debug("Initializing reported_score to 0")
        self._reported_score = 0 # only for 'flag'
        # If the score is the same as the value found:
        self.logger.debug("Initializing equal to {0}".format(equal))
        self._equal = equal 
开发者ID:moonso,项目名称:genmod,代码行数:20,代码来源:score_function.py

示例15: fill_table

# 需要导入模块: import intervaltree [as 别名]
# 或者: from intervaltree import IntervalTree [as 别名]
def fill_table(table, i, curr_ds, datasets, base_ds=0,
               knn=KNN, approx=APPROX):
    curr_ref = np.concatenate(datasets)
    if approx:
        match = nn_approx(curr_ds, curr_ref, knn=knn)
    else:
        match = nn(curr_ds, curr_ref, knn=knn, metric_p=1)

    # Build interval tree.
    itree_ds_idx = IntervalTree()
    itree_pos_base = IntervalTree()
    pos = 0
    for j in range(len(datasets)):
        n_cells = datasets[j].shape[0]
        itree_ds_idx[pos:(pos + n_cells)] = base_ds + j
        itree_pos_base[pos:(pos + n_cells)] = pos
        pos += n_cells

    # Store all mutual nearest neighbors between datasets.
    for d, r in match:
        interval = itree_ds_idx[r]
        assert(len(interval) == 1)
        j = interval.pop().data
        interval = itree_pos_base[r]
        assert(len(interval) == 1)
        base = interval.pop().data
        if not (i, j) in table:
            table[(i, j)] = set()
        table[(i, j)].add((d, r - base))
        assert(r - base >= 0) 
开发者ID:brianhie,项目名称:scanorama,代码行数:32,代码来源:scanorama.py


注:本文中的intervaltree.IntervalTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。