nmer.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:9k
- /*
- * ===========================================================================
- * PRODUCTION $Log: nmer.cpp,v $
- * PRODUCTION Revision 1000.5 2004/06/01 20:55:08 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.24
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: nmer.cpp,v 1000.5 2004/06/01 20:55:08 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:
- * CAlgoPlugin_Nmer -- wraps the algorithm to calculate n-mer frequencies
- */
- #include <ncbi_pch.hpp>
- #include "nmer.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_Nmer::~CAlgoPlugin_Nmer()
- {
- }
- // standard plugin announcement boilerplate
- void CAlgoPlugin_Nmer::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CAlgoPlugin_Nmer", "Composition/n-mer Frequencies",
- "Determine n-mer frequencies",
- "");
- // 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));
- args.AddArgument("nmer_size", "Size of n-mers",
- CPluginArg::eInteger);
- }
- void CAlgoPlugin_Nmer::RunCommand(CPluginMessage& msg)
- {
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- CPluginReply& reply = msg.SetReply();
- _TRACE("CAlgoPlugin_Nmer::Run()");
- if ( !m_Dialog.get() ) {
- m_Dialog.reset(new CMultiColDlg());
- m_Dialog->SetTitle("n-mer Frequencies");
- m_Dialog->SetLabel("Results of n-mer frequencies are as follows:");
- m_Dialog->SetColumn(0, "Sequence");
- m_Dialog->SetColumn(1, "Location", FL_ALIGN_LEFT, 2.0f);
- m_Dialog->SetColumn(2, "n-mer");
- m_Dialog->SetColumn(3, "Count", FL_ALIGN_CENTER);
- }
- int nmer_size = args["nmer_size"].AsInteger(); // the 'n' in nmer
- //
- // 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;
- // find the best ID for this bioseq
- try {
- CBioseq_Handle handle = doc.GetScope().GetBioseqHandle(loc);
- CSeqVector vec =
- handle.GetSequenceView(loc,
- CBioseq_Handle::eViewConstructed,
- CBioseq_Handle::eCoding_Iupac);
- vector<int> table;
- CNucProp::CountNmers(vec, nmer_size, table);
- m_Dialog->SetRows(0); // to clear any previous contents
- string& id_str = m_Dialog->SetCell(row, 0);
- string& loc_str = m_Dialog->SetCell(row, 1);
- 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());
- // preallocate rows in table for speed
- int row_count = 0;
- for(unsigned int k = 0; k < table.size(); k++) {
- if (table[k] != 0) {
- row_count++;
- }
- }
- m_Dialog->SetRows(row_count);
- for(unsigned int k = 0; k < table.size(); k++) {
- if (table[k] == 0) {
- continue;
- }
- CNucProp::Int2Nmer(k, nmer_size, m_Dialog->SetCell(row, 2));
- m_Dialog->SetCell(row, 3) = NStr::IntToString(table[k]);
- ++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->Show();
- reply.SetStatus(eMessageStatus_success);
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: nmer.cpp,v $
- * Revision 1000.5 2004/06/01 20:55:08 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.24
- *
- * Revision 1.24 2004/05/21 22:27:46 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.23 2004/03/05 17:35:37 dicuccio
- * Use sequence::GetId() instead of CSeq_id::GetStringDescr()
- *
- * Revision 1.22 2004/01/27 18:37:46 dicuccio
- * Code clean-up. Use standard names for plugins. Removed unnecessary #includes
- *
- * Revision 1.21 2004/01/07 15:50:36 dicuccio
- * Adjusted for API change in CPluginUtils::GetLabel(). Standardized exception
- * reporting in algorithms.
- *
- * Revision 1.20 2003/11/24 15:45:26 dicuccio
- * Renamed CVersion to CPluginVersion
- *
- * Revision 1.19 2003/11/06 20:12:12 dicuccio
- * Cleaned up handling of USING_SCOPE - removed from all headers
- *
- * Revision 1.18 2003/11/04 17:49:23 dicuccio
- * Changed calling parameters for plugins - pass CPluginMessage instead of paired
- * CPluginCommand/CPluginReply
- *
- * Revision 1.17 2003/10/07 13:47:00 dicuccio
- * Renamed CPluginURL* to CPluginValue*
- *
- * Revision 1.16 2003/09/04 14:05:24 dicuccio
- * Use IDocument instead of CDocument
- *
- * Revision 1.15 2003/09/03 14:46:53 rsmith
- * change namespace name from args to plugin_args to avoid clashes with variable names.
- *
- * Revision 1.14 2003/08/21 12:03:07 dicuccio
- * Make use of new typedef in plugin_utils.hpp for argument values.
- *
- * Revision 1.13 2003/08/18 15:05:11 jcherry
- * Reflect changes in nuc_prop.?pp. Pre-allocate dialog rows for speed.
- *
- * Revision 1.12 2003/08/05 17:03:55 dicuccio
- * Made multi-column output dialog a member variable - allows non-modal operation
- *
- * Revision 1.11 2003/07/28 11:51:48 dicuccio
- * Rewrote CTablePanel<> to be more flexible and better contained. Added standard
- * multicolumn list dialog. Deprecated use of COutputm_Dialog->
- *
- * Revision 1.10 2003/07/22 15:32:16 dicuccio
- * Changed to make use of new API in plugin_utils.hpp - GetArgValue()
- *
- * Revision 1.9 2003/07/21 19:32:53 dicuccio
- * Added constraints based on molecule type
- *
- * Revision 1.8 2003/07/14 11:12:57 shomrat
- * Plugin messageing system related changes
- *
- * Revision 1.7 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.6 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.5 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.4 2003/06/20 14:52:36 dicuccio
- * Revised plugin registration - moved GetInfo() into the plugin handler
- *
- * Revision 1.3 2003/06/10 14:45:22 jcherry
- * Moved actual algorithms for n-mers to a separate class,
- * implemented in count_nmers.?pp
- *
- * Revision 1.2 2003/06/09 19:14:39 jcherry
- * Retabbified, etc., to comply with conventions
- *
- * Revision 1.1 2003/06/09 17:30:10 jcherry
- * Initial version
- *
- * ===========================================================================
- */