lds_loader.cpp
来自「ncbi源码」· C++ 代码 · 共 567 行 · 第 1/2 页
CPP
567 行
/* * =========================================================================== * PRODUCTION $Log: lds_loader.cpp,v $ * PRODUCTION Revision 1000.5 2004/06/01 20:58:08 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.31 * PRODUCTION * =========================================================================== *//* $Id: lds_loader.cpp,v 1000.5 2004/06/01 20:58:08 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: Anatoliy Kuznetsov * * File Description: * CDataPlugin_LDSLoader - load sequence information from the local data storage(LDS). */#include <ncbi_pch.hpp>#include <corelib/ncbiapp.hpp>#include <corelib/ncbireg.hpp>#include <corelib/ncbitime.hpp>#include <gui/plugin/PluginInfo.hpp>#include <gui/core/version.hpp>#include <gui/core/doc_exception.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/idocument.hpp>#include <gui/core/plugin_utils.hpp>#include <gui/core/data_store.hpp>#include <gui/objutils/utils.hpp>#include <gui/plugin/PluginValue.hpp>#include <gui/plugin/PluginCommandSet.hpp>#include <gui/utils/message_box.hpp>#include <objmgr/scope.hpp>#include "lds_loader.hpp"#include "loader_utils.hpp"#include <objtools/lds/lds.hpp>#include <objtools/lds/lds_util.hpp>#include <objtools/lds/lds_reader.hpp>#include <objtools/lds/admin/lds_admin.hpp>#include "lds_search_dlg.hpp"BEGIN_NCBI_SCOPEUSING_SCOPE(objects);////////////////////////////////////////////////////////////////////// class CDataPlugin_LDSLoaderException defines some internal exception types used in// processing files.//// This class is used internally to avoid an ad-hoc exception mechanism;//class CDataPlugin_LDSLoaderException : EXCEPTION_VIRTUAL_BASE public CException{public: // Enumerated list of exception types enum EErrCode { eInvalidId }; // Convert an enumerated exception to a human-readable string representation // of this exception. virtual const char* GetErrCodeString(void) const { switch (GetErrCode()) { case eInvalidId: return "eInvalidId"; default: return CException::GetErrCodeString(); } } // constructor boilerplate NCBI_EXCEPTION_DEFAULT(CDataPlugin_LDSLoaderException, CException);};//////////////////////////////////////////////////////////////////void CDataPlugin_LDSLoader::GetInfo(CPluginInfo& info){ info.Reset(); // version info macro info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0, string(__DATE__) + " " + string(__TIME__), "CDataPlugin_LDSLoader", "Local sequence", "Open a molecule by sequence Id", ""); // command info CPluginCommandSet& cmds = info.SetCommands(); CPluginCommand& load_args = cmds.AddDataCommand(eDataCommand_load); load_args.AddArgument("acc", "Local sequence to load", CPluginArg::eString, CPluginArg::TData::e_Array); load_args.AddArgument("search_all", "Search all references", CPluginArg::eBoolean, CPluginArg::TData::e_Single); CPluginCommand& search_args = cmds.AddDataCommand(eDataCommand_search); {{ CPluginArg& arg = search_args.AddArgument("query", "Search string", CPluginArg::eString); arg.SetHidden(true); }}}CDataPlugin_LDSLoader::CDataPlugin_LDSLoader() : m_DbHolder(0){ if (CDataStore::HasObject("LDS_Database")) { CObject& obj = CDataStore::GetObject("LDS_Database"); m_DbHolder = dynamic_cast<CLDS_DatabaseHolder*>(&obj);// if (dbh)// m_db = dbh->GetDefaultDatabase(); }}CDataPlugin_LDSLoader::~CDataPlugin_LDSLoader(){}//// load a record from Genbank into a fully-prepared document//void CDataPlugin_LDSLoader::Load(CPluginMessage& msg){ const CPluginCommand& args = msg.GetRequest().GetCommand(); CPluginReply& reply = msg.SetReply(); reply.SetStatus(eMessageStatus_failed); bool request_success = false; if (!m_DbHolder) { reply.SetStatus(eMessageStatus_ignored); LOG_POST(Error << "Local data storage is not open."); return; } vector<string> str_vec = CPluginUtils::ArgToStringVec(args["acc"]); CLoaderStrFormatter::PrepareSearchVector(str_vec); if (str_vec.empty()) { reply.SetStatus(eMessageStatus_ignored); return; } bool search_all = args["search_all"].AsBoolean(); string alias = args["alias"].AsString(); LOG_POST(Info << "loading from " << alias); string lds_alias = args["alias"].AsString(); CLDS_Database* db = m_DbHolder->GetDatabase(lds_alias); if (!db) { reply.SetStatus(eMessageStatus_ignored); LOG_POST(Error << "LDS alias " << lds_alias << " not found."); return; } CStopWatch stw; stw.Start(); SLDS_TablesCollection& tables = db->GetTables(); CLDS_Set obj_search_results; CLDS_Query query(tables); query.FindSequences(str_vec, &obj_search_results); double elapsed = stw.Elapsed(); LOG_POST(Info << "LDS sequence search time = " << elapsed); unsigned int obj_found = 0; // Number of objects found CLDS_Set obj_read; // list of objects already loaded obj_found += obj_search_results.size(); if (obj_search_results.size() == 0) { LOG_POST(Info << "Failed to find local sequence(s)."); } else { ITERATE (CLDS_Set, rsit, obj_search_results) { try { int object_id = *rsit; if (!x_LoadLDS_BioTSE(object_id, db, &obj_read, reply)) { continue; } request_success = true; } catch (CLDS_Exception& _DEBUG_ARG(ex)) { _TRACE("failed to read LDS file: " << ex.what()); } } // ITERATE } if (search_all) { CLDS_Set slist_search_results; query.FindSeqIdList(str_vec, &slist_search_results); obj_found += slist_search_results.size(); ITERATE (CLDS_Set, it, slist_search_results) { try { int id = *it; CLDS_Query::SObjectDescr descr = query.GetObjectDescr(db->GetObjTypeMap(), id, true); if (LDS_SetTest(obj_read, descr.id)) { continue; } if (x_Load(descr, db, &obj_read, reply)) { request_success = true; } } catch (CLDS_Exception& _DEBUG_ARG(ex)) { _TRACE("failed to read object: " << ex.what()); } } // ITERATE } if (obj_found == 0) { NcbiMessageBox("Failed to find local sequence(s).", eDialog_Ok, eIcon_Stop, "Error"); } // set our status code // we don't set a default action - the documents are merely posted for // notification in case a user has called this plugin and expects // to receive the results in a return value if (request_success) { reply.SetStatus(eMessageStatus_success); }}void CDataPlugin_LDSLoader::Search(CPluginMessage& msg){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?