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

Go to the SVN repository for this file.

1 /* $Id: edit_cds_frame.cpp 45436 2020-08-03 17:23:15Z 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: Igor Filippov
27  */
28 
29 
30 #include <ncbi_pch.hpp>
35 #include <objmgr/util/sequence.hpp>
41 
42 #include <wx/button.h>
43 
45 
46 
47 IMPLEMENT_DYNAMIC_CLASS( CEditCdsFrame, wxDialog )
48 
49 
50 
51 BEGIN_EVENT_TABLE( CEditCdsFrame, wxDialog )
52 
53 ////@begin CEditCdsFrame event table entries
54 ////@end CEditCdsFrame event table entries
55 
57 
58 
59 /*!
60  * CEditCdsFrame constructors
61  */
62 
64 {
65  Init();
66 }
67 
69  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
70  : m_TopSeqEntry(seh)
71 {
72  Init();
73  Create(parent, id, caption, pos, size, style);
74 }
75 
76 
77 /*!
78  * CEditCdsFrame creator
79  */
80 
81 bool CEditCdsFrame::Create( wxWindow* parent,
82  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
83 {
84 ////@begin CEditCdsFrame creation
85  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
86  wxDialog::Create( parent, id, caption, pos, size, style );
87 
89  if (GetSizer())
90  {
91  GetSizer()->SetSizeHints(this);
92  }
93  Centre();
94 ////@end CEditCdsFrame creation
95 
96  return true;
97 }
98 
99 
100 /*!
101  * CEditCdsFrame destructor
102  */
103 
105 {
106 ////@begin CEditCdsFrame destruction
107 ////@end CEditCdsFrame destruction
108 }
109 
110 
111 /*!
112  * Member initialisation
113  */
114 
116 {
117 ////@begin CEditCdsFrame member initialisation
118  m_From = NULL;
119  m_To = NULL;
121 ////@end CEditCdsFrame member initialisation
122 }
123 
124 
125 /*!
126  * Control creation for CEditCdsFrame
127  */
128 
130 {
131 ////@begin CEditCdsFrame content construction
132  CEditCdsFrame* itemDialog1 = this;
133 
134  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
135  itemDialog1->SetSizer(itemBoxSizer2);
136 
137  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
138  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
139 
140  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
141  itemBoxSizer3->Add(itemBoxSizer5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
142 
143  wxStaticText* itemStaticText1 = new wxStaticText( itemDialog1, wxID_STATIC, _("Set Coding Region frame to:"), wxDefaultPosition, wxDefaultSize, 0 );
144  itemBoxSizer5->Add(itemStaticText1, 0, wxALIGN_LEFT|wxALL, 5);
145 
146  wxStaticText* itemStaticText2 = new wxStaticText( itemDialog1, wxID_STATIC, _("Where Coding Region frame is:"), wxDefaultPosition, wxDefaultSize, 0 );
147  itemBoxSizer5->Add(itemStaticText2, 0, wxALIGN_LEFT|wxALL, 5);
148 
149  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxVERTICAL);
150  itemBoxSizer3->Add(itemBoxSizer6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
151 
152  wxArrayString to_strs;
153  to_strs.Add(_("1"));
154  to_strs.Add(_("2"));
155  to_strs.Add(_("3"));
156  to_strs.Add(_("Best"));
157  m_To = new wxChoice( itemDialog1, wxID_ANY, wxDefaultPosition, wxDefaultSize, to_strs, 0 );
158  itemBoxSizer6->Add(m_To, 0, wxALIGN_LEFT|wxALL, 5);
159  m_To->SetSelection(3);
160 
161  wxArrayString from_strs;
162  from_strs.Add(_("1"));
163  from_strs.Add(_("2"));
164  from_strs.Add(_("3"));
165  from_strs.Add(_("Any"));
166  m_From = new wxChoice( itemDialog1, wxID_ANY, wxDefaultPosition, wxDefaultSize, from_strs, 0 );
167  itemBoxSizer6->Add(m_From, 0, wxALIGN_LEFT|wxALL, 5);
168  m_From->SetSelection(3);
169 
170  m_Retranslate = new wxCheckBox( itemDialog1, wxID_ANY, _("Retranslate adjusted coding regions"), wxDefaultPosition, wxDefaultSize, 0 );
171  m_Retranslate->SetValue(true);
172  itemBoxSizer2->Add(m_Retranslate, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
173 
174  m_Constraint = new CConstraintPanel( itemDialog1, m_TopSeqEntry);
175  itemBoxSizer2->Add(m_Constraint, 0, wxALIGN_LEFT|wxALL, 5);
177  m_Constraint->SetFieldName("CDS");
178 
179 
180  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
181  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
182 
183  wxButton* itemButton5 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
184  itemBoxSizer4->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
185 
186  wxButton* itemButton6 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
187  itemBoxSizer4->Add(itemButton6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
188 
189 ////@end CEditCdsFrame content construction
190 
191 }
192 
193 
194 /*!
195  * Should we show tooltips?
196  */
197 
199 {
200  return true;
201 }
202 
203 /*!
204  * Get bitmap resources
205  */
206 
207 wxBitmap CEditCdsFrame::GetBitmapResource( const wxString& name )
208 {
209  // Bitmap retrieval
210 ////@begin CEditCdsFrame bitmap retrieval
211  wxUnusedVar(name);
212  return wxNullBitmap;
213 ////@end CEditCdsFrame bitmap retrieval
214 }
215 
216 /*!
217  * Get icon resources
218  */
219 
220 wxIcon CEditCdsFrame::GetIconResource( const wxString& name )
221 {
222  // Icon retrieval
223 ////@begin CEditCdsFrame icon retrieval
224  wxUnusedVar(name);
225  return wxNullIcon;
226 ////@end CEditCdsFrame icon retrieval
227 }
228 
230 {
231  bool retranslate = m_Retranslate->GetValue();
232  string from = m_From->GetString(m_From->GetSelection()).ToStdString();
233  string to = m_To->GetString(m_To->GetSelection()).ToStdString();
234 
235  CRef<CCmdComposite> cmd(new CCmdComposite("Edit CDS Frame"));
236  bool create_general_only = objects::edit::IsGeneralIdProtPresent(m_TopSeqEntry);
238  string ncRNA_class;
240 
241 
242  action1->SetConstraint(constraint);
243  action1->ResetChangedFeatures();
244  action1->NOOP();
245  const map<CSeq_feat_Handle, CRef<CSeq_feat> >& feat_map = action1->GetChangedFeatures();
246 
247  // offset to use when creating new protein IDs (if needed)
248  int offset = 1;
249  for (auto& fh_feat : feat_map)
250  {
251  CSeq_feat_Handle fh = fh_feat.first;
252  CRef<CSeq_feat> feat = fh_feat.second;
253  if (!feat->IsSetData() || !feat->GetData().IsCdregion())
254  continue;
255 
256  if (feat->IsSetExcept_text() && NStr::Find(feat->GetExcept_text(), "RNA editing") != string::npos)
257  {
258  continue;
259  }
260 
261  bool go(false);
262  if (from == "Any")
263  go = true;
264 
265  if (!go && feat->GetData().GetCdregion().IsSetFrame())
266  {
267  CCdregion::EFrame frame = feat->GetData().GetCdregion().GetFrame();
268  if (from == "1" && (frame == CCdregion::eFrame_one || frame == CCdregion::eFrame_not_set))
269  go = true;
270  if (from == "2" && frame == CCdregion::eFrame_two)
271  go = true;
272  if (from == "3" && frame == CCdregion::eFrame_three)
273  go = true;
274  }
275  if (!go)
276  continue;
277 
278  if (to == "1")
279  feat->SetData().SetCdregion().SetFrame(CCdregion::eFrame_one);
280  if (to == "2")
281  feat->SetData().SetCdregion().SetFrame(CCdregion::eFrame_two);
282  if (to == "3")
283  feat->SetData().SetCdregion().SetFrame(CCdregion::eFrame_three);
284  if (to == "Best")
285  feat->SetData().SetCdregion().SetFrame(CSeqTranslator::FindBestFrame(*feat, fh.GetScope()));
286 
287  CIRef<IEditCommand> chgFeat(new CCmdChangeSeq_feat(fh, *feat));
288  cmd->AddCommand(*chgFeat);
289 
290  if (retranslate)
291  {
292  bool cds_change(false);
293  CRef<CCmdComposite> retranslate_cds_cmd = CRetranslateCDS::RetranslateCDSCommand(fh.GetScope(), *fh.GetOriginalSeq_feat(), *feat, cds_change, offset, create_general_only);
294  cmd->AddCommand(*retranslate_cds_cmd);
295  }
296  }
297 
298 
299  return cmd;
300 }
301 
bool IsGeneralIdProtPresent(objects::CSeq_entry_Handle tse)
@ eFieldType_Feature
Definition: aecr_frame.hpp:152
virtual CRef< CEditingActionConstraint > GetConstraint(const string &field, CFieldNamePanel::EFieldType field_type, int subtype, const string &ncRNA_class)
void SetSelection(int page)
bool SetFieldName(const string &field)
CSeq_entry_Handle m_TopSeqEntry
CEditCdsFrame()
Constructors.
wxChoice * m_From
CConstraintPanel * m_Constraint
bool Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &caption=_("Edit CDS Frame"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(200, 100), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
~CEditCdsFrame()
Destructor.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
static bool ShowToolTips()
Should we show tooltips?
CRef< CCmdComposite > GetCommand(void)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxCheckBox * m_Retranslate
void CreateControls()
Creates the controls and sizers.
void Init()
Initialises member variables.
static CRef< CCmdComposite > RetranslateCDSCommand(CScope &scope, const CSeq_feat &old_cds, CSeq_feat &cds, bool &cds_change, int &offset, bool create_general_only)
CSeq_entry_Handle –.
CSeq_feat_Handle –.
Definition: map.hpp:338
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
CIRef< IEditingAction > CreateAction(CSeq_entry_Handle seh, const string &field, CFieldNamePanel::EFieldType field_type, int subtype, const string &ncRNA_class=kEmptyStr, CConstRef< objects::CSeq_submit > submit=CConstRef< objects::CSeq_submit >(NULL))
#define NULL
Definition: ncbistd.hpp:225
static CCdregion::EFrame FindBestFrame(const CSeq_feat &cds, CScope &scope)
Find "best" frame for a coding region.
Definition: sequence.cpp:4376
CScope & GetScope(void) const
Get scope this handle belongs to.
CConstRef< CSeq_feat > GetOriginalSeq_feat(void) const
#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 SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
Definition: ncbistr.cpp:2887
bool IsSetData(void) const
the specific data Check if a value has been assigned to Data data member.
Definition: Seq_feat_.hpp:913
bool IsCdregion(void) const
Check if variant Cdregion is selected.
TFrame GetFrame(void) const
Get the Frame member data.
Definition: Cdregion_.hpp:534
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const TExcept_text & GetExcept_text(void) const
Get the Except_text member data.
Definition: Seq_feat_.hpp:1405
bool IsSetExcept_text(void) const
explain if except=TRUE Check if a value has been assigned to Except_text data member.
Definition: Seq_feat_.hpp:1393
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
const TCdregion & GetCdregion(void) const
Get the variant data.
bool IsSetFrame(void) const
Check if a value has been assigned to Frame data member.
Definition: Cdregion_.hpp:509
@ eFrame_not_set
not set, code uses one
Definition: Cdregion_.hpp:95
@ eFrame_three
reading frame
Definition: Cdregion_.hpp:98
END_EVENT_TABLE()
const struct ncbi::grid::netcache::search::fields::SIZE size
int offset
Definition: replacements.h:160
static static static wxID_ANY
Modified on Fri Mar 01 10:06:54 2024 by modify_doxy.py rev. 669887