NCBI C++ ToolKit
cross_aln_render.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: cross_aln_render.cpp 42766 2019-04-10 20:45:59Z katargir $
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: Vlad Lebedev
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 #include "cross_aln_render.hpp"
33 
34 #include <gui/opengl/glutils.hpp>
35 #include <math.h>
36 
37 
39 
40 
41 
43 
45 {
46  m_DS = NULL;
47  m_MinZoomX = log(1.0f / kMaxPixelsBase); // Enougth to fit seq. letters
48 
50  m_RP_Q.EnableZoom(true, false);
51  m_RP_Q.SetAdjustToLimits(true, false);
53 
54  m_CP.EnableZoom(false, false);
55  //m_CP.EnableOffset();
56 
58  m_RP_S.EnableZoom(true, false);
59  m_RP_S.SetAdjustToLimits(true, false);
61 
63 
66 }
67 
69 {
70 }
71 
72 
73 
75 {
76  if (!m_DS) return;
77 
78  CBioseq_Handle hndl1 = m_DS->GetQueryHandle();
79  CBioseq_Handle hndl2 = m_DS->GetSubjectHandle();
80 
81  if ( !hndl1 ) {
82  NCBI_THROW(CException, eUnknown, "The query sequence can't be resolved!");
83  }
84 
85  if ( !hndl2 ) {
86  NCBI_THROW(CException, eUnknown, "The subject sequence can't be resolved!");
87  }
88 
91 
94 }
95 
96 
98 {
99  m_DS = ds;
100 
102  x_SetupViewPorts(rc);
103 }
104 
105 
107 {
108  TVPUnit ruler_height = m_RulerPanel_Q.GetVPRect().Height();
109 
110  m_RP_Q.SetViewport( TVPRect(rc.Left(), rc.Top() - ruler_height + 1,
111  rc.Right(), rc.Top()) );
112 
113  m_CP.SetViewport( TVPRect(rc.Left(), rc.Bottom() + ruler_height, rc.Right(), rc.Top() - ruler_height) );
114 
115  m_RP_S.SetViewport( TVPRect(rc.Left(), rc.Bottom(),
116  rc.Right(), rc.Bottom() + ruler_height - 1) );
117 
120 }
121 
122 
123 
125 {
126  TSeqRange rQ = m_DS->GetQueryHitsRange();
127  TSeqRange rS = m_DS->GetSubjectHitsRange();
128 
129  // 3% offset on each side of each sequence
130  TModelUnit pQ = m_RP_Q.GetViewport().Width() * 3.0 / 100.0;
131  TModelUnit pS = m_RP_S.GetViewport().Width() * 3.0 / 100.0;
132 
133 
134  TModelRect rc2( max(TModelUnit(0.0), rQ.GetFrom()-pQ), 0, min(m_SeqLength_Q + TModelUnit(1.0),
135  rQ.GetTo() + TModelUnit(1) + pQ), m_RP_Q.GetViewport().Height());
136  TModelRect rc3( max(TModelUnit(0.0), rS.GetFrom()-pS), TModelUnit(0), min(m_SeqLength_S+TModelUnit(1.0),
137  rS.GetTo() + TModelUnit(1) + pS), m_RP_S.GetViewport().Height());
138 
139  TModelRect rcc(TModelUnit(0), TModelUnit(100), TModelUnit(1), TModelUnit(0));
140 
143 
145  m_RP_Q.SetVisibleRect (rc2);
146 
148  m_CP.SetVisibleRect (rcc);
149 
151  m_RP_S.SetVisibleRect (rc3);
152 
154 }
155 
156 
158 {
160 }
161 
162 
164 {
166 }
167 
168 
169 void CCrossAlnRenderer::SetObjectSelection(const vector<const CSeq_align*> sel_aligns)
170 {
171  m_CrossPanel.SetObjectSelection(sel_aligns);
172 }
173 
174 
176 {
177  if ( !m_DS ) {
178  return;
179  }
180 
181  // draw all panels
182  m_RulerPanel_Q.Render(m_RP_Q); // Query
183  m_CrossPanel.Render(m_CP); // Cross Panel
184  m_RulerPanel_S.Render(m_RP_S); // Subject
185 
187 }
188 
189 
190 
192 {
193  x_SetupViewPorts(rc);
194 }
195 
196 
198 {
200 }
201 
202 
204 {
205  m_CrossPanel.ColorByScore(score_id);
206 }
207 
208 
210 {
211  return m_CrossPanel.GetScoreId();
212 }
213 
214 
216 {
217  return m_CrossPanel.HitTest(m_CP, x, y, true);
218 }
219 
220 
221 
223 {
224  return m_CrossPanel.HitTest(m_CP, x, y);
225 }
226 
227 
228 void CCrossAlnRenderer::GetTooltip(int x, int y, string* title)
229 {
230  *title = "";
231 }
232 
233 
234 
236 {
237  TModelUnit scale_x = log(m_RP_Q.GetScaleX());
238  return (float)(1.0f - (scale_x - m_MinZoomX) / (m_MaxZoomX_Q - m_MinZoomX));
239 }
240 
241 
243 {
245  * (1.0f - value);
246 
247  m_RP_Q.SetScale(exp(scale), m_RP_Q.GetScaleY(),
249 
251 }
252 
253 
255 {
256  TModelUnit scale_x = log(m_RP_S.GetScaleX());
257  return (float)(1.0f - (scale_x - m_MinZoomX) / (m_MaxZoomX_S - m_MinZoomX));
258 }
259 
260 
262 {
264  * (1.0f - value);
265 
266  m_RP_S.SetScale(exp(scale), m_RP_S.GetScaleY(),
268 
270 }
271 
272 
273 
275 {
278 }
279 
280 
282  const TModelPoint& point)
283 {
284  if(scale_x > m_RP_Q.GetMinScaleX()) {
285  TModelPoint ref_p(point.X(), m_RP_Q.GetVisibleRect().Top());
286 
287  m_RP_Q.SetScaleRefPoint(scale_x, 1, ref_p); // -1
289  }
290 }
291 
292 
293 
295  const TModelPoint& point)
296 {
297  if(scale_x > m_RP_S.GetMinScaleX()) {
298  TModelPoint ref_p(point.X(), m_RP_S.GetVisibleRect().Top());
299 
300  m_RP_S.SetScaleRefPoint(scale_x, 1, ref_p); // -1
302  }
303 }
304 
305 
307  const TModelPoint& point)
308 {
309 }
310 
311 
313 {
314  // calculate model space limits
317 
320 
321  // our accuracy is within 5%
322  TModelUnit s5l = sMl / 100.0f * 5.0f;
323  TModelUnit s5r = sMr / 100.0f * 5.0f;
324 
325  TModelUnit q5l = qMl / 100.0f * 5.0f;
326  TModelUnit q5r = qMr / 100.0f * 5.0f;
327 
328  // calculate scale limits
329  TModelUnit qSx = m_RP_Q.GetScaleX();
330  TModelUnit sSx = m_RP_S.GetScaleX();
331 
332  // scale limits for subject sequence
333  TModelUnit s5s = sSx / 100.0f * 5.0f;
334  TModelUnit minAVs = sSx - s5s;
335  TModelUnit maxAVs = sSx + s5s;
336 
337  // scale limits for query sequence
338  TModelUnit q5s = qSx / 100.0f * 5.0f;
339  TModelUnit minAVq = qSx - q5s;
340  TModelUnit maxAVq = qSx + q5s;
341 
342  // our new zoom factor
343  m_RP_S.SetZoomFactor(1.05f);
344  m_RP_Q.SetZoomFactor(1.05f);
345 
346  // initially, zoom all the way
347  ZoomOnRange_Q(rc.Left(), rc.Right());
348  ZoomOnRange_S(rc.Bottom(), rc.Top());
349 
350  // "slowly" zoom out until the scales are correct or until nowhere to zoom
351  do {
356 
357  TModelUnit qSx = m_RP_Q.GetScaleX();
358  TModelUnit sSx = m_RP_S.GetScaleX();
359 
360  // check limits first, and then the scales
361  if (sVl <= sMl + s5l || qVl <= qMl + q5l ||
362  sVr >= sMr - s5r || qVr >= qMr - q5r ||
363  (qSx >= minAVq && qSx <= maxAVq) ||
364  (sSx >= minAVs && sSx <= maxAVs) ) {
365  break;
366  } else {
369  }
370  } while (true);
371 
373 }
374 
375 
377 {
379  rc.SetHorz(from, to);
380  m_RP_Q.ZoomRect(rc);
381 
382  // Now add five pixels offset on each side
383  m_RP_Q.OpenOrtho();
385  m_RP_Q.Close();
386 
387  rc.SetHorz(from - pQ, to + pQ);
388  m_RP_Q.ZoomRect(rc);
389 
391 }
392 
393 
395 {
397  rc.SetHorz(from, to);
398  m_RP_S.ZoomRect(rc);
399 
400  // Now add five pixels offset on each side
401  m_RP_S.OpenOrtho();
403  m_RP_S.Close();
404 
405  rc.SetHorz(from - pS, to + pS);
406  m_RP_S.ZoomRect(rc);
407 
409 }
410 
411 
412 
413 // Query
415 {
418 }
419 
420 
422 {
425 }
426 
427 
429 {
430  SetZoomX_Q(0.0f);
431 }
432 
434 {
435  SetZoomX_Q(1.0f);
436 }
437 
438 
439 // Subject
441 {
444 }
445 
446 
448 {
451 }
452 
453 
455 {
456  SetZoomX_S(0.0f);
457 }
458 
459 
461 {
462  SetZoomX_S(1.0f);
463 }
464 
465 
467 {
468  return m_CP;
469 }
470 
472 {
473  return m_CP;
474 }
475 
476 
478 {
479  return m_RP_Q;
480 }
481 
482 
484 {
485  return m_RP_S;
486 }
487 
488 
490 {
491  m_RP_Q.Scroll(dxQ, 0.0f);
492  m_RP_S.Scroll(dxS, 0.0f);
493 
495 }
496 
497 
CBioseq_Handle –.
CIRef< ICrossAlnDataSource > m_DS
void SetObjectSelection(const vector< const CSeq_align * > sel_aligns)
void Scroll(TModelUnit dxQ, TModelUnit dxS)
TModelRect SelectHitTest(int x, int y)
void SetZoomX_S(float value)
void SetViewport(const TVPRect &rc)
float GetZoomX_S(void) const
void SetScaleRef_S(TModelUnit m_x, TModelUnit m_y, const TModelPoint &point)
void SetDataSource(const TVPRect &rc, ICrossAlnDataSource *ds)
void ZoomOnRange_Q(TModelUnit from, TModelUnit to)
float GetZoomX_Q(void) const
void SquareOnRect(TModelRect rc)
void SetScaleRef_Q(TModelUnit m_x, TModelUnit m_y, const TModelPoint &point)
void SetZoomX_Q(float value)
void x_SetupViewPorts(const TVPRect &rc)
void GetObjectSelection(TConstObjects &objs) const
CConstRef< CObject_id > GetScoreId() const
void GetTooltip(int x, int y, string *title)
CCrossPanelIR m_CrossPanel
void ZoomOnRange_S(TModelUnit from, TModelUnit to)
TModelRect HitTest(int x, int y)
void SetScaleRef_C(TModelUnit m_x, TModelUnit m_y, const TModelPoint &point)
void ColorByScore(CConstRef< CObject_id > score_id)
void SetObjectSelection(const vector< const objects::CSeq_align * > sel_aligns)
void GetObjectSelection(TConstObjects &objs) const
CConstRef< objects::CObject_id > GetScoreId() const
void SetDataSource(ICrossAlnDataSource *ds)
void ResetObjectSelection()
void ColorBySegments()
virtual void Render(CGlPane &pane)
void ColorByScore(CConstRef< objects::CObject_id > score_id)
TModelRect HitTest(CGlPane &pane, int x, int y, bool select=false)
void SetLimits(TVPRect rcm1, TModelRect rcv1, TVPRect rcm2, TModelRect rcv2)
class CGlPane
Definition: glpane.hpp:62
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
void SetColor(EColorType type, const CRgbaColor &color)
Definition: ruler.cpp:133
@ eBackground
Definition: ruler.hpp:54
virtual TVPRect GetVPRect() const
Definition: ruler.cpp:295
@ eTop
Definition: ruler.hpp:93
void SetHorizontal(bool b_horz, ELabelPlacement place=eDefault, ELabelAlign aln=eAln_Center)
Definition: ruler.cpp:92
void SetAutoRange()
SetAutoRange() activates automatic mode; in this mode ruler's range is equal to the provided model li...
Definition: ruler.cpp:171
virtual void Render(CGlPane &pane)
Definition: ruler.cpp:460
IHitMatrixDataSource - abstract Data Source for Hit Matrix Widget.
char value[7]
Definition: config.c:431
const TVPUnit kMaxPixelsBase
#define NULL
Definition: ncbistd.hpp:225
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
GLdouble TModelUnit
Definition: gltypes.hpp:48
void SetModelLimitsRect(const TModelRect &R)
Definition: glpane.hpp:342
void ZoomInCenter(int options=fZoomXY)
Definition: glpane.cpp:338
T X() const
Definition: glpoint.hpp:59
void ZoomOutCenter(int options=fZoomXY)
Definition: glpane.cpp:343
T Height() const
Definition: glrect.hpp:90
void SetViewport(const TVPRect &R)
Definition: glpane.cpp:96
bool OpenOrtho()
Definition: glpane.hpp:427
T Top() const
Definition: glrect.hpp:84
T Bottom() const
Definition: glrect.hpp:82
TModelUnit UnProjectWidth(TVPUnit vp_w) const
Definition: glpane.cpp:755
T Width() const
Definition: glrect.hpp:86
T Right() const
Definition: glrect.hpp:83
TVPRect & GetViewport(void)
Definition: glpane.hpp:332
CGlRect< TVPUnit > TVPRect
Definition: gltypes.hpp:53
void SetScale(TModelUnit scale_x, TModelUnit scale_y, TModelPoint p_center)
Definition: glpane.cpp:361
void SetScaleRefPoint(TModelUnit scale_x, TModelUnit scale_y, TModelPoint p_ref)
Definition: glpane.cpp:382
CGlPoint< T > CenterPoint() const
Definition: glrect.hpp:94
void ZoomRect(const TModelRect &r)
Definition: glpane.cpp:348
TModelRect & GetModelLimitsRect(void)
Definition: glpane.hpp:347
T Left() const
Definition: glrect.hpp:81
void SetZoomFactor(TModelUnit factor=2.0)
Definition: glpane.hpp:473
void Scroll(TModelUnit dx, TModelUnit dy)
Definition: glpane.cpp:602
static bool CheckGlError()
Check if there are any OpenGL errors.
Definition: glutils.cpp:166
void Close(void)
Definition: glpane.cpp:178
void EnableZoom(bool en_x, bool en_y)
Definition: glpane.hpp:462
int TVPUnit
Definition: gltypes.hpp:47
void SetVisibleRect(const TModelRect &R)
Definition: glpane.cpp:113
void SetAdjustToLimits(bool adjust_x, bool adjust_y)
Definition: glpane.hpp:389
TModelRect & GetVisibleRect(void)
Definition: glpane.hpp:357
void SetMinScaleX(TModelUnit scale)
Definition: glpane.hpp:442
TModelUnit GetMinScaleX(void) const
Definition: glpane.hpp:452
TModelUnit GetScaleX(void) const
Definition: glpane.cpp:118
TModelUnit GetScaleY(void) const
Definition: glpane.cpp:123
void SetHorz(T left, T right)
Definition: glrect.hpp:117
void EnableOffset(bool b_en=true)
Offset is used as a workaround for OpenGL precision problems emerging when size of visible range is s...
Definition: glpane.hpp:405
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
TSeqPos GetBioseqLength(void) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TTo GetTo(void) const
Get the To member data.
Definition: Range_.hpp:269
TFrom GetFrom(void) const
Get the From member data.
Definition: Range_.hpp:222
T max(T x_, T y_)
T min(T x_, T y_)
Modified on Thu Feb 22 17:12:56 2024 by modify_doxy.py rev. 669887