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

Go to the SVN repository for this file.

1 /* $Id: assembly_tracking_panel.cpp 47029 2022-05-16 18:09:35Z asztalos $
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: Colleen Bollin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 ////@begin includes
32 ////@end includes
33 
34 #include <objects/seq/Seq_inst.hpp>
35 #include <objects/seq/Seq_hist.hpp>
45 
48 
49 #include <wx/filedlg.h>
51 
52 #include <wx/sizer.h>
53 #include <wx/button.h>
54 #include <wx/msgdlg.h>
55 
56 ////@begin XPM images
57 ////@end XPM images
58 
59 
62 
63 /*!
64  * CAssemblyTrackingPanel type definition
65  */
66 
67 IMPLEMENT_DYNAMIC_CLASS( CAssemblyTrackingPanel, wxPanel )
68 
69 
70 /*!
71  * CAssemblyTrackingPanel event table definition
72  */
73 
74 BEGIN_EVENT_TABLE( CAssemblyTrackingPanel, wxPanel )
75 
76 ////@begin CAssemblyTrackingPanel event table entries
77  EVT_BUTTON( ID_EXPORT_LIST_BTN, CAssemblyTrackingPanel::OnExportListBtnClick )
78 
79  EVT_BUTTON( ID_EXPORT_INTERVALS_BTN, CAssemblyTrackingPanel::OnExportIntervalsBtnClick )
80 
81  EVT_BUTTON( ID_IMPORT_INTERVALS_BTN, CAssemblyTrackingPanel::OnImportIntervalsBtnClick )
82 
83  EVT_BUTTON( ID_POPULATE_BTN, CAssemblyTrackingPanel::OnPopulateBtnClick )
84 
85 ////@end CAssemblyTrackingPanel event table entries
86 
88 
89 
90 /*!
91  * CAssemblyTrackingPanel constructors
92  */
93 
95 {
96  Init();
97 }
98 
99 CAssemblyTrackingPanel::CAssemblyTrackingPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
100 {
101  Init();
102  Create(parent, id, pos, size, style);
103 }
104 
105 
106 /*!
107  * CAssemblyTrackingPanel creator
108  */
109 
110 bool CAssemblyTrackingPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
111 {
112 ////@begin CAssemblyTrackingPanel creation
113  wxPanel::Create( parent, id, pos, size, style );
114 
115  CreateControls();
116  if (GetSizer())
117  {
118  GetSizer()->SetSizeHints(this);
119  }
120  Centre();
121 ////@end CAssemblyTrackingPanel creation
122  return true;
123 }
124 
125 
126 /*!
127  * CAssemblyTrackingPanel destructor
128  */
129 
131 {
132 ////@begin CAssemblyTrackingPanel destruction
133 ////@end CAssemblyTrackingPanel destruction
134 }
135 
136 
137 /*!
138  * Member initialisation
139  */
140 
142 {
143 ////@begin CAssemblyTrackingPanel member initialisation
146 ////@end CAssemblyTrackingPanel member initialisation
147  m_User.Reset(NULL);
148  m_Seq.Reset(NULL);
149 }
150 
151 
152 /*!
153  * Control creation for CAssemblyTrackingPanel
154  */
155 
157 {
158 ////@begin CAssemblyTrackingPanel content construction
159  CAssemblyTrackingPanel* itemPanel1 = this;
160 
161  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
162  itemPanel1->SetSizer(itemBoxSizer2);
163 
164  m_AccessionsPanel = new CAssemblyTrackingListPanel( itemPanel1, ID_WINDOW3, wxDefaultPosition, wxSize(100, 100), wxSIMPLE_BORDER );
165  itemBoxSizer2->Add(m_AccessionsPanel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
166 
167  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
168  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
169 
170  wxButton* itemButton5 = new wxButton( itemPanel1, ID_EXPORT_LIST_BTN, _("Export TPA Accession List"), wxDefaultPosition, wxDefaultSize, 0 );
171  itemBoxSizer4->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
172 
173  wxButton* itemButton6 = new wxButton( itemPanel1, ID_EXPORT_INTERVALS_BTN, _("Export Interval Table"), wxDefaultPosition, wxDefaultSize, 0 );
174  itemBoxSizer4->Add(itemButton6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
175 
176  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
177  itemBoxSizer2->Add(itemBoxSizer7, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
178 
179  wxButton* itemButton8 = new wxButton( itemPanel1, ID_IMPORT_INTERVALS_BTN, _("Import Interval Table"), wxDefaultPosition, wxDefaultSize, 0 );
180  itemBoxSizer7->Add(itemButton8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
181 
182  m_PopulateBtn = new wxButton( itemPanel1, ID_POPULATE_BTN, _("Populate Intervals from Assembly Alignment"), wxDefaultPosition, wxDefaultSize, 0 );
183  itemBoxSizer7->Add(m_PopulateBtn, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
184 
185  itemBoxSizer2->Add(380, 1, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 0);
186 
187 ////@end CAssemblyTrackingPanel content construction
188  m_PopulateBtn->Show(false);
189 }
190 
191 
192 /*!
193  * Should we show tooltips?
194  */
195 
197 {
198  return true;
199 }
200 
201 /*!
202  * Get bitmap resources
203  */
204 
205 wxBitmap CAssemblyTrackingPanel::GetBitmapResource( const wxString& name )
206 {
207  // Bitmap retrieval
208 ////@begin CAssemblyTrackingPanel bitmap retrieval
209  wxUnusedVar(name);
210  return wxNullBitmap;
211 ////@end CAssemblyTrackingPanel bitmap retrieval
212 }
213 
214 /*!
215  * Get icon resources
216  */
217 
218 wxIcon CAssemblyTrackingPanel::GetIconResource( const wxString& name )
219 {
220  // Icon retrieval
221 ////@begin CAssemblyTrackingPanel icon retrieval
222  wxUnusedVar(name);
223  return wxNullIcon;
224 ////@end CAssemblyTrackingPanel icon retrieval
225 }
226 
227 
228 /*!
229  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_EXPORT_LIST_BTN
230  */
231 
232 void CAssemblyTrackingPanel::OnExportListBtnClick( wxCommandEvent& event )
233 {
234  TransferDataFromWindow();
236  if (!table || !table->IsSetColumns() || !table->GetColumns()[0]->IsSetData() || table->GetColumns()[0]->GetData().GetSize() == 0) {
237  wxMessageBox(wxT("No accessions listed"), wxT("Error"),
238  wxOK | wxICON_ERROR, this);
239  return;
240  }
241  wxFileDialog table_save_file(this, wxT("Select a file"), wxEmptyString, wxEmptyString, wxT("*.*"),
242  wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
243 
244  if (table_save_file.ShowModal() == wxID_OK)
245  {
246  wxString path = table_save_file.GetPath();
247  wxString name = table_save_file.GetFilename();
248 
249  name.Trim(false);
250  name.Trim(true);
251 
252  if (name.IsEmpty())
253  {
254  wxMessageBox(wxT("Please, select file name"), wxT("Error"),
255  wxOK | wxICON_ERROR, this);
256  return;
257  }
258 
259  if (!SaveTableRowAsListFile(ToStdString(path), table, 0)) {
260  wxMessageBox(wxT("Cannot open file ")+ path, wxT("Error"),
261  wxOK | wxICON_ERROR, this);
262  }
263  }
264 
265 }
266 
267 
268 /*!
269  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_EXPORT_INTERVALS_BTN
270  */
271 
273 {
274  TransferDataFromWindow();
276  if (!table) {
277  wxMessageBox(wxT("No accessions listed"), wxT("Error"),
278  wxOK | wxICON_ERROR, this);
279  return;
280  }
281  wxFileDialog table_save_file(this, wxT("Select a file"), wxEmptyString, wxEmptyString, wxT("*.*"),
282  wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
283 
284  if (table_save_file.ShowModal() == wxID_OK)
285  {
286  wxString path = table_save_file.GetPath();
287  wxString name = table_save_file.GetFilename();
288 
289  name.Trim(false);
290  name.Trim(true);
291 
292  if (name.IsEmpty())
293  {
294  wxMessageBox(wxT("Please, select file name"), wxT("Error"),
295  wxOK | wxICON_ERROR, this);
296  return;
297  }
298  if (!SaveTableFile(ToStdString(path), table, false)) {
299  wxMessageBox(wxT("Cannot open file ")+ path, wxT("Error"),
300  wxOK | wxICON_ERROR, this);
301  }
302  }
303 
304 }
305 
306 
307 /*!
308  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_IMPORT_INTERVALS_BTN
309  */
310 
312 {
313  wxFileDialog table_file(this, wxT("Select a file"), wxEmptyString, wxEmptyString, wxT("*.*"),
314  wxFD_OPEN|wxFD_FILE_MUST_EXIST);
315 
316  if (table_file.ShowModal() == wxID_OK)
317  {
318  wxString path = table_file.GetPath();
319  wxString name = table_file.GetFilename();
321  if (table) {
322  CRef<CUser_object> new_obj(new CUser_object());
323  new_obj->SetType().SetStr("TpaAssembly");
325  SetUser_object(new_obj);
326  } else {
327  wxMessageBox(wxT("Unable to read table"), wxT("Error"),
328  wxOK | wxICON_ERROR, this);
329  }
330  }
331 }
332 
333 
334 /*!
335  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_POPULATE_BTN
336  */
337 
338 void CAssemblyTrackingPanel::OnPopulateBtnClick( wxCommandEvent& event )
339 {
340  if (!m_Seq || !m_Seq->IsSetInst() || !m_Seq->GetInst().IsSetHist()) {
341  return;
342  }
343  if (!m_User) {
344  m_User.Reset(new CUser_object());
345  }
346  if (m_User->IsSetData()) {
347  m_User->ResetData();
348  }
349 
350  ITERATE(CSeq_hist::TAssembly, ait, m_Seq->GetInst().GetHist().GetAssembly()) {
351  if ((*ait)->IsSetSegs() && (*ait)->GetSegs().IsDenseg()
352  && (*ait)->GetSegs().GetDenseg().IsSetDim() && (*ait)->GetSegs().GetDenseg().GetDim() > 1) {
353  // find start and stop for second sequence
354  try {
355  CRef<CSeq_interval> interval0 = (*ait)->GetSegs().GetDenseg().CreateRowSeq_interval(0);
356  CRef<CSeq_interval> interval1 = (*ait)->GetSegs().GetDenseg().CreateRowSeq_interval(1);
357  if (interval0 && interval1) {
358  string accession = "";
359  interval1->GetId().GetLabel(&accession,CSeq_id::eContent);
360  TSeqPos from = interval0->GetFrom();
361  TSeqPos to = interval0->GetTo();
362  if (interval1->IsSetStrand() && interval1->GetStrand() == eNa_strand_minus)
363  swap(from, to);
365  m_User->SetData().push_back(new_field);
366  }
367  } catch(const CException&) {} catch (const exception&) {}
368  }
369  }
371 }
372 
373 
375 {
376  if (user) {
377  m_User.Reset(new CUser_object());
378  m_User->Assign(*user);
379  } else {
380  m_User.Reset(NULL);
381  }
382 
384 }
385 
386 
388 {
389  TransferDataFromWindow();
391  CRef<CUser_object> user(new CUser_object());
392 
393  if (m_User) {
394  user->Assign(*m_User);
395  }
396 
397  user->SetType().SetStr("TpaAssembly");
398 
399  // remove previous fields
401  return user;
402 }
403 
404 
406 {
407  if (seq) {
408  m_Seq.Reset(seq);
409  } else {
410  m_Seq.Reset(NULL);
411  }
412  if (m_Seq && m_Seq->IsSetInst() && m_Seq->GetInst().IsSetHist()) {
413  m_PopulateBtn->Show(true);
414  } else {
415  m_PopulateBtn->Show(false);
416  }
417 }
418 
419 
420 void CAssemblyTrackingPanel::ChangeSeqdesc(const objects::CSeqdesc& desc)
421 {
422  m_User.Reset(new CUser_object());
423  m_User->Assign(desc.GetUser());
424 
426  TransferDataToWindow();
428 }
429 
430 
431 void CAssemblyTrackingPanel::UpdateSeqdesc(objects::CSeqdesc& desc)
432 {
433  TransferDataFromWindow();
435  desc.SetUser(*user);
436 }
437 
438 
440 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
USING_SCOPE(objects)
static bool ShowToolTips()
Should we show tooltips?
void OnImportIntervalsBtnClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_IMPORT_INTERVALS_BTN
virtual void UpdateSeqdesc(objects::CSeqdesc &desc)
CAssemblyTrackingListPanel * m_AccessionsPanel
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void Init()
Initialises member variables.
CRef< objects::CUser_object > GetUser_object()
virtual void ChangeSeqdesc(const objects::CSeqdesc &desc)
void SetUser_object(CRef< objects::CUser_object > user)
void OnExportListBtnClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_EXPORT_LIST_BTN
void SetBioseq(CConstRef< objects::CBioseq > seq)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CConstRef< objects::CBioseq > m_Seq
void OnExportIntervalsBtnClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_EXPORT_INTERVALS_BTN
CRef< objects::CUser_object > m_User
bool Create(wxWindow *parent, wxWindowID id=ID_CASSEMBLYTRACKINGPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void CreateControls()
Creates the controls and sizers.
void OnPopulateBtnClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_POPULATE_BTN
static CRef< objects::CUser_field > s_CreateTPAAssemblyField(const string &accession, int from, int to)
virtual bool TransferDataToWindow()
void SetUser_object(CRef< objects::CUser_object > user)
void PopulateFields(objects::CUser_object &user_obj)
virtual bool TransferDataFromWindow()
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
Definition: ncbimisc.hpp:1508
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
void GetLabel(string *label, ELabelType type=eDefault, TLabelFlags flags=fLabel_Default) const
Append a label for this Seq-id to the supplied string.
Definition: Seq_id.cpp:2039
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:573
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
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
void SetType(TType &value)
Assign a value to Type data member.
const TId & GetId(void) const
Get the Id member data.
TFrom GetFrom(void) const
Get the From member data.
bool IsSetStrand(void) const
Check if a value has been assigned to Strand data member.
TStrand GetStrand(void) const
Get the Strand member data.
TTo GetTo(void) const
Get the To member data.
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
list< CRef< CSeq_align > > TAssembly
Definition: Seq_hist_.hpp:248
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
bool SaveTableFile(wxWindow *parent, wxString &save_file_dir, wxString &save_file_name, CRef< objects::CSeq_table > values_table)
CRef< objects::CSeq_table > SeqTableFromAssemblyFields(const objects::CUser_object &obj)
CRef< objects::CSeq_table > ReadTabDelimitedTable(const wxString &filename, bool read_header)
bool SaveTableRowAsListFile(const string &save_file_name, CRef< objects::CSeq_table > values_table, int col)
void AddAssemblyUserFieldsFromSeqTable(CRef< objects::CUser_object > obj, CRef< objects::CSeq_table > table)
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sat Dec 09 04:45:57 2023 by modify_doxy.py rev. 669887