gc_content.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:11k
- /*
- * ===========================================================================
- * PRODUCTION $Log: gc_content.cpp,v $
- * PRODUCTION Revision 1000.5 2004/06/01 20:55:02 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.35
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: gc_content.cpp,v 1000.5 2004/06/01 20:55:02 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:
- * CAlgoPlugin_GcContent -- implements the algorithm to calculate GC composition
- */
- #include <ncbi_pch.hpp>
- #include "gc_content.hpp"
- #include <algo/sequence/nuc_prop.hpp>
- #include <gui/core/plugin_utils.hpp>
- #include <gui/core/version.hpp>
- #include <gui/dialogs/col/multi_col_dlg.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginInfo.hpp>
- #include <gui/plugin/PluginReply.hpp>
- #include <gui/plugin/PluginRequest.hpp>
- #include <gui/plugin/PluginValueConstraint.hpp>
- #include <objmgr/seq_vector.hpp>
- #include <objmgr/util/sequence.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- CAlgoPlugin_GcContent::~CAlgoPlugin_GcContent()
- {
- }
- // standard info boilerplate
- void CAlgoPlugin_GcContent::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CAlgoPlugin_GcContent", "Composition/GC Content",
- "Determine the G+C+S content of the current selections",
- "");
- // command info
- CPluginCommandSet& cmds = info.SetCommands();
- CPluginCommand& args = cmds.AddAlgoCommand(eAlgoCommand_run);
- args.AddArgument("locs", "Locations to evaluate",
- CSeq_loc::GetTypeInfo(),
- CPluginArg::TData::e_Array);
- args.SetConstraint("locs",
- (*CPluginValueConstraint::CreateSeqMol(),
- CSeq_inst::eMol_na,
- CSeq_inst::eMol_dna,
- CSeq_inst::eMol_rna));
- }
- void CAlgoPlugin_GcContent::RunCommand(CPluginMessage& msg)
- {
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- CPluginReply& reply = msg.SetReply();
- _TRACE("CGcContet::Run()");
- if ( !m_Dialog.get() ) {
- m_Dialog.reset(new CMultiColDlg());
- m_Dialog->SetTitle("GC Content");
- m_Dialog->SetLabel("GC Content for the following locations:");
- m_Dialog->SetColumn(0, "Sequence", FL_ALIGN_LEFT, 0.25f);
- m_Dialog->SetColumn(1, "Location", FL_ALIGN_LEFT, 0.50f);
- m_Dialog->SetColumn(2, "%GC", FL_ALIGN_CENTER, 0.25f);
- }
- //
- // first, evaluate whole sequences
- //
- int row = 0;
- plugin_args::TLocList locs;
- GetArgValue(args["locs"], locs);
- ITERATE (plugin_args::TLocList, iter, locs) {
- const CSeq_loc& loc = *iter->second;
- const IDocument& doc = *iter->first;
- try {
- CBioseq_Handle handle = doc.GetScope().GetBioseqHandle(loc);
- CSeqVector vec =
- handle.GetSequenceView(loc,
- CBioseq_Handle::eViewConstructed,
- CBioseq_Handle::eCoding_Iupac);
- int pct_gc = CNucProp::GetPercentGC(vec);
- string& id_str = m_Dialog->SetCell(row, 0);
- string& loc_str = m_Dialog->SetCell(row, 1);
- string& gc_str = m_Dialog->SetCell(row, 2);
- const CSeq_id& best_id =
- sequence::GetId(handle, sequence::eGetId_Best);
- id_str.erase();
- best_id.GetLabel(&id_str);
- loc_str = CPluginUtils::GetLabel(loc, &doc.GetScope());
- gc_str = NStr::IntToString(pct_gc);
- ++row;
- }
- catch (CException& e) {
- string str = CPluginUtils::GetLabel(loc, &doc.GetScope());
- LOG_POST(Error << "Error processing location " << str
- << ": " << e.what());
- }
- #ifndef _DEBUG
- catch (...) {
- string str = CPluginUtils::GetLabel(loc, &doc.GetScope());
- LOG_POST(Error << "Error processing location " << str);
- }
- #endif
- }
- //
- // prepare our dialog box
- //
- m_Dialog->SetRows(row);
- m_Dialog->Show();
- reply.SetStatus(eMessageStatus_success);
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: gc_content.cpp,v $
- * Revision 1000.5 2004/06/01 20:55:02 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.35
- *
- * Revision 1.35 2004/05/21 22:27:46 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.34 2004/03/05 17:35:37 dicuccio
- * Use sequence::GetId() instead of CSeq_id::GetStringDescr()
- *
- * Revision 1.33 2004/01/27 18:37:45 dicuccio
- * Code clean-up. Use standard names for plugins. Removed unnecessary #includes
- *
- * Revision 1.32 2004/01/07 15:50:36 dicuccio
- * Adjusted for API change in CPluginUtils::GetLabel(). Standardized exception
- * reporting in algorithms.
- *
- * Revision 1.31 2003/11/24 15:45:26 dicuccio
- * Renamed CVersion to CPluginVersion
- *
- * Revision 1.30 2003/11/06 20:12:12 dicuccio
- * Cleaned up handling of USING_SCOPE - removed from all headers
- *
- * Revision 1.29 2003/11/04 17:49:23 dicuccio
- * Changed calling parameters for plugins - pass CPluginMessage instead of paired
- * CPluginCommand/CPluginReply
- *
- * Revision 1.28 2003/10/07 13:47:00 dicuccio
- * Renamed CPluginURL* to CPluginValue*
- *
- * Revision 1.27 2003/09/04 14:05:24 dicuccio
- * Use IDocument instead of CDocument
- *
- * Revision 1.26 2003/09/03 14:46:53 rsmith
- * change namespace name from args to plugin_args to avoid clashes with variable names.
- *
- * Revision 1.25 2003/08/21 12:03:07 dicuccio
- * Make use of new typedef in plugin_utils.hpp for argument values.
- *
- * Revision 1.24 2003/08/05 17:03:55 dicuccio
- * Made multi-column output dialog a member variable - allows non-modal operation
- *
- * Revision 1.23 2003/07/28 11:51:48 dicuccio
- * Rewrote CTablePanel<> to be more flexible and better contained. Added standard
- * multicolumn list dialog. Deprecated use of COutputDlg.
- *
- * Revision 1.22 2003/07/22 15:32:16 dicuccio
- * Changed to make use of new API in plugin_utils.hpp - GetArgValue()
- *
- * Revision 1.21 2003/07/21 19:32:53 dicuccio
- * Added constraints based on molecule type
- *
- * Revision 1.20 2003/07/14 11:12:43 shomrat
- * Plugin messageing system related changes
- *
- * Revision 1.19 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.18 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.17 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.16 2003/06/20 14:52:36 dicuccio
- * Revised plugin registration - moved GetInfo() into the plugin handler
- *
- * Revision 1.15 2003/06/02 16:06:21 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.14 2003/05/19 13:39:07 dicuccio
- * Moved gui/core/plugin/ --> gui/plugin/. Merged core libraries into libgui_core
- *
- * Revision 1.13 2003/04/24 16:38:00 dicuccio
- * Updated to reflect changes in plugin API
- *
- * Revision 1.12 2003/03/25 13:47:42 dicuccio
- * Reimplemented to take one required argument instead of three optional ones -
- * makes standard processing easier
- *
- * Revision 1.11 2003/03/11 15:23:29 kuznets
- * iterate -> ITERATE
- *
- * Revision 1.10 2003/02/25 14:45:16 dicuccio
- * Changed accessors to match changes in plugin arguments accessors
- *
- * Revision 1.9 2003/02/24 13:03:15 dicuccio
- * Renamed classes in plugin spec:
- * CArgSeg --> CPluginArgSet
- * CArgument --> CPluginArg
- * CPluginArgs --> CPluginCommand
- * CPluginCommands --> CPluginCommandSet
- *
- * Revision 1.8 2003/02/20 19:49:53 dicuccio
- * Created new plugin architecture, based on ASN.1 spec. Moved GBENCH frameowrk
- * over to use new plugin architecture.
- *
- * Revision 1.7 2003/02/05 19:47:23 dicuccio
- * Fixed memory leak with output dialog. Changed ambiguous 'R' to 'S' for G+C
- *
- * Revision 1.6 2003/01/13 13:10:05 dicuccio
- * Namespace clean-up. Retired namespace gui -> converted all to namespace ncbi.
- * Moved all FLUID-generated code into namespace ncbi.
- *
- * Revision 1.5 2003/01/09 14:49:21 dicuccio
- * Use 'const CBioseq_Handle&' instead of 'CBioseq_Handle&'
- *
- * Revision 1.4 2002/12/30 18:14:18 dicuccio
- * Minor syntactic fixes. Reformatted some long lines.
- *
- * Revision 1.3 2002/12/30 17:21:40 ostell
- * Added support for most document type selections. Changed labels to use Labelxxx functions.
- *
- * Revision 1.2 2002/11/07 18:34:52 dicuccio
- * Changed to use string::empty()instead of compare to empty string.
- *
- * Revision 1.1 2002/11/05 20:59:20 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */