📄 phy_node.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: phy_node.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 18:09:38 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4 * PRODUCTION * =========================================================================== *//* $Id: phy_node.cpp,v 1000.1 2004/06/01 18:09:38 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Josh Cherry * * File Description: Things for representing and manipulating * phylogenetic trees * */#include <ncbi_pch.hpp>#include <algo/phy_tree/phy_node.hpp>BEGIN_NCBI_SCOPEstatic string s_EncodeLabel(const string& label);// recursive functionvoid PrintNode(CNcbiOstream& os, const TPhyTreeNode& node){ if (!node.IsLeaf()) { os << '('; for (TPhyTreeNode::TNodeList_CI it = node.SubNodeBegin(); it != node.SubNodeEnd(); ++it) { if (it != node.SubNodeBegin()) { os << ", "; } PrintNode(os, **it); } os << ')'; } if (node.IsLeaf() || !node.GetValue().GetLabel().empty()) { os << s_EncodeLabel(node.GetValue().GetLabel()); } if (node.GetValue().IsSetDist()) { os << ':' << node.GetValue().GetDist(); }}CNcbiOstream& operator<<(CNcbiOstream& os, const TPhyTreeNode& tree){ PrintNode(os, tree); os << ';' << endl; return os;};void WriteNexusTree(CNcbiOstream& os, const TPhyTreeNode& tree, const string& tree_name){ os << "#nexus\n\nbegin trees;\ntree " << tree_name << " = " << tree << "\nend;" << endl;};// Encode a label for Newick format: enclose it in single quotes,// but first escape any single quotes by doubling them.// e.g., "This 'label'" -> "'This ''label'''"static string s_EncodeLabel(const string& label) { if (label.find_first_of("'") == string::npos) { return '\'' + label + '\''; } string rv; rv.reserve(label.size() + 2); rv.append(1, '\''); for (unsigned int i = 0; i < label.size(); ++i) { rv.append(1, label[i]); if (label[i] == '\'') { // "'" -> "''" rv.append(1, label[i]); } } rv.append(1, '\''); return rv;}END_NCBI_SCOPE/* * =========================================================================== * $Log: phy_node.cpp,v $ * Revision 1000.1 2004/06/01 18:09:38 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4 * * Revision 1.4 2004/05/21 21:41:03 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.3 2004/02/11 21:50:23 jcherry * Added Nexus format output * * Revision 1.2 2004/02/10 17:01:42 dicuccio * Use basic_string::append() instead of push_back, as the latter isn't found on * MSVC * * Revision 1.1 2004/02/10 15:15:58 jcherry * Initial version * * =========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -