本文整理汇总了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
示例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__
################################################################################
示例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()
示例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
示例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()
示例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])
示例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
示例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
示例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)
示例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
示例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
示例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]]
示例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
示例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
示例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)