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

Go to the SVN repository for this file.

1 /* $Id: bulk_rna_edit.cpp 47479 2023-05-02 13:24:02Z ucko $
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: Igor Filippov
27  */
28 #include <ncbi_pch.hpp>
30 #include <objmgr/feat_ci.hpp>
31 #include <objmgr/util/sequence.hpp>
42 #include <wx/msgdlg.h>
43 
46 
47 
48 IMPLEMENT_DYNAMIC_CLASS( CBulkRna, wxDialog )
49 
50 BEGIN_EVENT_TABLE( CBulkRna, wxDialog )
51 
52  EVT_BUTTON( wxID_OK, CBulkRna::OnClickOk )
53 
54  EVT_BUTTON( wxID_CANCEL, CBulkRna::OnClickCancel )
55 
56 
58 
60 {
61  Init();
62 }
63 
64 CBulkRna::CBulkRna( wxWindow* parent, objects::CSeq_entry_Handle seh, IWorkbench* workbench, CConstRef<objects::CSeq_submit> seqSubmit,
65  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
66 {
67  this->m_Workbench = workbench;
68  this->m_SeqSubmit = seqSubmit;
69 
71  for ( ; fi ; ++fi )
72  {
73  m_FeatHandles.push_back(fi->GetSeq_feat_Handle());
74  }
75  Init();
76  Create(parent, id, caption, pos, size, style);
77 }
78 
79 CBulkRna::CBulkRna( wxWindow* parent, const vector<CSeq_feat_Handle> &feat_handles, IWorkbench* workbench,
80  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
81  : m_FeatHandles(feat_handles)
82 {
83  this->m_Workbench = workbench;
84  Init();
85  Create(parent, id, caption, pos, size, style);
86 }
87 
88 
89 bool CBulkRna::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
90 {
91  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
92  SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED);
93  wxDialog::Create( parent, id, caption, pos, size, style );
94 
96  if (GetSizer())
97  {
98  GetSizer()->SetSizeHints(this);
99  }
100  Centre();
101  return true;
102 }
103 
104 
106 {
107 }
108 
109 
110 /*!
111  * Member initialisation
112  */
113 
115 {
116  m_Grid=NULL;
117 }
118 
119 
121 {
122  CBulkRna* itemDialog1 = this;
123 
124  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
125  itemDialog1->SetSizer(itemBoxSizer2);
126 
127  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
128  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
129 
130  wxArrayString itemChoiceStrings, itemChoiceStringsWritable;
131 
132  if (m_FeatHandles.empty())
133  {
134  wxMessageBox(wxT("No RNA records found"), wxT("Error"), wxOK | wxICON_ERROR);
135  NCBI_THROW( CException, eUnknown, "No RNA records found" );
136  }
137 
139  if (values_table->GetNum_rows() < 1)
140  {
141  wxMessageBox(wxT("No RNA records found"), wxT("Error"), wxOK | wxICON_ERROR);
142  NCBI_THROW( CException, eUnknown, "No RNA records found" );
143  }
144  CRef<CSeq_table> choices = GetChoices(values_table);
145  int glyph_col = GetCollapsible();
146  m_GridPanel = new CSeqTableGridPanel(this, values_table, choices, glyph_col);
147  itemBoxSizer3->Add(m_GridPanel, 0, wxALIGN_TOP|wxALL, 5);
149  CSeqTableGrid *gridAdapter = new CSeqTableGrid(values_table);
150  m_Grid->SetTable(gridAdapter, true);
151  m_Grid->AutoSizeColumns();
152  int l_height = m_Grid->GetColLabelSize();
153  m_Grid->SetColLabelSize( 2 * l_height );
155 
156  int pos = 0;
157  ITERATE (CSeq_table::TColumns, it, values_table->GetColumns())
158  {
159  if (pos > 0)
160  {
161  if ((*it)->IsSetHeader() && (*it)->GetHeader().IsSetTitle() )
162  {
163  string title = (*it)->GetHeader().GetTitle();
164  if (!title.empty())
165  {
166  itemChoiceStrings.Add(wxString(title));
167  if (!IsReadOnlyColumn(title))
168  itemChoiceStringsWritable.Add(wxString(title));
169  }
170  if (IsReadOnlyColumn(title))
171  m_GridPanel->MakeColumnReadOnly(pos - 1, true);
172  }
173  }
174  pos++;
175  }
176 
177  if (glyph_col >= 0 && glyph_col+1 < m_Grid->GetNumberCols())
178  {
179  m_GridPanel->InitColumnCollapse(glyph_col+1);
180  }
181 
182 
183 
184  CStringConstraintSelect *itemStringConstraintPanel = new CStringConstraintSelect( itemDialog1, m_GridPanel, itemChoiceStrings, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
185  itemBoxSizer2->Add(itemStringConstraintPanel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxFIXED_MINSIZE, 0);
186 
187  m_AecrPanel = new CApplyEditconvertPanel( itemDialog1, m_GridPanel, itemChoiceStringsWritable, 0, true, wxID_ANY, wxDefaultPosition, wxSize(1032, 187));
188  itemBoxSizer2->Add(m_AecrPanel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxFIXED_MINSIZE, 1);
189 
190  wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
191  itemBoxSizer2->Add(itemBoxSizer13, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
192 
193  wxButton* itemButton14 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
194  itemBoxSizer13->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
195 
196  wxButton* itemButton15 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
197  itemBoxSizer13->Add(itemButton15, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
198 }
199 
200 
202 {
203  CRef<objects::CSeqTable_column> id_col(new objects::CSeqTable_column());
204  id_col->SetHeader().SetField_id(objects::CSeqTable_column_info::eField_id_location_id);
205  id_col->SetHeader().SetTitle(kSequenceIdColLabel);
206 
207  CRef<objects::CSeqTable_column> expand_col(new objects::CSeqTable_column());
208  expand_col->SetHeader().SetTitle("");
209  expand_col->SetHeader().SetField_name("expand");
210  expand_col->SetData().SetString();
211 
212  CRef<objects::CSeqTable_column> product_col(new objects::CSeqTable_column());
213  product_col->SetHeader().SetTitle("product");
214  product_col->SetHeader().SetField_name("product");
215  product_col->SetData().SetString();
216 
217  CRef<objects::CSeqTable_column> loc_col(new objects::CSeqTable_column());
218  loc_col->SetHeader().SetTitle("location");
219  loc_col->SetHeader().SetField_name("location");
220  loc_col->SetData().SetString();
221 
222  CRef<objects::CSeqTable_column> comment_col(new objects::CSeqTable_column());
223  comment_col->SetHeader().SetTitle("comment");
224  comment_col->SetHeader().SetField_name("comment");
225  comment_col->SetData().SetString();
226 
227  // bogus column to include last, otherwise deletion of the previous column will not work
228  CRef<objects::CSeqTable_column> bogus_col(new objects::CSeqTable_column());
229  bogus_col->SetHeader().SetTitle("");
230  bogus_col->SetHeader().SetField_name("");
231  bogus_col->SetData().SetString();
232 
233  CRef<objects::CSeq_table> table(new objects::CSeq_table());
234  table->SetColumns().push_back(id_col);
235  table->SetColumns().push_back(expand_col);
236  table->SetColumns().push_back(product_col);
237  table->SetColumns().push_back(loc_col);
238 
241  partial_start_col->SetHeader().SetField_name(kPartialStart);
242 
245  partial_stop_col->SetHeader().SetField_name(kPartialStop);
246 
247  table->SetColumns().push_back(comment_col);
248  table->SetColumns().push_back(bogus_col);
249 
250  size_t row = 0;
251 
252  for ( vector<CSeq_feat_Handle>::iterator fi = m_FeatHandles.begin(); fi != m_FeatHandles.end() ; ++fi )
253  {
254  string product,loc,comment;
255 
256  const CSeq_feat &feat = *fi->GetOriginalSeq_feat();
257  const CRNA_ref &rna = feat.GetData().GetRna();
258  product = rna.GetRnaProductName();
259 
260  if (feat.IsSetLocation())
261  feat.GetLocation().GetLabel(&loc);
262  if (feat.IsSetComment())
263  comment = feat.GetComment();
264  CRef<objects::CSeq_id> id(new objects::CSeq_id());
265  id->SetLocal().SetId(static_cast<CObject_id::TId>(row));
266  id_col->SetData().SetId().push_back(id);
267  expand_col->SetData().SetString().push_back("");
268  product_col->SetData().SetString().push_back(product);
269  loc_col->SetData().SetString().push_back(loc);
270  AddValueToColumn(partial_start_col, partial_start_feat_col->GetFromFeat(feat), row);
271  AddValueToColumn(partial_stop_col, partial_stop_feat_col->GetFromFeat(feat), row);
272  comment_col->SetData().SetString().push_back(comment);
273  bogus_col->SetData().SetString().push_back("");
274  row++;
275  }
276 
277  table->SetNum_rows(static_cast<CSeq_table::TNum_rows>(row));
278  return table;
279 }
280 
281 
283 {
284  CRef<CCmdComposite> cmd(new CCmdComposite("Bulk Rna Edit"));
287  m_Modified = false;
288  size_t row = 0;
289 
290  for ( vector<CSeq_feat_Handle>::iterator fi = m_FeatHandles.begin(); fi != m_FeatHandles.end() ; ++fi )
291  {
292  const CSeq_feat &feat = *fi->GetOriginalSeq_feat();
293  CRef<CSeq_feat> new_feat(new CSeq_feat());
294  new_feat->Assign(feat);
295  string product,loc,comment;
296  bool modified = false;
297  const CRNA_ref &rna = feat.GetData().GetRna();
298  product = rna.GetRnaProductName();
299 
300  if (feat.IsSetLocation())
301  feat.GetLocation().GetLabel(&loc);
302  if (feat.IsSetComment())
303  comment = feat.GetComment();
304 
305  string new_product;
306  try
307  {
308  if (row < values_table->GetColumn("product").GetData().GetString().size())
309  new_product = values_table->GetColumn("product").GetData().GetString()[row];
310  } catch(CSeqTableException&) {}
311 
312  if (new_product != product)
313  {
314  string remainder;
315  new_feat->SetData().SetRna().SetRnaProductName(new_product, remainder);
316  modified = true;
317  }
318 
319  string new_comment;
320  try
321  {
322  if (row < values_table->GetColumn("comment").GetData().GetString().size())
323  new_comment = values_table->GetColumn("comment").GetData().GetString()[row];
324  } catch(CSeqTableException&) {}
325 
326  if (new_comment != comment)
327  {
328  if (new_comment.empty())
329  new_feat->ResetComment();
330  else
331  new_feat->SetComment() = new_comment;
332  modified = true;
333  }
334 
335  string partial_start_val = partial_start_feat_col->GetFromFeat(feat);
336  string new_partial_start_val;
337  try
338  {
339  if (row < values_table->GetColumn(kPartialStart).GetData().GetString().size())
340  new_partial_start_val = values_table->GetColumn(kPartialStart).GetData().GetString()[row];
341  } catch(CSeqTableException&) {}
342 
343  if (new_partial_start_val != partial_start_val)
344  {
345  if (new_partial_start_val.empty())
346  partial_start_feat_col->ClearInFeature(*new_feat);
347  else
348  partial_start_feat_col->AddToFeature(*new_feat, new_partial_start_val, edit::eExistingText_replace_old);
349  modified = true;
350  }
351 
352  string partial_stop_val = partial_stop_feat_col->GetFromFeat(feat);
353  string new_partial_stop_val;
354  try
355  {
356  if (row < values_table->GetColumn(kPartialStop).GetData().GetString().size())
357  new_partial_stop_val = values_table->GetColumn(kPartialStop).GetData().GetString()[row];
358  } catch(CSeqTableException& ) {}
359 
360  if (new_partial_stop_val != partial_stop_val)
361  {
362  if (new_partial_stop_val.empty())
363  partial_stop_feat_col->ClearInFeature(*new_feat);
364  else
365  partial_stop_feat_col->AddToFeature(*new_feat, new_partial_stop_val, edit::eExistingText_replace_old);
366  modified = true;
367  }
368 
369  if (modified)
370  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(*fi,*new_feat)));
371  m_Modified |= modified;
372  row++;
373  }
374 
375  return cmd;
376 }
377 
378 
380 {
381  CRef<CSeq_table> values_table = m_GridPanel->GetValuesTable();
383  return cmd;
384 }
385 
387 {
388  return "Invalid operation in Bulk Rna Edit";
389 }
390 
391 
392 /*!
393  * Should we show tooltips?
394  */
395 
397 {
398  return true;
399 }
400 
401 /*!
402  * Get bitmap resources
403  */
404 
405 wxBitmap CBulkRna::GetBitmapResource( const wxString& name )
406 {
407  // Bitmap retrieval
408 ////@begin CBulkRna bitmap retrieval
409  wxUnusedVar(name);
410  return wxNullBitmap;
411 ////@end CBulkRna bitmap retrieval
412 }
413 
414 /*!
415  * Get icon resources
416  */
417 
418 wxIcon CBulkRna::GetIconResource( const wxString& name )
419 {
420  // Icon retrieval
421 ////@begin CBulkRna icon retrieval
422  wxUnusedVar(name);
423  return wxNullIcon;
424 ////@end CBulkRna icon retrieval
425 }
426 
427 /*!
428  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
429  */
430 
431 void CBulkRna::OnClickOk( wxCommandEvent& event )
432 {
433 ////@begin wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON in CBulkRna.
434  // Before editing this code, remove the block markers.
435  event.Skip();
436 ////@end wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON in CBulkRna.
437 }
438 
439 /*!
440  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
441  */
442 
443 void CBulkRna::OnClickCancel( wxCommandEvent& event )
444 {
445  bool modified = m_GridPanel->GetModified() | m_AecrPanel->GetModified();
446  if (modified)
447  {
448  wxMessageDialog dlg(this,_("Discard modifications?"), _("Attention"),wxOK|wxCANCEL|wxCENTRE);
449  if (dlg.ShowModal() == wxID_OK)
450  {
451  event.Skip();
452  }
453  }
454  else
455  event.Skip();
456 }
457 
459 {
460  objects.clear();
461  const CObject* obj = NULL;
462 
463  if (row < m_FeatHandles.size() )
464  {
465  if ( m_FeatHandles[row].GetOriginalSeq_feat()->IsSetLocation() )
466  {
467  bsh = m_FeatHandles[row].GetScope().GetBioseqHandle(m_FeatHandles[row].GetOriginalSeq_feat()->GetLocation()); // CBioseq_Handle GetBioseqHandle(const CSeq_loc& loc);
468  if (bsh)
469  {
470  if (m_SeqSubmit)
471  objects.push_back(SConstScopedObject(m_SeqSubmit,&bsh.GetScope()));
472  else
474  obj = bsh.GetBioseqCore().GetPointer();
475  }
476  }
477  }
478  return obj;
479 }
480 
User-defined methods of the data storage class.
USING_SCOPE(ncbi::objects)
CBioseq_Handle –.
CBulkRna()
Constructors.
static bool ShowToolTips()
Should we show tooltips?
CApplyEditconvertPanel * m_AecrPanel
bool m_Modified
void OnClickOk(wxCommandEvent &event)
void CreateControls()
Creates the controls and sizers.
bool IsReadOnlyColumn(string column_name)
CRef< CCmdComposite > GetCommandFromValuesTable(CRef< objects::CSeq_table >)
wxGrid * m_Grid
~CBulkRna()
Destructor.
void Init()
Initialises member variables.
vector< CSeq_feat_Handle > m_FeatHandles
void OnClickCancel(wxCommandEvent &event)
CRef< objects::CSeq_table > GetValuesTableFromSeqEntry()
virtual const CObject * RowToScopedObjects(int row, TConstScopedObjects &objects, CBioseq_Handle &bsh)
CRef< CCmdComposite > GetCommand()
CRef< objects::CSeq_table > GetChoices(CRef< objects::CSeq_table > values_table)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("RNA Editing"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
CSeqTableGridPanel * m_GridPanel
string GetErrorMessage()
wxBitmap GetBitmapResource(const wxString &name)
int GetCollapsible()
CFeat_CI –.
Definition: feat_ci.hpp:64
static CRef< CFeatureSeqTableColumnBase > Create(const string &sTitle, objects::CSeqFeatData::ESubtype subtype=objects::CSeqFeatData::eSubtype_any)
virtual void ClearInFeature(objects::CSeq_feat &in_out_feat)
virtual string GetFromFeat(const objects::CSeq_feat &in_out_feat)
virtual bool AddToFeature(objects::CSeq_feat &in_out_feat, const string &newValue, objects::edit::EExistingText existing_text)
CObject –.
Definition: ncbiobj.hpp:180
@RNA_ref.hpp User-defined methods of the data storage class.
Definition: RNA_ref.hpp:54
CConstRef< objects::CSeq_submit > m_SeqSubmit
Seq-loc and seq-align mapper exceptions.
void MakeColumnReadOnly(int pos, bool val=true)
wxGrid * GetGrid(void)
void InitColumnCollapse(int col)
CRef< objects::CSeq_table > GetValuesTable()
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
const CSeqTable_column & GetColumn(CTempString column_name) const
Definition: Seq_table.cpp:65
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define wxFIXED_MINSIZE
const string kPartialStart
const string kPartialStop
const char * kSequenceIdColLabel
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
void GetLabel(string *label) const
Appends a label suitable for display (e.g., error messages) label must point to an existing string ob...
Definition: Seq_loc.cpp:3467
TBioseqCore GetBioseqCore(void) const
Get bioseq core structure.
CConstRef< CSeq_entry > GetCompleteSeq_entry(void) const
Complete and get const reference to the seq-entry.
CScope & GetScope(void) const
Get scope this handle belongs to.
CSeq_entry_Handle GetTopLevelEntry(void) const
Get top level Seq-entry handle.
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
#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 SetHeader(THeader &value)
Assign a value to Header data member.
vector< CRef< CSeqTable_column > > TColumns
Definition: Seq_table_.hpp:92
const TString & GetString(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
bool IsSetComment(void) const
Check if a value has been assigned to Comment data member.
Definition: Seq_feat_.hpp:1037
void SetComment(const TComment &value)
Assign a value to Comment data member.
Definition: Seq_feat_.hpp:1058
const TLocation & GetLocation(void) const
Get the Location member data.
Definition: Seq_feat_.hpp:1117
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
void ResetComment(void)
Reset Comment data member.
Definition: Seq_feat_.cpp:99
const TComment & GetComment(void) const
Get the Comment member data.
Definition: Seq_feat_.hpp:1049
const TRna & GetRna(void) const
Get the variant data.
bool IsSetLocation(void) const
feature made from Check if a value has been assigned to Location data member.
Definition: Seq_feat_.hpp:1105
<!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
#define fi
static static static wxID_ANY
CRef< CSeqTable_column > AddStringColumnToTable(CRef< CSeq_table > table, string label)
void AddValueToColumn(CRef< CSeqTable_column > column, string value, size_t row, edit::EExistingText existing_text=edit::eExistingText_replace_old)
#define row(bind, expected)
Definition: string_bind.c:73
@ eExistingText_replace_old
Modified on Tue May 28 05:48:55 2024 by modify_doxy.py rev. 669887