def test_change_comment(self): translatetable = {'0': 'Chris', '1': 'Bruce', '2': 'Tom'} oldtree = "tree a = ((0[x],1[y]),2[z]);" newtree = "tree a = ((Chris[x],Bruce[y]),Tom[z]);" trans = TreeHandler()._detranslate_tree(oldtree, translatetable) assert trans == newtree, \ "Unable to correctly detranslate a tree with branchlengths"
def test_BEAST_format(self): translatetable = {'1': 'Chris', '2': 'Bruce', '3': 'Tom'} oldtree = "tree STATE_0 [&lnP=-584.441] = [&R] ((1:[&rate=1.0]48.056,3:[&rate=1.0]48.056):[&rate=1.0]161.121,2:[&rate=1.0]209.177);" newtree = "tree STATE_0 [&lnP=-584.441] = [&R] ((Chris:[&rate=1.0]48.056,Tom:[&rate=1.0]48.056):[&rate=1.0]161.121,Bruce:[&rate=1.0]209.177);" trans = TreeHandler()._detranslate_tree(oldtree, translatetable) assert trans == newtree, \ "Unable to correctly detranslate a BEAST tree"
def test_change(self): translatetable = {'0': 'Chris', '1': 'Bruce', '2': 'Tom'} oldtree = "tree a = ((0,1),2);" newtree = "tree a = ((Chris,Bruce),Tom);" trans = TreeHandler()._detranslate_tree(oldtree, translatetable) assert trans == newtree, \ "Unable to correctly detranslate a simple tree"
def test_change_branchlengths(self): translatetable = {'0': 'Chris', '1': 'Bruce', '2': 'Tom'} oldtree = "tree a = ((0:0.1,1:0.2):0.3,2:0.4);" newtree = "tree a = ((Chris:0.1,Bruce:0.2):0.3,Tom:0.4);" trans = TreeHandler()._detranslate_tree(oldtree, translatetable) assert trans == newtree, \ "Unable to correctly detranslate a tree with branchlengths"
def test_preamble(): translatetable = {'1': 'Chris', '2': 'Bruce', '3': 'Tom'} oldtree = "tree STATE_0=((1:[&rate=1.0]48.056,3:[&rate=1.0]48.056):[&rate=1.0]161.121,2:[&rate=1.0]209.177);" newtree = "tree STATE_0=((Chris:[&rate=1.0]48.056,Tom:[&rate=1.0]48.056):[&rate=1.0]161.121,Bruce:[&rate=1.0]209.177);" trans = TreeHandler()._detranslate_tree(oldtree, translatetable) assert trans == newtree, \ "Unable to correctly detranslate a BEAST tree"
def test_leading_BEAST_format(): translatetable = {'1': 'Chris', '2': 'Bruce', '3': 'Tom'} oldtree = "tree STATE_0 [&lnP=-8411959.874895355,posterior=-8411959.874895355] = [&R] ((1:[&rate=1.0]48.056,3:[&rate=1.0]48.056):[&rate=1.0]161.121,2:[&rate=1.0]209.177);" newtree = "tree STATE_0 [&lnP=-8411959.874895355,posterior=-8411959.874895355] = [&R] ((Chris:[&rate=1.0]48.056,Tom:[&rate=1.0]48.056):[&rate=1.0]161.121,Bruce:[&rate=1.0]209.177);" trans = TreeHandler()._detranslate_tree(oldtree, translatetable) assert trans == newtree, \ "Unable to correctly detranslate a BEAST tree"
def setUp(self): th = TreeHandler() self.findall = th._findall_chunks
def test_invalid_preamble(): with pytest.raises(ValueError): TreeHandler()._detranslate_tree( 'tree STATE_0 [abcde=1234 = ((1:[&rate=1.0]48.056,3:[&rate=1.0]48.056):[&rate=1.0]161.121,2:[&rate=1.0]209.177);', {})
def findall(): th = TreeHandler() return th._findall_chunks