user_feat_table_reader.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:8k
- /*
- * ===========================================================================
- * PRODUCTION $Log: user_feat_table_reader.cpp,v $
- * PRODUCTION Revision 1000.3 2004/06/01 20:58:44 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: user_feat_table_reader.cpp,v 1000.3 2004/06/01 20:58:44 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: Josh Cherry
- *
- * File Description:
- *
- */
- #include <ncbi_pch.hpp>
- #include <corelib/ncbifile.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/utils/system_path.hpp>
- #include <gui/core/version.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginInfo.hpp>
- #include <gui/plugin/PluginValueConstraint.hpp>
- #include <gui/utils/message_box.hpp>
- #include <objmgr/object_manager.hpp>
- #include <objects/seqset/Seq_entry.hpp>
- #include <serial/iterator.hpp>
- #include <serial/objostrasn.hpp>
- #include <serial/serial.hpp>
- #include "user_feat_table_reader.hpp"
- #include <objtools/data_loaders/table/user_feature_dload.hpp>
- #include <sqlite/sqlite.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- void CUsrFeatTableReader::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CUsrFeatTableReader",
- "Tabular user features",
- "Load the contents of a table of user features",
- "");
- // command info
- CPluginCommandSet& cmds = info.SetCommands();
- CPluginCommand& import_args = cmds.AddDataCommand(eDataCommand_import);
- import_args.AddArgument("id", "ID",
- CSeq_id::GetTypeInfo(),
- CPluginArg::TData::e_Single);
-
- import_args.AddArgument("fname", "File to load", CPluginArg::eFile);
- import_args.AddDefaultArgument("offset", "Numbering convention in file",
- CPluginArg::eString,
- "Start of sequence is 1");
- import_args.SetConstraint("offset", (*CPluginValueConstraint::CreateSet(),
- "Start of sequence is 1",
- "Start of sequence is 0"));
- import_args.AddDefaultArgument("mode", "Accession to use",
- CPluginArg::eString,
- "Get accession from file");
- import_args.SetConstraint("mode", (*CPluginValueConstraint::CreateSet(),
- "Get accession from file",
- "Use this ID"));
- import_args.AddOptionalArgument("type",
- ""type" of user feature (overrides any in file)",
- CPluginArg::eString);
- }
- void CUsrFeatTableReader::Import(CPluginMessage& msg)
- {
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- CPluginReply& reply = msg.SetReply();
- const CPluginArg& arg = args["id"];
- IDocument* doc = const_cast<IDocument*>(arg.GetDocument());
- const CSeq_id* id = dynamic_cast<const CSeq_id*>(arg.GetObject());
- const string& fname = args["fname"].AsString();
- CUsrFeatDataLoader* loader = NULL;
- TLoaders::iterator iter = m_Loaders.find(fname);
- if (iter != m_Loaders.end()) {
- loader = iter->second;
- }
- string import_name;
- bool delete_file = true;
- if ( !CSQLite::IsValidDB(fname) ) {
- if (NcbiMessageBox("Do you want to save the generated SQL file "
- "for future use?",
- eDialog_YesNo, eIcon_Question,
- "Save SQL File?") == eYes) {
- import_name = fname;
- import_name += ".db";
- delete_file = false;
- }
- } else {
- import_name = fname;
- delete_file = false;
- }
- if (import_name.empty()) {
- import_name = CSystemPath::ResolvePath("<home>", "tmp");
- CDir dir(import_name);
- if ( !dir.Exists() ) {
- dir.Create();
- }
- import_name = CFile::GetTmpNameEx(import_name, "tdb_");
- }
- // figure out parameters
- string offset_string = args["offset"].AsString();
- CUsrFeatDataLoader::EOffset offset;
- if (offset_string == "Start of sequence is 0") {
- offset = CUsrFeatDataLoader::eBeginIsZero;
- } else {
- offset = CUsrFeatDataLoader::eBeginIsOne;
- }
- const CSeq_id* id_to_use = 0;
- if (args["mode"].AsString() == "Use this ID") {
- id_to_use = id;
- }
- string type_string;
- if (args.HasArgument("type") &&
- CPluginUtils::IsValid(args["type"])) {
- type_string = args["type"].AsString();
- }
- if ( !loader ) {
- try {
- loader = new CUsrFeatDataLoader(fname, import_name,
- delete_file, offset,
- type_string, id_to_use);
- }
- catch (exception& e) {
- NcbiMessageBox(e.what(), eDialog_Ok, eIcon_Exclamation);
- reply.SetStatus(eMessageStatus_failed);
- return;
- }
- CDocManager::GetObjectManager().RegisterDataLoader(*loader);
- m_Loaders[loader->GetName()] = loader;
- }
- // create our data loader
- CScope& scope = doc->GetScope();
- scope.AddDataLoader(loader->GetName(), 80);
- doc->PostDocumentChanged();
- reply.SetStatus(eMessageStatus_success);
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: user_feat_table_reader.cpp,v $
- * Revision 1000.3 2004/06/01 20:58:44 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9
- *
- * Revision 1.9 2004/05/21 22:27:48 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.8 2004/02/17 20:35:28 rsmith
- * moved core/settings.[ch]pp and core/system_path.[ch]pp to config and utils, respectively.
- *
- * Revision 1.7 2004/02/17 15:17:31 jcherry
- * Removed help url in favor of new help system
- *
- * Revision 1.6 2004/02/11 21:01:52 jcherry
- * Use file argument rather than manually launching file chooser
- *
- * Revision 1.5 2004/01/27 18:45:34 dicuccio
- * Added missing header files
- *
- * Revision 1.4 2003/12/22 19:30:11 dicuccio
- * Updated to match change in IDocument - UpdateAllViews() goes away
- *
- * Revision 1.3 2003/11/24 15:45:41 dicuccio
- * Renamed CVersion to CPluginVersion
- *
- * Revision 1.2 2003/11/14 21:30:15 jcherry
- * Added url for help
- *
- * Revision 1.1 2003/11/14 19:09:19 jcherry
- * Initial version
- *
- * ===========================================================================
- */