NCBI C++ ToolKit
sequence_display.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: sequence_display.hpp 33815 2007-05-04 17:18:18Z kazimird $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Authors: Paul Thiessen
27 *
28 * File Description:
29 * Classes to hold rows in a sequence/alignment display
30 *
31 * ===========================================================================
32 */
33 
34 #ifndef CN3D_SEQUENCE_DISPLAY__HPP
35 #define CN3D_SEQUENCE_DISPLAY__HPP
36 
37 #include <corelib/ncbistd.hpp>
38 #include <corelib/ncbistl.hpp>
39 
40 #include <map>
41 
42 #include "viewable_alignment.hpp"
44 #include "sequence_set.hpp"
45 
46 
47 BEGIN_SCOPE(Cn3D)
48 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 // The sequence view is composed of rows which can be from sequence, alignment,
53 // or any string - anything derived from DisplayRow.
54 ////////////////////////////////////////////////////////////////////////////////
55 
57 {
58 public:
59  virtual ~DisplayRow(void) { }
60 
61  virtual unsigned int Width(void) const = 0;
63  char *character, Vector *color, bool *drawBackground, Vector *cellBackgroundColor) const = 0;
65  const Sequence **sequence, int *index) const = 0;
66  virtual const Sequence * GetSequence(void) const = 0;
67  virtual void SelectedRange(unsigned int from, unsigned int to,
68  BlockMultipleAlignment::eUnalignedJustification justification, bool toggle) const = 0;
69 
70  virtual DisplayRow * Clone(const Old2NewAlignmentMap& newAlignments) const = 0;
71 };
72 
74 {
75 public:
76  unsigned int row;
78 
80  row(r), alignment(a) { }
81  virtual ~DisplayRowFromAlignment(void) { }
82 
83  unsigned int Width(void) const { return alignment->AlignmentWidth(); }
84 
85  DisplayRow * Clone(const Old2NewAlignmentMap& newAlignments) const
86  { return new DisplayRowFromAlignment(row, newAlignments.find(alignment)->second); }
87 
89  char *character, Vector *color, bool *drawBackground, Vector *cellBackgroundColor) const;
90 
92  const Sequence **sequence, int *index) const
93  {
94  bool ignore;
95  return alignment->GetSequenceAndIndexAt(column, row, justification, sequence, index, &ignore);
96  }
97 
98  const Sequence * GetSequence(void) const
99  {
100  return alignment->GetSequenceOfRow(row);
101  }
102 
103  void SelectedRange(unsigned int from, unsigned int to,
104  BlockMultipleAlignment::eUnalignedJustification justification, bool toggle) const
105  {
106  alignment->SelectedRange(row, from, to, justification, toggle);
107  }
108 };
109 
111 {
112 public:
113  const Sequence * const sequence;
114  const unsigned int fromIndex, toIndex;
115 
116  DisplayRowFromSequence(const Sequence *s, unsigned int from, unsigned int to);
117  virtual ~DisplayRowFromSequence(void) { }
118 
119  unsigned int Width(void) const { return toIndex - fromIndex + 1; }
120 
121  DisplayRow * Clone(const Old2NewAlignmentMap& newAlignments) const
123 
125  char *character, Vector *color, bool *drawBackground, Vector *cellBackgroundColor) const;
126 
128  const Sequence **sequenceHandle, int *index) const;
129 
130  const Sequence * GetSequence(void) const
131  { return sequence; }
132 
133  void SelectedRange(unsigned int from, unsigned int to,
134  BlockMultipleAlignment::eUnalignedJustification justification, bool toggle) const;
135 };
136 
138 {
139 public:
143  const bool hasBackgroundColor;
145 
146  DisplayRowFromString(const std::string& s, const Vector color = Vector(0,0,0.5),
147  const std::string& t = "", bool hasBG = false, Vector bgColor = Vector(1,1,1),
151  virtual ~DisplayRowFromString(void) { }
152 
153  unsigned int Width(void) const { return theString.size(); }
154 
155  DisplayRow * Clone(const Old2NewAlignmentMap& newAlignments) const
156  { return new DisplayRowFromString(
158  alignment ? newAlignments.find(alignment)->second : NULL); }
159 
161  char *character, Vector *color, bool *drawBackground, Vector *cellBackgroundColor) const;
162 
164  const Sequence **sequenceHandle, int *index) const { return false; }
165 
166  const Sequence * GetSequence(void) const { return NULL; }
167 
168  void SelectedRange(unsigned int from, unsigned int to,
169  BlockMultipleAlignment::eUnalignedJustification justification, bool toggle) const
170  { } // do nothing
171 };
172 
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 // The SequenceDisplay is the structure that holds the DisplayRows of the view.
176 // It's also derived from ViewableAlignment, in order to be plugged into a
177 // SequenceViewerWidget.
178 ////////////////////////////////////////////////////////////////////////////////
179 
180 class SequenceViewer;
181 class UpdateViewer;
182 class ViewerWindowBase;
183 class Molecule;
184 
186 {
187  friend class SequenceViewer;
188  friend class UpdateViewer;
189 
190 public:
191  SequenceDisplay(bool editable, ViewerWindowBase* const *parentViewerWindow);
192  virtual ~SequenceDisplay(void);
193 
194  // these functions add a row to the end of the display, from various sources
195  void AddRowFromAlignment(unsigned int row, BlockMultipleAlignment *fromAlignment);
196  void AddRowFromSequence(const Sequence *sequence, unsigned int from, unsigned int to);
197  void AddRowFromString(const std::string& anyString);
198 
199  // adds a string row to the alignment, that contains block boundary indicators
201  void UpdateBlockBoundaryRow(const BlockMultipleAlignment *forAlignment) const;
202  void AddBlockBoundaryRow(BlockMultipleAlignment *forAlignment); // adds to end of display!
203  void AddBlockBoundaryRows(void);
204  void RemoveBlockBoundaryRows(void);
205 
206  // returns a list of all sequences in the display (in order) for the given alignment
207  typedef std::vector < const Sequence * > SequenceList;
208  void GetSequences(const BlockMultipleAlignment *forAlignment, SequenceList *seqs) const;
209 
210  // returns a list of all protein sequences in the display (in order)
211  void GetProteinSequences(SequenceList *seqs) const;
212 
213  // fills the vector with the current row ordering for the given alignment
214  void GetRowOrder(const BlockMultipleAlignment *forAlignment, std::vector < unsigned int > *dependentRowOrder) const;
215 
216  // to inform the display that new rows have been added to or removed from the multiple
217  void RowsAdded(unsigned int nRowsAddedToMultiple, BlockMultipleAlignment *multiple, int where = -1);
218  void RowsRemoved(const std::vector < unsigned int >& rowsRemoved, const BlockMultipleAlignment *multiple);
219 
220  // row scoring and sorting functions - only for single-alignment displays!
221  // sorting necessarily always leaves master at the top
222  bool CalculateRowScoresWithThreader(double weightPSSM);
223  void SortRowsByIdentifier(void);
224  void SortRowsByThreadingScore(double weightPSSM);
225  void SortRowsBySelfHit(void);
226  void FloatPDBRowsToTop(void);
227  void FloatHighlightsToTop(void);
228  void FloatGVToTop(void);
229  bool SortRowsByLoopLength(unsigned int row, unsigned int alnIndex);
230 
231  // a sort of clustering of similar sequences around a particular row
232  bool ProximitySort(unsigned int displayRow);
233 
234  // create a new copy of this object
235  SequenceDisplay * Clone(const Old2NewAlignmentMap& newAlignments) const;
236 
237  // clear out all rows from this display
238  void Empty(void);
239 
240 private:
241  const bool isEditable;
242 
243  // generic row manipulation functions
244  void AddRow(DisplayRow *row);
245  BlockMultipleAlignment * GetAlignmentForRow(unsigned int row) const;
246  void UpdateBlockBoundaryRow(DisplayRowFromString *blockBoundaryRow) const;
247 
249 
250  unsigned int startingColumn;
251  typedef std::vector < DisplayRow * > RowVector;
253 
254  unsigned int maxRowWidth;
255  void UpdateMaxRowWidth(void);
256  void UpdateAfterEdit(const BlockMultipleAlignment *forAlignment);
257 
259 
260  void SortRows(void);
261 
262 public:
263 
264  unsigned int NRows(void) const { return rows.size(); }
265  bool IsEditable(void) const { return isEditable; }
266  const Sequence * GetSequenceForRow(unsigned int row) const
267  {
268  if (row < NRows())
269  return rows[row]->GetSequence();
270  else
271  return NULL;
272  }
273 
274  // redraw all molecules associated with the SequenceDisplay
275  void RedrawAlignedMolecules(void) const;
276 
277  // find coordinates of this residue in the display; returns false if not found
278  bool GetDisplayCoordinates(const Molecule *molecule, unsigned int seqIndex,
279  BlockMultipleAlignment::eUnalignedJustification justification, unsigned int *column, unsigned int *row);
280 
281  // column to scroll to when this display is first shown
282  void SetStartingColumn(unsigned int column) { startingColumn = column; }
283  unsigned int GetStartingColumn(void) const { return startingColumn; }
284 
285  // methods required by ViewableAlignment base class
286  void GetSize(unsigned int *setColumns, unsigned int *setRows) const
287  { *setColumns = maxRowWidth; *setRows = rows.size(); }
288  bool GetRowTitle(unsigned int row, wxString *title, wxColour *color) const;
289  bool GetCharacterTraitsAt(unsigned int column, unsigned int row, // location
290  char *character, // character to draw
291  wxColour *color, // color of this character
292  bool *drawBackground, // special background color?
293  wxColour *cellBackgroundColor
294  ) const;
295 
296  // callbacks for ViewableAlignment
297  void MouseOver(int column, int row) const;
298  bool MouseDown(int column, int row, unsigned int controls);
299  void SelectedRectangle(int columnLeft, int rowTop, int columnRight, int rowBottom);
300  void DraggedCell(int columnFrom, int rowFrom, int columnTo, int rowTo);
301 };
302 
303 END_SCOPE(Cn3D)
304 
305 #endif // CN3D_SEQUENCE_DISPLAY__HPP
static const char * bgColor
unsigned int AlignmentWidth(void) const
const Sequence * GetSequenceOfRow(unsigned int row) const
bool GetSequenceAndIndexAt(unsigned int alignmentColumn, unsigned int row, eUnalignedJustification justification, const Sequence **sequence, unsigned int *index, bool *isAligned) const
void SelectedRange(unsigned int row, unsigned int alnIndexFrom, unsigned int alnIndexTo, eUnalignedJustification justification, bool toggle) const
virtual ~DisplayRowFromAlignment(void)
const Sequence * GetSequence(void) const
DisplayRowFromAlignment(unsigned int r, BlockMultipleAlignment *a)
DisplayRow * Clone(const Old2NewAlignmentMap &newAlignments) const
bool GetSequenceAndIndexAt(unsigned int column, BlockMultipleAlignment::eUnalignedJustification justification, const Sequence **sequence, int *index) const
unsigned int Width(void) const
bool GetCharacterTraitsAt(unsigned int column, BlockMultipleAlignment::eUnalignedJustification justification, char *character, Vector *color, bool *drawBackground, Vector *cellBackgroundColor) const
void SelectedRange(unsigned int from, unsigned int to, BlockMultipleAlignment::eUnalignedJustification justification, bool toggle) const
BlockMultipleAlignment *const alignment
const Sequence * GetSequence(void) const
const Sequence *const sequence
virtual ~DisplayRowFromSequence(void)
DisplayRowFromSequence(const Sequence *s, unsigned int from, unsigned int to)
DisplayRow * Clone(const Old2NewAlignmentMap &newAlignments) const
bool GetCharacterTraitsAt(unsigned int column, BlockMultipleAlignment::eUnalignedJustification justification, char *character, Vector *color, bool *drawBackground, Vector *cellBackgroundColor) const
const unsigned int toIndex
bool GetSequenceAndIndexAt(unsigned int column, BlockMultipleAlignment::eUnalignedJustification justification, const Sequence **sequenceHandle, int *index) const
void SelectedRange(unsigned int from, unsigned int to, BlockMultipleAlignment::eUnalignedJustification justification, bool toggle) const
unsigned int Width(void) const
const unsigned int fromIndex
BlockMultipleAlignment *const alignment
const std::string title
DisplayRow * Clone(const Old2NewAlignmentMap &newAlignments) const
bool GetSequenceAndIndexAt(unsigned int column, BlockMultipleAlignment::eUnalignedJustification justification, const Sequence **sequenceHandle, int *index) const
const Sequence * GetSequence(void) const
DisplayRowFromString(const std::string &s, const Vector color=Vector(0, 0, 0.5), const std::string &t="", bool hasBG=false, Vector bgColor=Vector(1, 1, 1), BlockMultipleAlignment *a=NULL)
virtual ~DisplayRowFromString(void)
bool GetCharacterTraitsAt(unsigned int column, BlockMultipleAlignment::eUnalignedJustification justification, char *character, Vector *color, bool *drawBackground, Vector *cellBackgroundColor) const
void SelectedRange(unsigned int from, unsigned int to, BlockMultipleAlignment::eUnalignedJustification justification, bool toggle) const
unsigned int Width(void) const
virtual bool GetSequenceAndIndexAt(unsigned int column, BlockMultipleAlignment::eUnalignedJustification justification, const Sequence **sequence, int *index) const =0
virtual void SelectedRange(unsigned int from, unsigned int to, BlockMultipleAlignment::eUnalignedJustification justification, bool toggle) const =0
virtual DisplayRow * Clone(const Old2NewAlignmentMap &newAlignments) const =0
virtual const Sequence * GetSequence(void) const =0
virtual ~DisplayRow(void)
virtual unsigned int Width(void) const =0
virtual bool GetCharacterTraitsAt(unsigned int column, BlockMultipleAlignment::eUnalignedJustification justification, char *character, Vector *color, bool *drawBackground, Vector *cellBackgroundColor) const =0
bool GetRowTitle(unsigned int row, wxString *title, wxColour *color) const
bool GetCharacterTraitsAt(unsigned int column, unsigned int row, char *character, wxColour *color, bool *drawBackground, wxColour *cellBackgroundColor) const
bool ProximitySort(unsigned int displayRow)
bool CalculateRowScoresWithThreader(double weightPSSM)
void AddBlockBoundaryRows(void)
void FloatPDBRowsToTop(void)
BlockMultipleAlignment * GetAlignmentForRow(unsigned int row) const
DisplayRowFromString * FindBlockBoundaryRow(const BlockMultipleAlignment *forAlignment) const
void SortRowsByThreadingScore(double weightPSSM)
void AddRowFromAlignment(unsigned int row, BlockMultipleAlignment *fromAlignment)
void UpdateMaxRowWidth(void)
const Sequence * GetSequenceForRow(unsigned int row) const
bool SortRowsByLoopLength(unsigned int row, unsigned int alnIndex)
unsigned int NRows(void) const
void AddRowFromString(const std::string &anyString)
void RedrawAlignedMolecules(void) const
void SortRowsBySelfHit(void)
void UpdateAfterEdit(const BlockMultipleAlignment *forAlignment)
void FloatHighlightsToTop(void)
SequenceDisplay * Clone(const Old2NewAlignmentMap &newAlignments) const
void GetProteinSequences(SequenceList *seqs) const
bool GetDisplayCoordinates(const Molecule *molecule, unsigned int seqIndex, BlockMultipleAlignment::eUnalignedJustification justification, unsigned int *column, unsigned int *row)
unsigned int GetStartingColumn(void) const
void RowsAdded(unsigned int nRowsAddedToMultiple, BlockMultipleAlignment *multiple, int where=-1)
SequenceDisplay(bool editable, ViewerWindowBase *const *parentViewerWindow)
unsigned int maxRowWidth
virtual ~SequenceDisplay(void)
void AddRow(DisplayRow *row)
void GetSize(unsigned int *setColumns, unsigned int *setRows) const
bool MouseDown(int column, int row, unsigned int controls)
void GetSequences(const BlockMultipleAlignment *forAlignment, SequenceList *seqs) const
void RemoveBlockBoundaryRows(void)
void RowsRemoved(const std::vector< unsigned int > &rowsRemoved, const BlockMultipleAlignment *multiple)
bool IsEditable(void) const
unsigned int startingColumn
void AddRowFromSequence(const Sequence *sequence, unsigned int from, unsigned int to)
ViewerWindowBase *const * viewerWindow
void GetRowOrder(const BlockMultipleAlignment *forAlignment, std::vector< unsigned int > *dependentRowOrder) const
void MouseOver(int column, int row) const
void DraggedCell(int columnFrom, int rowFrom, int columnTo, int rowTo)
std::vector< DisplayRow * > RowVector
void SortRowsByIdentifier(void)
void AddBlockBoundaryRow(BlockMultipleAlignment *forAlignment)
void UpdateBlockBoundaryRow(const BlockMultipleAlignment *forAlignment) const
std::vector< const Sequence * > SequenceList
void SelectedRectangle(int columnLeft, int rowTop, int columnRight, int rowBottom)
void SetStartingColumn(unsigned int column)
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
static const char * column
Definition: stats.c:23
string
Definition: cgiapp.hpp:690
#define NULL
Definition: ncbistd.hpp:225
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
n background color
unsigned int a
Definition: ncbi_localip.c:102
EIPRangeType t
Definition: ncbi_localip.c:101
The NCBI C++/STL use hints.
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
std::map< BlockMultipleAlignment *, BlockMultipleAlignment * > Old2NewAlignmentMap
#define row(bind, expected)
Definition: string_bind.c:73
Modified on Fri Sep 20 14:57:27 2024 by modify_doxy.py rev. 669887