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

Go to the SVN repository for this file.

1 /* $Id: hit_matrix_demo_dlg.cpp 46042 2021-01-21 17:33:25Z grichenk $
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: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbistd.hpp>
34 #include <corelib/ncbitime.hpp>
35 
36 #include "hit_matrix_demo_dlg.hpp"
37 
40 
42 
44 
45 #include <serial/objistr.hpp>
46 #include <serial/serial.hpp>
47 
48 
49 #include <wx/msgdlg.h>
50 #include <wx/statline.h>
51 #include <wx/sizer.h>
52 #include <wx/textctrl.h>
53 #include <wx/button.h>
54 #include <wx/bitmap.h>
55 #include <wx/icon.h>
56 
57 
60 
61 
62 IMPLEMENT_DYNAMIC_CLASS( CHitMatrixDemoDlg, wxDialog )
63 
64 BEGIN_EVENT_TABLE( CHitMatrixDemoDlg, wxDialog )
65 
66 ////@begin CHitMatrixDemoDlg event table entries
68 
70 
72 
73  EVT_BUTTON( wxID_CLOSE, CHitMatrixDemoDlg::OnCloseClick )
74 
75 ////@end CHitMatrixDemoDlg event table entries
77 
78 
80 {
81  Init();
82 }
83 
84 
85 CHitMatrixDemoDlg::CHitMatrixDemoDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
86 {
87  Init();
88  Create(parent, id, caption, pos, size, style);
89 }
90 
91 
92 bool CHitMatrixDemoDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
93 {
94 ////@begin CHitMatrixDemoDlg creation
95  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
96  wxDialog::Create( parent, id, caption, pos, size, style );
97 
99  Centre();
100 ////@end CHitMatrixDemoDlg creation
101  return true;
102 }
103 
104 
106 {
107 ////@begin CHitMatrixDemoDlg destruction
108 ////@end CHitMatrixDemoDlg destruction
109 }
110 
111 
113 {
114 ////@begin CHitMatrixDemoDlg member initialisation
116  m_AccInput = NULL;
117  m_FileInput = NULL;
118 ////@end CHitMatrixDemoDlg member initialisation
119 
120  if ( !m_ObjMgr ) {
123 
124  m_Scope.Reset(new CScope(*m_ObjMgr));
125  m_Scope->AddDefaults();
126  }
127 }
128 
129 #define DEF_FILE "E:\\Users\\Yazhuk\\Gbench Data\\blast.asn"
130 
131 
133 {
134 ////@begin CHitMatrixDemoDlg content construction
135  CHitMatrixDemoDlg* itemDialog1 = this;
136 
137  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
138  itemDialog1->SetSizer(itemBoxSizer2);
139 
140  m_MatrixWidget = new CHitMatrixWidget( itemDialog1, ID_WIDGET, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
141  itemBoxSizer2->Add(m_MatrixWidget, 1, wxGROW|wxALL, 5);
142 
143  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
144  itemBoxSizer2->Add(itemBoxSizer4, 0, wxGROW|wxALL, 5);
145 
146  wxFlexGridSizer* itemFlexGridSizer5 = new wxFlexGridSizer(0, 2, 0, 0);
147  itemBoxSizer4->Add(itemFlexGridSizer5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 0);
148 
149  m_AccInput = new wxTextCtrl( itemDialog1, ID_ACC_TEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
150  m_AccInput->SetMaxLength(20);
151  m_AccInput->SetHelpText(_("Enter Accession"));
153  m_AccInput->SetToolTip(_("Enter Accession"));
154  itemFlexGridSizer5->Add(m_AccInput, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
155 
156  wxButton* itemButton7 = new wxButton( itemDialog1, ID_ACC, _("Load Accession"), wxDefaultPosition, wxDefaultSize, 0 );
157  itemFlexGridSizer5->Add(itemButton7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
158 
159  m_FileInput = new wxTextCtrl( itemDialog1, ID_FILE_TEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
160  m_FileInput->SetMaxLength(256);
161  m_FileInput->SetHelpText(_("Enter asn file name"));
163  m_FileInput->SetToolTip(_("Enter asn file name"));
164  itemFlexGridSizer5->Add(m_FileInput, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
165 
166  wxButton* itemButton9 = new wxButton( itemDialog1, ID_FILE, _("Load File"), wxDefaultPosition, wxDefaultSize, 0 );
167  itemFlexGridSizer5->Add(itemButton9, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
168 
169  itemFlexGridSizer5->AddGrowableCol(0);
170 
171  wxStaticLine* itemStaticLine10 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
172  itemBoxSizer4->Add(itemStaticLine10, 0, wxGROW|wxALL, 5);
173 
174  wxButton* itemButton11 = new wxButton( itemDialog1, wxID_CLOSE, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
175  itemBoxSizer4->Add(itemButton11, 0, wxALIGN_BOTTOM|wxALL, 5);
176 
177 ////@end CHitMatrixDemoDlg content construction
179  m_FileInput->SetValue(ToWxString(DEF_FILE));
180 }
181 
182 
184 {
185  return true;
186 }
187 
188 
189 wxBitmap CHitMatrixDemoDlg::GetBitmapResource( const wxString& name )
190 {
191  // Bitmap retrieval
192 ////@begin CHitMatrixDemoDlg bitmap retrieval
193  wxUnusedVar(name);
194  return wxNullBitmap;
195 ////@end CHitMatrixDemoDlg bitmap retrieval
196 }
197 
198 
199 wxIcon CHitMatrixDemoDlg::GetIconResource( const wxString& name )
200 {
201  // Icon retrieval
202 ////@begin CHitMatrixDemoDlg icon retrieval
203  wxUnusedVar(name);
204  return wxNullIcon;
205 ////@end CHitMatrixDemoDlg icon retrieval
206 }
207 
208 
209 
210 void CHitMatrixDemoDlg::OnCloseWindow(wxCloseEvent& event)
211 {
212  Destroy();
213 }
214 
215 
216 
217 void CHitMatrixDemoDlg::OnCloseClick( wxCommandEvent& event )
218 {
219  Close();
220 }
221 
222 
223 
224 void CHitMatrixDemoDlg::OnAccClick( wxCommandEvent& event )
225 {
226  CSeq_id id;
227 
228  string acc = ToStdString(m_AccInput->GetValue());
229  try {
230  id.Set(acc);
231  }
232  catch (CSeqIdException&) {
233  string msg("Accession '");
234  msg += acc + " not recognized as a valid accession";
235  wxMessageBox(ToWxString(msg), wxT("Cannot load accesion"),
236  wxOK | wxICON_ERROR);
237  return;
238  }
239 
240  // retrieve our sequence
241  CBioseq_Handle handle = m_Scope->GetBioseqHandle(id);
242  if(handle) {
244 
245  m_Builder.Init(*m_Scope, handle);
247 
248  if(m_DataSource->SelectDefaultIds()) {
250  }
251  } else {
252  string msg("Can't find sequence for accession '");
253  msg += acc + "'";
254  wxMessageBox(ToWxString(msg), wxT("Cannot load accesion"),
255  wxOK | wxICON_ERROR);
256  return;
257  }
258 }
259 
260 
262 
263 
264 /// loads a serializable object of type T
265 template <class T>
266  bool LoadObject(const wxString& filename, CScope& scope, CHitMatrixDSBuilder& builder)
267 {
268  try {
269  CNcbiIfstream istr(filename.fn_str());
270  unique_ptr<CObjectIStream> os(CObjectIStream::Open(eSerial_AsnText, istr));
271 
272  CRef<T> obj(new T());
273  *os >> *obj;
274 
275  builder.Init(scope, *obj);
276  return true;
277  } catch(CException& /*e*/) {
278  return false;
279  }
280 }
281 
282 
283 
284 void CHitMatrixDemoDlg::OnFileClick( wxCommandEvent& event )
285 {
287 
288  wxString filename = m_FileInput->GetValue();
289  try {
290  bool ok = LoadObject<CSeq_align>(filename, *m_Scope, m_Builder);
291  if( ! ok) {
292  ok = LoadObject<CSeq_annot>(filename, *m_Scope, m_Builder);
293  }
294  if( ! ok) {
295  ok = LoadObject<CBioseq>(filename, *m_Scope, m_Builder);
296  }
297  if(ok) {
299 
300  if(m_DataSource->SelectDefaultIds()) {
302  }
303  } else {
304  wxMessageBox(wxT("This type of file is not supported"),
305  wxT("Error loading file."),
306  wxOK | wxICON_ERROR);
307  }
308  } catch(CException& e) {
309  LOG_POST(Error << e.ReportAll());
310  wxString s = ToWxString(e.GetMsg());
311  wxMessageBox(s, wxT("Error loading file."), wxOK | wxICON_ERROR);
312  }
313 }
314 
315 
CBioseq_Handle –.
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:366
virtual void Create()
creates controls and performs basic initialization
CHitMatrixDSBuilder.
CIRef< IHitMatrixDataSource > CreateDataSource()
void Init(objects::CScope &scope, const objects::CSeq_align &align)
initial data set from which an alignment will be build
CHitMatrixDemoDlg()
Constructors.
void OnCloseClick(wxCommandEvent &event)
void OnFileClick(wxCommandEvent &event)
CHitMatrixWidget * m_MatrixWidget
wxBitmap GetBitmapResource(const wxString &name)
CIRef< IHitMatrixDataSource > m_DataSource
void OnAccClick(wxCommandEvent &event)
void OnCloseWindow(wxCloseEvent &event)
~CHitMatrixDemoDlg()
Destructor.
static bool ShowToolTips()
Should we show tooltips?
CHitMatrixDSBuilder m_Builder
bool Create(wxWindow *parent, wxWindowID id=10000, const wxString &caption=_("CHitMatrixDemoDlg"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(600, 600), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|0x1000)
Creation.
CRef< CObjectManager > m_ObjMgr
void CreateControls()
Creates the controls and sizers.
void Init()
Initialises member variables.
wxIcon GetIconResource(const wxString &name)
class CHitMatrixWidget
virtual void SetDataSource(IHitMatrixDataSource *p_ds)
CScope –.
Definition: scope.hpp:92
CSeqIdException –.
Definition: Seq_id.hpp:1001
vector< CConstRef< objects::CSeq_align > > TAlignVector
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define ID_WIDGET
#define ID_ACC_TEXT
#define ID_ACC
#define ID_FILE_TEXT
#define ID_FILE
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define T(s)
Definition: common.h:230
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
#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
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
string ReportAll(TDiagPostFlags flags=eDPF_Exception) const
Report all exceptions.
Definition: ncbiexpt.cpp:370
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
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
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
USING_SCOPE(objects)
#define DEF_FILE
IHitMatrixDataSource::TAlignVector TAlignVector
bool LoadObject(const wxString &filename, CScope &scope, CHitMatrixDSBuilder &builder)
loads a serializable object of type T
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
Defines: CTimeFormat - storage class for time format.
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Wed Jun 12 11:16:12 2024 by modify_doxy.py rev. 669887