📄 sequence_viewer_window.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: sequence_viewer_window.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 18:29:17 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.54 * PRODUCTION * =========================================================================== *//* $Id: sequence_viewer_window.cpp,v 1000.2 2004/06/01 18:29:17 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: Paul Thiessen** File Description:* implementation of GUI part of main sequence/alignment viewer** ===========================================================================*/#ifdef _MSC_VER#pragma warning(disable:4018) // disable signed/unsigned mismatch warning in MSVC#endif#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#ifdef __WXMSW__#include <windows.h>#include <wx/msw/winundef.h>#endif#include <wx/wx.h>#include "taxonomy_tree.hpp"#include "sequence_viewer_window.hpp"#include "sequence_viewer.hpp"#include "alignment_manager.hpp"#include "sequence_set.hpp"#include "show_hide_dialog.hpp"#include "sequence_display.hpp"#include "messenger.hpp"#include "wx_tools.hpp"#include "molecule_identifier.hpp"#include "cn3d_tools.hpp"#include "cn3d_blast.hpp"USING_NCBI_SCOPE;BEGIN_SCOPE(Cn3D)static double prevPSSMWeight = -1.0; // so scoring dialog remembers prev valueBEGIN_EVENT_TABLE(SequenceViewerWindow, wxFrame) INCLUDE_VIEWER_WINDOW_BASE_EVENTS EVT_CLOSE ( SequenceViewerWindow::OnCloseWindow) EVT_MENU (MID_SHOW_HIDE_ROWS, SequenceViewerWindow::OnShowHideRows) EVT_MENU (MID_DELETE_ROW, SequenceViewerWindow::OnDeleteRow) EVT_MENU (MID_MOVE_ROW, SequenceViewerWindow::OnMoveRow) EVT_MENU (MID_SHOW_UPDATES, SequenceViewerWindow::OnShowUpdates) EVT_MENU_RANGE(MID_REALIGN_ROW, MID_REALIGN_ROWS, SequenceViewerWindow::OnRealign) EVT_MENU_RANGE(MID_SORT_IDENT, MID_PROXIMITY_SORT, SequenceViewerWindow::OnSort) EVT_MENU (MID_SCORE_THREADER, SequenceViewerWindow::OnScoreThreader) EVT_MENU_RANGE(MID_MARK_BLOCK, MID_CLEAR_MARKS, SequenceViewerWindow::OnMarkBlock) EVT_MENU_RANGE(MID_EXPORT_FASTA, MID_EXPORT_HTML, SequenceViewerWindow::OnExport) EVT_MENU (MID_SELF_HIT, SequenceViewerWindow::OnSelfHit) EVT_MENU_RANGE(MID_TAXONOMY_FULL, MID_TAXONOMY_ABBR, SequenceViewerWindow::OnTaxonomy) EVT_MENU (MID_HIGHLIGHT_BLOCKS, SequenceViewerWindow::OnHighlightBlocks)END_EVENT_TABLE()SequenceViewerWindow::SequenceViewerWindow(SequenceViewer *parentSequenceViewer) : ViewerWindowBase(parentSequenceViewer, wxPoint(0,500), wxSize(1000,200)), sequenceViewer(parentSequenceViewer), taxonomyTree(NULL){ SetWindowTitle(); viewMenu->Append(MID_SHOW_HIDE_ROWS, "Show/Hide &Rows"); viewMenu->Append(MID_SCORE_THREADER, "Show PSSM+Contact &Scores"); viewMenu->Append(MID_SELF_HIT, "Show Se&lf-Hits"); wxMenu *subMenu = new wxMenu; subMenu->Append(MID_EXPORT_FASTA, "&FASTA"); subMenu->Append(MID_EXPORT_A2M, "&A2M FASTA"); subMenu->Append(MID_EXPORT_TEXT, "&Text"); subMenu->Append(MID_EXPORT_HTML, "&HTML"); viewMenu->Append(MID_EXPORT, "&Export...", subMenu); subMenu = new wxMenu; subMenu->Append(MID_TAXONOMY_FULL, "&Full"); subMenu->Append(MID_TAXONOMY_ABBR, "&Abbreviated"); viewMenu->Append(MID_TAXONOMY, "Show Ta&xonomy...", subMenu); viewMenu->Append(MID_HIGHLIGHT_BLOCKS, "&Highlight blocks"); editMenu->AppendSeparator(); subMenu = new wxMenu; subMenu->Append(MID_SORT_IDENT, "By &Identifier"); subMenu->Append(MID_SORT_THREADER, "By &Score"); subMenu->Append(MID_FLOAT_PDBS, "Float &PDBs"); subMenu->Append(MID_FLOAT_HIGHLIGHTS, "Float Hi&ghlights"); subMenu->Append(MID_FLOAT_G_V, "Float &Geometry Violations"); subMenu->Append(MID_SORT_SELF_HIT, "By Self-&Hit"); subMenu->Append(MID_PROXIMITY_SORT, "&Proximity Sort", "", true); editMenu->Append(MID_SORT_ROWS, "Sort &Rows...", subMenu); editMenu->Append(MID_DELETE_ROW, "De&lete Row", "", true); mouseModeMenu->Append(MID_MOVE_ROW, "&Move Row", "", true); updateMenu = new wxMenu; updateMenu->Append(MID_SHOW_UPDATES, "&Show Imports"); updateMenu->AppendSeparator(); updateMenu->Append(MID_REALIGN_ROW, "Realign &Individual Rows", "", true); updateMenu->Append(MID_REALIGN_ROWS, "Realign Rows from &List"); updateMenu->AppendSeparator(); updateMenu->Append(MID_MARK_BLOCK, "Mark &Block", "", true); updateMenu->Append(MID_CLEAR_MARKS, "&Clear Marks"); menuBar->Append(updateMenu, "&Imports"); EnableDerivedEditorMenuItems(false); SetMenuBar(menuBar);}SequenceViewerWindow::~SequenceViewerWindow(void){ if (taxonomyTree) delete taxonomyTree;}void SequenceViewerWindow::OnCloseWindow(wxCloseEvent& event){ if (viewer) { if (event.CanVeto()) { Show(false); // just hide the window if we can event.Veto(); return; } SaveDialog(true, false); viewer->RemoveBlockBoundaryRows(); viewer->GUIDestroyed(); // make sure SequenceViewer knows the GUI is gone GlobalMessenger()->UnPostRedrawSequenceViewer(viewer); // don't try to redraw after destroyed! } Destroy();}void SequenceViewerWindow::SetWindowTitle(void){ SetTitle(wxString(GetWorkingTitle().c_str()) + " - Sequence/Alignment Viewer");}void SequenceViewerWindow::EnableDerivedEditorMenuItems(bool enabled){ if (menuBar->FindItem(MID_SHOW_HIDE_ROWS)) { bool editable = (sequenceViewer->GetCurrentDisplay() && sequenceViewer->GetCurrentDisplay()->IsEditable()); if (editable) menuBar->Enable(MID_SHOW_HIDE_ROWS, !enabled); // can't show/hide when editor is on else menuBar->Enable(MID_SHOW_HIDE_ROWS, false); // can't show/hide in non-alignment display menuBar->Enable(MID_DELETE_ROW, enabled); // can only delete row when editor is on menuBar->Enable(MID_SORT_ROWS, enabled); menuBar->Enable(MID_MOVE_ROW, enabled); // can only move row when editor is on menuBar->Enable(MID_REALIGN_ROW, enabled); // can only realign rows when editor is on menuBar->Enable(MID_REALIGN_ROWS, enabled); // can only realign rows when editor is on menuBar->Enable(MID_MARK_BLOCK, enabled); menuBar->Enable(MID_CLEAR_MARKS, enabled); menuBar->Enable(MID_SELF_HIT, editable); menuBar->Enable(MID_TAXONOMY, editable); menuBar->Enable(MID_SCORE_THREADER, editable); menuBar->Enable(MID_HIGHLIGHT_BLOCKS, editable); if (!enabled) CancelDerivedSpecialModesExcept(-1); }}void SequenceViewerWindow::OnDeleteRow(wxCommandEvent& event){ if (event.GetId() == MID_DELETE_ROW) { CancelAllSpecialModesExcept(MID_DELETE_ROW); if (DoDeleteRow()) SetCursor(*wxCROSS_CURSOR); else DeleteRowOff(); }}void SequenceViewerWindow::OnMoveRow(wxCommandEvent& event){ OnMouseMode(event); // set checks via base class viewerWidget->SetMouseMode(SequenceViewerWidget::eDragVertical);}bool SequenceViewerWindow::RequestEditorEnable(bool enable){ // turn on editor if (enable) { return QueryShowAllRows(); } // turn off editor else { return SaveDialog(true, true); }}bool SequenceViewerWindow::SaveDialog(bool prompt, bool canCancel){ static bool overrideCanCancel = false, prevPrompt, prevCanCancel; if (overrideCanCancel) { prompt = prevPrompt; canCancel = prevCanCancel; overrideCanCancel = false; } // if editor is checked on, then this save command was initiated outside the menu; // if so, then need to turn off editor pretending it was done from 'enable editor' menu item if (menuBar->IsChecked(MID_ENABLE_EDIT)) { overrideCanCancel = true; prevPrompt = prompt; prevCanCancel = canCancel; Command(MID_ENABLE_EDIT); return true; } // quick & dirty check for whether save is necessary, by whether Undo is enabled if (!menuBar->IsEnabled(MID_UNDO)) { viewer->KeepCurrent(); // remove any unnecessary copy from stack return true; } int option = wxID_YES; if (prompt) { option = wxYES_NO | wxYES_DEFAULT | wxICON_EXCLAMATION | wxCENTRE; if (canCancel) option |= wxCANCEL; wxMessageDialog dialog(NULL, "Do you want to keep the changes to this alignment?", "", option); option = dialog.ShowModal(); if (option == wxID_CANCEL) return false; // user cancelled this operation } if (option == wxID_YES) { sequenceViewer->SaveAlignment(); // save data } else { sequenceViewer->Revert(); // revert to original UpdateDisplay(sequenceViewer->GetCurrentDisplay()); } return true;}void SequenceViewerWindow::OnShowHideRows(wxCommandEvent& event){ vector < const Sequence * > slaveSequences; sequenceViewer->alignmentManager->GetAlignmentSetSlaveSequences(&slaveSequences); wxString *titleStrs = new wxString[slaveSequences.size()]; for (int i=0; i<slaveSequences.size(); ++i) titleStrs[i] = slaveSequences[i]->identifier->ToString().c_str(); vector < bool > visibilities; sequenceViewer->alignmentManager->GetAlignmentSetSlaveVisibilities(&visibilities); wxString title = "Show/Hide Slaves of "; title.Append(sequenceViewer->alignmentManager->GetCurrentMultipleAlignment()->GetMaster()->identifier->ToString().c_str()); ShowHideDialog dialog( titleStrs, &visibilities, sequenceViewer->alignmentManager, true, this, -1, title, wxPoint(250, 50)); dialog.ShowModal(); //delete titleStrs; // apparently deleted by wxWindows}bool SequenceViewerWindow::QueryShowAllRows(void){ vector < bool > visibilities; sequenceViewer->alignmentManager->GetAlignmentSetSlaveVisibilities(&visibilities); int i; for (i=0; i<visibilities.size(); ++i) if (!visibilities[i]) break; if (i == visibilities.size()) return true; // we're okay if all rows already visible // if some rows hidden, ask user whether to show all rows, or cancel wxMessageDialog query(NULL, "This operation requires all alignment rows to be visible. Do you wish to show all rows now?", "Query", wxOK | wxCANCEL | wxCENTRE | wxICON_QUESTION); if (query.ShowModal() == wxID_CANCEL) return false; // user cancelled // show all rows for (i=0; i<visibilities.size(); ++i) visibilities[i] = true; sequenceViewer->alignmentManager->ShowHideCallbackFunction(visibilities); return true;}// process events from the realign menuvoid SequenceViewerWindow::OnShowUpdates(wxCommandEvent& event){ sequenceViewer->alignmentManager->ShowUpdateWindow();}void SequenceViewerWindow::OnRealign(wxCommandEvent& event){ // setup one-at-a-time row realignment if (event.GetId() == MID_REALIGN_ROW) { CancelAllSpecialModesExcept(MID_REALIGN_ROW); if (DoRealignRow()) SetCursor(*wxCROSS_CURSOR); else RealignRowOff(); return; } // bring up selection dialog for realigning multiple rows if (sequenceViewer->GetCurrentAlignments().size() == 0) { ERRORMSG("SequenceViewerWindow::OnRealign() - no alignment!"); return; } BlockMultipleAlignment *alignment = sequenceViewer->GetCurrentAlignments().front(); // get titles of current slave display rows (*not* rows from the AlignmentSet!) SequenceDisplay::SequenceList sequences; sequenceViewer->GetCurrentDisplay()->GetSequences(alignment, &sequences); wxString *titleStrs = new wxString[sequences.size() - 1];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -