test_taxtree.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:9k
- /*
- * ===========================================================================
- * PRODUCTION $Log: test_taxtree.cpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 21:13:30 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: test_taxtree.cpp,v 1000.2 2004/06/01 21:13:30 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 <corelib/ncbistd.hpp>
- #include <corelib/ncbiapp.hpp>
- #include <corelib/ncbienv.hpp>
- #include <corelib/ncbiargs.hpp>
- #include <gui/utils/fltk_utils.hpp>
- #include <gui/utils/message_box.hpp>
- #include <gui/widgets/fl/status_bar_ex.hpp>
- #include <gui/widgets/tax_tree/tax_tree.hpp>
- #include <gui/widgets/tax_tree/tax_tree_ds.hpp>
- #include <objects/entrez2/entrez2_client.hpp>
- #include <objects/entrez2/Entrez2_eval_boolean.hpp>
- #include <objects/entrez2/Entrez2_boolean_exp.hpp>
- #include <objects/entrez2/Entrez2_boolean_element.hpp>
- #include <objects/entrez2/Entrez2_boolean_reply.hpp>
- #include <objects/entrez2/Entrez2_id_list.hpp>
- #include <objmgr/object_manager.hpp>
- #include <objmgr/scope.hpp>
- #include <objtools/data_loaders/genbank/gbloader.hpp>
- #include <gui/utils/dialog.hpp>
- #include <FL/Fl.H>
- #include <FL/Fl_Double_Window.H>
- #include <FL/Fl_Menu_Bar.H>
- #include <FL/Fl_Group.H>
- #include <FL/Fl_Box.H>
- #include <FL/Fl_Input.H>
- #include <FL/Fl_Choice.H>
- // #include "entrez2_ds.hpp"
- BEGIN_NCBI_SCOPE
- USING_SCOPE(ncbi::objects);
- #include "test_taxtree_.cpp"
- CTaxTreeTestDlg::CTaxTreeTestDlg()
- {
- m_Window.reset(x_CreateWindow());
- m_Tree->SetReporter(m_StatusBar);
- }
- void CTaxTreeTestDlg::x_OnSubmitQuery()
- {
- CFltkCursorGuard WAIT_GUARD;
- CStatusBarGuard LOCK(*m_StatusBar, "Submitting query...");
- string query = m_Query->value();
- if (query.empty()) {
- return;
- }
- //
- // prepare the Entrez query
- //
- CEntrez2_eval_boolean req;
- req.SetReturn_UIDs(true);
- CEntrez2_boolean_exp& exp = req.SetQuery();
- // set the database we're querying
- exp.SetDb().Set("nucleotide");
- // set the query
- CRef<CEntrez2_boolean_element> elem(new CEntrez2_boolean_element());
- elem->SetStr(query);
- exp.SetExp().push_back(elem);
- // set some limits - if num > 0, we assume it's correct
- CRef<CEntrez2_boolean_reply> query_res;
- try {
- // now, submit our query. this gets us the UIDs we want
- query_res = x_GetClient().AskEval_boolean(req);
- const CEntrez2_id_list& ids = query_res->GetUids();
- vector<int> uids;
- uids.reserve(ids.GetNum());
- _TRACE("query: " << query << " UIDs: " << ids.GetNum());
- CTaxTreeDS_ObjMgr::TUidVec seq_ids;
- seq_ids.reserve(uids.size());
- CEntrez2_id_list::TConstUidIterator iter = ids.GetConstUidIterator();
- for (size_t i = 0; i < ids.GetNum(); ++i, ++iter) {
- uids.push_back(*iter);
- CRef<CSeq_id> id(new CSeq_id());
- id->SetGi(*iter);
- seq_ids.push_back(id);
- }
- if ( !m_ObjMgr ) {
- m_ObjMgr.Reset(new CObjectManager());
- m_ObjMgr->RegisterDataLoader(*new CGBDataLoader(),
- CObjectManager::eDefault);
- m_Scope.Reset(new CScope(*m_ObjMgr));
- m_Scope->AddDefaults();
- }
- m_DataSource.Reset(new CTaxTreeDS_ObjMgr(*m_Scope, seq_ids));
- // m_DataSource.Reset(new CTaxTreeDS_Entrez2(uids));
- m_Tree->SetDataSource(*m_DataSource);
- // m_Tree->SetGis(uids);
- }
- catch (CException& e) {
- LOG_POST(Info << "exception: " << e.what());
- LOG_POST(Info << "query failed; reconnecting...");
- }
- }
- void CTaxTreeTestDlg::x_OnShowRelatedSeqs()
- {
- CTaxTreeDataSource::TUidVec gis;
- m_Tree->GetSelectedUids(gis);
- if (gis.size() != 1) {
- NcbiMessageBox("Please select one and only one sequence");
- return;
- }
- CStatusBarGuard LOCK(*m_StatusBar, "Submitting query...");
- int gi = gis.front();
- vector<int> gis_n;
- x_GetClient().GetNeighbors(gi, "nucleotide", "nucleotide_nucleotide",
- gis_n);
- m_StatusBar->SetMessage("Found " +
- NStr::IntToString(gis_n.size()) +
- " related sequences");
- // m_Tree->SetGis(gis);
- }
- CEntrez2Client& CTaxTreeTestDlg::x_GetClient()
- {
- if ( !m_Client ) {
- m_Client.Reset(new CEntrez2Client());
- }
- return *m_Client;
- }
- class CTestTreeApp : public CNcbiApplication
- {
- private:
- virtual void Init(void);
- virtual int Run(void);
- virtual void Exit(void);
- };
- void CTestTreeApp::Init(void)
- {
- // Create command-line argument descriptions class
- auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
- // Specify USAGE context
- arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
- "CTreeBrowser demo program");
- // Setup arg.descriptions for this application
- SetupArgDescriptions(arg_desc.release());
- }
- int CTestTreeApp::Run(void)
- {
- // Get arguments
- CArgs args = GetArgs();
- char *argv[1];
- argv[0] = "app";
- CTaxTreeTestDlg window;
- window.Show(1, argv);
- return 0;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Cleanup
- void CTestTreeApp::Exit(void)
- {
- SetDiagStream(0);
- }
- /////////////////////////////////////////////////////////////////////////////
- // MAIN
- END_NCBI_SCOPE
- USING_SCOPE(ncbi);
- int main(int argc, const char* argv[])
- {
- // Execute main application function
- return CTestTreeApp().AppMain(argc, argv, 0, eDS_Default, 0);
- }
- /*
- * ===========================================================================
- * $Log: test_taxtree.cpp,v $
- * Revision 1000.2 2004/06/01 21:13:30 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9
- *
- * Revision 1.9 2004/05/28 19:27:51 dicuccio
- * Compilation fixes
- *
- * Revision 1.8 2004/05/21 22:27:55 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.7 2004/05/13 17:31:46 dicuccio
- * Renamed data source file
- *
- * Revision 1.6 2004/04/20 20:18:37 gorelenk
- * Fixed error in implementations of
- * CTaxTreeTestDlg::x_OnShowRelatedSeqs and
- * CTaxTreeTestDlg::x_OnSubmitQuery .
- *
- * Revision 1.5 2004/01/28 01:08:11 ucko
- * Use CTaxTreeDS_ObjMgr rather than CTaxTreeDS_Entrez2, which isn't
- * (yet) in the tree.
- *
- * Revision 1.4 2004/01/27 18:49:26 dicuccio
- * Restored functionality
- *
- * Revision 1.3 2003/12/23 15:39:19 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.2 2003/12/22 22:00:19 ucko
- * Don't try to call SetGi, since it doesn't seem to exist yet....
- *
- * Revision 1.1 2003/12/22 19:43:01 dicuccio
- * Initial revision
- *
- * Revision 1.1 2003/12/09 19:08:16 dicuccio
- * Moved test_treebrowser from widgets/FLU/demo to here
- *
- * Revision 1.1 2003/12/09 15:51:31 dicuccio
- * Deprecated Fl_Toggle_Tree - replaced with Flu_Tree_Browser. Added CTreeBrowser
- * as a standard tree interface
- *
- * Revision 1.2 2003/08/21 12:06:42 dicuccio
- * Many bug fixes - Fl_Toggle_Tree is nearly completed. Reimplemented correct
- * clipping of the widget to its extent. Added scroll bar (not yet working).
- * Removed dead code
- *
- * Revision 1.1 2003/07/30 12:25:25 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */