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

Go to the SVN repository for this file.

1 /* $Id: ld_glyph.cpp 41823 2018-10-17 17:34:58Z 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: Melvin Quintos
27 *
28 * File Description:
29 * Melvin Quintos -- Handles the display of LD Blocks
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
35 #include <gui/utils/app_popup.hpp>
38 #include <gui/objutils/tooltip.hpp>
40 #include <gui/opengl/irender.hpp>
41 #include <objmgr/util/sequence.hpp>
42 #include <util/xregexp/regexp.hpp>
44 
47 
48 static string s_ChrName(const CSeq_loc& loc, CScope* scope)
49 {
50  string acc, chr;
51  CRegexp rgxChr("(\\d\\d)(\\.\\d+)?$"); // find a non blank, non-comment line
52 
53  const CSeq_id& id = *loc.GetId();
54  if (id.IsGi())
55  acc = sequence::GetAccessionForGi(id.GetGi(),*scope);
56  else if (id.IsOther())
57  acc = id.GetOther().GetAccession();
58  else
59  chr = "unknown";
60 
61  if (rgxChr.IsMatch(acc)) {
62  string sub = rgxChr.GetSub(acc,1);
63  int v = NStr::StringToInt(sub);
64  chr = "chr" + NStr::IntToString(v);
65  }
66  return chr;
67 }
68 
69 //
70 // CLDBlockGlyph::CLDBlockGlyph()
71 //
73 {
74  const CSeq_feat& or_feat = feat.GetOriginalFeature();
75  const CUser_object &user = or_feat.GetData().GetUser();
76 
77  m_Value.blockId = user.GetField("block_id").GetData().GetInt();
78  m_Value.score = user.GetField("score").GetData().GetReal();
79  m_Value.popId = user.GetField("pop_id").GetData().GetInt();
80 
81  m_Location.Reset(&feat.GetLocation());
82 }
83 
85 {
86  string url, url_base, start, stop, chr;
87  url_base = "https://hapmap1.be-md.ncbi.nlm.nih.gov/cgi-perl/gbrowse/hapmap27_B36/?";
88 
90  start = "start=" + NStr::IntToString(range.GetFrom());
91  stop = ";stop=" + NStr::IntToString(range.GetToOpen());
92  chr = ";ref=" + s_ChrName(*m_Location, &(m_Context->GetScope()));
93 
94  url = url_base + start + stop + chr;
95 
97  return true;
98 }
99 
100 
101 bool CLDBlockGlyph::NeedTooltip(const TModelPoint& p, ITooltipFormatter& tt, string& t_title) const
102 {
103  GetTooltip(p, tt, t_title);
104  return true;
105 }
106 
107 
108 void CLDBlockGlyph::GetTooltip(const TModelPoint& /*pos*/, ITooltipFormatter& tt, string& /*t_title*/) const
109 {
110  tt.AddRow("Score:", NStr::DoubleToString(m_Value.score));
111  tt.AddRow("Pop ID:", NStr::IntToString(m_Value.popId));
112 }
113 
114 
116 {
117  // TODO
118  return true;
119 }
120 
122 {
123  const int binHeight = 10; //m_ConfigSettings->GetGwasBinHeight();
124 
125  IRender& gl = GetGl();
126 
127  TModelUnit top = GetTop();
128  TModelUnit bottom = top + GetHeight();
130 
131  TModelUnit line_y1 = 1 + top;
132  TModelUnit line_y2 = line_y1 + binHeight;
133 
134  // SETUP COMMON attributes
136 
137  TModelUnit x1 = range.GetFrom();
138  TModelUnit x2 = range.GetToOpen();
139  TModelUnit y1 = line_y1;
140  TModelUnit y2 = line_y2;
141 
142  TModelUnit dx1 = x1 - offset;
143  TModelUnit dx2 = x2 - offset;
144 
145  TModelUnit xx1 = max<TModelUnit>(0, dx1);
146  TModelUnit xx2 = max<TModelUnit>(0, dx2);
147 
148  float cScore = 1 - m_Value.score;
149 
150  // Calculate the color
151  unsigned int dc = (unsigned int)((cScore * 9)+.5);
152  dc = min<unsigned int>(dc, 6);
153  unsigned char B = 225 + (5 *dc);
154  unsigned char G = 32 + (32*dc);
155  unsigned char R = 32 + (32*dc);
156 
157  CRgbaColor color(R,G,B);
158  CRgbaColor color2 = color;
159  color2.Lighten(0.30f);
160 
161  TModelUnit mid = y1 + (y2 - y1) * 0.5f;
162 
163  gl.ShadeModel(GL_SMOOTH);
164  gl.Begin(GL_TRIANGLE_STRIP);
165  gl.ColorC(color);
166  gl.Vertex2d(xx1, y1);
167  gl.Vertex2d(xx2, y1);
168 
169  gl.ColorC(color2);
170  gl.Vertex2d(xx1, mid);
171  gl.Vertex2d(xx2, mid);
172 
173  gl.ColorC(color);
174  gl.Vertex2d(xx1, y2);
175  gl.Vertex2d(xx2, y2);
176  gl.End();
177  gl.ShadeModel(GL_FLAT);
178 
179  // draw border
180  gl.Color3f(0,0,.5f);
181  m_Context->DrawRect(x1, y1, x2, y2);
182 
183  // draw label
185  TModelUnit midx = x1 + (x2 - x1) * 0.5f;
186  string label = "LD" + NStr::IntToString(m_Value.blockId);
187 
188  if (m_Context->WillLabelFit(range, font, label)) {
189  gl.Color3f(1,1,1);
190  m_Context->TextOut(&font, label.c_str(), midx,
191  bottom, true);
192  }
193 
194 }
195 
197 {
198  SetHeight(10);
200  SetWidth(range.GetLength());
201  SetLeft(range.GetFrom());
202 }
203 
205 {
206  return m_Location->GetTotalRange();
207 }
208 
virtual bool OnLeftDblClick(const TModelPoint &p)
Definition: ld_glyph.cpp:84
virtual void x_Draw() const
The default renderer for this layout object.
Definition: ld_glyph.cpp:121
virtual void x_UpdateBoundingBox()
Update the bounding box assuming children's sizes are fixed if any.
Definition: ld_glyph.cpp:196
virtual bool IsClickable() const
Query if this glyph is clickable.
Definition: ld_glyph.cpp:115
CConstRef< objects::CSeq_loc > m_Location
Definition: ld_glyph.hpp:118
SValue m_Value
Definition: ld_glyph.hpp:119
virtual void GetTooltip(const TModelPoint &p, ITooltipFormatter &tt, string &t_title) const
Get the tooltip if available.
Definition: ld_glyph.cpp:108
virtual TSeqRange GetRange(void) const
get the total range of this object.
Definition: ld_glyph.cpp:204
CLDBlockGlyph(const objects::CMappedFeat &feat)
Definition: ld_glyph.cpp:72
virtual bool NeedTooltip(const TModelPoint &p, ITooltipFormatter &tt, string &t_title) const
Check if need to show tooltip.
Definition: ld_glyph.cpp:101
CMappedFeat –.
Definition: mapped_feat.hpp:59
CRegexp –.
Definition: regexp.hpp:70
void TextOut(const CGlTextureFont *font, const char *text, TModelUnit x, TModelUnit y, bool center, bool adjust_flip=true) const
const TModelUnit & GetOffset() const
void DrawRect(const TModelRect &rc) const
objects::CScope & GetScope()
bool WillLabelFit(const TModelRect &rc) const
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
CScope –.
Definition: scope.hpp:92
CRenderingContext * m_Context
the rendering context
Definition: seq_glyph.hpp:346
virtual void SetHeight(TModelUnit h)
Definition: seq_glyph.hpp:650
virtual void SetWidth(TModelUnit w)
Definition: seq_glyph.hpp:646
virtual void SetLeft(TModelUnit l)
Definition: seq_glyph.hpp:654
virtual TModelUnit GetTop() const
Definition: seq_glyph.hpp:599
virtual TModelUnit GetHeight() const
Definition: seq_glyph.hpp:587
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
const CUser_field & GetField(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Access a named field in this user object.
Definition: User_object.cpp:71
primitive interface to arrange tabular data in the tooltips
Definition: tooltip.hpp:55
#define G(x, y, z)
Definition: md4.c:179
int offset
Definition: replacements.h:160
GLdouble TModelUnit
Definition: gltypes.hpp:48
virtual void Begin(GLenum mode)=0
Start rendering.
void Color3f(GLfloat r, GLfloat g, GLfloat b)
Definition: irender.hpp:95
IRender & GetGl()
convenience function for getting current render manager
void Vertex2d(GLdouble x, GLdouble y)
Definition: irender.hpp:185
virtual void ShadeModel(GLenum mode)=0
Set shade model for default lighting: glShadeModel(GL_FLAT or GL_SMOOTH)
virtual void End()=0
Finish rendering (create buffer and send to renderer)
virtual void ColorC(const CRgbaColor &c)=0
Set current color (glColor{3,4}{f,d}{v,})
virtual void AddRow(const string &sContents="", unsigned colspan=2)=0
add a row with a cell, spanning across all columns
void Lighten(float scale)
Definition: rgba_color.cpp:463
static bool PopupURL(const string &url)
launch an application to handle a URL
Definition: app_popup.cpp:181
const CSeq_id * GetId(void) const
Get the id of the location return NULL if has multiple ids or no id at all.
Definition: Seq_loc.hpp:941
string GetAccessionForGi(TGi gi, CScope &scope, EAccessionVersion use_version=eWithAccessionVersion, EGetIdType flags=0)
Retrieve the accession for a given GI.
Definition: sequence.cpp:686
const CSeq_loc & GetLocation(void) const
const CSeq_feat & GetOriginalFeature(void) const
Get original feature with unmapped location/product.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
bool IsMatch(CTempString str, TMatch flags=fMatch_default)
Check existence substring which match a specified pattern.
Definition: regexp.cpp:193
CTempString GetSub(CTempString str, size_t idx=0) const
Get pattern/subpattern from previous GetMatch().
Definition: regexp.cpp:156
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string DoubleToString(double value, int precision=-1, TNumToStringFlags flags=0)
Convert double to string.
Definition: ncbistr.hpp:5187
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static const char label[]
const TData & GetData(void) const
Get the Data member data.
TInt GetInt(void) const
Get the variant data.
TReal GetReal(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const TUser & GetUser(void) const
Get the variant data.
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
n background color
USING_SCOPE(objects)
static string s_ChrName(const CSeq_loc &loc, CScope *scope)
Definition: ld_glyph.cpp:48
range(_Ty, _Ty) -> range< _Ty >
C++ wrappers for the Perl-compatible regular expression (PCRE) library.
Modified on Mon Apr 22 04:00:16 2024 by modify_doxy.py rev. 669887