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

Go to the SVN repository for this file.

1 /////////////////////////////////////////////////////////////////////////////
2 // Name: demo_align_table_frame.cpp
3 // Purpose:
4 // Author: Yury Voronov
5 // Modified by:
6 // Created: 17/01/2008 21:42:34
7 // RCS-ID:
8 // Copyright:
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11 
12 #include <ncbi_pch.hpp>
13 
18 #include <gui/objutils/utils.hpp>
19 
20 #include <serial/serial.hpp>
21 #include <serial/objistr.hpp>
22 #include <serial/iterator.hpp>
23 
28 #include <objmgr/scope.hpp>
29 
30 #include <objmgr/align_ci.hpp>
31 #include <objmgr/seq_vector.hpp>
34 
36 
39 
40 /*!
41  * CwxDemoAlignTableFrame type definition
42  */
43 
45 
46 
47 /*!
48  * CwxDemoAlignTableFrame event table definition
49  */
50 
51 BEGIN_EVENT_TABLE( CwxDemoAlignTableFrame, wxFrame )
52 
53 ////@begin CwxDemoAlignTableFrame event table entries
55 
57 
59 
61 
62 ////@end CwxDemoAlignTableFrame event table entries
63 
65 
66 
67 /*!
68  * CwxDemoAlignTableFrame constructors
69  */
70 
72 {
73  Init();
74 }
75 
76 CwxDemoAlignTableFrame::CwxDemoAlignTableFrame( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
77 {
78  Init();
79  Create( parent, id, caption, pos, size, style );
80 }
81 
82 
83 /*!
84  * CwxDemoAlignTableFrame creator
85  */
86 
87 bool CwxDemoAlignTableFrame::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
88 {
89 ////@begin CwxDemoAlignTableFrame creation
90  wxFrame::Create( parent, id, caption, pos, size, style );
91 
93  Centre();
94 ////@end CwxDemoAlignTableFrame creation
95  return true;
96 }
97 
98 
99 /*!
100  * CwxDemoAlignTableFrame destructor
101  */
102 
104 {
105 ////@begin CwxDemoAlignTableFrame destruction
106 ////@end CwxDemoAlignTableFrame destruction
107 }
108 
109 
110 /*!
111  * Member initialisation
112  */
113 
115 {
116 ////@begin CwxDemoAlignTableFrame member initialisation
118  m_Segments = true;
120 ////@end CwxDemoAlignTableFrame member initialisation
121 
123 
125  m_Scope->AddDefaults();
126 }
127 
128 
129 /*!
130  * Control creation for CwxDemoAlignTableFrame
131  */
132 
134 {
135 ////@begin CwxDemoAlignTableFrame content construction
136  CwxDemoAlignTableFrame* itemFrame1 = this;
137 
138  wxMenuBar* menuBar = new wxMenuBar;
139  wxMenu* itemMenu3 = new wxMenu;
140  itemMenu3->Append(wxID_OPEN, _("&Open...\tCtrl+O"), wxEmptyString, wxITEM_NORMAL);
141  itemMenu3->Append(wxID_LOAD, _("&Load...\tCtrl+L"), wxEmptyString, wxITEM_NORMAL);
142  itemMenu3->AppendSeparator();
143  itemMenu3->Append(wxID_EXIT, _("E&xit\tAlt+F4"), wxEmptyString, wxITEM_NORMAL);
144  menuBar->Append(itemMenu3, _("File"));
145  wxMenu* itemMenu8 = new wxMenu;
146  itemMenu8->Append(ID_SEGMENTS, _("Segments"), wxEmptyString, wxITEM_RADIO);
147  itemMenu8->Check(ID_SEGMENTS, true);
148  itemMenu8->Append(ID_SPANS, _("Spans"), wxEmptyString, wxITEM_RADIO);
149  menuBar->Append(itemMenu8, _("View"));
150  wxMenu* itemMenu11 = new wxMenu;
151  itemMenu11->Append(wxID_ABOUT, _("About..."), wxEmptyString, wxITEM_NORMAL);
152  menuBar->Append(itemMenu11, _("Help"));
153  itemFrame1->SetMenuBar(menuBar);
154 
155  m_AlignTableCtrl = new wxListCtrl( itemFrame1, ID_ALIGNTABLE, wxDefaultPosition, wxSize(100, 100), wxLC_REPORT|wxLC_VIRTUAL );
156 
157 ////@end CwxDemoAlignTableFrame content construction
158 
159  delete m_AlignTableCtrl;
160  m_AlignTableCtrl = new CAlnTableWidget( itemFrame1, ID_ALIGNTABLE );
161  m_Segments = true;
162 }
163 
164 bool CwxDemoAlignTableFrame::LoadAccession( const wxString& anAccession ){
165 
166  CRef<CSeq_id> id;
167  id.Reset( new CSeq_id() );
168 
169  string accession( anAccession.c_str() );
170 
171  try {
172  id->Set( accession );
173 
174  } catch( CSeqIdException& ){
175  string msg("Accession '");
176  msg += anAccession;
177  msg += "' not recognized as a valid accession";
178 
179  wxMessageDialog dlg(
180  NULL, wxT("Unhandled Accession"),
181  msg, wxOK | wxICON_ERROR
182  );
183  dlg.ShowModal();
184 
185  return false;
186  }
187 
188  CRef<CScope> scope( new CScope(*m_ObjectManager) );
189  scope->AddDefaults();
190 
191  // retrieve our sequence
192  CBioseq_Handle handle = scope->GetBioseqHandle( *id );
193  if( !handle ){
194  string msg("Can't find sequence for accession '");
195  msg += anAccession;
196  msg += "'";
197  wxMessageDialog dlg(
198  NULL, wxT("Sequence Not Found"),
199  msg, wxOK | wxICON_ERROR
200  );
201  dlg.ShowModal();
202 
203  return false;
204  }
205 
206  CRef<CSeq_entry> seq( new CSeq_entry() );
207  seq->SetSeq( const_cast<CBioseq&>( *handle.GetCompleteBioseq() ) );
208 
209  scope->AddTopLevelSeqEntry(*seq);
210 
211  m_Seq_id = id;
212  m_Scope = scope;
213 
214  InitData();
215  /*
216  CRef<CSeq_loc> loc;
217  loc.Reset( new CSeq_loc( CSeq_loc::e_Whole ) );
218  loc->SetWhole( *id );
219 
220  if( m_Segments ){
221  ((CAlnTableWidget*)m_AlignTableCtrl)->SetDataSource(*new CAlnTableDS(*scope, *loc));
222  } else {
223  vector< CConstRef<CSeq_align> > align_vec;
224  CAlign_CI align_iter(*scope, *loc);
225  for ( ; align_iter; ++align_iter) {
226  const CSeq_align& align = align_iter.GetOriginalSeq_align();
227  CConstRef<CSeq_align> ref( &align );
228  align_vec.push_back( ref );
229  }
230 
231  CAlnMultiDSBuilder builder;
232  builder.Init( *scope, align_vec );
233  builder.SetSyncCreate( true );
234  builder.PreCreateDataSource( false );
235 
236  CRef<IAlnMultiDataSource> dataSource = builder.CreateDataSource();
237 
238  ((CAlnSpanWidget*)m_AlignTableCtrl)->SetModel( new CAlnSpanVertModel( *dataSource ), true );
239  }
240  */
241 
242  return true;
243 }
244 
245 bool CwxDemoAlignTableFrame::LoadFile( const wxString& aFileName )
246 {
247  CRef<CSeq_entry> seq( new CSeq_entry() );
248 
249  try {
250  CNcbiIfstream istr(aFileName.fn_str());
251  unique_ptr<CObjectIStream> os( CObjectIStream::Open( eSerial_AsnText, istr ) );
252 
253  *os >> *seq;
254 
255  } catch( CException& /*e*/) {
256 
257  string msg("This type of file is not supported");
258  wxMessageDialog dlg(
259  NULL, wxT("Error loading file"),
260  msg, wxOK | wxICON_ERROR
261  );
262  dlg.ShowModal();
263 
264  return false;
265  }
266 
267  CRef<CScope> scope( new CScope(*m_ObjectManager) );
268  scope->AddDefaults();
269  scope->AddTopLevelSeqEntry(*seq);
270 
271  CRef<CSeq_id> id;
272  id.Reset( new CSeq_id() );
273 
274  if( seq->IsSeq() ){
275  CBioseq& bioseq = seq->SetSeq();
276  if( bioseq.CanGetId() ){
277  list< CRef< CSeq_id > >& id_list = bioseq.SetId();
278  if( !id_list.empty() ){
279  id.Reset( id_list.front() );
280  }
281  }
282  }
283 
284  m_Seq_id = id;
285  m_Scope = scope;
286 
287  InitData();
288 
289  return true;
290 }
291 
293 
294 
295  CRef<CSeq_loc> loc;
296  loc.Reset( new CSeq_loc( CSeq_loc::e_Whole ) );
297  loc->SetWhole( *m_Seq_id );
298 
299  CRef<CScope> scope = m_Scope;
300 
301  if( m_Segments ){
302  ((CAlnTableWidget*)m_AlignTableCtrl)->SetDataSource(*new CAlnTableDS(*scope, *loc));
303  } else {
304  vector< CConstRef<CSeq_align> > align_vec;
305  CAlign_CI align_iter(*scope, *loc);
306  for ( ; align_iter; ++align_iter) {
307  const CSeq_align& align = align_iter.GetOriginalSeq_align();
308  CConstRef<CSeq_align> ref( &align );
309  align_vec.push_back( ref );
310  }
311 
312  CAlnMultiDSBuilder builder;
313  builder.Init( *scope, align_vec );
314  builder.SetSyncCreate( true );
315  builder.PreCreateDataSource( false );
316 
317  CRef<IAlnMultiDataSource> dataSource = builder.CreateDataSource();
318 
319  IwxTableModel* model = ((CAlnSpanWidget*)m_AlignTableCtrl)->GetModel();
320  ((CAlnSpanWidget*)m_AlignTableCtrl)->RemoveModel();
321  delete model;
322 
323  ((CAlnSpanWidget*)m_AlignTableCtrl)->SetAlnModel( *(new CAlnSpanVertModel( *dataSource )) );
324  }
325 }
326 
327 /*!
328  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_OPEN
329  */
330 
331 void CwxDemoAlignTableFrame::OnOpenClick( wxCommandEvent& event )
332 {
333  wxFileDialog dlg(
334  this,
335  wxT("Choose a data file"), wxEmptyString, wxEmptyString,
336  wxT("ASN files (*.asn)|*.asn"), wxFD_OPEN | wxFD_FILE_MUST_EXIST
337  );
338 
339  if( dlg.ShowModal() == wxID_OK ){
340  LoadFile( dlg.GetPath() );
341  }
342 }
343 
344 
345 /*!
346  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_LOAD
347  */
348 
349 void CwxDemoAlignTableFrame::OnLoadClick( wxCommandEvent& event )
350 {
351  // Show Choose/Accession dialog
352  wxTextEntryDialog dlg(
353  this,
354  _("Please enter an accession from GenBank"), _("Enter accession"),
355  wxEmptyString,
356  wxOK | wxCANCEL
357  );
358 
359  if( dlg.ShowModal() == wxID_OK ){
360  LoadAccession( dlg.GetValue() );
361  }
362 }
363 
364 
365 /*!
366  * Should we show tooltips?
367  */
368 
370 {
371  return true;
372 }
373 
374 /*!
375  * Get bitmap resources
376  */
377 
378 wxBitmap CwxDemoAlignTableFrame::GetBitmapResource( const wxString& name )
379 {
380  // Bitmap retrieval
381 ////@begin CwxDemoAlignTableFrame bitmap retrieval
382  wxUnusedVar(name);
383  return wxNullBitmap;
384 ////@end CwxDemoAlignTableFrame bitmap retrieval
385 }
386 
387 /*!
388  * Get icon resources
389  */
390 
391 wxIcon CwxDemoAlignTableFrame::GetIconResource( const wxString& name )
392 {
393  // Icon retrieval
394 ////@begin CwxDemoAlignTableFrame icon retrieval
395  wxUnusedVar(name);
396  return wxNullIcon;
397 ////@end CwxDemoAlignTableFrame icon retrieval
398 }
399 
400 
401 /*!
402  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_SEGMENTS
403  */
404 
405 void CwxDemoAlignTableFrame::OnSegmentsClick( wxCommandEvent& event )
406 {
407  RemoveChild( m_AlignTableCtrl );
408  delete m_AlignTableCtrl;
410  m_Segments = true;
411 
412  InitData();
413  m_AlignTableCtrl->SetSize( GetClientSize() );
414  Refresh();
415 }
416 
417 
418 /*!
419  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_SPANS
420  */
421 
422 void CwxDemoAlignTableFrame::OnSpansClick( wxCommandEvent& event )
423 {
424  RemoveChild( m_AlignTableCtrl );
425  delete m_AlignTableCtrl;
427  m_Segments = false;
428 
429  InitData();
430  m_AlignTableCtrl->SetSize( GetClientSize() );
431  Refresh();
432 }
433 
CAlign_CI –.
Definition: align_ci.hpp:63
void Init(objects::CScope &scope, const objects::CSeq_align &align)
initial data set from which an alignment will be build
void SetSyncCreate(bool sync)
CRef< IAlnMultiDataSource > CreateDataSource()
void PreCreateDataSource(bool sparse)
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
CScope –.
Definition: scope.hpp:92
CSeqIdException –.
Definition: Seq_id.hpp:969
Definition: Seq_entry.hpp:56
void OnOpenClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_OPEN
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void OnSegmentsClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for ID_SEGMENTS
static bool ShowToolTips()
Should we show tooltips?
void OnLoadClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_LOAD
CRef< objects::CObjectManager > m_ObjectManager
void Init()
Initialises member variables.
bool LoadAccession(const wxString &anAccName)
bool Create(wxWindow *parent, wxWindowID id=10000, const wxString &caption=_("Align Table Demo"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void OnSpansClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for ID_SPANS
void CreateControls()
Creates the controls and sizers.
bool LoadFile(const wxString &aFileName)
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
USING_SCOPE(objects)
#define ID_ALIGNTABLE
#define ID_SPANS
#define ID_SEGMENTS
#define wxID_LOAD
IMPLEMENT_CLASS(CFloatingFrame, CFloatingFrameBaseClass) const static long kFloatFrameStyle
CFloatingFrame.
#define NULL
Definition: ncbistd.hpp:225
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
void SetWhole(TWhole &v)
Definition: Seq_loc.hpp:982
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.
CSeq_entry_Handle AddTopLevelSeqEntry(CSeq_entry &top_entry, TPriority pri=kPriority_Default, EExist action=eExist_Default)
Add seq_entry, default priority is higher than for defaults or loaders Add object to the score with p...
Definition: scope.cpp:522
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
CConstRef< CBioseq > GetCompleteBioseq(void) const
Get the complete bioseq.
const CSeq_align & GetOriginalSeq_align(void) const
Get original alignment.
Definition: align_ci.cpp:225
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
@ e_Whole
whole sequence
Definition: Seq_loc_.hpp:100
bool IsSeq(void) const
Check if variant Seq is selected.
Definition: Seq_entry_.hpp:257
TSeq & SetSeq(void)
Select the variant.
Definition: Seq_entry_.cpp:108
TId & SetId(void)
Assign a value to Id data member.
Definition: Bioseq_.hpp:296
bool CanGetId(void) const
Check if it is safe to call GetId method.
Definition: Bioseq_.hpp:284
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
The Object manager core.
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
Modified on Mon Feb 26 04:02:25 2024 by modify_doxy.py rev. 669887