phylo_tree_reader.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:5k
- /*
- * ===========================================================================
- * PRODUCTION $Log: phylo_tree_reader.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 21:11:46 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: phylo_tree_reader.cpp,v 1000.1 2004/06/01 21:11:46 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: Vladimir Tereshkov
- *
- * File Description:
- *
- */
- #include <ncbi_pch.hpp>
- #include <gui/widgets/phylo_tree/phylo_tree_reader.hpp>
- BEGIN_NCBI_SCOPE
- CPhyloPhylipReader::CPhyloPhylipReader()
- {
- m_Phylip = "";
- }
-
- CPhyloPhylipReader::CPhyloPhylipReader(string str)
- {
- m_Phylip = str;
- }
- CPhyloPhylipReader::~CPhyloPhylipReader()
- {
- }
- void CPhyloPhylipReader::x_Tokenize(const string& str, vector<string>& tokens, const string& delimiters)
- {
- string::size_type lastPos = str.find_first_not_of(delimiters, 0);
- string::size_type pos = str.find_first_of(delimiters, lastPos);
- while (string::npos != pos || string::npos != lastPos) {
- tokens.push_back(str.substr(lastPos, pos - lastPos));
- lastPos = str.find_first_not_of(delimiters, pos);
- pos = str.find_first_of(delimiters, lastPos);
- }
- }
- CPhyloTreeNode * CPhyloPhylipReader::x_Parse(CPhyloTreeNode * par, string str)
- {
- str = str.substr(1, str.length()-2);
-
- // no nested nodes found
- if (str.find_first_of("(")==string::npos){
- // retrieving nodes
- vector <string> vectNodes; x_Tokenize(str, vectNodes, ",");
-
- for (vector<string>::iterator it=vectNodes.begin(); it!=vectNodes.end(); it++){
- CPhyloTreeNode * childNode = new CPhyloTreeNode;
-
- // retrieving name/value pair for each node
- vector <string> vectValue; x_Tokenize(*it, vectValue, ":");
-
- // initializing child node
- if (vectValue.size()>0){
- childNode->GetValue()->SetLabel(vectValue[0]);
- if (vectValue.size()>1){
- childNode->GetValue()->SetDistance(NStr::StringToDouble(vectValue[1]));
- }
- }
- par->InsertNode(par->SubNodeBegin(), childNode);
- }
- }
- return par;
- }
-
- CPhyloTreeNode * CPhyloPhylipReader::GetTree(void)
- {
- CPhyloTreeNode *node1 = new CPhyloTreeNode;
- CPhyloTreeNode *node2 = new CPhyloTreeNode;
- CPhyloTreeNode *node3 = new CPhyloTreeNode;
- CPhyloTreeNode *node4 = new CPhyloTreeNode;
- CPhyloTreeNode *node5 = new CPhyloTreeNode;
- CPhyloTreeNode *node6 = new CPhyloTreeNode;
- CPhyloTreeNode *node7 = new CPhyloTreeNode;
-
- x_Parse(node1, m_Phylip);
- x_Parse(node2, m_Phylip);
- x_Parse(node3, m_Phylip);
- x_Parse(node4, m_Phylip);
- x_Parse(node5, m_Phylip);
- x_Parse(node6, m_Phylip);
- x_Parse(node7, m_Phylip);
- node3->InsertNode(node3->SubNodeBegin(), node5);
- node2->InsertNode(node2->SubNodeBegin(), node3);
- node2->InsertNode(node2->SubNodeBegin(), node4);
- node1->InsertNode(node1->SubNodeBegin(), node2);
- node1->InsertNode(node1->SubNodeBegin(), node6);
- node1->InsertNode(node1->SubNodeBegin(), node7);
- for (int i=0; i<5; i++){
- CPhyloTreeNode *n = new CPhyloTreeNode;
- x_Parse(n, m_Phylip);
- node7->InsertNode(node7->SubNodeBegin(), n);
- }
- return node1;
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: phylo_tree_reader.cpp,v $
- * Revision 1000.1 2004/06/01 21:11:46 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2
- *
- * Revision 1.2 2004/05/21 22:27:54 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.1 2004/02/13 17:05:07 tereshko
- * Phylogenetic Tree Widget initial revision
- *
- * ===========================================================================
- */