view_multialign.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:20k
- /*
- * ===========================================================================
- * PRODUCTION $Log: view_multialign.cpp,v $
- * PRODUCTION Revision 1000.6 2004/06/01 20:59:28 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.51
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: view_multialign.cpp,v 1000.6 2004/06/01 20:59:28 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:
- * User-modifiable implementation file for extension of Multiple Alignment
- * viewer for GBENCH
- */
- #include <ncbi_pch.hpp>
- #include "view_multialign.hpp"
- #include <gui/core/plugin_utils.hpp>
- #include <gui/core/version.hpp>
- #include <gui/plugin/PluginRequest.hpp>
- #include <gui/plugin/PluginCommand.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginInfo.hpp>
- #include <gui/plugin/PluginValue.hpp>
- #include <gui/objutils/utils.hpp>
- #include <objects/seqset/Seq_entry.hpp>
- #include <objtools/alnmgr/alnmix.hpp>
- #include <objtools/alnmgr/alnvec.hpp>
- #include <gui/widgets/aln_multiple/align_row.hpp>
- #include <gui/widgets/aln_multiple/alnvec_multi_ds.hpp>
- #include <gui/widgets/aln_multiple/align_row.hpp>
- #include <serial/iterator.hpp>
- BEGIN_NCBI_SCOPE
- // We include the generated _.cpp file here. This avoids a nasty bug in some
- // versions of gcc in which inline functions are not intantiated.
- #include "view_multialign_.cpp"
- DEFINE_MENU(Menu)
- SUBMENU("Display")
- MENU_ITEM(eCmdZoomIn, "Zoom In")
- MENU_ITEM(eCmdZoomOut, "Zoom Out")
- MENU_ITEM(eCmdZoomAll, "Zoom All")
- MENU_ITEM(eCmdZoomSeq, "Zoom to Sequence")
- MENU_ITEM(eCmdZoomSel, "Zoom Selection")
- MENU_SEPARATOR()
- MENU_ITEM(eCmdSetSelMaster , "Set Selected as Master")
- MENU_ITEM(eCmdSetConsMaster, "Set Consensus as Master")
- MENU_ITEM(eCmdUnsetMaster, "Unset Master")
- MENU_SEPARATOR()
- MENU_ITEM(eCmdHideSelected, "Hide Selected Rows")
- MENU_ITEM(eCmdShowAll, "Show All Rows")
- MENU_SEPARATOR()
- MENU_ITEM(eCmdMoveSelectedUp, "Move Selected Items Up")
- END_SUBMENU()
- SUBMENU("Selection")
- MENU_ITEM(eCmdResetSelection, "Reset Selection")
- MENU_SEPARATOR()
- MENU_ITEM(eCmdMarkSelected, "Mark Selected")
- MENU_ITEM(eCmdUnMarkSelected, "UnMark Selected")
- MENU_ITEM(eCmdUnMarkAll, "UnMark All")
- MENU_SEPARATOR()
- MENU_ITEM(eCmdMoveSelectedUp, "Move Selected Items Up")
- END_SUBMENU()
- SUBMENU("View")
- END_SUBMENU()
- SUBMENU("Tools")
- END_SUBMENU()
- SUBMENU("&Help")
- END_SUBMENU()
- END_MENU()
- // Events map
- EVENT_MAP_RX_BEGIN(CAlnMultiView)
- EVENT_ACCEPT(CViewEvent::eSelectionChanged, OnSelChangedEvent)
- EVENT_MAP_RX_END
- //
- // standard plugin announcement boilerplate
- //
- void CAlnMultiView::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CAlnMultiView",
- "Multiple Alignment Viewer",
- "Multiple Alignment Viewer", "");
- // command info
- CPluginCommandSet& cmds = info.SetCommands();
- CPluginCommand& args = cmds.AddViewCommand(eViewCommand_new_view);
- args.AddArgument("alignments", "Alignments to merge and render",
- CSeq_annot::GetTypeInfo(),
- CPluginArg::TData::e_Array);
- args.SetConstraint("alignments",
- *CPluginValueConstraint::CreateAnnotType
- (CSeq_annot::TData::e_Align));
- }
- CAlnMultiView::CAlnMultiView(const CPluginMessage& msg, const string& pool_name)
- : CAlnView()
- {
- m_Window.reset(x_CreateWindow());
- m_AlnWidget->Create();
- m_AlnWidget->SetListener(this);
- // Setup menu and command handling
- m_Menu->SetItems(Menu);
- m_Menu->SetCmdTarget(static_cast<CCommandTarget*>(this));
- AddChildCmdTarget(static_cast<CCommandTarget*>(m_AlnWidget));
- m_StyleCatalog.SetDefaultStyle(new CAlnVecRowDisplayStyle());
- m_StyleCatalog.SetWidgetStyle(m_AlnWidget->GetDisplayStyle());
- m_AlnWidget->SetStyleCatalog(&m_StyleCatalog);
- // set our core components
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- plugin_args::TAnnotList aligns;
- GetArgValue(args["alignments"], aligns);
- CRef<CSeq_annot> annot(new CSeq_annot());
- const IDocument* doc = NULL;
- ITERATE (plugin_args::TAnnotList, iter, aligns) {
- doc = iter->first;
- annot->SetData().SetAlign()
- .insert(annot->SetData().SetAlign().end(),
- iter->second->GetData().GetAlign().begin(),
- iter->second->GetData().GetAlign().end());
- }
- // extract the alignments from the argument
- if (annot.GetPointer() && doc) {
- x_SetDocument(*doc);
- m_AnnotData.Reset(annot);
- }
- // create the view menu manager
- m_ViewMenuMgr.reset(new CViewMenuMgr(m_Menu, "View", this, pool_name));
- m_AlgoMenuMgr.reset(new CAlgoMenuMgr(m_Menu, "Tools", this));
- }
- BEGIN_CMD_MAP(CAlnMultiView, CAlnView)
- ON_COMMAND(eCmdResetSelection, &CAlnMultiView::OnResetSelection)
- ON_COMMAND(eCmdSetConsMaster, &CAlnMultiView::OnMakeConsensusRowMaster)
- ON_COMMAND(eCmdMarkSelected, &CAlnMultiView::OnMarkSelected)
- ON_COMMAND(eCmdUnMarkAll, &CAlnMultiView::OnUnMarkAll)
- END_CMD_MAP()
- void CAlnMultiView::OnDocumentChanged()
- {
- if (m_Document) {
- SetTitle(m_Document->GetShortTitle() + ": " + GetTitle());
- // create our alignment manager
- m_DataSource.Reset(new CAlnVecMultiDataSource());
- m_DataSource->Init(*m_AnnotData, m_Document->GetScope());
- m_AlnWidget->SetDataSource(m_DataSource);
- SetSelBuffer().Clear();
- SetSelBuffer().AddSelection(GetDocument(), *m_AnnotData);
- m_ViewMenuMgr->AddActiveViews(m_Document);
- m_ViewMenuMgr->AddNewViews();// (GetSelBuffer());
- m_AlgoMenuMgr->AddAlgoMenu();// (GetSelBuffer());
- }
- }
- void CAlnMultiView::OnSelectionChanged(const CSelectionBuffer& buf)
- {
- if (m_Document) {
- if ( !GetSelBuffer() ) {
- SetSelBuffer().AddSelection(GetDocument(), *m_AnnotData);
- }
- m_ViewMenuMgr->AddActiveViews(m_Document);
- m_ViewMenuMgr->AddNewViews();// (GetSelBuffer());
- m_AlgoMenuMgr->AddAlgoMenu();// (GetSelBuffer());
- }
- }
- void CAlnMultiView::OnVisibleRangeChanged(const CSeq_loc& loc)
- {
- }
- const string& CAlnMultiView::GetTitle(void) const
- {
- static string s_str("Multiple Alignment View");
- return s_str;
- }
- void CAlnMultiView::x_OnFileClose()
- {
- Hide();
- }
- void CAlnMultiView::x_OnHelp()
- {
- }
- void CAlnMultiView::OnResetSelection()
- {
- if (m_AlnWidget) {
- m_AlnWidget->OnResetSelection();
- }
- SetSelBuffer().Clear();
- SetSelBuffer().AddSelection(GetDocument(), *m_AnnotData);
- m_ViewMenuMgr->AddActiveViews(m_Document);
- m_ViewMenuMgr->AddNewViews();// (GetSelBuffer());
- m_AlgoMenuMgr->AddAlgoMenu();// (GetSelBuffer());
- }
- void CAlnMultiView::OnMakeConsensusRowMaster()
- {
- if (m_DataSource.GetPointer() && m_AlnWidget) {
- IAlnMultiDataSource::TNumrow row = m_DataSource->GetConsensusRow();
-
- if(row == -1) { // create it
- m_DataSource->CreateConsensus();
- row = m_DataSource->GetConsensusRow();
- }
- m_DataSource->SetAnchor(row); //last row - consensus
- m_AlnWidget->SetDataSource(m_DataSource);
- //m_AlnWidget->MakeConsensusRowMaster();
- //m_AlnWidget->redraw();
- }
- }
- void CAlnMultiView::OnMarkSelected(void)
- {
- if (m_AlnWidget) {
- m_AlnWidget->OnMarkSelected();
- // fill our selection buffer
- SetSelBuffer().Clear();
- // GetMarks() returns marked locations
- CAlnMultiWidget::TPSeqLocList locs;
- m_AlnWidget->GetMarks(locs);
- ITERATE (CAlnMultiWidget::TPSeqLocList, iter, locs) {
- SetSelBuffer().AddSelection(GetDocument(), **iter);
- }
- /**
- // GetSelection() returns selections in alignment coordinates
- const CAlnMultiWidget::TRangeColl& range_coll = m_AlnWidget->GetSelection();
- ITERATE (CAlnMultiWidget::TRangeColl, iter, range_coll) {
- CRef<CSeq_loc> loc(new CSeq_loc());
- loc.SetInt().SetFrom(iter->GetFrom());
- loc.SetInt().SetTo (iter->GetTo());
- }
- **/
- }
-
- if ( !GetSelBuffer() ) {
- SetSelBuffer().AddSelection(GetDocument(),
- m_DataSource->GetAlnMgr().GetDenseg());
- }
- m_ViewMenuMgr->AddActiveViews(m_Document);
- m_ViewMenuMgr->AddNewViews();// (GetSelBuffer());
- m_AlgoMenuMgr->AddAlgoMenu();// (GetSelBuffer());
- m_ViewMenuMgr->AddActiveViews(m_Document);
- }
- void CAlnMultiView::OnUnMarkAll(void)
- {
- if (m_AlnWidget) {
- m_AlnWidget->OnUnMarkAll();
- }
- SetSelBuffer().Clear();
- SetSelBuffer().AddSelection(GetDocument(),
- m_DataSource->GetAlnMgr().GetDenseg());
- m_ViewMenuMgr->AddActiveViews(m_Document);
- m_ViewMenuMgr->AddNewViews();// (GetSelBuffer());
- m_AlgoMenuMgr->AddAlgoMenu();// (GetSelBuffer());
- }
- void CAlnMultiView :: SendSelChangedEvent()
- {
- /* CObjectFor< vector<CRef<objects::CSeq_id> > > csid;
- //csid = m_pDataSource->ConvertId2SeqId(m_pMatrixPane->GetSelectedIDs());
- // fire external event
- FireEvent(CViewEvent::CreateEvent(CViewEvent::eSelectionChanged,
- CViewEvent::eEventViews,
- CViewEvent::TEventObject(&csid), this)); */
- }
- typedef vector<CConstRef<CSeq_id> > TRSeqIdVector;
- void CAlnMultiView :: OnSelChangedEvent(CViewEvent::TEventObject obj)
- {
- m_bBlockEvents = true;
- CObjectFor<TRSeqIdVector>* p_ids =
- dynamic_cast< CObjectFor<TRSeqIdVector> *>(obj.GetPointer());
- if(p_ids) {
- CScope& scope = m_Document->GetScope();
- /*const vector<CConstRef<CSeq_id> >& ids = p_ids->GetData();
- vector<CAlnVec::TNumrow> sel_rows;
- int n_ids = ids.size();
- for( int i = 0; i < n_ids; i++ ) {
- const CSeq_id& id = *ids[i];
- //find row corresponding to id
- int n_rows = m_DataSource->GetNumRows();
- for( CAlnVec::TNumrow row = 0; row < n_rows; row++ ) {
- const CSeq_id& row_id = m_DataSource->GetSeqId(row);
- if(CSeqUtils::Match(row_id, id, scope)) {
- sel_rows.push_back(row);
- break;
- }
- }
- }
- //select rows
- m_AlnWidget->Select(sel_rows, true); */
- m_AlnWidget->SetSelectedIds(*p_ids, scope);
- }
- m_bBlockEvents = false;
- }
- void CAlnMultiView::OnNotify(IAlnMultiPaneParent::ENotification notification)
- {
- if(! m_bBlockEvents) {
- switch(notification) {
- case IAlnMultiPaneParent::eRowSelChanged: {
- CObjectFor<TRSeqIdVector> vids;
- m_AlnWidget->GetSelectedIds(vids.GetData());
- // fire external event
- FireEvent(CViewEvent::CreateEvent(CViewEvent::eSelectionChanged,
- CViewEvent::eEventViews,
- CViewEvent::TEventObject(&vids), this));
- }; break;
- }
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: view_multialign.cpp,v $
- * Revision 1000.6 2004/06/01 20:59:28 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.51
- *
- * Revision 1.51 2004/05/21 22:27:49 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.50 2004/05/03 17:52:36 dicuccio
- * gui/utils -->gui/objutils where needed
- *
- * Revision 1.49 2004/04/16 14:44:17 dicuccio
- * Pass appropriate ISelection interface to dynamic menus
- *
- * Revision 1.48 2004/04/07 13:05:10 dicuccio
- * Changed view API - require CPluginMessage instead of CPluginArgSet
- *
- * Revision 1.47 2004/04/06 16:27:44 yazhuk
- * Added eCmdMoveSelectedUp command
- *
- * Revision 1.46 2004/04/02 19:44:17 dicuccio
- * CHanged handling of default object if no selections present
- *
- * Revision 1.45 2004/04/02 16:45:21 yazhuk
- * Implemented selection broadcasting
- *
- * Revision 1.44 2004/03/30 17:13:08 tereshko
- * Added support for events broadcasting
- *
- * Revision 1.43 2004/03/25 13:19:30 dicuccio
- * Call CAlnVecWidget::Create() to intialize the widget
- *
- * Revision 1.42 2004/03/09 22:09:23 ucko
- * Add missing inclulde of <align_row.hpp> (once indirectly included?)
- *
- * Revision 1.41 2004/02/11 16:13:24 yazhuk
- * Removed #include "view_multialign_ds.hpp"
- *
- * Revision 1.40 2004/02/11 15:24:03 yazhuk
- * Replaced constructor with arguments with default constructor and Init() call;
- * Replaced CViewMultiAlignDS with CAlnVecMultiDataSource
- *
- * Revision 1.39 2004/01/27 18:45:01 dicuccio
- * Let multiple alignment viewer handle multiple input alignments
- *
- * Revision 1.38 2004/01/09 01:16:34 ucko
- * Remove extra semicolon after END_MENU() [breaks on WorkShop]
- *
- * Revision 1.37 2004/01/08 20:25:13 yazhuk
- * Migrated from FLTK-style menus to CMenuBar and CComandTraget, cleaned-up
- * obsolete code. Fixed bugs in consensus row creation.
- *
- * Revision 1.36 2003/12/22 19:33:16 dicuccio
- * Lots of changes. Changed to match new APIs in IView. Added better handling of messages received from other views
- *
- * Revision 1.35 2003/12/19 20:00:41 yazhuk
- * Added Catalog setup
- *
- * Revision 1.34 2003/11/24 15:45:43 dicuccio
- * Renamed CVersion to CPluginVersion
- *
- * Revision 1.33 2003/11/19 20:45:27 friedman
- * Added handling a visible range change event
- *
- * Revision 1.32 2003/11/04 12:51:27 friedman
- * Added event message pool callbacks for the document all-view message pool.
- *
- * Revision 1.31 2003/10/30 17:08:53 yazhuk
- * In SetDataSource replaced references with pointers
- *
- * Revision 1.30 2003/10/27 20:03:26 dicuccio
- * Rearranged Update() to be consistent
- *
- * Revision 1.29 2003/10/10 19:30:15 yazhuk
- * Added x_OnZoomAll(), x_OnSetConsensusMaster(), x_OnZoomSequnce()
- *
- * Revision 1.28 2003/10/10 17:20:27 dicuccio
- * Implemented OnExit() as callback for all views when closed from system icon
- *
- * Revision 1.27 2003/10/07 13:47:06 dicuccio
- * Renamed CPluginURL* to CPluginValue*
- *
- * Revision 1.26 2003/09/30 20:22:37 dicuccio
- * Exposed marking interface. Implemented consensus creation
- *
- * Revision 1.25 2003/09/24 18:26:47 dicuccio
- * Large clean-ups to alignment viewers. Reimplemented data sources and alignment
- * generation mechanism to be more generic.
- *
- * Revision 1.24 2003/09/12 12:55:41 dicuccio
- * Switched to use Andrey's new viewer.
- *
- * Revision 1.23 2003/09/04 14:54:21 dicuccio
- * Use IDocument instead of CDocument. Changed APIs to match changes in IView
- *
- * 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/06/26 15:33:41 dicuccio
- * Moved GetURLValue() from PluginURL.hpp to plugin_utils.hpp. Fixed compilation
- * errors relating to missing #includes
- *
- * Revision 1.20 2003/06/25 17:03:00 dicuccio
- * Split CPluginHandle into a handle (pointer-to-implementation) and
- * implementation file. Lots of #include file clean-ups.
- *
- * Revision 1.19 2003/06/23 13:23:13 dicuccio
- * Deprecated seq_utils.[h,c]pp - moved functions into gui.utils/utils.hpp
- *
- * Revision 1.18 2003/06/20 14:53:52 dicuccio
- * Revised plugin registration - moved GetInfo() into the plugin handler
- *
- * Revision 1.17 2003/06/02 16:06:22 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.16 2003/05/22 18:50:04 dicuccio
- * Standardized construction, argument specification for all alignment views
- *
- * Revision 1.15 2003/05/19 13:43:32 dicuccio
- * Moved gui/core/plugin --> gui/plugin/. Merged core libraries into libgui_core
- *
- * Revision 1.14 2003/04/24 16:40:38 dicuccio
- * Updated to reflect changes in plugin API. Added new common alignment view base
- * class - handles notions of creating alignment manager in a standard way
- *
- * Revision 1.13 2003/03/17 14:54:14 dicuccio
- * Changed base class CView - added member variable for FLTK gui component for
- * child windows, which is now maintained via an auto_ptr<>. Eliminated
- * Show()/Hide() as a pure virtual requirement.
- *
- * Revision 1.12 2003/03/03 14:54:05 dicuccio
- * Fixed initialization of CAlnMix to avoid creation of alternale object manager
- *
- * Revision 1.11 2003/02/20 19:49:58 dicuccio
- * Created new plugin architecture, based on ASN.1 spec. Moved GBENCH frameowrk
- * over to use new plugin architecture.
- *
- * Revision 1.10 2003/01/13 13:10:08 dicuccio
- * Namespace clean-up. Retired namespace gui -> converted all to namespace ncbi.
- * Moved all FLUID-generated code into namespace ncbi.
- *
- * Revision 1.9 2003/01/10 17:37:48 dicuccio
- * Regenerated code with fluid-1.1.2
- *
- * Revision 1.8 2003/01/09 14:50:41 dicuccio
- * Use 'const CBioseq_Handle&' instead of 'CBioseq_Handle&'
- *
- * Revision 1.7 2002/12/20 19:52:21 dicuccio
- * Cnaged TRange::SetFrom()/TRange::SetTo() --> TRange::Set()
- *
- * Revision 1.6 2002/12/20 19:22:51 dicuccio
- * Lots of changes to the menus. Standardized the menu syntax across all views.
- * Changed to use new dynamic menu managers.
- *
- * Revision 1.5 2002/12/13 13:18:52 dicuccio
- * Added work-around for inlining problems in some versions of gcc: directly
- * include a FLUID-generated '*_.cpp' file in the corresponding '*.cpp' and
- * remove this file from the build. Thanks Aaron!
- *
- * Revision 1.4 2002/12/09 20:37:14 dicuccio
- * Switch to using CSeq_id::GetStringDescr()
- *
- * Revision 1.3 2002/11/29 16:08:34 dicuccio
- * Removed BEGIN/END_SCOPE - use USING_SCOPE instead. FIxed some function
- * overload resolution issues for Windows.
- *
- * Revision 1.2 2002/11/22 18:05:07 dicuccio
- * Fixed memory leak - must remember to delete main window.
- *
- * Revision 1.1 2002/11/19 17:04:36 dicuccio
- * Initial revision.
- *
- * ===========================================================================
- */