tree_export.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:5k
- /*
- * ===========================================================================
- * PRODUCTION $Log: tree_export.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:58:24 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: tree_export.cpp,v 1000.1 2004/06/01 20:58:24 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:
- * CDataPlugin_TreeExport - write phylogenetic tree to a file
- */
- #include <ncbi_pch.hpp>
- #include "tree_export.hpp"
- #include <gui/core/idocument.hpp>
- #include <gui/core/plugin_utils.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 <algo/phy_tree/phy_tree_serial.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- void CDataPlugin_TreeExport::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CDataPlugin_TreeExport",
- "Tree file", "Tree export plugin", "");
- // command info
- CPluginCommandSet& cmds = info.SetCommands();
- CPluginCommand& save_args = cmds.AddDataCommand(eDataCommand_save);
- save_args.AddArgument("file", "File name", CPluginArg::eFile);
- save_args.AddArgument("tree", "Tree", CPhyTreeSerial::GetTypeInfo());
- save_args.AddDefaultArgument("fmt", "Format", CPluginArg::eString,
- "Newick");
- save_args.SetConstraint("fmt",
- (*CPluginValueConstraint::CreateSet(),
- "Newick", "Nexus"));
- }
- //
- // Save()
- // Save the information in the tree into a file
- //
- void CDataPlugin_TreeExport::Save(CPluginMessage& msg)
- {
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- CPluginReply& reply = msg.SetReply();
- string fname = args["file"].AsString();
- try {
- const string& fmt = args["fmt"].AsString();
- const CPhyTreeSerial *tree =
- dynamic_cast<const CPhyTreeSerial *>(&args["tree"].AsObject());
- if (!tree) {
- throw runtime_error("CDataPlugin_TreeExport::Save: not a tree");
- }
- CNcbiOfstream ostr(fname.c_str());
- if (fmt == "Newick") {
- ostr << tree->GetTree();
- } else if (fmt == "Nexus") {
- WriteNexusTree(ostr, tree->GetTree());
- } else {
- throw runtime_error(string("Invalid format: ") + fmt);
- }
- reply.SetStatus(eMessageStatus_success);
- }
- catch (CException& e) {
- string msg("Failed to save file:n");
- msg += e.GetMsg();
- NcbiMessageBox(msg);
- reply.SetStatus(eMessageStatus_failed);
- }
- #ifndef _DEBUG
- catch (...) {
- NcbiMessageBox("Failed to save file:nUnknown errorn");
- reply.SetStatus(eMessageStatus_failed);
- }
- #endif
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: tree_export.cpp,v $
- * Revision 1000.1 2004/06/01 20:58:24 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
- *
- * Revision 1.4 2004/05/25 17:21:59 dicuccio
- * Modified class names. Fonts to 12 point
- *
- * Revision 1.3 2004/05/21 22:27:48 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.2 2004/03/11 17:43:41 dicuccio
- * Use new file chooser dialog
- *
- * Revision 1.1 2004/02/17 05:39:01 jcherry
- * Initial version
- *
- * ===========================================================================
- */