phylo_tree_ds.cpp
来自「ncbi源码」· C++ 代码 · 共 321 行
CPP
321 行
/* * =========================================================================== * PRODUCTION $Log: phylo_tree_ds.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 21:11:37 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.18 * PRODUCTION * =========================================================================== *//* $Id: phylo_tree_ds.cpp,v 1000.1 2004/06/01 21:11:37 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 <corelib/ncbiobj.hpp>#include <corelib/ncbistd.hpp>#include <algorithm>#include <gui/objutils/utils.hpp>#include <gui/widgets/phylo_tree/phylo_tree_ds.hpp>BEGIN_NCBI_SCOPECPhyloTreeDataSource::CPhyloTreeDataSource() : m_Level(0), m_Size(0), m_Width(0){ m_Level = m_Size = m_Width = 0; m_Hash.clear(); m_Root = new CPhyloTreeNode;}CPhyloTreeDataSource::~CPhyloTreeDataSource(){ }CPhyloTreeDataSource::CPhyloTreeDataSource(IPhyloTreeReader * reader) { m_Level = m_Size = m_Width = 0; m_Hash.clear(); Init(reader); x_MeasureTree(m_Root);}CPhyloTreeDataSource::CPhyloTreeDataSource(TPhyTreeNode& node, const TIds& seqids, objects::CScope& scope): m_SeqIds(seqids), m_Scope(&scope){ m_Level = m_Size = m_Width = 0; m_Hash.clear(); m_Root = new CPhyloTreeNode; Init(node, m_Root); x_MeasureTree(m_Root);}void CPhyloTreeDataSource::Init(IPhyloTreeReader * reader){ m_Root = reader->GetTree();}void CPhyloTreeDataSource::Init(TPhyTreeNode & node, CPhyloTreeNode * pos){ for (TPhyTreeNode::TNodeList_CI it = node.SubNodeBegin(); it != node.SubNodeEnd(); it++) { if (!(*it)->IsLeaf()){ CPhyloTreeNode * internal = new CPhyloTreeNode((*it)->GetValue().GetId(), (*it)->GetValue().GetLabel(), (*it)->GetValue().IsSetDist()?(*it)->GetValue().GetDist():-1); pos->InsertNode(pos->SubNodeBegin(), internal); Init(**it, internal); } else { pos->InsertNode(pos->SubNodeBegin(), new CPhyloTreeNode((*it)->GetValue().GetId(), (*it)->GetValue().GetLabel(), (*it)->GetValue().IsSetDist()?(*it)->GetValue().GetDist():-1)); } } }CPhyloTreeNode * CPhyloTreeDataSource::GetTree(void){ return m_Root; }void CPhyloTreeDataSource::x_MeasureTree(CPhyloTreeNode * node){ m_Hash.insert(pair<int, CPhyloTreeNode *>(node->GetID(), node)); node->IDX().first = m_Level; node->IDX().second = m_Size; if (node->GetParent()){ // any other node node->SetAnnWedge(node->GetParent()->GetValue()->GetAnnWedge() * node->CountLeafs() / node->GetParent()->GetValue()->CountLeafs()); } else { //root node->SetAnnWedge(6.28); } if (node->IsLeaf()) m_Size++; else { for(CPhyloTreeNode::TNodeList_I it = node->SubNodeBegin(); it != node->SubNodeEnd(); it++ ) { m_Level++; if (m_Width < m_Level) m_Width = m_Level; x_MeasureTree((*it)->GetValue()); m_Level--; } } }void CPhyloTreeDataSource::SetSelection(CPhyloTreeNode * node, bool bSel, bool andChilds, bool checkParents){ node->SetSelected(bSel); if (andChilds) x_DescentToChilds(node, bSel); if (checkParents) x_AscendToRoot(node, bSel);}void CPhyloTreeDataSource::x_DescentToChilds(CPhyloTreeNode * node, bool bSel){ node->SetSelected(bSel); if (!node->IsLeaf()) { for(CPhyloTreeNode::TNodeList_I it = node->SubNodeBegin(); it != node->SubNodeEnd(); it++ ) { x_DescentToChilds((*it)->GetValue(), bSel); } } }void CPhyloTreeDataSource::x_AscendToRoot(CPhyloTreeNode * node, bool bSel){ CPhyloTreeNode * parent = node->GetParent()?node->GetParent()->GetValue():NULL; if (parent){ bool bAllSelected = true; for (CPhyloTreeNode::TNodeList_I it = parent->SubNodeBegin(); it != parent->SubNodeEnd(); it++ ) { bAllSelected = (*it)->GetValue()->GetSelected(); if (!bAllSelected) break; } if (bAllSelected && bSel) parent->SetSelected(bSel); x_AscendToRoot(parent, bSel); }}CPhyloTreeNode * CPhyloTreeDataSource::GetNode(int idx){ map <int, CPhyloTreeNode *>::iterator itf = m_Hash.find(idx); return (itf!=m_Hash.end()) ? itf->second : NULL;}CPhyloTreeDataSource::TIdsCPhyloTreeDataSource::ConvertId2SeqId(const vector<int> & ids){ CPhyloTreeDataSource::TIds retValue; retValue.clear(); ITERATE (vector<int>, it, ids) { if (*it >= 0 && *it < m_SeqIds.size()) { retValue.push_back(m_SeqIds[*it]); } } return retValue;}vector<int> CPhyloTreeDataSource::ConvertSeqId2Id(const CPhyloTreeDataSource::TIds & seqids){ vector <int> retValue; retValue.clear(); ITERATE (TIds, it, seqids) { ITERATE(TIds, itS, m_SeqIds) { if(CSeqUtils::Match(**it, **itS, m_Scope)) { retValue.push_back(itS - m_SeqIds.begin()); break; } } } return retValue;} vector<int> CPhyloTreeDataSource::GetSelectedIds(void) const{ vector <int> retValue; ITERATE(TNodeHash, it, m_Hash) { if (it->second->GetSelected()) { retValue.push_back(it->first); } } return retValue;}const TModelRect CPhyloTreeDataSource::GetBoundRect(void){ TModelRect brect(0,0,0,0); if (m_Hash.size()>0){ CPhyloTreeNode * firstNode = m_Hash.begin()->second; brect.Init(firstNode->XY().first, firstNode->XY().second, firstNode->XY().first, firstNode->XY().second); } ITERATE(TNodeHash, it, m_Hash) { CPhyloTreeNode * node = it->second; if (brect.Left() > node->XY().first) { brect.SetLeft(node->XY().first); } if (brect.Right() < node->XY().first) { brect.SetRight(node->XY().first); } if (brect.Top() > node->XY().second) { brect.SetTop(node->XY().second); } if (brect.Bottom()< node->XY().second) { brect.SetBottom(node->XY().second); } } return brect;}const double CPhyloTreeDataSource::GetNormDistance(bool fromRoot){ double norm = 0; ITERATE(TNodeHash, it, m_Hash) { double dist = fromRoot?it->second->GetDistFromRoot():it->second->GetDistance(); if (dist > norm) norm = dist; } return norm;} END_NCBI_SCOPE/* * =========================================================================== * $Log: phylo_tree_ds.cpp,v $ * Revision 1000.1 2004/06/01 21:11:37 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.18 * * Revision 1.18 2004/05/21 22:27:54 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.17 2004/05/11 20:53:12 tereshko * Work in progress * * Revision 1.16 2004/05/07 15:36:41 dicuccio * Formatting changes. Use ITERATE() instead of for(;;) * * Revision 1.15 2004/05/03 13:23:57 dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.14 2004/04/28 19:27:10 tereshko * Added support for distances rendering * * Revision 1.13 2004/04/20 21:57:19 tereshko * Major rendering, labeling and performance improvements * * Revision 1.12 2004/04/16 16:40:13 dicuccio * Use typedef instead of raw STL container for IDs * * Revision 1.11 2004/04/16 14:51:00 dicuccio * Pass CScope as non-const reference, not CRef<> * * Revision 1.10 2004/04/13 20:28:53 tereshko * Numerous renderers improvements * * Revision 1.9 2004/04/07 13:08:42 dicuccio * Changed CSeqUtils::Match() - scope is optional (pointer) parameter * * Revision 1.8 2004/04/02 16:21:06 yazhuk * Replaced vector<CRef<>> with vector<CConstRef<>>, added Scope data member, * using CSeqUtils::Match() to compare ids * * Revision 1.7 2004/04/01 21:46:37 tereshko * Added ability of auto-selecting parent nodes * * Revision 1.6 2004/03/31 17:53:34 tereshko * Added function for retrieval of preprocessed selection * * Revision 1.5 2004/03/30 17:11:44 tereshko * Added support for events broadcasting * * Revision 1.4 2004/03/09 15:26:18 jcherry * Distances and labels for internal nodes too * * Revision 1.3 2004/03/02 18:28:26 tereshko * Added support for calculating annual vertex weight * * Revision 1.2 2004/02/17 23:44:41 tereshko * Changes due to integration into viewer * * Revision 1.1 2004/02/13 17:05:01 tereshko * Phylogenetic Tree Widget initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?