entrez_search_dlg.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:15k
- /*
- * ===========================================================================
- * PRODUCTION $Log: entrez_search_dlg.cpp,v $
- * PRODUCTION Revision 1000.0 2004/06/01 21:27:00 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: entrez_search_dlg.cpp,v 1000.0 2004/06/01 21:27:00 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:
- * CEntrezSearchDlg -- search Entrez databases for sequence information
- */
- #include <ncbi_pch.hpp>
- #include "entrez_search_dlg.hpp"
- #include "entrez_record_table.hpp"
- #include <gui/core/version.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/utils/message_box.hpp>
- #include <gui/utils/fltk_utils.hpp>
- #include <objects/entrez2/entrez2_client.hpp>
- #include <objects/entrez2/Entrez2_info.hpp>
- #include <objects/entrez2/Entrez2_eval_boolean.hpp>
- #include <objects/entrez2/Entrez2_boolean_reply.hpp>
- #include <objects/entrez2/Entrez2_boolean_exp.hpp>
- #include <objects/entrez2/Entrez2_boolean_element.hpp>
- #include <objects/entrez2/Entrez2_id_list.hpp>
- #include <objects/entrez2/Entrez2_docsum.hpp>
- #include <objects/entrez2/Entrez2_docsum_list.hpp>
- #include <objects/entrez2/Entrez2_docsum_data.hpp>
- #include <objects/entrez2/Entrez2_db_id.hpp>
- #include <objects/entrez2/Entrez2_limits.hpp>
- #include <objmgr/util/sequence.hpp>
- #include <gui/plugin/PluginMessage.hpp>
- #include <gui/plugin/PluginRequest.hpp>
- #include <gui/plugin/PluginCommand.hpp>
- #include <gui/plugin/PluginArg.hpp>
- #include <gui/plugin/PluginValue.hpp>
- #include <gui/core/plugin_utils.hpp>
- #include <gui/core/plugin_handle.hpp>
- #include <gui/core/plugin_registry.hpp>
- #include <gui/objutils/label.hpp>
- #include <serial/serial.hpp>
- #include <serial/objostr.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- #include "entrez_search_dlg_.cpp"
- CEntrezSearchDlg::CEntrezSearchDlg()
- : m_Start(0)
- , m_Visible(10)
- , m_Length(0)
- {
- m_Window.reset(x_CreateWindow());
- CenterOnActive();
- // retrieve our list of databases
- list<string> dbs;
- m_Table->GetDatabases(dbs);
- int default_idx = 0;
- ITERATE (list<string>, iter, dbs) {
- int idx = m_DB->add(iter->c_str());
- if (*iter == "Nucleotide") {
- default_idx = idx;
- }
- }
- m_DB->value(default_idx);
- m_Table->SetDatabase(m_DB->text(default_idx));
- m_Table->SetReporter(m_StatusBar);
- m_StatusBar->PushMessage("Ready");
- }
- void CEntrezSearchDlg::SetQuery(const string& str)
- {
- m_QueryStr->value(str.c_str());
- x_OnChangeTerms();
- }
- void CEntrezSearchDlg::SetDB(const string& str)
- {
- for (int i = 0; i < m_DB->size(); ++i) {
- const char* ptr = m_DB->text(i);
- if (ptr && str == ptr) {
- m_DB->value(i);
- x_OnChangeDB();
- break;
- }
- }
- }
- void CEntrezSearchDlg::x_OnPrevious()
- {
- if (m_Visible > 0 && m_Start > 0) {
- m_Start = max(0, m_Start - m_Visible);
- x_OnSearch();
- }
- }
- void CEntrezSearchDlg::x_OnNext()
- {
- if (m_Visible > 0 && (m_Start + m_Visible < m_Length)) {
- m_Start = min(m_Length - m_Visible, m_Start + m_Visible);
- m_Start = max(0, m_Start);
- x_OnSearch();
- }
- }
- void CEntrezSearchDlg::x_OnLoad()
- {
- CStatusBarGuard GUARD(*m_StatusBar, "Loading accessions...");
- m_Table->OnNewDocument();
- #if 0
- CPluginArg::TValues value_list;
- // this is a hack to get the nice GUI effect we want
- // we simply create a new default scope and use it to load our sequences
- CRef<CScope> scope(new CScope(CDocManager::GetObjectManager()));
- scope->AddDefaults();
- try {
- // gather our docsums and prepare to do the docsum -> seqid conversion
- CEntrez2_docsum_list docsums;
- for (size_t i = 0; i < m_Table->GetRows(); ++i) {
- if ( !m_Table->IsRowSelected(i) ) {
- continue;
- }
- CRef<CEntrez2_docsum> ref = m_Table->GetData(i);
- docsums.SetList().push_back(ref);
- }
- docsums.SetCount(docsums.GetList().size());
- // retrieve our handler and get our IDs.
- const char* p = m_DB->text();
- if ( !p ) {
- throw runtime_error("No database chosen.");
- }
- IEntrezDBHandler& handler = m_DbManager.GetHandler(p);
- IEntrezDBHandler::TIds ids = handler.GetSeqIds(docsums);
- // force loading to make a nice GUI statement...
- size_t idx = 0;
- ITERATE (IEntrezDBHandler::TIds, iter, ids) {
- string str;
- try {
- CBioseq_Handle handle = scope->GetBioseqHandle(**iter);
- if (handle) {
- str = "Loaded sequence ";
- string id_str;
- CLabel::GetLabel(**iter, &id_str, CLabel::eDefault, scope);
- str += id_str;
- CRef<CPluginValue> value(new CPluginValue());
- value->SetString(id_str);
- value_list.push_back(value);
- }
- }
- catch (CException& e) {
- str = "Failed to load sequence ";
- CLabel::GetLabel(**iter, &str, CLabel::eDefault);
- str += ": " + e.GetMsg();
- }
- catch (...) {
- }
- if (str.empty()) {
- str = "Failed to load sequence ";
- CLabel::GetLabel(**iter, &str, CLabel::eDefault);
- }
- m_StatusBar->SetMessage(str);
- ++idx;
- m_StatusBar->SetPctCompleted(100 * idx / ids.size());
- }
- }
- catch (CException& e) {
- string str("Can't load accessions:n");
- str += e.GetMsg();
- NcbiMessageBox(str);
- }
- catch (std::exception& e) {
- string str("Can't load accessions:n");
- str += e.what();
- NcbiMessageBox(str);
- }
- catch (...) {
- }
- if (value_list.size() != 0) {
- CPluginHandle ph =
- CPluginRegistry::GetPlugin("CDataPlugin_GenbankLoader");
- if (ph) {
- CRef<CPluginMessage> msg = ph.CreateMessage(eDataCommand_load);
- CPluginArg& arg = msg->SetRequest().SetCommand()["acc"];
- arg.SetList(value_list);
- CPluginUtils::CallPlugin(*msg);
- }
- }
- m_StatusBar->SetPctCompleted(0);
- #endif
- }
- void CEntrezSearchDlg::x_OnChangeTerms()
- {
- m_Start = 0;
- x_OnSearch();
- }
- void CEntrezSearchDlg::x_OnChangeVisible()
- {
- m_Visible = m_VisibleRecords->mvalue()->argument();
- x_OnSearch();
- }
- void CEntrezSearchDlg::x_OnChangeDB()
- {
- // determine our database
- m_Start = 0;
- m_Table->SetDatabase(m_DB->text(m_DB->value()));
- x_OnSearch();
- }
- void CEntrezSearchDlg::x_OnSearch()
- {
- //
- // first, retrieve a list of the docsums for our search
- //
- string query = m_QueryStr->value();
- if ( query.empty() ) {
- return;
- }
- try {
- size_t total_count = 0;
- m_Table->Query(query, total_count, m_Start, m_Visible);
- m_Length = total_count;
- }
- catch (CException& e) {
- string str("Query failed:n");
- str += e.GetMsg();
- NcbiMessageBox(str);
- }
- catch (std::exception& e) {
- string str("Query failed:n");
- str += e.what();
- NcbiMessageBox(str);
- }
- catch (...) {
- NcbiMessageBox("Query failed");
- }
- #if 0
- CFltkCursorGuard WAIT_GUARD;
- CStatusBarGuard GUARD(*m_StatusBar, "Submitting search...");
- //
- // reset the list data
- //
- m_Table->Clear();
- m_Table->redraw();
- // get our handler
- try {
- const char* p = m_DB->text();
- if (p) {
- // set some limits - if num > 0, we assume it's correct
- size_t start = 0;
- size_t visible = 0;
- size_t total = 0;
- if (m_Visible > 0) {
- start = m_Start;
- visible = m_Visible;
- }
- IEntrezDBHandler& handler = m_DbManager.GetHandler(p);
- CRef<objects::CEntrez2_docsum_list> docsums =
- handler.Query(query, total, start, visible);
- m_Length = total;
- //
- // set our columns up correctly
- //
- vector<IEntrezDBHandler::SHeaderInfo> headers;
- handler.GetHeaders(headers);
- m_Table->SetCols(0);
- ITERATE (vector<IEntrezDBHandler::SHeaderInfo>, iter, headers) {
- m_Table->SetColumn(iter - headers.begin(),
- iter->name,
- CEntrezRecordTable::eString,
- FL_ALIGN_LEFT,
- iter->rel_width);
- }
- //
- // now, add the docsums to the list...
- // we only want certain fields from each docsum
- //
- m_Table->SetRows(0);
- if (visible) {
- m_Table->Reserve(visible);
- } else {
- m_Table->Reserve(m_Length);
- }
- if (docsums.GetPointer() &&
- docsums->IsSetList() &&
- docsums->GetList().size() != 0) {
- vector<string> cols;
- size_t row = 0;
- NON_CONST_ITERATE(CEntrez2_docsum_list::TList, iter,
- docsums->SetList()) {
- const CEntrez2_docsum& docsum = **iter;
- cols.clear();
- handler.Format(docsum, cols);
- ITERATE (vector<string>, col_iter, cols) {
- m_Table->SetCell(row, col_iter - cols.begin(),
- *col_iter);
- }
- m_Table->SetData(row).Reset(*iter);
- ++row;
- }
- }
- //
- // add a nice status message
- //
- m_TitleStr = "Search Results";
- if (docsums.GetPointer() && docsums->GetCount() != 0) {
- int start = m_Start + 1;
- int end = start + m_Visible;
- if (m_Visible == -1) {
- end = start + docsums->GetCount();
- }
- end -= 1;
- end = min(end, m_Start + docsums->GetCount());
- m_TitleStr += " - Showing ";
- m_TitleStr += NStr::IntToString(start) + " - ";
- m_TitleStr += NStr::IntToString(end) + " of ";
- m_TitleStr += NStr::IntToString(m_Length);
- m_TitleStr += " matching records.";
- } else {
- m_TitleStr += " - No records found.";
- }
- m_Window->label(m_TitleStr.c_str());
- m_StatusBar->SetPctCompleted(0);
- }
- }
- catch (CException& e) {
- string str("Can't submit query:n");
- str += e.GetMsg();
- NcbiMessageBox(str);
- }
- catch (std::exception& e) {
- string str("Can't submit query:n");
- str += e.what();
- NcbiMessageBox(str);
- }
- catch (...) {
- }
- #endif
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: entrez_search_dlg.cpp,v $
- * Revision 1000.0 2004/06/01 21:27:00 gouriano
- * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.3
- *
- * Revision 1.3 2004/05/28 15:06:14 dicuccio
- * Adjusted .fl files: include ncbi_pch.hpp, added CVS Id tags, fixed fonts
- *
- * Revision 1.2 2004/05/26 02:06:29 ucko
- * Explicitly cast through int when converting between enum types.
- *
- * Revision 1.1 2004/05/25 17:15:40 dicuccio
- * Initial revision - moved over from old GenBank search
- *
- * Revision 1.21 2004/05/07 15:35:13 dicuccio
- * Fixed unsigned/signed comparison
- *
- * Revision 1.20 2004/03/05 17:36:41 dicuccio
- * Use sequence::GetId() instead of CSeq_id::GetStringDescr()
- *
- * Revision 1.19 2004/01/20 18:16:48 dicuccio
- * Chnaged to match new API in CTablePanel
- *
- * Revision 1.18 2004/01/06 20:15:54 dicuccio
- * Use CFltkCursorGuard on load / import / search
- *
- * Revision 1.17 2003/12/30 15:02:57 dicuccio
- * Fixed bug in progress bar - advance proportional to actual number of loaded sequences
- *
- * Revision 1.16 2003/12/22 19:29:20 dicuccio
- * Added explicit passing of query string and database
- *
- * Revision 1.15 2003/12/10 15:10:04 dicuccio
- * Fixed numerous bugs in search: forgot to assign docsum to data; fixed bugs in
- * resetting counts of docsums
- *
- * Revision 1.14 2003/12/09 15:47:21 dicuccio
- * Use CDialog::CenterOnActive() to center the window
- *
- * Revision 1.13 2003/12/05 13:07:53 dicuccio
- * Split management interface into a separate plugin. Fixed linker error
- * introduced with status bar
- *
- * Revision 1.12 2003/12/04 18:14:07 dicuccio
- * Lots of updates. Added a status bar to track actions. General code-clean-up
- *
- * Revision 1.11 2003/11/24 15:45:35 dicuccio
- * Renamed CVersion to CPluginVersion
- *
- * Revision 1.10 2003/11/04 17:49:24 dicuccio
- * Changed calling parameters for plugins - pass CPluginMessage instead of paired
- * CPluginCommand/CPluginReply
- *
- * Revision 1.9 2003/10/14 12:48:11 dicuccio
- * Lots of clean-ups. Added code for correctly handling client timeouts.
- *
- * Revision 1.8 2003/10/07 13:47:05 dicuccio
- * Renamed CPluginURL* to CPluginValue*
- *
- * Revision 1.7 2003/09/30 19:53:18 dicuccio
- * Wrap entrez query in try/catch to avoid unseemly errors on failed search
- *
- * Revision 1.6 2003/09/17 16:26:56 dicuccio
- * Removed lines between cells in table. Removed cancel button
- *
- * Revision 1.5 2003/09/16 14:08:37 dicuccio
- * Changed retrieval to use UID as gi instead of searching for a docsum field
- *
- * Revision 1.4 2003/08/18 14:44:59 dicuccio
- * Added PopSet as a search database option. Fixed mapping og genomes <->
- * proteins
- *
- * Revision 1.3 2003/08/05 17:07:18 dicuccio
- * Changed calling semantics for the message queue - pass by reference, not
- * CConstRef<>
- *
- * Revision 1.2 2003/08/01 14:37:20 dicuccio
- * Solved issue with plugin communication - make sure that sequences are loaded
- * when the load button is clicked, not when the dialog closes
- *
- * Revision 1.1 2003/07/31 17:04:00 dicuccio
- * Added GenBank search
- *
- * ===========================================================================
- */