wbplg_aligner.cpp
来自「ncbi源码」· C++ 代码 · 共 559 行 · 第 1/2 页
CPP
559 行
/* * =========================================================================== * PRODUCTION $Log: wbplg_aligner.cpp,v $ * PRODUCTION Revision 1000.4 2004/06/01 20:54:41 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.54 * PRODUCTION * =========================================================================== *//* $Id: wbplg_aligner.cpp,v 1000.4 2004/06/01 20:54:41 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: Yuri Kapustin * * File Description: * CAlgoPlugin_NeedlemanWunsch -- wraps global alignment algorithms */#include <ncbi_pch.hpp>#include "wbplg_aligner.hpp"//#include "dlg_messagebox.hpp"#include <gui/dialogs/progress/progress_dlg.hpp>#include <algo/align/mm_aligner.hpp>#include <algo/align/nw_aligner.hpp>#include <algo/align/nw_formatter.hpp>#include <corelib/ncbitime.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/idocument.hpp>#include <gui/core/plugin_utils.hpp>#include <gui/core/selection_buffer.hpp>#include <gui/core/version.hpp>#include <gui/plugin/PluginArgSet.hpp>#include <gui/plugin/PluginCommandSet.hpp>#include <gui/plugin/PluginInfo.hpp>#include <gui/plugin/PluginMessage.hpp>#include <gui/plugin/PluginRequest.hpp>#include <gui/plugin/PluginValue.hpp>#include <gui/plugin/PluginValueConstraint.hpp>#include <gui/utils/message_box.hpp>#include <objects/general/Date.hpp>#include <objects/seq/Annot_descr.hpp>#include <objects/seq/Annotdesc.hpp>#include <objects/seqalign/Dense_seg.hpp>#include <objects/seqalign/Seq_align.hpp>#include <objmgr/seq_vector.hpp>#include <objmgr/util/feature.hpp>#include <objmgr/util/sequence.hpp>#include <serial/iterator.hpp>#include <util/tables/raw_scoremat.h>#include <stdio.h>//////////BEGIN_NCBI_SCOPEUSING_SCOPE(objects);// GetInfo()// static interface to retrieve plugin registration informationvoid CAlgoPlugin_NeedlemanWunsch::GetInfo(CPluginInfo& info){ info.Reset(); // version info macro info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0, string(__DATE__) + " " + string(__TIME__), "CAlgoPlugin_NeedlemanWunsch", "Alignments/Global (Needleman-Wunsch) Alignment", "Align sequences using the Needleman-Wunsch " "alignment algorithm", ""); // command info CPluginCommandSet& cmds = info.SetCommands(); CPluginCommand& args = cmds.AddAlgoCommand(eAlgoCommand_run); args.AddArgument("seqs", "Sequences to align", CSeq_loc::GetTypeInfo(), CPluginArg::TData::e_Array); args.SetConstraint("seqs", *CPluginValueConstraint::CreateSeqSameMol()); args.AddDefaultArgument("Wm", "Match cost (nucl only)", CPluginArg::eInteger, NStr::IntToString(CNWAligner::GetDefaultWm())); args.AddDefaultArgument("Wms", "Mismatch cost (nucl only)", CPluginArg::eInteger, NStr::IntToString(CNWAligner::GetDefaultWms())); args.AddDefaultArgument("Wg", "Cost to open gap", CPluginArg::eInteger, NStr::IntToString(CNWAligner::GetDefaultWg())); args.AddDefaultArgument("Ws", "Cost to extend gap", CPluginArg::eInteger, NStr::IntToString(CNWAligner::GetDefaultWs())); args.AddDefaultArgument("esf1", "Free ends, 1st sequence", CPluginArg::eString, "none"); args.SetConstraint("esf1", (*CPluginValueConstraint::CreateSet(), "none", "left", "right", "both")); args.AddDefaultArgument("esf2", "Free ends, 2nd sequence", CPluginArg::eString, "none"); args.SetConstraint("esf2", (*CPluginValueConstraint::CreateSet(), "none", "left", "right", "both"));}//// callback to check the plugin's execution status//static bool progress_callback (CNWAligner::SProgressInfo* pInfo){ Fl::check(); if ( !pInfo ) { return false; } IReporter* reporter = reinterpret_cast<IReporter*>(pInfo->m_data); if( !reporter ) { return false; } if(false/*reporter->IsCancelled()*/) { return true; } else { char buf[128]; float pct_done = (100.0f / pInfo->m_iter_total) * pInfo->m_iter_done; sprintf( buf, "%2.0lf %% completed", pct_done); reporter->SetMessage(buf); reporter->SetPctCompleted((int)pct_done); return false; }}void CAlgoPlugin_NeedlemanWunsch::RunCommand(CPluginMessage& msg){ const CPluginCommand& cmd = msg.GetRequest().GetCommand(); CPluginReply& reply = msg.SetReply(); reply.SetStatus(eMessageStatus_failed); // check to see that we were passed sequences to begin with if ( !CPluginUtils::IsValid(cmd["seqs"]) ) { reply.SetStatus(eMessageStatus_failed); return; } // make sure we have exactly two sequences // FIXME: change to create a multi-pairwise alignment plugin_args::TLocList locs; GetArgValue(cmd["seqs"], locs); if (locs.size() != 2) { reply.SetStatus(eMessageStatus_ignored); return; } // make sure that the sequences are of a known type; fetch the sequences CRef<CScope> new_scope; vector<string> seqs; vector<string> seq_labels; typedef vector< CConstRef<CSeq_id> > TIds; TIds seq_ids; const SNCBIPackedScoreMatrix* scoremat = 0; ITERATE (plugin_args::TLocList, loc_iter, locs) { const CSeq_loc& loc = *loc_iter->second; const IDocument& doc = *loc_iter->first; CScope& scope = doc.GetScope(); if ( !new_scope ) { new_scope.Reset(&scope); } if ( !sequence::IsOneBioseq(loc, &scope) ) { string msg = CPluginUtils::GetLabel(loc, &doc.GetScope()); LOG_POST(Info << "CAlgoPlugin_NeedlemanWunsch: " "location on multiple bioseqs ignored: " << msg); continue; } CBioseq_Handle handle = scope.GetBioseqHandle(sequence::GetId(loc, &scope)); CSeqVector vec = handle.GetSequenceView(loc, CBioseq_Handle::eViewConstructed, CBioseq_Handle::eCoding_Iupac); // save our sequence seqs.push_back(string()); vec.GetSeqData(0, vec.size(), seqs.back()); NStr::ToUpper(seqs.back()); // save a label for this sequence seq_labels.push_back(CPluginUtils::GetLabel(loc, &doc.GetScope())); // save the gi for this sequence seq_ids.push_back(CConstRef<CSeq_id>(handle.GetSeqId())); scoremat = vec.IsNucleotide() ? 0: &NCBISM_Blosum62; } const size_t nw_limit = 200*1024*1024; vector<string>::const_iterator iter_seqs = seqs.begin(); double dim_square = (iter_seqs++)->length(); dim_square *= iter_seqs->length(); bool use_myers_miller = dim_square > nw_limit; // // main algorithm // string output; CNWAligner::TScore score = 0; try { CProgressDlg dlg_prg; dlg_prg.SetTitle("Calculation status"); dlg_prg.SetMessage("Calculation in progress...\nplease wait"); dlg_prg.Show(); const char* seq1 = seqs[0].c_str(), * seq2 = seqs[1].c_str(); size_t dim1 = seqs[0].size(), dim2 = seqs[1].size(); auto_ptr<CNWAligner> aligner ( use_myers_miller ? new CMMAligner (seq1, dim1, seq2, dim2, scoremat) : new CNWAligner (seq1, dim1, seq2, dim2, scoremat) ); if(use_myers_miller) { LOG_POST( Info << "CAlgoPlugin_NeedlemanWunsch: Using Myers-Miller method"); } aligner->SetWm (cmd["Wm" ].AsInteger()); aligner->SetWms(cmd["Wms"].AsInteger()); aligner->SetWg (cmd["Wg" ].AsInteger()); aligner->SetWs (cmd["Ws" ].AsInteger()); // end-space free alignment setup const string esf1 = cmd["esf1"].AsString(); bool left1 = (esf1 == "left") || (esf1 == "both"); bool right1 = (esf1 == "right") || (esf1 == "both"); const string esf2 = cmd["esf2"].AsString(); bool left2 = (esf2 == "left") || (esf2 == "both"); bool right2 = (esf2 == "right") || (esf2 == "both"); aligner->SetEndSpaceFree(left1, right1, left2, right2); aligner->SetProgressCallback(progress_callback, &dlg_prg); score = aligner->Run(); dlg_prg.Hide(); // create a seq-align structure for our alignment
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?