five_column_reader.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: five_column_reader.cpp,v $
- * PRODUCTION Revision 1000.5 2004/06/01 20:58:38 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: five_column_reader.cpp,v 1000.5 2004/06/01 20:58:38 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: Plugin to load five-column feature table
- */
- #include <ncbi_pch.hpp>
- #include "five_column_reader.hpp"
- #include <objtools/readers/readfeat.hpp>
- #include <gui/core/idocument.hpp>
- #include <gui/core/version.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginInfo.hpp>
- #include <gui/plugin/PluginValue.hpp>
- #include <gui/plugin/PluginValueConstraint.hpp>
- #include <objects/general/Int_fuzz.hpp>
- #include <objects/general/Object_id.hpp>
- #include <objects/seqfeat/Cdregion.hpp>
- #include <objects/seqfeat/Feat_id.hpp>
- #include <objects/seqfeat/Genetic_code.hpp>
- #include <objects/seqfeat/SeqFeatData.hpp>
- #include <objects/seqfeat/Seq_feat.hpp>
- #include <objects/seqloc/Seq_interval.hpp>
- #include <objects/seqloc/Seq_loc.hpp>
- #include <corelib/ncbistd.hpp>
- #include <objmgr/util/feature.hpp>
- #include <serial/objostr.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- void CFiveColumnReader::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CFiveColumnReader",
- "Five-column feature table",
- "Load the contents of a five-column feature table",
- "");
- // 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("mode", "Accession to use",
- CPluginArg::eString,
- "Use this ID");
- import_args.SetConstraint("mode", (*CPluginValueConstraint::CreateSet(),
- "Use this ID",
- "Get accession from file"));
- }
- void CFiveColumnReader::Import(CPluginMessage& msg)
- {
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- CPluginReply& reply = msg.SetReply();
- reply.SetStatus(eMessageStatus_failed);
- LOG_POST(Info << "CFiveColumnReader::Load: start point.");
- 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();
- try {
- _TRACE("CFiveColumnReader::Load: reading file...");
- CNcbiIfstream is(fname.c_str());
- CRef<CSeq_annot> annot;
- if (args["mode"].AsString() == "Get accession from file") {
- annot = CFeature_table_reader::ReadSequinFeatureTable(is);
- } else {
- // use the id we're handed
- // may need to throw away the first line of file
- // (this allows use of a file that does have a
- // ">Features" line)
- string first;
- getline(is, first);
- if (!(first[0] == '>')) {
- // it's not a ">" line, so rewind the file
- is.seekg(0);
- }
- string id_string = id->GetSeqIdString();
- annot = CFeature_table_reader
- ::ReadSequinFeatureTable(is, id_string, fname);
- }
-
- // this is not the same 'name' that's filled in by
- // ReadSequinFeatureTable, which is within a desc
- annot->SetName(fname);
- string comment = string("Annotations loaded from file ")
- + fname;
- annot->AddComment(comment);
- // save the object in the reply for framework processing
- reply.AddObject(*doc, *annot);
- reply.AddAction(CPluginReplyAction::e_Add_to_document);
- reply.SetStatus(eMessageStatus_success);
- }
- catch (CException& e) {
- LOG_POST(Info << "failed to read five-column file: " << e.what());
- _TRACE("failed to read five-column file: " << e.what() );
- }
- #ifndef _DEBUG
- catch (...) {
- _TRACE("failed to read five-column file: unknown error");
- }
- #endif
- }
- END_NCBI_SCOPE
- /*
- * =====================================================================
- * $Log: five_column_reader.cpp,v $
- * Revision 1000.5 2004/06/01 20:58:38 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/13 15:11:28 mjohnson
- * Removed hardcoded plugin help URL
- *
- * Revision 1.7 2004/02/11 21:01:52 jcherry
- * Use file argument rather than manually launching file chooser
- *
- * Revision 1.6 2003/11/24 15:45:39 dicuccio
- * Renamed CVersion to CPluginVersion
- *
- * Revision 1.5 2003/11/18 17:49:26 dicuccio
- * Added standard processing of return values
- *
- * Revision 1.4 2003/11/14 00:20:30 jcherry
- * Added url for help
- *
- * Revision 1.3 2003/11/06 20:12:15 dicuccio
- * Cleaned up handling of USING_SCOPE - removed from all headers
- *
- * Revision 1.2 2003/11/04 17:49:25 dicuccio
- * Changed calling parameters for plugins - pass CPluginMessage instead of paired
- * CPluginCommand/CPluginReply
- *
- * Revision 1.1 2003/11/03 14:58:36 jcherry
- * Initial version
- *
- * =====================================================================
- */