📄 sequence_display.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: sequence_display.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 18:29:04 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.73 * PRODUCTION * =========================================================================== *//* $Id: sequence_display.cpp,v 1000.3 2004/06/01 18:29:04 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:* Classes to hold rows in a sequence/alignment display** ===========================================================================*/#ifdef _MSC_VER#pragma warning(disable:4018) // disable signed/unsigned mismatch warning in MSVC#endif#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <corelib/ncbistl.hpp>#include <corelib/ncbistre.hpp>#include <corelib/ncbi_limits.h>#include <algorithm>#include "sequence_display.hpp"#include "viewer_window_base.hpp"#include "viewer_base.hpp"#include "molecule.hpp"#include "messenger.hpp"#include "structure_set.hpp"#include "style_manager.hpp"#include "sequence_viewer_window.hpp"#include "sequence_viewer.hpp"#include "alignment_manager.hpp"#include "cn3d_colors.hpp"#include "update_viewer.hpp"#include "update_viewer_window.hpp"#include "cn3d_tools.hpp"#include "cn3d_threader.hpp"#include "conservation_colorer.hpp"#include "molecule_identifier.hpp"#include "cn3d_blast.hpp"USING_NCBI_SCOPE;BEGIN_SCOPE(Cn3D)// block marker string stuffstatic const char blockLeftEdgeChar = '<', blockRightEdgeChar = '>', blockOneColumnChar = '^', blockInsideChar = '-';static const string blockBoundaryStringTitle("(blocks)");// color converterstatic inline void Vector2wxColor(const Vector& colorVec, wxColor *colorWX){ colorWX->Set( static_cast<unsigned char>((colorVec[0] + 0.000001) * 255), static_cast<unsigned char>((colorVec[1] + 0.000001) * 255), static_cast<unsigned char>((colorVec[2] + 0.000001) * 255) );}////////////////////////////////////////////////////////////////////////////////// The sequence view is composed of rows which can be from sequence, alignment,// or any string - anything derived from DisplayRow, implemented below.////////////////////////////////////////////////////////////////////////////////bool DisplayRowFromAlignment::GetCharacterTraitsAt( int column, BlockMultipleAlignment::eUnalignedJustification justification, char *character, Vector *color, bool *drawBackground, Vector *cellBackgroundColor) const{ bool isHighlighted, result = alignment->GetCharacterTraitsAt( column, row, justification, character, color, &isHighlighted, drawBackground, cellBackgroundColor); // always apply highlight color, even if alignment has set its own background color if (isHighlighted) { *drawBackground = true; *cellBackgroundColor = GlobalColors()->Get(Colors::eHighlight); } return result;}DisplayRowFromSequence::DisplayRowFromSequence(const Sequence *s, int from, int to) : sequence(s), fromIndex(from), toIndex(to){ if (from < 0 || from >= sequence->Length() || from > to || to < 0 || to >= sequence->Length()) ERRORMSG("DisplayRowFromSequence::DisplayRowFromSequence() - from/to indexes out of range");}bool DisplayRowFromSequence::GetCharacterTraitsAt( int column, BlockMultipleAlignment::eUnalignedJustification justification, char *character, Vector *color, bool *drawBackground, Vector *cellBackgroundColor) const{ int index = column + fromIndex; if (index > toIndex) return false; *character = tolower(sequence->sequenceString[index]); if (sequence->molecule) *color = sequence->molecule->GetResidueColor(index); else color->Set(0,0,0); if (GlobalMessenger()->IsHighlighted(sequence, index)) { *drawBackground = true; *cellBackgroundColor = GlobalColors()->Get(Colors::eHighlight); } else { *drawBackground = false; } return true;}bool DisplayRowFromSequence::GetSequenceAndIndexAt( int column, BlockMultipleAlignment::eUnalignedJustification justification, const Sequence **sequenceHandle, int *seqIndex) const{ int index = column + fromIndex; if (index > toIndex) return false; *sequenceHandle = sequence; *seqIndex = index; return true;}void DisplayRowFromSequence::SelectedRange(int from, int to, BlockMultipleAlignment::eUnalignedJustification justification, bool toggle) const{ from += fromIndex; to += fromIndex; // skip if selected outside range if (from < fromIndex && to < fromIndex) return; if (from > toIndex && to > toIndex) return; // trim to within range if (from < fromIndex) from = fromIndex; else if (from > toIndex) from = toIndex; if (to < fromIndex) to = fromIndex; else if (to > toIndex) to = toIndex; if (toggle) GlobalMessenger()->ToggleHighlights(sequence, from, to); else GlobalMessenger()->AddHighlights(sequence, from, to);}bool DisplayRowFromString::GetCharacterTraitsAt(int column, BlockMultipleAlignment::eUnalignedJustification justification, char *character, Vector *color, bool *drawBackground, Vector *cellBackgroundColor) const{ if (column >= theString.size()) return false; *character = theString[column]; *color = stringColor; if (hasBackgroundColor) { *drawBackground = true; *cellBackgroundColor = backgroundColor; } else { *drawBackground = false; } return true;}////////////////////////////////////////////////////////////////////////////////// The SequenceDisplay is the structure that holds the DisplayRows of the view.// It's also derived from ViewableAlignment, in order to be plugged into a// SequenceDisplayWidget.////////////////////////////////////////////////////////////////////////////////SequenceDisplay::SequenceDisplay(bool editable, ViewerWindowBase* const *parentViewerWindow) : isEditable(editable), maxRowWidth(0), viewerWindow(parentViewerWindow), startingColumn(0){}SequenceDisplay::~SequenceDisplay(void){ for (int i=0; i<rows.size(); ++i) delete rows[i];}void SequenceDisplay::Empty(void){ for (int i=0; i<rows.size(); ++i) delete rows[i]; rows.clear(); startingColumn = maxRowWidth = 0;}SequenceDisplay * SequenceDisplay::Clone(const Old2NewAlignmentMap& newAlignments) const{ SequenceDisplay *copy = new SequenceDisplay(isEditable, viewerWindow); for (int row=0; row<rows.size(); ++row) copy->rows.push_back(rows[row]->Clone(newAlignments)); copy->startingColumn = startingColumn; copy->maxRowWidth = maxRowWidth; return copy;}void SequenceDisplay::AddRow(DisplayRow *row){ rows.push_back(row); if (row->Width() > maxRowWidth) maxRowWidth = row->Width();}BlockMultipleAlignment * SequenceDisplay::GetAlignmentForRow(int row) const{ if (row < 0 || row >= rows.size()) return NULL; const DisplayRowFromAlignment *displayRow = dynamic_cast<const DisplayRowFromAlignment*>(rows[row]); if (displayRow) return displayRow->alignment; const DisplayRowFromString *stringRow = dynamic_cast<const DisplayRowFromString*>(rows[row]); if (stringRow) return stringRow->alignment; return NULL;}void SequenceDisplay::UpdateMaxRowWidth(void){ RowVector::iterator r, re = rows.end(); maxRowWidth = 0; for (r=rows.begin(); r!=re; ++r) if ((*r)->Width() > maxRowWidth) maxRowWidth = (*r)->Width();}void SequenceDisplay::AddRowFromAlignment(int row, BlockMultipleAlignment *fromAlignment){ if (!fromAlignment || row < 0 || row >= fromAlignment->NRows()) { ERRORMSG("SequenceDisplay::AddRowFromAlignment() failed"); return; } AddRow(new DisplayRowFromAlignment(row, fromAlignment));}void SequenceDisplay::AddRowFromSequence(const Sequence *sequence, int from, int to){ if (!sequence) { ERRORMSG("SequenceDisplay::AddRowFromSequence() failed"); return; } AddRow(new DisplayRowFromSequence(sequence, from, to));}void SequenceDisplay::AddRowFromString(const string& anyString){ AddRow(new DisplayRowFromString(anyString));}bool SequenceDisplay::GetRowTitle(int row, wxString *title, wxColour *color) const{ const DisplayRow *displayRow = rows[row]; const DisplayRowFromString *strRow = dynamic_cast<const DisplayRowFromString*>(displayRow); if (strRow && !strRow->title.empty()) { *title = strRow->title.c_str(); color->Set(0,0,0); // black return true; } const Sequence *sequence = displayRow->GetSequence(); if (!sequence) return false; // set title *title = sequence->identifier->ToString().c_str(); // set color - by object if there's an associated molecule const DisplayRowFromAlignment *alnRow = dynamic_cast<const DisplayRowFromAlignment*>(displayRow); const Molecule *molecule; if (alnRow && (molecule=alnRow->alignment->GetSequenceOfRow(alnRow->row)->molecule) != NULL) Vector2wxColor(molecule->parentSet->styleManager->GetObjectColor(molecule), color); else color->Set(0,0,0); // ... black otherwise return true;}bool SequenceDisplay::GetCharacterTraitsAt(int column, int row, char *character, wxColour *color, bool *drawBackground, wxColour *cellBackgroundColor) const{ if (row < 0 || row > rows.size()) { WARNINGMSG("SequenceDisplay::GetCharacterTraitsAt() - row out of range"); return false; } const DisplayRow *displayRow = rows[row]; if (column >= displayRow->Width()) return false; Vector colorVec, bgColorVec; if (!displayRow->GetCharacterTraitsAt(column, (*viewerWindow) ? (*viewerWindow)->GetCurrentJustification() : BlockMultipleAlignment::eLeft, character, &colorVec, drawBackground, &bgColorVec)) return false; Vector2wxColor(colorVec, color); if (*drawBackground) Vector2wxColor(bgColorVec, cellBackgroundColor); return true;}void SequenceDisplay::MouseOver(int column, int row) const{ if (*viewerWindow) { wxString idLoc, status; if (row >= 0 && row < rows.size()) { const DisplayRow *displayRow = rows[row]; const Sequence *sequence = NULL; // show id if we're in sequence area if (column >= 0 && column < displayRow->Width()) { // show title and seqloc int index = -1; if (displayRow->GetSequenceAndIndexAt(column, (*viewerWindow)->GetCurrentJustification(), &sequence, &index)) { if (index >= 0) { wxString title; wxColour color; if (GetRowTitle(row, &title, &color)) idLoc.Printf("%s, loc %i", title.c_str(), index + 1); // show one-based numbering } } // show PDB residue number if available (assume resID = index+1) if (sequence && index >= 0 && sequence->molecule) { const Residue *residue = sequence->molecule->residues.find(index + 1)->second; if (residue && residue->namePDB.size() > 0) { wxString n = residue->namePDB.c_str(); n = n.Strip(wxString::both); if (n.size() > 0) idLoc = idLoc + " (PDB " + n + ")"; } } // show alignment block number and row-wise string const DisplayRowFromAlignment *alnRow =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -