本文整理汇总了Python中skbio.metadata.IntervalMetadata.sort方法的典型用法代码示例。如果您正苦于以下问题:Python IntervalMetadata.sort方法的具体用法?Python IntervalMetadata.sort怎么用?Python IntervalMetadata.sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.metadata.IntervalMetadata
的用法示例。
在下文中一共展示了IntervalMetadata.sort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestIntervalMetadata
# 需要导入模块: from skbio.metadata import IntervalMetadata [as 别名]
# 或者: from skbio.metadata.IntervalMetadata import sort [as 别名]
#.........这里部分代码省略.........
self.assertEqual(self.im_empty, self.im_1)
# non-empty + non-empty
self.im_empty.merge(self.im_2)
self.im_2.merge(self.im_1)
self.assertEqual(self.im_empty, self.im_2)
def test_merge_unequal_upper_bounds(self):
n = 3
im1 = IntervalMetadata(n)
for im in [self.im_empty, self.im_1]:
with self.assertRaisesRegex(
ValueError,
r'not equal \(%d != %d\)' % (self.upper_bound, n)):
im.merge(im1)
def test_merge_to_unbounded(self):
for im in [self.im_empty, self.im_1, IntervalMetadata(None)]:
obs = IntervalMetadata(None)
obs.merge(im)
self.assertIsNone(obs.upper_bound)
self.assertEqual(obs._intervals, im._intervals)
def test_merge_unbounded_to_bounded(self):
im = IntervalMetadata(None)
with self.assertRaisesRegex(
ValueError,
r'Cannot merge an unbound IntervalMetadata object '
'to a bounded one'):
self.im_1.merge(im)
# original im is not changed
self.assertIsNone(im.upper_bound)
self.assertEqual(im._intervals, [])
def test_sort(self):
interval = Interval(
self.im_2,
[(1, 2), (3, 8)],
metadata={'gene': 'sagA', 'bound': 0})
im = deepcopy(self.im_2)
self.im_2.sort(False)
# check sorting does not have other side effects
self.assertEqual(im, self.im_2)
self.assertEqual(self.im_2._intervals,
[self.im_2_2, self.im_2_1, interval])
self.im_2.sort()
self.assertEqual(im, self.im_2)
self.assertEqual(self.im_2._intervals,
[interval, self.im_2_1, self.im_2_2])
self.im_empty.sort()
self.assertEqual(self.im_empty, IntervalMetadata(self.upper_bound))
def test_add_eq_upper_bound(self):
self.im_empty.add(bounds=[(1, 2), (4, self.upper_bound)],
metadata={'gene': 'sagA', 'bound': 0})
self.assertTrue(self.im_empty._is_stale_tree)
interval = self.im_empty._intervals[0]
self.assertEqual(interval.bounds, [(1, 2), (4, self.upper_bound)])
self.assertEqual(interval.metadata, {'gene': 'sagA', 'bound': 0})
self.assertTrue(isinstance(self.im_empty._interval_tree, IntervalTree))
def test_add_gt_upper_bound(self):
with self.assertRaises(ValueError):
self.im_empty.add(bounds=[(1, 2), (4, self.upper_bound+1)],
metadata={'gene': 'sagA', 'bound': 0})