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

Go to the SVN repository for this file.

1 /* $Id: seqid_fix_dlg.cpp 43676 2019-08-14 14:28:05Z 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 
32 ////@begin includes
33 ////@end includes
34 #include <wx/sizer.h>
35 #include <wx/button.h>
36 #include <wx/msgdlg.h>
37 #include <wx/stattext.h>
41 
42 ////@begin XPM images
43 ////@end XPM images
44 
46 
47 /*!
48  * CSeqIdFixDlg type definition
49  */
50 
51 IMPLEMENT_DYNAMIC_CLASS( CSeqIdFixDlg, wxDialog )
52 
53 
54 /*!
55  * CSeqIdFixDlg event table definition
56  */
57 
58 BEGIN_EVENT_TABLE( CSeqIdFixDlg, wxDialog )
59 
60 ////@begin CSeqIdFixDlg event table entries
62 
63 ////@end CSeqIdFixDlg event table entries
64 
66 
67 
68 /*!
69  * CSeqIdFixDlg constructors
70  */
71 
73 {
74  Init();
75 }
76 
77 CSeqIdFixDlg::CSeqIdFixDlg( wxWindow* parent, CRef<objects::CSeq_entry> entry_to_add, CConstRef<objects::CSeq_entry> curr_entry, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
78 : m_EntryToAdd(entry_to_add), m_CurrEntry(curr_entry), m_OldIds(NULL)
79 {
80  Init();
81  Create(parent, id, caption, pos, size, style);
82 }
83 
84 
85 /*!
86  * CSeqIdFixDlg creator
87  */
88 
89 bool CSeqIdFixDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
90 {
91 ////@begin CSeqIdFixDlg creation
92  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
93  wxDialog::Create( parent, id, caption, pos, size, style );
94 
96  if (GetSizer())
97  {
98  GetSizer()->SetSizeHints(this);
99  }
100  Centre();
101 ////@end CSeqIdFixDlg creation
102  return true;
103 }
104 
105 
106 /*!
107  * CSeqIdFixDlg destructor
108  */
109 
111 {
112 ////@begin CSeqIdFixDlg destruction
113 ////@end CSeqIdFixDlg destruction
114 }
115 
116 
117 /*!
118  * Member initialisation
119  */
120 
122 {
123 ////@begin CSeqIdFixDlg member initialisation
124 ////@end CSeqIdFixDlg member initialisation
125  m_NewGrid = NULL;
126  m_OldGrid = NULL;
127  m_OldIds = NULL;
128 }
129 
130 
131 /*!
132  * Control creation for CSeqIdFixDlg
133  */
134 
136 {
137 ////@begin CSeqIdFixDlg content construction
138  CSeqIdFixDlg* itemDialog1 = this;
139 
140  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
141  itemDialog1->SetSizer(itemBoxSizer2);
142 
143  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
144  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
145 
146  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
147  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
148 
149  wxButton* itemButton5 = new wxButton( itemDialog1, ID_RECHECK_SEQID_PROBLEMS_BTN, _("Recheck Problems"), wxDefaultPosition, wxDefaultSize, 0 );
150  itemBoxSizer4->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
151 
152  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
153  itemBoxSizer2->Add(itemBoxSizer6, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
154 
155  wxButton* itemButton7 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
156  itemBoxSizer6->Add(itemButton7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
157 
158  wxButton* itemButton8 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
159  itemBoxSizer6->Add(itemButton8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
160 
161 ////@end CSeqIdFixDlg content construction
162 
163  // no multiple choice values for these tables
165 
166  if (m_CurrEntry) {
168  if (m_OldIds && m_OldIds->IsSetColumns() && m_OldIds->GetNum_rows() > 0) {
169  wxStaticText* old_banner = new wxStaticText( this, wxID_STATIC, _("Existing Sequence IDs"), wxDefaultPosition, wxDefaultSize, 0 );
170  itemBoxSizer3->Add(old_banner, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
171 
172  m_OldGrid = new CSeqTableGridPanel(this, m_OldIds, choices);
173  itemBoxSizer3->Add(m_OldGrid, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
174  // make all columns read-only
176  }
177  }
178 
180 
181  CRef<objects::CSeqTable_column> problems = GetSeqIdProblems(new_table, m_OldIds, 100);
182  new_table->SetColumns().push_back(problems);
183 
184  // add in a column for new sequence IDs
185  CRef<objects::CSeqTable_column> new_ids(new objects::CSeqTable_column());
186  new_ids->SetHeader().SetTitle(kNewId);
187  new_ids->SetData().SetString();
188  objects::CSeq_table::TColumns::iterator it = new_table->SetColumns().begin();
189  it++;
190  new_table->SetColumns().insert(it, new_ids);
191 
192  // copy over any IDs that are not duplicates or not too long
194  for (size_t i = 0; i < orig_ids->GetData().GetId().size(); i++) {
195  string id_str = "";
196  if (!problems || !problems->IsSetData()
197  || !problems->GetData().IsString()
198  || i >= problems->GetData().GetSize()
199  || NStr::IsBlank(problems->GetData().GetString()[i])) {
200  orig_ids->GetData().GetId()[i]->GetLabel(&id_str, objects::CSeq_id::eContent);
201  }
202  new_ids->SetData().SetString().push_back(id_str);
203  }
204 
205  wxStaticText* new_banner = new wxStaticText( this, wxID_STATIC, _("New Sequence IDs"), wxDefaultPosition, wxDefaultSize, 0 );
206  itemBoxSizer3->Add(new_banner, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
207 
208  m_NewGrid = new CSeqTableGridPanel(this, new_table, choices);
209  itemBoxSizer3->Add(m_NewGrid, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
210  // make all columns other than new_id read-only
213 
214 }
215 
216 
217 /*!
218  * Should we show tooltips?
219  */
220 
222 {
223  return true;
224 }
225 
226 /*!
227  * Get bitmap resources
228  */
229 
230 wxBitmap CSeqIdFixDlg::GetBitmapResource( const wxString& name )
231 {
232  // Bitmap retrieval
233 ////@begin CSeqIdFixDlg bitmap retrieval
234  wxUnusedVar(name);
235  return wxNullBitmap;
236 ////@end CSeqIdFixDlg bitmap retrieval
237 }
238 
239 /*!
240  * Get icon resources
241  */
242 
243 wxIcon CSeqIdFixDlg::GetIconResource( const wxString& name )
244 {
245  // Icon retrieval
246 ////@begin CSeqIdFixDlg icon retrieval
247  wxUnusedVar(name);
248  return wxNullIcon;
249 ////@end CSeqIdFixDlg icon retrieval
250 }
251 
252 
254 {
257  if (m_OldGrid) {
258  old_ids = m_OldGrid->GetValuesTable();
259  }
260 
262  CRef<objects::CSeqTable_column> new_problems = GetSeqIdProblems(values_table, old_ids, 100);
263  prev_problems->SetData().SetString().clear();
264  if (new_problems && new_problems->IsSetData() && new_problems->GetData().IsString() && new_problems->GetData().GetSize() > 0) {
265  prev_problems->SetData().SetString().assign(new_problems->GetData().GetString().begin(), new_problems->GetData().GetString().end());
266  } else {
267  for (int i = 0; i < values_table->GetNum_rows(); i++) {
268  prev_problems->SetData().SetString().push_back("");
269  }
270  }
271  m_NewGrid->SetValuesTable(values_table);
274 }
275 
276 
278 {
281  if (m_OldGrid) {
282  old_ids = m_OldGrid->GetValuesTable();
283  }
284 
285  CRef<objects::CSeqTable_column> problems = GetSeqIdProblems(values_table, old_ids, 100);
286  if (problems) {
287  wxMessageBox(ToWxString(SummarizeIdProblems(problems)), wxT("Error"), wxOK, this);
288  values_table.Reset(NULL);
290  }
291  return values_table;
292 }
293 
294 
295 /*!
296  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RECHECK_PROBLEMS_BTN
297  */
298 
299 void CSeqIdFixDlg::OnRecheckSeqidProblemsBtnClick( wxCommandEvent& event )
300 {
302 }
303 
304 
306 
307 
308 
static bool ShowToolTips()
Should we show tooltips?
void x_RefreshProblems()
void CreateControls()
Creates the controls and sizers.
void OnRecheckSeqidProblemsBtnClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_RECHECK_SEQID_PROBLEMS_BTN
CRef< objects::CSeq_table > GetReplacementTable()
CSeqIdFixDlg()
Constructors.
CRef< objects::CSeq_entry > m_EntryToAdd
void Init()
Initialises member variables.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CConstRef< objects::CSeq_entry > m_CurrEntry
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
~CSeqIdFixDlg()
Destructor.
bool Create(wxWindow *parent, wxWindowID id=10104, const wxString &caption=_("Sequence ID Problems"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
CSeqTableGridPanel * m_OldGrid
CSeqTableGridPanel * m_NewGrid
CRef< objects::CSeq_table > m_OldIds
void MakeColumnReadOnly(int pos, bool val=true)
void SetValuesTable(CRef< objects::CSeq_table > table)
CRef< objects::CSeq_table > GetValuesTable()
#define _(proto)
Definition: ct_nlmzip_i.h:78
const string kProblems
const char * kNewId
const char * kSequenceIdColLabel
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
@ eContent
Definition: feature.hpp:87
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
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
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
END_EVENT_TABLE()
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
#define ID_RECHECK_SEQID_PROBLEMS_BTN
CRef< CSeqTable_column > FindSeqTableColumnByName(CRef< objects::CSeq_table > values_table, string column_name)
CRef< objects::CSeq_table > GetIdsFromSeqEntry(const objects::CSeq_entry &entry)
string SummarizeIdProblems(CRef< objects::CSeqTable_column > problems)
CRef< objects::CSeqTable_column > GetSeqIdProblems(CRef< objects::CSeq_table > new_ids, CRef< objects::CSeq_table > old_ids, size_t max_len)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Wed May 22 11:29:44 2024 by modify_doxy.py rev. 669887