entrez_record_table.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:11k
- /*
- * ===========================================================================
- * PRODUCTION $Log: entrez_record_table.cpp,v $
- * PRODUCTION Revision 1000.0 2004/06/01 21:26:40 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: entrez_record_table.cpp,v 1000.0 2004/06/01 21:26:40 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:
- * CGBSearchPlugin - load sequence information form Genbank.
- */
- #include <ncbi_pch.hpp>
- #include <gui/widgets/fl/menu.hpp>
- #include <gui/core/algo_menu.hpp>
- #include "entrez_record_table.hpp"
- #include <gui/utils/message_box.hpp>
- #include <gui/objutils/label.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/core/plugin_handle.hpp>
- #include <gui/core/plugin_registry.hpp>
- #include <gui/core/plugin_utils.hpp>
- #include <gui/plugin/PluginArg.hpp>
- #include <gui/plugin/PluginValue.hpp>
- #include <objmgr/bioseq_handle.hpp>
- #include <objmgr/scope.hpp>
- #include <objects/seq/Seq_annot.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- CEntrezRecordTable::CEntrezRecordTable(int x, int y, int w, int h,
- const char* label)
- : TParent(x, y, w, h, label)
- , m_Reporter(NULL)
- {
- m_Handler.StandardConfig();
- SetCellBox(CFltkUtils::eBox_RightEdge);
- }
- void CEntrezRecordTable::SetReporter(IReporter* reporter)
- {
- m_Reporter = reporter;
- }
- bool CEntrezRecordTable::SetDatabase(const string& db)
- {
- m_DbName = db;
- try {
- IEntrezDBHandler& handler = m_DbManager.GetHandler(m_DbName);
- return true;
- }
- catch (...) {
- return false;
- }
- }
- void CEntrezRecordTable::GetDatabases(list<string>& db)
- {
- CEntrezDBManager::TEntries entries;
- m_DbManager.GetDatabases(entries);
- ITERATE (CEntrezDBManager::TEntries, iter, entries) {
- db.push_back(iter->visible_db_name);
- }
- }
- void CEntrezRecordTable::Query(const string& terms, size_t& total_count,
- size_t start, size_t visible)
- {
- Clear();
- redraw();
- // get our handler
- try {
- // set some limits - if num > 0, we assume it's correct
- IEntrezDBHandler& handler = m_DbManager.GetHandler(m_DbName);
- CRef<objects::CEntrez2_docsum_list> docsums =
- handler.Query(terms, total_count, start, visible);
- //
- // set our columns up correctly
- //
- vector<IEntrezDBHandler::SHeaderInfo> headers;
- handler.GetHeaders(headers);
- SetCols(0);
- ITERATE (vector<IEntrezDBHandler::SHeaderInfo>, iter, headers) {
- SetColumn(iter - headers.begin(),
- iter->name, eString, FL_ALIGN_LEFT,
- iter->rel_width);
- }
- //
- // now, add the docsums to the list...
- // we only want certain fields from each docsum
- //
- SetRows(0);
- if (visible) {
- Reserve(visible);
- } else {
- Reserve(total_count);
- }
- 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) {
- SetCell(row, col_iter - cols.begin(), *col_iter);
- }
- SetData(row).Reset(*iter);
- ++row;
- }
- }
- //
- // add a nice status message
- //
- if (m_Reporter) {
- string str("Search Results");
- if (docsums.GetPointer() && docsums->GetCount() != 0) {
- int start_idx = start + 1;
- int end_idx = start_idx + visible;
- if (visible == -1) {
- end_idx = start_idx + docsums->GetCount();
- }
- end_idx -= 1;
- end_idx = min(end_idx, start_idx + docsums->GetCount());
- str += " - Showing ";
- str += NStr::IntToString(start_idx) + " - ";
- str += NStr::IntToString(end_idx) + " of ";
- str += NStr::IntToString(total_count);
- str += " matching records.";
- } else {
- str += " - No records found.";
- }
- m_Reporter->SetMessage(str);
- m_Reporter->SetPctCompleted(0);
- }
- // finally, save our query string
- m_Query = terms;
- }
- 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 (...) {
- }
- }
- #if 0
- void CEntrezRecordTable::GetSelections(TConstScopedObjects& objs) const
- {
- CEntrez2_docsum_list docsums;
- for (size_t i = 0; i < GetRows(); ++i) {
- if ( !IsRowSelected(i) ) {
- continue;
- }
- CRef<CEntrez2_docsum> ref = GetData(i);
- docsums.SetList().push_back(ref);
- }
- docsums.SetCount(docsums.GetList().size());
- // retrieve our handler and get our IDs.
- try {
- IEntrezDBHandler& handler = m_DbManager.GetHandler(m_DbName);
- IEntrezDBHandler::TIds ids = handler.GetSeqIds(docsums);
- ITERATE (IEntrezDBHandler::TIds, iter, ids) {
- SConstScopedObject obj;
- obj.object.Reset(iter->GetPointer());
- objs.push_back(obj);
- }
- }
- catch (...) {
- }
- }
- void CEntrezRecordTable::SetSelections(const TConstScopedObjects& objs)
- {
- }
- #endif
- void CEntrezRecordTable::OnNewDocument()
- {
- try {
- IEntrezDBHandler& handler = m_DbManager.GetHandler(m_DbName);
- CPluginArg::TValues value_list;
- for (size_t i = 0; i < GetRows(); ++i) {
- if ( !IsRowSelected(i) ) {
- continue;
- }
- CRef<CScope> scope(new CScope(CDocManager::GetObjectManager()));
- scope->AddDefaults();
- IEntrezDBHandler::TIds ids = handler.GetSeqIds(*GetData(i));
- size_t idx = 0;
- ITERATE (IEntrezDBHandler::TIds, iter, ids) {
- const CSeq_id& id = **iter;
- CBioseq_Handle handle = scope->GetBioseqHandle(id);
- if (handle) {
- string id_str;
- CLabel::GetLabel(id, &id_str, CLabel::eDefault, scope);
- CRef<CPluginValue> value(new CPluginValue());
- value->SetString(id_str);
- value_list.push_back(value);
- if (m_Reporter) {
- string msg("Loaded sequence ");
- msg += id_str;
- m_Reporter->SetMessage(msg);
- int pct = 100 * ++idx / ids.size();
- m_Reporter->SetPctCompleted(pct);
- }
- }
- }
- }
- // now load them all
- 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);
- }
- }
- catch (...) {
- }
- }
- void CEntrezRecordTable::OnNewBulkDocument()
- {
- try {
- CFltkCursorGuard WAIT_GUARD;
- IEntrezDBHandler& handler = m_DbManager.GetHandler(m_DbName);
- CPluginArg::TValues value_list;
- IEntrezDBHandler::TIds ids;
- for (size_t i = 0; i < GetRows(); ++i) {
- if ( !IsRowSelected(i) ) {
- continue;
- }
- IEntrezDBHandler::TIds temp = handler.GetSeqIds(*GetData(i));
- ids.insert(ids.end(), temp.begin(), temp.end());
- }
- CRef<CSeq_annot> annot(new CSeq_annot());
- string title("Query Results: '");
- title += m_Query;
- title += "', ";
- title += NStr::IntToString(ids.size());
- title += " sequences";
- annot->AddTitle(title);
- annot->SetCreateDate(CTime(CTime::eCurrent));
- annot->SetData().SetIds().swap(ids);
- CRef<CScope> scope(new CScope(CDocManager::GetObjectManager()));
- scope->AddDefaults();
- CDocManager::CreateDocument(*scope, *annot);
- CDocManager::UpdateAllViews();
- }
- catch (...) {
- }
- }
- void CEntrezRecordTable::OnLoadNuclNeighbors()
- {
- }
- void CEntrezRecordTable::OnLoadProtNeighbors()
- {
- }
- enum EEntrezResultsDlgCommands {
- eCmd_NewDocument = eBaseCmdLast + 200,
- eCmd_NewBatchDocument,
- eCmd_LoadNucleotideNeighbors,
- eCmd_LoadProteinNeighbors
- };
- static
- DEFINE_MENU(PopupMenu)
- MENU_ITEM(eCmd_NewDocument, "Open in New Document")
- MENU_ITEM(eCmd_NewBatchDocument, "Open in Combined Document")
- MENU_ITEM(eCmd_LoadNucleotideNeighbors, "Open Nucleotide Neighbors")
- MENU_ITEM(eCmd_LoadProteinNeighbors, "Open Protein Neighbors")
- END_MENU()
- BEGIN_CMD_MAP(CEntrezRecordTable, CCommandTarget)
- ON_COMMAND(eCmd_NewDocument, &CEntrezRecordTable::OnNewDocument)
- ON_COMMAND(eCmd_NewBatchDocument, &CEntrezRecordTable::OnNewBulkDocument)
- ON_COMMAND(eCmd_LoadNucleotideNeighbors, &CEntrezRecordTable::OnLoadNuclNeighbors)
- ON_COMMAND(eCmd_LoadProteinNeighbors, &CEntrezRecordTable::OnLoadProtNeighbors)
- END_CMD_MAP()
- int CEntrezRecordTable::handle(int event)
- {
- m_Handler.OnFLTKEvent(event);
- switch (m_Handler.GetGUISignal()) {
- case CGUIEvent::ePopupSignal:
- {{
- CPopupMenu menu(x(), y(), w(), h());
- menu.SetCmdTarget(static_cast<CCommandTarget*>(this));
- add(&menu);
- menu.SetItems(PopupMenu);
- menu.popup();
- remove(menu);
- }}
- return 1;
- default:
- break;
- }
- return TParent::handle(event);
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * ===========================================================================
- */