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

Go to the SVN repository for this file.

1 /* $Id: aln_multi_cgi.cpp 43735 2019-08-26 13:41:17Z ucko $
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  * Author: Andrey Yazhuk
27  *
28  * File Description:
29  */
30 
31 #include <ncbi_pch.hpp>
32 #include <corelib/ncbistl.hpp>
33 
34 #include <cgi/cgictx.hpp>
37 #include <gui/opengl/glutils.hpp>
38 #include <gui/opengl/glpane.hpp>
39 
42 
48 
50 
51 #include <objmgr/bioseq_handle.hpp>
52 
53 
54 USING_SCOPE(ncbi); //using namespace ncbi;
55 //USING_SCOPE(objects);
56 
57 
58 static const int kColorGradNumber = 32; /// number of gradient colors in alignment
59 
60 
62 {
63 public:
64  enum EErrCode {
69  };
70 
71  virtual const char* GetErrCodeString(void) const
72  {
73  switch(GetErrCode()) {
74  case eInvalidAccession: return "eInvalidException";
75  case eCannotLoadBioseq: return "eCannotLoadBioseq";
76  case eInvalidVisibleRange: return "eInvalidVisibleRange";
77  case eInvalidAnchor: return "eInvalidAnchor";
78  default: return CException::GetErrCodeString();
79  };
80  }
81 
83 };
84 
85 /////////////////////////////////////////////////////////////////////////////
86 // CAlnMultiCGIApplication::
87 //
88 
90 {
91 public:
93 
94  virtual void Render(CCgiContext& ctx);
95 protected:
96  virtual void x_PreProcess(CCgiContext& ctx);
97 private:
101 
102  // Renderer setup
108 
109  //parameter
111 };
112 
113 
114 
116 : m_Renderer(TVPRect(0, 0, m_Width, m_Height))
117 {
118  //setup ?
119 }
120 
121 //extracting arguments, verifying and loading data
123 {
124  SetEnvironment("NCBI_SERVICE_NAME_ID1", "ID1LXA");
125 
126  // retrieve our CGI rendering params
127  const CCgiRequest& request = ctx.GetRequest();
128  const TCgiEntries& entries = request.GetEntries();
129 
130  m_Start = m_Stop = -1;
131 
132  TCgiEntries::const_iterator it_acc = entries.find("acc");
133  TCgiEntries::const_iterator it_start = entries.find("start");
134  TCgiEntries::const_iterator it_stop = entries.find("stop");
135  TCgiEntries::const_iterator it_anchor = entries.find("anchor");
136 
137  if(it_acc == entries.end()) {
138  NCBI_THROW(CAlnMultiCGIException, eInvalidAccession, "Accession is not specified.");
139  } else {
140  string s = string("Accession: ") + it_acc->second;
141  LOG_POST(s);
142 
143  //extract other parameters
144  if(it_start != entries.end() && it_start->second.size()) {
145  m_Start = NStr::StringToInt(it_start->second);
146  }
147  if(it_stop != entries.end() && it_stop->second.size()) {
148  m_Stop = NStr::StringToInt(it_stop->second);
149  }
150 
153 
154  m_Scope.Reset(new CScope(*m_ObjMgr));
155  m_Scope->AddDefaults();
156 
157  CSeq_id id(it_acc->second);
159 
160  if(m_Handle) { // setup data source and visible range
163 
164  // attempt to set anchor
165  if(it_anchor != entries.end() && it_anchor->second.size()) {
166  CSeq_id anchor_id(it_anchor->second);
167 
168  bool b_set = false;
169  typedef IAlnMultiDataSource::TNumrow TNumrow;
170  TNumrow n_rows = m_DataSource->GetNumRows();
171  for( TNumrow row = 0; row < n_rows && ! b_set; row++ ) {
172  if(m_DataSource->CanGetId(row)) {
173  const CSeq_id& id = m_DataSource->GetSeqId(row);
174  if(id.Match(anchor_id)) {
176  b_set = true;
177  }
178  }
179  }
180  if(! b_set) {
181  NCBI_THROW(CAlnMultiCGIException, eInvalidAnchor,
182  "Anchor accession is invalid.");
183  }
184 
185  }
186 
187  //calculate visible range
188  int aln_start = m_DataSource->GetAlnStart();
189  int aln_stop = m_DataSource->GetAlnStop();
190  if(m_Start > -1) {
191  if(m_Start < 0 || m_Start > aln_stop) {
192  NCBI_THROW(CAlnMultiCGIException, eInvalidVisibleRange,
193  "Visible start out of range.");
194  }
195 
196  } else m_Start = aln_start;
197  if(m_Stop > -1) {
198  if(m_Stop < 0 || m_Stop > aln_stop) {
199  NCBI_THROW(CAlnMultiCGIException, eInvalidVisibleRange,
200  "Visible end out of range.");
201  }
202 
203  } else m_Stop = aln_stop;
204 
205  //setup model
208 
209  //m_Model.EnableScoring(false);
212 
215  size_t h = (size_t) -rc_vis.Height();
216  m_Height = min(m_Height, h);
217  }
218  else {
219  string msg = "Cannot load Bioseq for accession \"";
220  msg += it_acc->second;
221  msg += "\"";
222  NCBI_THROW(CAlnMultiCGIException, eCannotLoadBioseq, msg.c_str());
223  }
224 
225  }
226 }
227 
229 {
230  if(m_Handle) {
232 
233  //adjus visible space
234  CGlPane& port = m_Model.GetAlignPort();
235  port.SetViewport(TVPRect(0, 0, m_Width, m_Height)); ///### this have to be eliminated
236  port.ZoomAll();
237 
238  // adjust visible range
239  TModelRect rc_vis = port.GetVisibleRect();
240  rc_vis.SetHorz(m_Start, m_Stop + 1);
241  port.SetVisibleRect(rc_vis);
242 
243 
244  m_Renderer.Render();
245  }
246  //debugging trick
247  //CImageIO::WriteImage(m_Context->GetBuffer(), "test.png", m_Format);
248 }
249 
250 
251 
252 /////////////////////////////////////////////////////////////////////////////
253 // MAIN
254 //
255 
256 int main(int argc, const char* argv[])
257 {
258  int result = CAlnMultiCGIApplication().AppMain(argc, argv, 0, eDS_Default, 0);
259  _TRACE("back to normal diags");
260  return result;
261 }
static const int kColorGradNumber
USING_SCOPE(ncbi)
int main(int argc, const char *argv[])
CAlnMultiRenderer m_Renderer
CRef< IAlnMultiDataSource > m_DataSource
CRef< CObjectManager > m_ObjMgr
CAlnMultiDSBuilder m_Builder
virtual void Render(CCgiContext &ctx)
CRowStyleCatalog m_StyleCatalog
virtual void x_PreProcess(CCgiContext &ctx)
number of gradient colors in alignment
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
NCBI_EXCEPTION_DEFAULT(CAlnMultiCGIException, CException)
void Init(objects::CScope &scope, const objects::CSeq_align &align)
initial data set from which an alignment will be build
CRef< IAlnMultiDataSource > CreateDataSource()
class CAlnMultiModel - represents a visual model of an alignment.
virtual CWidgetDisplayStyle * GetDisplayStyle()
virtual void SetStyleCatalog(const CRowStyleCatalog *catalog)
virtual void SetDataSource(IAlnMultiDataSource *p_ds)
CGlPane & GetAlignPort()
class CAlnMultiRenderer - renders multiple alignment represented by IAlnMultiRendererContext (the Mod...
virtual void Resize(const TVPRect &rc)
void SetContext(IAlnMultiRendererContext *pContext)
virtual void Render()
renders OpenGL graphics
CBioseq_Handle –.
CCgiRequest::
Definition: ncbicgi.hpp:685
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:366
class CGlPane
Definition: glpane.hpp:62
CRowDisplayStyle is a base class representing a display style for IAlignRow.
CRowStyleCatalog is a collection of CRowDisplayStyle-s assigned to rows in alignment.
void SetDefaultStyle(CRowDisplayStyle *style)
assumes ownership
void SetWidgetStyle(const CWidgetDisplayStyle *style)
CScope –.
Definition: scope.hpp:92
virtual TSeqPos GetAlnStart(void) const =0
virtual bool CanGetId(TNumrow row) const =0
IAlnExplorer::TNumrow TNumrow
virtual TNumrow GetNumRows(void) const =0
number of rows in alignment
virtual TSeqPos GetAlnStop(void) const =0
virtual bool SetAnchor(TNumrow anchor)=0
virtual const objects::CSeq_id & GetSeqId(TNumrow row) const =0
CS_CONTEXT * ctx
Definition: t0006.c:12
CNcbiEnvironment & SetEnvironment(void)
Get a non-const copy of the application's cached environment.
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
Definition: ncbiapp.cpp:832
string
Definition: cgiapp.hpp:687
const TCgiEntries & GetEntries(void) const
Get a set of entries(decoded) received from the client.
Definition: ncbicgi.hpp:1181
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
@ eDS_Default
Try standard log file (app.name + ".log") in /log/, use stderr on failure.
Definition: ncbidiag.hpp:1790
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:453
#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
EErrCode
Error types that an application can generate.
Definition: ncbiexpt.hpp:884
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
T Height() const
Definition: glrect.hpp:90
void SetViewport(const TVPRect &R)
Definition: glpane.cpp:96
CGlRect< TVPUnit > TVPRect
Definition: gltypes.hpp:53
void ZoomAll(int options=fZoomXY)
Definition: glpane.cpp:289
TModelRect & GetModelLimitsRect(void)
Definition: glpane.hpp:347
void SetVisibleRect(const TModelRect &R)
Definition: glpane.cpp:113
TModelRect & GetVisibleRect(void)
Definition: glpane.hpp:357
void SetHorz(T left, T right)
Definition: glrect.hpp:117
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
Magic spell ;-) needed for some weird compilers... very empiric.
The NCBI C++/STL use hints.
T min(T x_, T y_)
The Object manager core.
#define row(bind, expected)
Definition: string_bind.c:73
else result
Definition: token2.c:20
static wxAcceleratorEntry entries[3]
Modified on Wed Jul 17 13:22:41 2024 by modify_doxy.py rev. 669887