本文整理汇总了Python中skbio.stats.distance.DissimilarityMatrix.write方法的典型用法代码示例。如果您正苦于以下问题:Python DissimilarityMatrix.write方法的具体用法?Python DissimilarityMatrix.write怎么用?Python DissimilarityMatrix.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.stats.distance.DissimilarityMatrix
的用法示例。
在下文中一共展示了DissimilarityMatrix.write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DissimilarityMatrixTests
# 需要导入模块: from skbio.stats.distance import DissimilarityMatrix [as 别名]
# 或者: from skbio.stats.distance.DissimilarityMatrix import write [as 别名]
class DissimilarityMatrixTests(DissimilarityMatrixTestData):
def setUp(self):
super(DissimilarityMatrixTests, self).setUp()
self.dm_1x1 = DissimilarityMatrix(self.dm_1x1_data, ['a'])
self.dm_2x2 = DissimilarityMatrix(self.dm_2x2_data, ['a', 'b'])
self.dm_2x2_asym = DissimilarityMatrix(self.dm_2x2_asym_data,
['a', 'b'])
self.dm_3x3 = DissimilarityMatrix(self.dm_3x3_data, ['a', 'b', 'c'])
self.dms = [self.dm_1x1, self.dm_2x2, self.dm_2x2_asym, self.dm_3x3]
self.dm_shapes = [(1, 1), (2, 2), (2, 2), (3, 3)]
self.dm_sizes = [1, 4, 4, 9]
self.dm_transposes = [
self.dm_1x1, self.dm_2x2,
DissimilarityMatrix([[0, -2], [1, 0]], ['a', 'b']), self.dm_3x3]
self.dm_redundant_forms = [np.array(self.dm_1x1_data),
np.array(self.dm_2x2_data),
np.array(self.dm_2x2_asym_data),
np.array(self.dm_3x3_data)]
def test_io(self):
# Very basic check that read/write public API is present and appears to
# be functioning. Roundtrip from memory -> disk -> memory and ensure
# results match.
fh = StringIO()
self.dm_3x3.write(fh)
fh.seek(0)
deserialized = DissimilarityMatrix.read(fh)
self.assertEqual(deserialized, self.dm_3x3)
self.assertTrue(type(deserialized) == DissimilarityMatrix)
def test_deprecated_io(self):
fh = StringIO()
npt.assert_warns(UserWarning, self.dm_3x3.to_file, fh)
fh.seek(0)
deserialized = npt.assert_warns(UserWarning,
DissimilarityMatrix.from_file, fh)
self.assertEqual(deserialized, self.dm_3x3)
self.assertTrue(type(deserialized) == DissimilarityMatrix)
def test_init_from_dm(self):
ids = ['foo', 'bar', 'baz']
# DissimilarityMatrix -> DissimilarityMatrix
exp = DissimilarityMatrix(self.dm_3x3_data, ids)
obs = DissimilarityMatrix(self.dm_3x3, ids)
self.assertEqual(obs, exp)
# Test that copy of data is not made.
self.assertTrue(obs.data is self.dm_3x3.data)
obs.data[0, 1] = 424242
self.assertTrue(np.array_equal(obs.data, self.dm_3x3.data))
# DistanceMatrix -> DissimilarityMatrix
exp = DissimilarityMatrix(self.dm_3x3_data, ids)
obs = DissimilarityMatrix(
DistanceMatrix(self.dm_3x3_data, ('a', 'b', 'c')), ids)
self.assertEqual(obs, exp)
# DissimilarityMatrix -> DistanceMatrix
with self.assertRaises(DistanceMatrixError):
DistanceMatrix(self.dm_2x2_asym, ['foo', 'bar'])
def test_init_no_ids(self):
exp = DissimilarityMatrix(self.dm_3x3_data, ('0', '1', '2'))
obs = DissimilarityMatrix(self.dm_3x3_data)
self.assertEqual(obs, exp)
self.assertEqual(obs['1', '2'], 12.0)
def test_init_invalid_input(self):
# Empty data.
with self.assertRaises(DissimilarityMatrixError):
DissimilarityMatrix([], [])
# Another type of empty data.
with self.assertRaises(DissimilarityMatrixError):
DissimilarityMatrix(np.empty((0, 0)), [])
# Invalid number of dimensions.
with self.assertRaises(DissimilarityMatrixError):
DissimilarityMatrix([1, 2, 3], ['a'])
# Dimensions don't match.
with self.assertRaises(DissimilarityMatrixError):
DissimilarityMatrix([[1, 2, 3]], ['a'])
data = [[0, 1], [1, 0]]
# Duplicate IDs.
with self.assertRaises(DissimilarityMatrixError):
DissimilarityMatrix(data, ['a', 'a'])
# Number of IDs don't match dimensions.
with self.assertRaises(DissimilarityMatrixError):
DissimilarityMatrix(data, ['a', 'b', 'c'])
# Non-hollow.
data = [[0.0, 1.0], [1.0, 0.01]]
with self.assertRaises(DissimilarityMatrixError):
DissimilarityMatrix(data, ['a', 'b'])
#.........这里部分代码省略.........