• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python distance.DissimilarityMatrix类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中skbio.core.distance.DissimilarityMatrix的典型用法代码示例。如果您正苦于以下问题:Python DissimilarityMatrix类的具体用法?Python DissimilarityMatrix怎么用?Python DissimilarityMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_from_file_with_file_path

    def test_from_file_with_file_path(self):
        """Should identify the filepath correctly and parse from it."""

        # should fail with the expected exception
        with self.assertRaises(DissimilarityMatrixFormatError):
            DissimilarityMatrix.from_file(self.bad_dm_fp)

        obs = DissimilarityMatrix.from_file(self.dm_2x2_asym_fp)
        self.assertEqual(self.dm_2x2_asym, obs)
        self.assertTrue(isinstance(obs, DissimilarityMatrix))

        obs = DissimilarityMatrix.from_file(self.dm_3x3_fp)
        self.assertEqual(self.dm_3x3, obs)
        self.assertTrue(isinstance(obs, DissimilarityMatrix))
开发者ID:charudatta-navare,项目名称:scikit-bio,代码行数:14,代码来源:test_distance.py


示例2: test_round_trip_read_write

    def test_round_trip_read_write(self):
        """Test reading, writing, and reading again works as expected."""
        for dm_f in self.dm_fs:
            # Read.
            dm1 = DissimilarityMatrix.from_file(dm_f)

            # Write.
            out_f = StringIO()
            dm1.to_file(out_f)
            out_f.seek(0)

            # Read.
            dm2 = DissimilarityMatrix.from_file(out_f)
            self.assertEqual(dm1, dm2)
开发者ID:charudatta-navare,项目名称:scikit-bio,代码行数:14,代码来源:test_distance.py


示例3: test_filter_asymmetric

    def test_filter_asymmetric(self):
        # 2x2
        ids = ['b', 'a']
        exp = DissimilarityMatrix([[0, -2], [1, 0]], ids)
        obs = self.dm_2x2_asym.filter(ids)
        self.assertEqual(obs, exp)

        # 3x3
        dm = DissimilarityMatrix([[0, 10, 53], [42, 0, 22.5], [53, 1, 0]],
                                 ('bro', 'brah', 'breh'))
        ids = ['breh', 'brah']
        exp = DissimilarityMatrix([[0, 1], [22.5, 0]], ids)
        obs = dm.filter(ids)
        self.assertEqual(obs, exp)
开发者ID:BANSHEE-,项目名称:scikit-bio,代码行数:14,代码来源:test_distance.py


示例4: test_from_file_real_file

    def test_from_file_real_file(self):
        """Should correctly parse a real on-disk file."""
        self.tmp_f.write('\n'.join(DM_3x3_WHITESPACE_F))
        self.tmp_f.seek(0)

        obs = DissimilarityMatrix.from_file(self.tmp_f)
        self.assertEqual(obs, self.dm_3x3)
开发者ID:Jorge-C,项目名称:bipy,代码行数:7,代码来源:test_distance.py


示例5: test_from_file_invalid_input

    def test_from_file_invalid_input(self):
        """Raises error on ill-formatted dissimilarity matrix file."""
        # Empty dm.
        with self.assertRaises(DissimilarityMatrixFormatError):
            _ = DissimilarityMatrix.from_file([])

        # Number of values don't match number of IDs.
        with self.assertRaises(DissimilarityMatrixFormatError):
            _ = DissimilarityMatrix.from_file(self.bad_dm_f1)

        # Mismatched IDs.
        with self.assertRaises(DissimilarityMatrixFormatError):
            _ = DissimilarityMatrix.from_file(self.bad_dm_f2)

        # Extra data at end.
        with self.assertRaises(DissimilarityMatrixFormatError):
            _ = DissimilarityMatrix.from_file(self.bad_dm_f3)

        # Missing data.
        with self.assertRaises(DissimilarityMatrixFormatError):
            _ = DissimilarityMatrix.from_file(self.bad_dm_f4)

        # Header, but no data.
        with self.assertRaises(DissimilarityMatrixFormatError):
            _ = DissimilarityMatrix.from_file(self.bad_dm_f5)

        # Non-hollow.
        with self.assertRaises(DissimilarityMatrixError):
            _ = DissimilarityMatrix.from_file(self.bad_dm_f6)
开发者ID:Jorge-C,项目名称:bipy,代码行数:29,代码来源:test_distance.py


示例6: test_filter_subset

    def test_filter_subset(self):
        ids = ('c', 'a')
        exp = DissimilarityMatrix([[0, 4.2], [4.2, 0]], ids)
        obs = self.dm_3x3.filter(ids)
        self.assertEqual(obs, exp)

        ids = ('b', 'a')
        exp = DissimilarityMatrix([[0, 0.01], [0.01, 0]], ids)
        obs = self.dm_3x3.filter(ids)
        self.assertEqual(obs, exp)

        # 4x4
        dm = DissimilarityMatrix([[0, 1, 55, 7], [1, 0, 16, 1],
                                  [55, 16, 0, 23], [7, 1, 23, 0]])
        ids = np.asarray(['3', '0', '1'])
        exp = DissimilarityMatrix([[0, 7, 1], [7, 0, 1], [1, 1, 0]], ids)
        obs = dm.filter(ids)
        self.assertEqual(obs, exp)
开发者ID:BANSHEE-,项目名称:scikit-bio,代码行数:18,代码来源:test_distance.py


示例7: test_from_file_real_file

    def test_from_file_real_file(self):
        """Should correctly parse a real on-disk file."""
        with tempfile.TemporaryFile(mode='r+',
                                    prefix='skbio.core.tests.test_distance',
                                    suffix='.txt') as fh:
            fh.write('\n'.join(DM_3x3_WHITESPACE_F))
            fh.seek(0)

            obs = DissimilarityMatrix.from_file(fh)
        self.assertEqual(obs, self.dm_3x3)
开发者ID:charudatta-navare,项目名称:scikit-bio,代码行数:10,代码来源:test_distance.py


示例8: test_init_from_dm

    def test_init_from_dm(self):
        """Constructs a dm from a dm."""
        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'])
开发者ID:charudatta-navare,项目名称:scikit-bio,代码行数:22,代码来源:test_distance.py


示例9: setUp

    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_f_lines = [DM_1x1_F, DM_2x2_F, self.dm_2x2_asym_lines,
                           self.dm_3x3_lines]
        self.dm_fs = [self.dm_1x1_f, self.dm_2x2_f, self.dm_2x2_asym_f,
                      self.dm_3x3_f]
        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)]
开发者ID:charudatta-navare,项目名称:scikit-bio,代码行数:23,代码来源:test_distance.py


示例10: DissimilarityMatrixTests

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_f_lines = [DM_1x1_F, DM_2x2_F, self.dm_2x2_asym_lines,
                           self.dm_3x3_lines]
        self.dm_fs = [self.dm_1x1_f, self.dm_2x2_f, self.dm_2x2_asym_f,
                      self.dm_3x3_f]
        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_round_trip_read_write(self):
        """Test reading, writing, and reading again works as expected."""
        for dm_f in self.dm_fs:
            # Read.
            dm1 = DissimilarityMatrix.from_file(dm_f)

            # Write.
            out_f = StringIO()
            dm1.to_file(out_f)
            out_f.seek(0)

            # Read.
            dm2 = DissimilarityMatrix.from_file(out_f)
            self.assertEqual(dm1, dm2)

    def test_from_file(self):
        """Should parse and return a valid DissimilarityMatrix given a file."""
        for dm_f, dm in zip(self.dm_fs, self.dms):
            obs = DissimilarityMatrix.from_file(dm_f)
            self.assertEqual(obs, dm)

    def test_from_file_with_file_path(self):
        """Should identify the filepath correctly and parse from it."""

        # should fail with the expected exception
        with self.assertRaises(DissimilarityMatrixFormatError):
            DissimilarityMatrix.from_file(self.bad_dm_fp)

        obs = DissimilarityMatrix.from_file(self.dm_2x2_asym_fp)
        self.assertEqual(self.dm_2x2_asym, obs)
        self.assertTrue(isinstance(obs, DissimilarityMatrix))

        obs = DissimilarityMatrix.from_file(self.dm_3x3_fp)
        self.assertEqual(self.dm_3x3, obs)
        self.assertTrue(isinstance(obs, DissimilarityMatrix))

    def test_from_file_extra_junk(self):
        """Should correctly parse a file with extra whitespace and comments."""
        obs = DissimilarityMatrix.from_file(self.dm_3x3_whitespace_f)
        self.assertEqual(obs, self.dm_3x3)

    def test_from_file_list_of_strings(self):
        """Should correctly parse a list of strings."""
        obs = DissimilarityMatrix.from_file(DM_3x3_WHITESPACE_F)
        self.assertEqual(obs, self.dm_3x3)

    def test_from_file_real_file(self):
        """Should correctly parse a real on-disk file."""
        with tempfile.TemporaryFile(mode='r+',
                                    prefix='skbio.core.tests.test_distance',
                                    suffix='.txt') as fh:
            fh.write('\n'.join(DM_3x3_WHITESPACE_F))
            fh.seek(0)

            obs = DissimilarityMatrix.from_file(fh)
        self.assertEqual(obs, self.dm_3x3)

    def test_from_file_invalid_input(self):
        """Raises error on ill-formatted dissimilarity matrix file."""
        # Empty dm.
        with self.assertRaises(DissimilarityMatrixFormatError):
            DissimilarityMatrix.from_file([])

        # Number of values don't match number of IDs.
        with self.assertRaises(DissimilarityMatrixFormatError):
            DissimilarityMatrix.from_file(self.bad_dm_f1)

        # Mismatched IDs.
        with self.assertRaises(DissimilarityMatrixFormatError):
            DissimilarityMatrix.from_file(self.bad_dm_f2)

        # Extra data at end.
        with self.assertRaises(DissimilarityMatrixFormatError):
            DissimilarityMatrix.from_file(self.bad_dm_f3)

#.........这里部分代码省略.........
开发者ID:charudatta-navare,项目名称:scikit-bio,代码行数:101,代码来源:test_distance.py


示例11: test_from_file_list_of_strings

 def test_from_file_list_of_strings(self):
     """Should correctly parse a list of strings."""
     obs = DissimilarityMatrix.from_file(DM_3x3_WHITESPACE_F)
     self.assertEqual(obs, self.dm_3x3)
开发者ID:charudatta-navare,项目名称:scikit-bio,代码行数:4,代码来源:test_distance.py


示例12: test_from_file_extra_junk

 def test_from_file_extra_junk(self):
     """Should correctly parse a file with extra whitespace and comments."""
     obs = DissimilarityMatrix.from_file(self.dm_3x3_whitespace_f)
     self.assertEqual(obs, self.dm_3x3)
开发者ID:charudatta-navare,项目名称:scikit-bio,代码行数:4,代码来源:test_distance.py


示例13: test_from_file

 def test_from_file(self):
     """Should parse and return a valid DissimilarityMatrix given a file."""
     for dm_f, dm in zip(self.dm_fs, self.dms):
         obs = DissimilarityMatrix.from_file(dm_f)
         self.assertEqual(obs, dm)
开发者ID:charudatta-navare,项目名称:scikit-bio,代码行数:5,代码来源:test_distance.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sequence.NucleotideSequence类代码示例发布时间:2022-05-27
下一篇:
Python alignment.SequenceCollection类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap