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

Python nexus.NexusReader类代码示例

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

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



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

示例1: test_find_unique_sites_2

    def test_find_unique_sites_2(self):
        nexus = NexusReader()
        nexus.read_string("""Begin data;
        Dimensions ntax=4 nchar=7;
        Format datatype=standard symbols="01" gap=-;
        Matrix
        Harry              10000?-
        Simon              1100011
        Betty              1110000
        Louise             1111000
        ;""")
        unique = find_unique_sites(nexus)

        # site 1 should NOT be in the uniques (3x1 and 1x0)
        # - i.e. are we ignoring sites with ONE absent taxon
        assert 1 not in unique
        # these should also NOT be in unique
        assert 0 not in unique
        assert 2 not in unique
        assert 4 not in unique  # constant
        # site 3 is a simple unique site - check we found it
        assert 3 in unique
        # sites 5 and 6 should also be unique
        # - are we handling missing data appropriately?
        assert 5 in unique
        assert 6 in unique
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:26,代码来源:test_find_unique_sites.py


示例2: setUp

 def setUp(self):
     self.nex1 = NexusReader()
     self.nex1.read_string(
         """Begin data;
         Dimensions ntax=2 nchar=1;
         Format datatype=standard symbols="12" gap=-;
         Matrix
         Harry              1
         Simon              2
         ;"""
     )
     self.nex2 = NexusReader()
     self.nex2.read_string(
         """Begin data;
         Dimensions ntax=2 nchar=1;
         Format datatype=standard symbols="34" gap=-;
         Matrix
         Harry              3
         Simon              4
         ;"""
     )
     self.nex3 = NexusReader()
     self.nex3.read_string(
         """Begin data;
         Dimensions ntax=3 nchar=1;
         Format datatype=standard symbols="345" gap=-;
         Matrix
         Betty              3
         Boris              4
         Simon              5
         ;"""
     )
开发者ID:nishmadahal,项目名称:PTP,代码行数:32,代码来源:test_CombineNexuses.py


示例3: test_read_string

 def test_read_string(self):
     handle = open(os.path.join(EXAMPLE_DIR, 'example.nex'))
     data = handle.read()
     handle.close()
     nex = NexusReader()
     nex.read_string(data)
     assert 'data' in nex.blocks
     assert 'Simon' in nex.blocks['data'].matrix
开发者ID:nishmadahal,项目名称:PTP,代码行数:8,代码来源:test_reader.py


示例4: test_write_to_file

 def test_write_to_file(self):
     tmp = NamedTemporaryFile(delete=False, suffix=".nex")
     tmp.close()
     nex = NexusReader(os.path.join(EXAMPLE_DIR, 'example.nex'))
     nex.write_to_file(tmp.name)
     assert os.path.isfile(tmp.name)
     n2 = NexusReader(tmp.name)
     assert n2.data.matrix == nex.data.matrix
     assert sorted(n2.data.taxa) == sorted(nex.data.taxa)
     os.unlink(tmp.name)        # cleanup
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:10,代码来源:test_reader.py


示例5: test_notimplemented_exception

 def test_notimplemented_exception(self):
     with self.assertRaises(NotImplementedError):
         nex = NexusReader()
         nex.read_string(
             """Begin something;
             Dimensions ntax=5 nchar=1;
             Format datatype=standard symbols="01" gap=-;
             Matrix
             Harry              1
             ;""")
         anonymise(nex)
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:11,代码来源:test_anonymise.py


示例6: test_incorrect_dimensions_warnings_nchar

 def test_incorrect_dimensions_warnings_nchar(self):
     with warnings.catch_warnings(record=True) as w:
         nex = NexusReader()
         nex.read_string(
             """Begin data;
             Dimensions ntax=1 nchar=5;
             Format datatype=standard symbols="01" gap=-;
             Matrix
             Harry              1
             ;""")
         assert len(w) == 1, 'Expected 1 warning, got %r' % w 
         assert issubclass(w[-1].category, UserWarning)
         assert "Expected" in str(w[-1].message)
         assert nex.data.nchar == 1
开发者ID:nishmadahal,项目名称:PTP,代码行数:14,代码来源:test_reader.py


示例7: test_labelled_unrooted

 def test_labelled_unrooted(self):
     nex = NexusReader()
     nex.read_string("""
     #NEXUS
 
     begin trees;
         translate
             0 Tom,
             1 Simon,
             2 Fred;
             tree unrooted [U] = (0,1,2);
     end;
     """)
     assert len(nex.trees.trees) == 1
     assert nex.trees.trees == ['tree unrooted [U] = (0,1,2);']
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:15,代码来源:test_handler_TreeHandler.py


示例8: test_treelabel

 def test_treelabel(self):
     nex = NexusReader()
     nex.read_string("""
     #NEXUS
 
     begin trees;
         translate
             0 Tom,
             1 Simon,
             2 Fred;
             tree TREEONE = (0,1,2);
     end;
     """)
     assert len(nex.trees.trees) == 1
     assert nex.trees.trees == ['tree TREEONE = (0,1,2);']
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:15,代码来源:test_handler_TreeHandler.py


示例9: Test_Binarise

class Test_Binarise(unittest.TestCase):
    def setUp(self):
        self.nex = NexusReader()
        self.nex.read_string(
        """Begin data;
        Dimensions ntax=3 nchar=2;
        Format datatype=standard symbols="01" gap=-;
        Charstatelabels
            1 char1, 2 char2;
        Matrix
        Maori               14
        Dutch               25
        Latin               36
        ;""")
        self.nex = binarise(self.nex)
    
    def test_to_binary(self):
        """Test Nexus -> Binary: Two Character"""
        expected = {
            'char1_0': {"Maori": '1', "Dutch": "0", "Latin": "0"},
            'char1_1': {"Maori": '0', "Dutch": "1", "Latin": "0"},
            'char1_2': {"Maori": '0', "Dutch": "0", "Latin": "1"},
            'char2_0': {"Maori": '1', "Dutch": "0", "Latin": "0"},
            'char2_1': {"Maori": '0', "Dutch": "1", "Latin": "0"},
            'char2_2': {"Maori": '0', "Dutch": "0", "Latin": "1"},
        }
        
        for char, data in expected.items():
            for taxon, exp_value in data.items():
                assert self.nex.data[char][taxon] == exp_value
    
    def test_to_binary_nchar(self):
        """Test Nexus -> Binary: Number of Characters"""
        assert len(self.nex.characters) == 6
        
    def test_to_binary_symbollist(self):
        """Test Nexus -> Binary: Update Symbol List"""
        # check symbol list was updated
        assert len(self.nex.symbols) == 2
        assert '1' in self.nex.symbols
        assert '0' in self.nex.symbols
        
    def test_to_binary_nexus(self):
        """Test Nexus -> Binary: Nexus"""
        nexus = self.nex.make_nexus(interleave=False)
        assert re.search("Dutch\s+010010", nexus)
        assert re.search("Maori\s+100100", nexus)
        assert re.search("Latin\s+001001", nexus)
开发者ID:nishmadahal,项目名称:PTP,代码行数:48,代码来源:test_binarise.py


示例10: Test_TreeHandler_Regression_Mesquite

class Test_TreeHandler_Regression_Mesquite(unittest.TestCase):
    """Regression: Test that we can parse MESQUITE taxa blocks"""
    def setUp(self):
        self.nex = NexusReader(
            os.path.join(REGRESSION_DIR, 'mesquite_formatted_branches.trees')
        )

    def test_attributes(self):
        assert len(self.nex.trees.attributes) == 2
        assert self.nex.trees.attributes[0] == \
            """Title 'Trees from "temp.trees"';"""
        assert self.nex.trees.attributes[1] == \
            """LINK Taxa = Untitled_Block_of_Taxa;"""

    def test_found_trees(self):
        assert self.nex.trees.ntrees == 1

    def test_found_taxa(self):
        assert len(self.nex.trees.taxa) == 3
        assert 'A' in self.nex.trees.taxa
        assert 'B' in self.nex.trees.taxa
        assert 'C' in self.nex.trees.taxa

    def test_was_translated(self):
        assert self.nex.trees.was_translated

    def test_translation(self):
        assert self.nex.trees.translators['1'] == 'A'
        assert self.nex.trees.translators['2'] == 'B'
        assert self.nex.trees.translators['3'] == 'C'

    def test_write(self):
        written = self.nex.write()
        assert """Title 'Trees from "temp.trees"';""" in written
        assert """LINK Taxa = Untitled_Block_of_Taxa;""" in written
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:35,代码来源:test_regressions.py


示例11: Test_TaxaHandler_Regression_Mesquite

class Test_TaxaHandler_Regression_Mesquite(unittest.TestCase):
    """Regression: Test that we can parse MESQUITE taxa blocks"""
    def setUp(self):
        self.nex = NexusReader(os.path.join(REGRESSION_DIR, 'mesquite_taxa_block.nex'))
        
    def test_taxa_block(self):
        for taxon in ['A', 'B', 'C']:
            assert taxon in self.nex.taxa
        # did we get the right number of taxa in the matrix?
        assert self.nex.taxa.ntaxa == len(self.nex.taxa.taxa) == 3
        
    def test_taxa_block_attributes(self):
        assert 'taxa' in self.nex.blocks
        assert len(self.nex.taxa.attributes) == 1
        assert 'TITLE Untitled_Block_of_Taxa;' in self.nex.taxa.attributes
    
    def test_write(self):
        expected_patterns = [
            '^begin taxa;$',
            '^\s+TITLE Untitled_Block_of_Taxa;$',
            '^\s+dimensions ntax=3;$',
            '^\s+taxlabels$',
            "^\s+\[1\] 'A'$",
            "^\s+\[2\] 'B'$",
            "^\s+\[3\] 'C'$",
            '^;$',
            '^end;$',
        ]
        written = self.nex.write()
        for expected in expected_patterns:
            assert re.search(expected, written, re.MULTILINE), 'Expected "%s"' % expected
开发者ID:nishmadahal,项目名称:PTP,代码行数:31,代码来源:test_regressions.py


示例12: test_generic_readwrite

 def test_generic_readwrite(self):
     expected = """Begin data;
     Dimensions ntax=4 nchar=2;
     Format datatype=standard symbols="01" gap=-;
     Matrix
     Harry              00
     Simon              01
     Betty              10
     Louise             11
     ;
     """.split("\n")
     nex = NexusReader()
     nex.handlers['data'] = GenericHandler
     nex.read_file(os.path.join(EXAMPLE_DIR, 'example.nex'))
     for line in nex.data.write().split("\n"):
         e = expected.pop(0).strip()
         assert line.strip() == e
开发者ID:nishmadahal,项目名称:PTP,代码行数:17,代码来源:test_reader.py


示例13: test_ok_starting_with_zero

 def test_ok_starting_with_zero(self):
     nex = NexusReader()
     nex.read_string("""
     #NEXUS
 
     begin trees;
         translate
             0 Tom,
             1 Simon,
             2 Fred;
             tree tree = (0,1,2)
     end;
     """)
     assert len(nex.trees.translators) == 3
     assert '0' in nex.trees.translators
     assert '1' in nex.trees.translators
     assert '2' in nex.trees.translators
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:17,代码来源:test_handler_TreeHandler.py


示例14: test_ok_starting_with_one

 def test_ok_starting_with_one(self):
     nex = NexusReader()
     nex.read_string("""
     #NEXUS
 
     begin trees;
         translate
             1 Tom,
             2 Simon,
             3 Fred;
             tree tree = (1,2,3)
     end;
     """)
     assert len(nex.trees.translators) == 3
     assert '1' in nex.trees.translators
     assert '2' in nex.trees.translators
     assert '3' in nex.trees.translators
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:17,代码来源:test_handler_TreeHandler.py


示例15: Test_TallyBySite

class Test_TallyBySite(unittest.TestCase):
    def setUp(self):
        self.nex = NexusReader()
        self.nex.read_string(
            """Begin data;
            Dimensions ntax=3 nchar=6;
            Format datatype=standard symbols="12" gap=-;
            Matrix
            Harry              0111-?
            Simon              0011-?
            Elvis              0001-?
            ;"""
        )
    
    def test_errorcheck(self):
        self.assertRaises(TypeError, tally_by_site, "I am a string")
        self.assertRaises(TypeError, tally_by_site, 0)
    
    def test_tally_by_site(self):
        tally = tally_by_site(self.nex)
        # 000
        assert 'Harry' in tally[0]['0']
        assert 'Simon' in tally[0]['0']
        assert 'Elvis' in tally[0]['0']
        # 100
        assert 'Harry' in tally[1]['1']
        assert 'Simon' in tally[1]['0']
        assert 'Elvis' in tally[1]['0']
        # 110
        assert 'Harry' in tally[2]['1']
        assert 'Simon' in tally[2]['1']
        assert 'Elvis' in tally[2]['0']
        # 111
        assert 'Harry' in tally[3]['1']
        assert 'Simon' in tally[3]['1']
        assert 'Elvis' in tally[3]['1']
        # ---
        assert 'Harry' in tally[4]['-']
        assert 'Simon' in tally[4]['-']
        assert 'Elvis' in tally[4]['-']
        # ???
        assert 'Harry' in tally[5]['?']
        assert 'Simon' in tally[5]['?']
        assert 'Elvis' in tally[5]['?']
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:44,代码来源:test_tally_by_site.py


示例16: Test_DataHandler_Regression_Mesquite

class Test_DataHandler_Regression_Mesquite(unittest.TestCase):
    """Regression: Test that we can parse MESQUITE data blocks"""

    def setUp(self):
        self.nex = NexusReader()
        self.nex.read_string("""
        #NEXUS

        Begin data;
        TITLE Untitled_Block_of_Taxa;
        LINK Taxa = Untitled_Block_of_Taxa;
        Dimensions ntax=2 nchar=2;
        Format datatype=standard gap=- symbols="01";
        Matrix
        Harry              00
        Simon              01
            ;
        End;
        """)
    
    def test_attributes(self):
        assert len(self.nex.data.attributes) == 2
        assert self.nex.data.attributes[0] == \
            """TITLE Untitled_Block_of_Taxa;"""
        assert self.nex.data.attributes[1] == \
            """LINK Taxa = Untitled_Block_of_Taxa;"""

    def test_write(self):
        expected_patterns = [
            '^begin data;$',
            '^\s+TITLE Untitled_Block_of_Taxa;$',
            '^\s+LINK Taxa = Untitled_Block_of_Taxa;$',
            '^\s+dimensions ntax=2 nchar=2;$',
            '^\s+format datatype=standard gap=- symbols="01";$',
            "^matrix$",
            "^Harry\s+00",
            "^Simon\s+01$",
            '^\s+;$',
            '^end;$',
        ]
        written = self.nex.write()
        for expected in expected_patterns:
            assert re.search(expected, written, re.MULTILINE), \
                'Expected "%s"' % expected
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:44,代码来源:test_regressions.py


示例17: test_regression_include_invisible_taxa

 def test_regression_include_invisible_taxa(self):
     """Include taxa that have no entries"""
     data = """
     #NEXUS
     
     BEGIN DATA;
         DIMENSIONS  NTAX=15 NCHAR=7;
         FORMAT DATATYPE=STANDARD MISSING=? GAP=- INTERLEAVE=YES;
     MATRIX
     
     Gertrude                0000001
     Debbie                  0001000
     Zarathrustra            0000000
     Christie                0010000
     Benny                   0100000
     Bertha                  0100000
     Craig                   0010000
     Fannie-May              0000010
     Charles                 0010000
     Annik                   1000000
     Frank                   0000010
     Amber                   1000000
     Andreea                 1000000
     Edward                  0000100
     Donald                  0001000
     ;
     END;
     """
     
     nex = NexusReader()
     nex.read_string(data)
     msnex = multistatise(nex)
     
     for taxon, sites in msnex.data.matrix.items():
         if taxon[0] == 'Z':
             continue  # will check later
         
         # first letter of taxa name is the expected character state
         assert taxon[0] == sites[0], \
             "%s should be %s not %s" % (taxon, taxon[0], sites[0])
     # deal with completely missing taxa
     assert 'Zarathrustra' in msnex.data.matrix
     assert msnex.data.matrix['Zarathrustra'][0] == '?'
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:43,代码来源:test_multistatise.py


示例18: setUp

 def setUp(self):
     self.nex = NexusReader()
     self.nex.read_string(
         """Begin data;
         Dimensions ntax=3 nchar=4;
         Format datatype=standard symbols="12" gap=-;
         Matrix
         Harry              0111
         Simon              0011
         Elvis              0001
         ;"""
     )
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:12,代码来源:test_count_binary_set_size.py


示例19: test_count_other_values_two

 def test_count_other_values_two(self):
     expected = {"Harry": 1, "Simon": 2, "Peter": 1, "Betty": 0, "Louise": 0}
     nexus = NexusReader()
     nexus.read_string(
         """#NEXUS 
     Begin data;
     Dimensions ntax=5 nchar=3;
     Format datatype=standard symbols="01" gap=-;
     Matrix
     Harry              0A0  [No missing]
     Simon              0AB  [one missing]
     Peter              0-B  [one gap]
     Betty              ?-1  [one gap and one missing = 2 missing]
     Louise             ???  [three missing]
         ;
     End;
     """
     )
     count = count_site_values(nexus, ["A", "B"])
     for taxon in count:
         assert count[taxon] == expected[taxon]
开发者ID:pombredanne,项目名称:PTP-web-server,代码行数:21,代码来源:test_CountSiteValues.py


示例20: test_count_other_values_one

 def test_count_other_values_one(self):
     expected = {
         'Harry': 1, 'Simon': 1, 'Peter': 0, 'Betty': 0, 'Louise': 0
     }
     nexus = NexusReader()
     nexus.read_string("""#NEXUS
     Begin data;
     Dimensions ntax=5 nchar=3;
     Format datatype=standard symbols="01" gap=-;
     Matrix
     Harry              0A0  [No missing]
     Simon              0A0  [one missing]
     Peter              0-0  [one gap]
     Betty              ?-1  [one gap and one missing = 2 missing]
     Louise             ???  [three missing]
         ;
     End;
     """)
     count = count_site_values(nexus, 'A')
     for taxon in count:
         assert count[taxon] == expected[taxon]
开发者ID:SimonGreenhill,项目名称:python-nexus,代码行数:21,代码来源:test_count_site_values.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python gettextutils._函数代码示例发布时间:2022-05-27
下一篇:
Python nextgisweb.DBSession类代码示例发布时间: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