📄 pattern.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: pattern.cpp,v $ * PRODUCTION Revision 1000.6 2004/06/01 20:55:24 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.33 * PRODUCTION * =========================================================================== *//* $Id: pattern.cpp,v 1000.6 2004/06/01 20:55: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: gbench plugin for finding regular expressions in sequences * */#include <ncbi_pch.hpp>#include "pattern.hpp"#include <algo/sequence/find_pattern.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/PluginRequest.hpp>#include <gui/plugin/PluginValueConstraint.hpp>#include <gui/objutils/utils.hpp>#include <objmgr/seq_vector.hpp>#include <objmgr/util/sequence.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);CAlgoPlugin_Pattern::~CAlgoPlugin_Pattern(){}// standard plugin announce bopilerplatevoid CAlgoPlugin_Pattern::GetInfo(CPluginInfo& info){ info.Reset(); // version info macro info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0, string(__DATE__) + " " + string(__TIME__), "CAlgoPlugin_Pattern", "Search/Regular Expression Sequence Search", "Find all non-overlapping occurrences of a pattern", ""); // 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.AddArgument("pattern", "Pattern to find", CPluginArg::eString); args.AddArgument("label", "Label for matches", CPluginArg::eString);}void CAlgoPlugin_Pattern::RunCommand(CPluginMessage& msg){ const CPluginCommand& args = msg.GetRequest().GetCommand(); CPluginReply& reply = msg.SetReply(); _TRACE("CAlgoPlugin_Pattern::Run()"); // pattern (r.e.) to find string pattern(args["pattern"].AsString()); // label to appear in feature table string label(args["label"].AsString()); if ( !m_Dialog.get() ) { m_Dialog.reset(new CMultiColDlg()); m_Dialog->SetWindowSize(600, 350); m_Dialog->SetTitle("Pattern Search Results"); m_Dialog->SetColumn(0, "Sequence"); m_Dialog->SetColumn(1, "Location"); m_Dialog->SetColumn(2, "Position", FL_ALIGN_CENTER); m_Dialog->SetColumn(3, "Matched Sequence", FL_ALIGN_LEFT, 2.0f); } m_Dialog->SetLabel(string("A search for the pattern\n") + pattern + string("\nproduced:")); // clear any previous contents m_Dialog->SetRows(0); vector<TSeqPos> starts; vector<TSeqPos> ends; // // 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); string seq; vec.GetSeqData( (TSeqPos) 0, vec.size(), seq ); CFindPattern::Find(seq, pattern, starts, ends); 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 dialog for speed m_Dialog->SetRows(row + starts.size()); for( unsigned int k = 0; k < starts.size(); k++) { string& pos_str = m_Dialog->SetCell(row, 2); // 1-based indexing for dialog pos_str = NStr::IntToString(starts[k] + 1) + " - " + NStr::IntToString(ends[k] + 1); m_Dialog->SetCell(row, 3) = seq.substr(starts[k], ends[k] - starts[k] + 1); ++row; } // // add a feature table to doc // CRef<CSeq_annot> annot(new CSeq_annot()); for( unsigned int k = 0; k < starts.size(); k++) { // create feature CRef<CSeq_feat> feat(new CSeq_feat()); // set correct location {{ CSeq_loc& floc = feat->SetLocation(); floc.SetInt().SetId().Assign(sequence::GetId(loc)); floc.SetInt().SetFrom(starts[k]); floc.SetInt().SetTo(ends[k]); // assume plus strand for now floc.SetInt().SetStrand(eNa_strand_plus); CRef<CSeq_loc> new_loc = CSeqUtils::RemapChildToParent(loc, floc); feat->SetLocation(*new_loc); }} // set feature data feat->SetData().SetRegion() = label; // save in annot annot->SetData().SetFtable().push_back(feat); } // add description to annot annot->AddName("Pattern Matches"); string comment("Matches to pattern \'"); comment += pattern + "\'"; annot->AddComment(comment); reply.AddObject(doc, *annot); // attach annot to doc //const_cast<IDocument&>(doc).AttachAnnot(*annot); } 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 } // update all views //CDocManager::UpdateAllViews(); // // prepare our dialog box // m_Dialog->Show(); reply.AddAction(CPluginReplyAction::e_Add_to_document); reply.SetStatus(eMessageStatus_success);}END_NCBI_SCOPE/* * =========================================================================== * $Log: pattern.cpp,v $ * Revision 1000.6 2004/06/01 20:55:24 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.33 * * Revision 1.33 2004/05/21 22:27:47 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.32 2004/05/03 13:05:42 dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.31 2004/04/01 14:14:02 lavr * Spell "occurred", "occurrence", and "occurring" * * Revision 1.30 2004/03/05 17:35:37 dicuccio * Use sequence::GetId() instead of CSeq_id::GetStringDescr() * * Revision 1.29 2004/02/13 15:08:50 mjohnson * Removed local URL for plugin help. * * Revision 1.28 2004/01/27 18:37:53 dicuccio * Code clean-up. Use standard names for plugins. Removed unnecessary #includes * * Revision 1.27 2004/01/07 15:50:37 dicuccio * Adjusted for API change in CPluginUtils::GetLabel(). Standardized exception * reporting in algorithms. * * Revision 1.26 2003/12/17 17:58:50 jcherry * Set dialog label every time * * Revision 1.25 2003/12/16 22:25:09 jcherry * Added plugin for searching against patterns loaded from file * * Revision 1.24 2003/12/15 20:16:08 jcherry * Changed CFindPattern::Find to take a string rather than a CSeqVector * * Revision 1.23 2003/12/15 19:53:05 jcherry * Preallocate rows in dialog for speed * * Revision 1.22 2003/11/24 15:45:26 dicuccio * Renamed CVersion to CPluginVersion * * Revision 1.21 2003/11/18 17:48:37 dicuccio * Added standard processing of return values * * Revision 1.20 2003/11/14 00:20:29 jcherry * Added url for help * * 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/27 17:46:48 dicuccio * Removed dead #includes * * Revision 1.16 2003/10/14 16:24:37 dicuccio * Correctly remap new feature locations through the parent location to the master * sequence * * Revision 1.15 2003/10/07 13:47:00 dicuccio * Renamed CPluginURL* to CPluginValue* * * Revision 1.14 2003/09/25 17:21:35 jcherry * Added name to annot * * 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/08/21 12:03:07 dicuccio * Make use of new typedef in plugin_utils.hpp for argument values. * * Revision 1.10 2003/08/11 18:03:53 jcherry * Fixed to use 0-based indexing for feature table (but retain * 1-based indexing for dialog box) * * Revision 1.9 2003/08/05 17:03:55 dicuccio * Made multi-column output dialog a member variable - allows non-modal operation * * Revision 1.8 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.7 2003/07/22 15:32:16 dicuccio * Changed to make use of new API in plugin_utils.hpp - GetArgValue() * * Revision 1.6 2003/07/14 11:13:05 shomrat * Plugin messageing system related changes * * Revision 1.5 2003/07/09 17:20:07 jcherry * Added code to add comment to annotation. * Removed some gratuitous code. * * Revision 1.4 2003/07/08 22:09:00 jcherry * Added code to attach results as feature table to document handed * * Revision 1.3 2003/07/03 19:14:12 jcherry * Initial version * * Revision 1.1 2003/07/03 19:06:39 jcherry * Initial version * * =========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -