genbank_loader.cpp

来自「ncbi源码」· C++ 代码 · 共 386 行

CPP
386
字号
/* * =========================================================================== * PRODUCTION $Log: genbank_loader.cpp,v $ * PRODUCTION Revision 1000.5  2004/06/01 20:57:58  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.38 * PRODUCTION * =========================================================================== *//*  $Id: genbank_loader.cpp,v 1000.5 2004/06/01 20:57:58 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: *    CDataPlugin_GenbankLoader - load sequence information form Genbank. */#include <ncbi_pch.hpp>#include "genbank_loader.hpp"#include <gui/core/doc_exception.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/idocument.hpp>#include <gui/core/version.hpp>#include <gui/core/plugin_utils.hpp>#include <gui/plugin/PluginCommandSet.hpp>#include <gui/plugin/PluginInfo.hpp>#include <gui/plugin/PluginValue.hpp>#include <gui/utils/message_box.hpp>#include <gui/objutils/label.hpp>#include <objmgr/scope.hpp>#include <objmgr/util/sequence.hpp>#include "loader_utils.hpp"#include "gb_manage_dlg.hpp"BEGIN_NCBI_SCOPEUSING_SCOPE(objects);//// class CDataPlugin_GenbankLoaderException defines some internal exception types used in// processing files.//// This class is used internally to avoid an ad-hoc exception mechanism;// currently, it reports only errors concerning invalid format types.//class CDataPlugin_GenbankLoaderException : EXCEPTION_VIRTUAL_BASE public CException{public:    // Enumerated list of exception types    enum EErrCode {        eInvalidId    };    // Convert an enuerated 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_GenbankLoaderException, CException);};void CDataPlugin_GenbankLoader::GetInfo(CPluginInfo& info){    info.Reset();    // version info macro    info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,                 string(__DATE__) + " " + string(__TIME__),                 "CDataPlugin_GenbankLoader", "Genbank Accession",                 "Open a Genbank accession",                 "");    // command info    CPluginCommandSet& cmds    = info.SetCommands();    CPluginCommand& load_args  = cmds.AddDataCommand(eDataCommand_load);    load_args.AddArgument("acc", "Accessions to load",                          CPluginArg::eString,                          CPluginArg::TData::e_Array);}CDataPlugin_GenbankLoader::CDataPlugin_GenbankLoader(){}CDataPlugin_GenbankLoader::~CDataPlugin_GenbankLoader(){}//// load a record from Genbank into a fully-prepared document//void CDataPlugin_GenbankLoader::Load(CPluginMessage& msg){    const CPluginCommand& args = msg.GetRequest().GetCommand();    CPluginReply& reply = msg.SetReply();    vector<string> str_vec = CPluginUtils::ArgToStringVec(args["acc"]);    reply.SetStatus(eMessageStatus_failed);    size_t load_success = 0;    ITERATE (vector<string>, iter, str_vec) {        //        // now, go about loading our entry, if we can        // check to make sure the Accession is (moderately) valid        // if the user puts in just a number, assume its a gi        //        string acc = NStr::TruncateSpaces(*iter);        if (acc.empty()) {            continue;        }        CLoaderStrFormatter::AddGIPrefix(&acc);        try {            CConstRef<CSeq_id> id(new CSeq_id(acc));            if (id->Which() == CSeq_id::e_not_set) {                NCBI_THROW(CDataPlugin_GenbankLoaderException, eInvalidId,                           "Accession " + acc + " is not valid");            }            CRef<CScope> scope(new CScope(CDocManager::GetObjectManager()));            scope->AddDefaults();            CBioseq_Handle handle = scope->GetBioseqHandle(*id);            if ( !handle ) {                LOG_POST(Error                         << "failed to load sequence for accession " << acc);                continue;            }            // marshal our document with this scope            IDocument* doc = CDocManager::CreateDocument(*scope, *id);            reply.AddObject(*doc);            ++load_success;            LOG_POST(Info <<                     "CDataPlugin_GenbankLoader: loaded accession " << acc);            // Needs to be added to MRU list            // Get label for the MRU list            string label("GenBank: ");            CLabel::GetLabel(*handle.GetSeqId(), &label,                             CLabel::eDefault, &handle.GetScope());            // Create a new Plugin Message containing only this entry            //  for the MRU list            CRef<CPluginMessage> new_msg(new CPluginMessage());            new_msg->Assign(msg);            CPluginCommand& new_args = new_msg->SetRequest().SetCommand();            CPluginArg& acc_arg = new_args["acc"];            acc_arg.SetString(acc);            acc_arg.SetList();            // add to MRU list            CDocManager::AddMRUEntry(*new_msg, label);        }        catch (CException& e) {            string msg("Failed to load accession '");            msg += acc;            msg += "':\n";            msg += e.GetMsg();            NcbiMessageBox(msg);        }        catch (std::exception& e) {            string msg("Failed to load accession '");            msg += acc;            msg += "':\n";            msg += e.what();            NcbiMessageBox(msg);        }#ifndef _DEBUG        catch (...) {            string msg("Failed to load accession '");            msg += acc;            msg += "':\nUnknown error";            NcbiMessageBox(msg);        }#endif    }    if (str_vec.size() != load_success) {        reply.SetStatus(eMessageStatus_failed);        if (load_success) {            NcbiMessageBox("Failed to load some accessions.");        } else {            NcbiMessageBox("Failed to load any accessions.");        }        return;    }    if (load_success != 0) {        LOG_POST(Info << "CDataPlugin_GenbankLoader: all accessions loaded successfully");    }    reply.SetStatus(eMessageStatus_success);}END_NCBI_SCOPE/* * =========================================================================== * $Log: genbank_loader.cpp,v $ * Revision 1000.5  2004/06/01 20:57:58  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.38 * * Revision 1.38  2004/05/25 17:21:59  dicuccio * Modified class names.  Fonts to 12 point * * Revision 1.37  2004/05/21 22:27:48  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.36  2004/05/18 11:22:34  friedman * Add recently loaded documents to the MRU list. * * Revision 1.35  2004/01/06 20:48:17  dicuccio * Moved CFltkCursorGuard into CPlugin::Execute() - broadly applied to all plugins * * Revision 1.34  2004/01/06 20:15:54  dicuccio * Use CFltkCursorGuard on load / import / search * * Revision 1.33  2004/01/05 18:50:28  vasilche * Fixed path to include files. * * Revision 1.32  2003/12/10 15:15:44  dicuccio * Added message box to warn when accessions fail to load. * * Revision 1.31  2003/12/05 13:07:53  dicuccio * Split management interface into a separate plugin.  Fixed linker error * introduced with status bar * * Revision 1.30  2003/11/24 15:45:36  dicuccio * Renamed CVersion to CPluginVersion * * Revision 1.29  2003/11/18 17:49:01  dicuccio * Added standard processing of return values * * Revision 1.28  2003/11/06 20:12:15  dicuccio * Cleaned up handling of USING_SCOPE - removed from all headers * * Revision 1.27  2003/11/04 17:49:24  dicuccio * Changed calling parameters for plugins - pass CPluginMessage instead of paired * CPluginCommand/CPluginReply * * Revision 1.26  2003/10/10 17:19:00  dicuccio * Added Manage() interface. * * Revision 1.25  2003/10/07 13:47:05  dicuccio * Renamed CPluginURL* to CPluginValue* * * Revision 1.24  2003/09/04 14:51:24  dicuccio * Use IDocument instead of CDocument * * Revision 1.23  2003/08/05 17:16:25  kuznets * Changes to improve code reuse between loaders + CLDS_Database passed as the * construction parameter to the lds search dialog * * Revision 1.22  2003/07/14 11:16:52  shomrat * Plugin messageing system related changes * * Revision 1.21  2003/06/25 17:02:58  dicuccio * Split CPluginHandle into a handle (pointer-to-implementation) and * implementation file.  Lots of #include file clean-ups. * * Revision 1.20  2003/06/20 14:52:57  dicuccio * Revised plugin registration - moved GetInfo() into the plugin handler * * Revision 1.19  2003/06/02 16:06:22  dicuccio * Rearranged src/objects/ subtree.  This includes the following shifts: *     - src/objects/asn2asn --> arc/app/asn2asn *     - src/objects/testmedline --> src/objects/ncbimime/test *     - src/objects/objmgr --> src/objmgr *     - src/objects/util --> src/objmgr/util *     - src/objects/alnmgr --> src/objtools/alnmgr *     - src/objects/flat --> src/objtools/flat *     - src/objects/validator --> src/objtools/validator *     - src/objects/cddalignview --> src/objtools/cddalignview * In addition, libseq now includes six of the objects/seq... libs, and libmmdb * replaces the three libmmdb? libs. * * Revision 1.18  2003/05/30 14:15:42  dicuccio * Renamed MessageBox to NcbiMessageBox because brain-dead MSVC thinks this is * ::MessageBox and rewrites the symbol as MessageBoxA, which results in an * unresolved external and conflict with the Win32 API :(. * * Revision 1.17  2003/05/30 13:10:37  dicuccio * Use MessageBox() instead of fl_alter() * * Revision 1.16  2003/05/19 13:40:44  dicuccio * Moved gui/core/plugin/ -> gui/plugin/.  Merged core libraries into libgui_core. * Removed old, unused dialog box. * * Revision 1.15  2003/05/01 12:54:34  dicuccio * Changed a useful trace -> log post for failure to load accession * * Revision 1.14  2003/04/29 14:52:31  dicuccio * Deprecated old accession entry dialog.  Added correct plugin argument to specify accession names * * Revision 1.13  2003/04/24 16:39:08  dicuccio * Updated to reflect changes in plugin API.  Changed location of document * marshal from framework to plugin * * Revision 1.12  2003/02/26 14:26:56  dicuccio * Removed unnecessary _TRACE() statements * * Revision 1.11  2003/02/24 13:03:16  dicuccio * Renamed classes in plugin spec: *     CArgSeg --> CPluginArgSet *     CArgument --> CPluginArg *     CPluginArgs --> CPluginCommand *     CPluginCommands --> CPluginCommandSet * * Revision 1.10  2003/02/20 19:49:56  dicuccio * Created new plugin architecture, based on ASN.1 spec.  Moved GBENCH * frameowrk over to use new plugin architecture. * * Revision 1.9  2003/02/06 18:48:36  dicuccio * Made 'catch (...)' conditional for non-debug builds * * Revision 1.8  2003/01/15 21:08:34  dicuccio * Removed dead _TRACE() statements * * Revision 1.7  2003/01/13 13:10:07  dicuccio * Namespace clean-up.  Retired namespace gui -> converted all to namespace * ncbi.  Moved all FLUID-generated code into namespace ncbi. * * Revision 1.6  2003/01/03 17:25:50  dicuccio * Fixed (finally!) issues regarding input validation of seq-ids. * * Revision 1.5  2002/12/30 18:44:20  dicuccio * Fixed a number of buglets in accession dialog and in handling of empty * accessions. * * Revision 1.4  2002/12/30 17:48:28  dicuccio * Added mechanism for data loader plugins to announce supported modes of * operation (load, import, save currently) * * Revision 1.3  2002/12/20 19:17:58  dicuccio * Added better handling of sueqnece ID errors (try not to segfault...) * * Revision 1.2  2002/12/12 15:22:38  dicuccio * Minot tweak to avoid a compiler warning. * * Revision 1.1  2002/11/25 20:51:01  dicuccio * Initial revision. * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?