def write(self, features=None, outfile=None, format=10): """ Inherits from Tree but adds the tenth format, that allows to display marks for CodeML. TODO: internal writting format need to be something like 0 """ from re import sub if int(format)==11: nwk = ' %s 1\n' % (len(self)) nwk += sub('\[&&NHX:mark=([ #0-9.]*)\]', r'\1', \ write_newick(self, features=['mark'],format=9)) elif int(format)==10: nwk = sub('\[&&NHX:mark=([ #0-9.]*)\]', r'\1', \ write_newick(self, features=['mark'],format=9)) else: nwk = write_newick(self, features=features,format=format) if outfile is not None: open(outfile, "w").write(nwk) return nwk else: return nwk
def write(self, features=None, outfile=None, format=10): """ Inherits from Tree but adds the tenth format, that allows to display marks for CodeML. TODO: internal writting format need to be something like 0 """ from re import sub if int(format) == 11: nwk = ' %s 1\n' % (len(self)) nwk += sub('\[&&NHX:mark=([ #0-9.]*)\]', r'\1', \ write_newick(self, features=['mark'],format=9)) elif int(format) == 10: nwk = sub('\[&&NHX:mark=([ #0-9.]*)\]', r'\1', \ write_newick(self, features=['mark'],format=9)) else: nwk = write_newick(self, features=features, format=format) if outfile is not None: open(outfile, "w").write(nwk) return nwk else: return nwk
n.remove_child(child) for grandchild in child.children: n.add_child(grandchild) num_collapsed += 1 msg = '' if num_collapsed: msg = 'Collapsed {} internal branch{}'.format( num_collapsed, 'es' if num_collapsed > 1 else '') if num_set_zero_tip: if msg: msg += ', set {} external branch{} to zero'.format( num_set_zero_tip, 'es' if num_set_zero_tip > 1 else '') else: msg += 'Set {} external branch{} to zero'.format( num_set_zero_tip, 'es' if num_set_zero_tip > 1 else '') if num_set_zero_root: if msg: msg += ', set {} root child branch{} to zero'.format( num_set_zero_root, 'es' if num_set_zero_root > 1 else '') else: msg += 'Set {} root child branch{} to zero'.format( num_set_zero_root, 'es' if num_set_zero_root > 1 else '') if not msg: msg = 'Did not find any branches to modify' logging.info('{} (criterion: {} <{} {}).'.format( msg, params.feature, '' if params.strict else '=', threshold)) nwk = write_newick(tr, format_root_node=True, format=1) with open(params.output_tree, 'w+') as f: f.write('%s\n' % nwk)