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

Go to the SVN repository for this file.

1 /* $Id: seqtest.cpp 16339 2008-03-10 18:33:35Z dicuccio $
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: Denis Vakatov
27  *
28  * File Description:
29  * CSeqTestApp -- test of OpenGL framework for rendering images as a CGI app
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <cgi/cgictx.hpp>
35 #include <gui/opengl/glutils.hpp>
36 #include <gui/opengl/glcamera.hpp>
37 
40 
42 #include <gui/widgets/seq_graphic/seqgraphic_ds.hpp>
43 
44 #include "../seqgraphic_render.hpp"
45 
46 
47 USING_SCOPE(ncbi); //using namespace ncbi;
49 
50 /////////////////////////////////////////////////////////////////////////////
51 // CSeqTestApplication::
52 //
53 
55 {
56 public:
58 
59  virtual void Init();
60  virtual void Render(CCgiContext& ctx);
61 
62 private:
63  // camrea set-up
65 
68 
69  // data source and renderer
71 };
72 
73 
74 
76 {
80  m_Camera.SetFarPlane(500.0f);
81 }
82 
83 
85 {
86  string syb_path = GetEnvironment().Get("SYBASE");
87  if (syb_path.empty()) {
88  syb_path = "/export/home/sybase/clients/current";
89  CDir dir(syb_path);
90  if ( !dir.Exists() ) {
91  syb_path = "/netopt/Sybase/clients/current";
92  }
93  SetEnvironment("SYBASE", syb_path);
94  }
95 
97 }
98 
100 {
101  // retrieve our CGI rendering params
102  const CCgiRequest& request = ctx.GetRequest();
103  const TCgiEntries& entries = request.GetEntries();
104 
105  //
106  // retrieve the seq-id of interest
107  //
108 
109  TCgiEntries::const_iterator acc_iter = entries.find("id");
110  if ( acc_iter == entries.end() ) {
111  LOG_POST(Error << "Error: accession not indicated to cgi");
112  return;
113  }
114 
115  CSeq_id id(acc_iter->second);
117  m_ObjMgr->RegisterDataLoader(*new CGBDataLoader("GenBank", "id1"),
119 
120  m_Scope.Reset(new CScope(*m_ObjMgr));
121  m_Scope->AddDefaults();
122 
123  if (!m_Scope->GetBioseqHandle(id) ) {
124  LOG_POST(Error << "Failed to retrieve sequence for "
125  << acc_iter->second);
126  return;
127  }
128 
129  m_DataSource.Reset(new CSeqGraphicDataSource( m_Scope.GetObject(), id));
130  //m_DataSource.Reset(new CTestDataSource(acc_iter->second));
131 
132 
133  // Setup configuration
134  // Create an empty config and pass it to the widget
136  config->SetHistogram(CSeqFeatData::e_Imp,
138  config->SetHistogram(CSeqFeatData::e_Imp,
140 
141  //
142  // and set up our renderer
143  //
144 
145  // make sure we reflect the whole window, and our sequence
146  TVPRect rc(0, 0, m_Width, m_Height);
147 
148  CSeqGraphicRenderer renderer;
149  renderer.SetConfig(config);
150  renderer.SetDataSource(rc, m_DataSource);
151 
152  //
153  // rendering options
154  //
155 
156  // rendered width
157  TSeqPos from = 0;
158  TSeqPos to = m_DataSource->GetSequenceLength();
159 
160  TCgiEntries::const_iterator from_iter = entries.find("from");
161  if (from_iter != entries.end()) {
162  from = NStr::StringToInt(from_iter->second);
163  }
164  TCgiEntries::const_iterator to_iter = entries.find("to");
165  if (to_iter != entries.end()) {
166  to = NStr::StringToInt(to_iter->second);
167  }
168 
169  renderer.ZoomOnRange(TSeqRange(from, to));
170 
171  //
172  // and draw!
173  //
174  renderer.draw();
175 }
176 
177 
178 
179 /////////////////////////////////////////////////////////////////////////////
180 // MAIN
181 //
182 
183 int main(int argc, const char* argv[])
184 {
185  int result = CSeqTestApplication().AppMain(argc, argv, 0, eDS_Default, 0);
186  _TRACE("back to normal diags");
187  return result;
188 }
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:855
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:470
CObjectManager –.
CCgiRequest::
Definition: ncbicgi.hpp:676
const CNcbiEnvironment & GetEnvironment(void) const
Get the application's cached environment.
Definition: ncbiapp.hpp:686
const_iterator end() const
Definition: map.hpp:292
#define NULL
Definition: ncbistd.hpp:225
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:626
USING_SCOPE(objects)
virtual void Init(void)
This method is called on the CGI application initialization – before starting to process a HTTP requ...
void SetLayout(EType type)
Definition: glcamera.cpp:103
CDataLoader * RegisterDataLoader(TPluginManagerParamTree *params=0, const string &driver_name=kEmptyStr)
Add data loader using plugin manager.
virtual bool Exists(void) const
Check if directory "dirname" exists.
Definition: ncbifile.hpp:4004
CRef< CScope > m_Scope
Definition: seqtest.cpp:67
CRef< CObjectManager > m_ObjMgr
Definition: seqtest.cpp:66
CDir –.
Definition: ncbifile.hpp:1665
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
struct config config
static wxAcceleratorEntry entries[3]
const_iterator find(const key_type &key) const
Definition: map.hpp:293
const string & Get(const string &name, bool *found=NULL) const
Get environment value by name.
Definition: ncbienv.cpp:108
CRange< TSeqPos > TSeqRange
typedefs for sequence ranges
Definition: range.hpp:419
#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:198
CNcbiEnvironment & SetEnvironment(void)
Get a non-const copy of the application's cached environment.
Definition: ncbiapp.hpp:691
Try standard log file (app.name + ".log") in /log/, use stderr on failure.
Definition: ncbidiag.hpp:1763
The Object manager core.
Magic spell ;-) needed for some weird compilers... very empiric.
const TCgiEntries & GetEntries(void) const
Get a set of entries(decoded) received from the client.
Definition: ncbicgi.hpp:1154
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1041
CScope –.
Definition: scope.hpp:90
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
void SetFarPlane(GLdouble)
Definition: glcamera.cpp:125
void SetNearPlane(GLdouble)
Definition: glcamera.cpp:114
virtual void Render(CCgiContext &ctx)
Definition: seqtest.cpp:99
static CS_CONTEXT * ctx
Definition: ct_dynamic.c:24
virtual void Init()
This method is called on the CGI application initialization – before starting to process a HTTP requ...
Definition: seqtest.cpp:84
CGlCamera m_Camera
Definition: seqtest.cpp:64
TObjectType & GetObject(void)
Get object.
Definition: ncbiobj.hpp:1002
void SetFieldOfView(GLdouble f)
Definition: glcamera.cpp:180
CRef< CSeqGraphicDataSource > m_DataSource
Definition: seqtest.cpp:70
void ZoomOnRange(const TModelRange &range, bool round_to_base=false)
zoom to the given range.
#define _TRACE(message)
Definition: ncbidbg.hpp:120
static int result
Definition: cursor5.c:11
int main(int argc, const char *argv[])
Definition: seqtest.cpp:183
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:768
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:531
const CCgiRequest & GetRequest(void) const
Definition: cgictx.hpp:374
Modified on Tue Jan 16 15:48:13 2018 by modify_doxy.py rev. 546573