tax_tree_ds.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:6k
- /*
- * ===========================================================================
- * PRODUCTION $Log: tax_tree_ds.cpp,v $
- * PRODUCTION Revision 1000.0 2004/06/01 21:31:39 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: tax_tree_ds.cpp,v 1000.0 2004/06/01 21:31:39 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: Mike DiCuccio
- *
- * File Description:
- *
- */
- #include <ncbi_pch.hpp>
- #include <gui/widgets/tax_tree/tax_tree_ds.hpp>
- #include <objects/seq/Bioseq.hpp>
- #include <objmgr/util/sequence.hpp>
- #include <objmgr/seqdesc_ci.hpp>
- #include <gui/objutils/label.hpp>
- #include <algorithm>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- CTaxTreeDS_ObjMgr::CTaxTreeDS_ObjMgr(CScope& scope, const TUidVec& uids)
- : m_Scope(&scope)
- , m_Mode(eDisplay_Default)
- , m_Ids(uids)
- {
- m_TaxCache.Init();
- TTaxMap tax_map;
- GetTaxMap(tax_map);
- vector<TTaxId> tax_ids_in;
- vector<TTaxId> tax_ids_out;
- tax_ids_in.reserve(tax_map.size());
- ITERATE(TTaxMap, iter, tax_map) {
- _TRACE("tax-id: " << iter->first << " seqs: " << iter->second.size());
- tax_ids_in.push_back(iter->first);
- }
- if (tax_ids_in.size() == 0) {
- NCBI_THROW(CException, eUnknown,
- "Can't generate common tree for sequences:n"
- "No taxonomy IDs found.");
- }
- if ( !m_TaxCache.GetPopsetJoin(tax_ids_in, tax_ids_out) ) {
- NCBI_THROW(CException, eUnknown,
- "Can't generate common tree for sequences");
- }
- }
- ITreeIterator& CTaxTreeDS_ObjMgr::GetIterator(EDisplayMode mode)
- {
- if ( !m_Iter || mode != m_Mode) {
- // first, fill our internal tree structure
- CTaxon1::EIteratorMode iter_mode = CTaxon1::eIteratorMode_Default;
- switch (mode) {
- default:
- case eDisplay_All:
- break;
- case eDisplay_Best:
- iter_mode = CTaxon1::eIteratorMode_Best;
- break;
- case eDisplay_Blast:
- iter_mode = CTaxon1::eIteratorMode_Blast;
- break;
- }
- m_Iter.Reset(m_TaxCache.GetTreeIterator(iter_mode));
- m_Mode = mode;
- }
- return *m_Iter;
- }
- void CTaxTreeDS_ObjMgr::GetTaxMap(TTaxMap& tax_map)
- {
- TUidVec uids;
- GetUids(uids);
- ITERATE (TUidVec, iter, uids) {
- TTaxId tax_id = 0;
- // first, see if we can get it from the sequence
- CBioseq_Handle handle = m_Scope->GetBioseqHandle(**iter);
- tax_id = sequence::GetTaxId(handle);
- // if not, try the tax server
- if ( !tax_id ) {
- m_TaxCache.GetTaxId4GI(*iter, tax_id);
- }
- // if we've got something, add it to our cache
- if (tax_id) {
- tax_map[tax_id].push_back(*iter);
- } else {
- string str;
- CLabel::GetLabel(**iter, &str, CLabel::eDefault, m_Scope);
- LOG_POST(Info << "No tax-id for sequence: " << str);
- }
- }
- }
- void CTaxTreeDS_ObjMgr::GetUids(TUidVec& uids)
- {
- uids = m_Ids;
- }
- void CTaxTreeDS_ObjMgr::GetTitle(const CSeq_id& id, string* title) const
- {
- if (title) {
- title->erase();
- CBioseq_Handle handle = m_Scope->GetBioseqHandle(id);
- const CSeq_id& best_id = sequence::GetId(handle, sequence::eGetId_Best);
- best_id.GetLabel(title, CSeq_id::eContent);
- }
- }
- void CTaxTreeDS_ObjMgr::GetTitle(const ITaxon1Node& node, string* title) const
- {
- if (title) {
- *title = node.GetName();
- }
- }
- const CRef<objects::CScope> & CTaxTreeDS_ObjMgr::GetScope(void)
- {
- return m_Scope;
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: tax_tree_ds.cpp,v $
- * Revision 1000.0 2004/06/01 21:31:39 gouriano
- * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2
- *
- * Revision 1.2 2004/05/21 22:27:55 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.1 2004/05/13 17:31:46 dicuccio
- * Renamed data source file
- *
- * Revision 1.8 2004/04/09 16:53:32 tereshko
- * Added functionality to send/accept selections
- *
- * Revision 1.7 2004/04/07 13:12:44 dicuccio
- * Changed internal storage of sequence information to use CConstRef<CSeq_id>
- *
- * Revision 1.6 2004/04/01 19:03:13 dicuccio
- * Added support for limiting the list of displayed nodes. Changed retrieval of
- * tax-id to favor sequence first
- *
- * Revision 1.5 2004/03/05 17:43:00 dicuccio
- * Use sequence::GetId() instead of CSeq-id::GetStringDescr()
- *
- * Revision 1.4 2004/01/27 18:49:25 dicuccio
- * Restored functionality
- *
- * Revision 1.3 2004/01/07 18:55:36 dicuccio
- * Code clean-up. Don't forget to initialize or CTaxon1 class
- *
- * Revision 1.2 2003/12/23 15:39:18 dicuccio
- * Altered the data source - expose an ITreeIterator; the widget no longer
- * directly creates a CTaxon1 class. Chaned storage notion from 'gi' to 'uid'
- *
- * Revision 1.1 2003/12/22 19:42:59 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */