external.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:9k
- /*
- * ===========================================================================
- * PRODUCTION $Log: external.cpp,v $
- * PRODUCTION Revision 1000.5 2004/06/01 20:56:05 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.25
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: external.cpp,v 1000.5 2004/06/01 20:56:05 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 "external.hpp"
- #include <gui/utils/exec.hpp>
- #include "../basic/output_dlg.hpp"
- #include <gui/core/idocument.hpp>
- #include <gui/core/plugin_utils.hpp>
- #include <gui/plugin/PluginRequest.hpp>
- #include <gui/plugin/PluginInfo.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginValueConstraint.hpp>
- #include <gui/core/version.hpp>
- #include <objmgr/util/sequence.hpp>
- #include <objmgr/scope.hpp>
- #include <objmgr/seq_vector.hpp>
- #include <objects/seqloc/Seq_loc.hpp>
- #include <connect/ncbi_pipe.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- // stuff for running external apps
- void CExternal::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CExternal", "Run external executable",
- "A crude interface for running external executables",
- "");
- // command info
- CPluginCommandSet& cmds = info.SetCommands();
- CPluginCommand& args = cmds.AddAlgoCommand(eAlgoCommand_run);
- args.AddArgument("locs", "Sequences to evaluate",
- CSeq_loc::GetTypeInfo(),
- CPluginArg::TData::e_Array);
- args.SetConstraint("locs",
- *CPluginValueConstraint::CreateSeqSameMol());
- args.AddArgument("path", "path name to executable",
- CPluginArg::eString);
- }
- void CExternal::RunCommand(CPluginMessage& msg)
- {
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- CPluginReply& reply = msg.SetReply();
- _TRACE("CExternal::Run()");
- if ( !m_OutputDlg.get() ) {
- m_OutputDlg.reset(new COutputDlg());
- }
- m_OutputDlg->SetTitle("Results of executing external app");
- string str;
- vector<string> seqs;
- /****************************************/
- CPluginArg::TValues seq_list;
- args["path"];
- args["locs"].AsList(seq_list);
- CRef<CScope> new_scope;
- vector<string> seq_labels;
- vector<int> seq_gis;
- plugin_args::TLocList locs;
- GetArgValue(args["seqs"], locs);
- ITERATE (plugin_args::TLocList, iter, locs) {
- const CSeq_loc& loc = *iter->second;
- const IDocument& doc = *iter->first;
- CScope& scope = doc.GetScope();
- if ( !new_scope ) {
- new_scope.Reset(&scope);
- }
- if ( !sequence::IsOneBioseq(loc, &scope) ) {
- string str = CPluginUtils::GetLabel(loc, &doc.GetScope());
- LOG_POST(Info << "CExternal: "
- "location on multiple bioseqs ignored: " << str);
- continue;
- }
- CBioseq_Handle handle =
- scope.GetBioseqHandle(sequence::GetId(loc, &scope));
- CSeqVector vec =
- handle.GetSequenceView(loc,
- CBioseq_Handle::eViewConstructed,
- CBioseq_Handle::eCoding_Iupac);
- // save our sequence
- seqs.push_back(string());
- vec.GetSeqData(0, vec.size(), seqs.back());
- NStr::ToUpper(seqs.back());
- // save a label for this sequence
- seq_labels.push_back(CPluginUtils::GetLabel(loc, &doc.GetScope()));
- // save the gi for this sequence
- const CSeq_id& gi_id =
- sequence::GetId(handle, sequence::eGetId_ForceGi);
- _TRACE("gi = " << gi_id.GetGi());
- seq_gis.push_back(gi_id.GetGi());
- }
- /***************************************/
- // stdin will contain all sequences, separated by spaces
- string std_in;
- for(size_t i = 0; i < seqs.size(); i++) {
- std_in += seqs[i];
- if (i != seqs.size() - 1) {
- std_in += ' ';
- }
- }
- string std_out, std_err;
- vector<string> arguments;
- CExecute::Exec(args["path"].AsString().c_str(), arguments,
- std_in, std_out, std_err );
- if ( !str.empty() ) {
- str += "n";
- }
- str += "standard output:nn";
- str += std_out + "nn";
- str += "standard error:nn";
- str += std_err + "nn";
- //
- // prepare our dialog box
- //
- if (str.empty()) {
- str = "No output";
- }
- m_OutputDlg->SetText(str);
- m_OutputDlg->Show();
- reply.SetStatus(eMessageStatus_success);
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: external.cpp,v $
- * Revision 1000.5 2004/06/01 20:56:05 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.25
- *
- * Revision 1.25 2004/05/21 22:27:47 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.24 2004/03/11 17:40:36 dicuccio
- * Use sequence::GetId() instead of CSeq_id::GetStringDescr()
- *
- * Revision 1.23 2004/01/27 18:45:23 dicuccio
- * Added missing header files
- *
- * Revision 1.22 2004/01/07 15:50:39 dicuccio
- * Adjusted for API change in CPluginUtils::GetLabel(). Standardized exception
- * reporting in algorithms.
- *
- * Revision 1.21 2003/11/24 15:45:29 dicuccio
- * Renamed CVersion to CPluginVersion
- *
- * Revision 1.20 2003/11/06 21:17:19 ucko
- * Adjust for scope fixes in public headers.
- *
- * Revision 1.19 2003/11/04 21:17:46 dicuccio
- * Changed calling semantics to match new plugin API
- *
- * Revision 1.18 2003/10/07 15:31:17 ucko
- * Fixed fallout from URL -> Value conversion
- *
- * Revision 1.17 2003/10/07 13:47:04 dicuccio
- * Renamed CPluginURL* to CPluginValue*
- *
- * Revision 1.16 2003/09/25 19:10:30 jcherry
- * Moved exec.?pp to gui/utils
- *
- * Revision 1.15 2003/09/25 17:36:27 jcherry
- * Renamed CExec to CExecute to avoid name conflict. Made Exec()
- * really return the process's exit status.
- *
- * Revision 1.14 2003/09/04 17:34:04 ucko
- * Really use IDocument instead of CDocument.
- *
- * Revision 1.13 2003/09/04 14:05:24 dicuccio
- * Use IDocument instead of CDocument
- *
- * Revision 1.12 2003/09/03 14:46:53 rsmith
- * change namespace name from args to plugin_args to avoid clashes with variable names.
- *
- * Revision 1.11 2003/09/02 23:12:02 jcherry
- * Partial accommodation of changes to CPipe
- *
- * Revision 1.10 2003/08/21 12:03:08 dicuccio
- * Make use of new typedef in plugin_utils.hpp for argument values.
- *
- * Revision 1.9 2003/07/28 18:17:04 jcherry
- * Moved code for actually executing a program to a separate
- * class (CExec). Moved 'external' into a new project.
- *
- * Revision 1.8 2003/07/22 15:32:16 dicuccio
- * Changed to make use of new API in plugin_utils.hpp - GetArgValue()
- *
- * Revision 1.7 2003/07/14 11:12:28 shomrat
- * Plugin messageing system related changes
- *
- * Revision 1.6 2003/07/01 15:08:41 jcherry
- * Moved a bunch of stuff into CNucProp and CProtProp
- * Put these in c++/{src,include}/algo/sequence
- *
- * Revision 1.5 2003/06/26 15:33:40 dicuccio
- * Moved GetURLValue() from PluginURL.hpp to plugin_utils.hpp. Fixed compilation
- * errors relating to missing #includes
- *
- * Revision 1.4 2003/06/25 17:02:57 dicuccio
- * Split CPluginHandle into a handle (pointer-to-implementation) and
- * implementation file. Lots of #include file clean-ups.
- *
- * Revision 1.3 2003/06/20 14:52:36 dicuccio
- * Revised plugin registration - moved GetInfo() into the plugin handler
- *
- * Revision 1.2 2003/06/19 20:20:25 jcherry
- * Corrected minor error
- *
- * Revision 1.1 2003/06/19 19:12:42 jcherry
- * Initial version of interface for running external executables
- * from gbench. For now this just passes sequences on stdin.
- *
- * ===========================================================================
- */