本文整理汇总了Python中bst.BinarySearchTree.find_largest_le方法的典型用法代码示例。如果您正苦于以下问题:Python BinarySearchTree.find_largest_le方法的具体用法?Python BinarySearchTree.find_largest_le怎么用?Python BinarySearchTree.find_largest_le使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bst.BinarySearchTree
的用法示例。
在下文中一共展示了BinarySearchTree.find_largest_le方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Genotype
# 需要导入模块: from bst import BinarySearchTree [as 别名]
# 或者: from bst.BinarySearchTree import find_largest_le [as 别名]
class Genotype(object):
#---------------------------------------------
# Constructors
#---------------------------------------------
def __init__(self, data, snp, sample_id):
'''
Construct a genotype set from data arrays:
- snp: SNP metadata record array (contains chromosome, name, morgans, base-pair location)
- data: a 3-D genotype data array: (individual x SNP x allele)
- sample_id: genotyped individuals' ID set
'''
# People's IDs
self.sample_id = sample_id
self.data = data
self._num_snps = self.data.shape[0]
self._num_samples = self.data.shape[1]
self._snp_range = None
# SNP metadata: SNP label, chromosome number, Genetic distance in Morgans, and
# base pair location for each SNP
self.snp = snp
# Base-pair-location to snp-index map, lazily-initialized + cached
base_pair = self.snp['base_pair']
self._base_pair = base_pair # np.array([int(base_pair)]) if base_pair.size == 1 else base_pair
self._bp_to_snp = dict_invert(dict(enumerate(self._base_pair)))
# Construct a BST for fast bp queries
self._snp_tree = BinarySearchTree(values=self._base_pair[optimal_insertion_order(self._num_snps)])
self._snp_index_tree = util.list_index_tree(self._base_pair)
# A genetic map: lists the two allele letters corresponding to 1 and 2 for each SNP, according
# their order in the self.snp array.
self.map = []
# General metadata, for easy handling of CGI data
self.metadata = []
# samples for which the parent-of-origin phase is determined
self.poo_phase = np.zeros((self._num_samples,), dtype=np.byte)
@staticmethod
def empty(snp, sample_id, sz):
'''Allocate an empty data array of size sz.'''
return Genotype(snp, sample_id, np.zeros(sz, dtype=np.byte))
def copy(self):
'''Return a deep copy of this object.'''
return Genotype(self.data.copy(), self.snp.copy(), self.sample_id.copy())
#---------------------------------------------
# Operators
#---------------------------------------------
def __key(self):
'''Uniquely-identifying key of this object.'''
return (self.data.tolist(), self.snp.tolist(),
self.sample_id.tolist() if self.sample_id is not None else None)
def __eq__(self, y):
'''Equality of objects.'''
return self.__key() == y.__key()
def __ne__(self, y):
'''Inequality of objects.'''
return self.__key() != y.__key()
def __hash__(self):
'''Object hash code.'''
return hash(self.__key())
def __repr__(self):
return 'Genotype[snps=%d, samples=%d]' % (self.num_snps, self.num_samples)
#---------------------------------------------
# Methods
#---------------------------------------------
def clear(self, snp, person):
'''Set the data for the individuals whose index is person at snp indices snp
to MISSING.'''
self.data[snp, person, :] = constants.MISSING
def nearest_snp(self, bp):
'''Nearest SNP neighbor to a base pair location bp.'''
return util.nearest_neighbor_in_list_tree(bp, self._base_pair, self._snp_index_tree)
def nearest_snp_multiple(self, bp):
'''Nearest SNP neighbor to each element of a base pair collection bp.'''
return util.nearest_neighbor_in_list_tree_multiple(bp, self._base_pair, self._snp_index_tree)
def segment_intersect(self, segment_in_bp):
'''Return endpoints of the SNP index range contained in the base-pair segment segment.
If segment does not intersect our SNP range, return None. The range is [start_index,stop_index)
where start=inclusive and stop is exclsive.'''
left = self._snp_tree.find_smallest_ge(segment_in_bp[0])
if left is None: return None
right = self._snp_tree.find_largest_le(segment_in_bp[1])
if right is None: return None
return (self._bp_to_snp[left], self._bp_to_snp[right] + 1)
def segments_intersect(self, segments_in_bp):
'''Find SNP range of each segment in the list segments_in_bp whose unit is base pairs.'''
segments = []
for x in segments_in_bp:
y = self.segment_intersect(x)
#.........这里部分代码省略.........