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

Go to the SVN repository for this file.

1 /* $Id: extend_partial_features.cpp 42192 2019-01-10 16:52:15Z filippov $
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>
31 
32 ////@begin includes
33 ////@end includes
34 
35 #include <wx/stattext.h>
36 #include <wx/msgdlg.h>
37 
39 #include <objmgr/seq_vector.hpp>
40 #include <objmgr/util/sequence.hpp>
47 
48 ////@begin XPM images
49 ////@end XPM images
50 
52 
54 
55 /*!
56  * CExtendPartialFeatDlg type definition
57  */
58 
59 IMPLEMENT_DYNAMIC_CLASS( CExtendPartialFeatDlg, CBulkCmdDlg )
60 
61 
62 /*!
63  * CExtendPartialFeatDlg event table definition
64  */
65 
66 BEGIN_EVENT_TABLE( CExtendPartialFeatDlg, CBulkCmdDlg )
67 
68 ////@begin CExtendPartialFeatDlg event table entries
69 
71 
72 ////@end CExtendPartialFeatDlg event table entries
73 
75 
76 
77 /*!
78  * CExtendPartialFeatDlg constructors
79  */
80 
82 {
83  Init();
84 }
85 
86 CExtendPartialFeatDlg::CExtendPartialFeatDlg( wxWindow* parent, IWorkbench* wb, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
87  : CBulkCmdDlg(wb)
88 {
89  Init();
90  Create(parent, id, caption, pos, size, style);
91 }
92 
93 
94 /*!
95  * CExtendPartialFeatDlg creator
96  */
97 
98 bool CExtendPartialFeatDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
99 {
100 ////@begin CExtendPartialFeatDlg creation
101  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
102  CBulkCmdDlg::Create( parent, id, caption, pos, size, style );
103 
104  CreateControls();
105  if (GetSizer())
106  {
107  GetSizer()->SetSizeHints(this);
108  }
109  Centre();
110 ////@end CExtendPartialFeatDlg creation
111  return true;
112 }
113 
114 
115 /*!
116  * CExtendPartialFeatDlg destructor
117  */
118 
120 {
121 ////@begin CExtendPartialFeatDlg destruction
122 ////@end CExtendPartialFeatDlg destruction
123 }
124 
125 
126 /*!
127  * Member initialisation
128  */
129 
131 {
132 ////@begin CExtendPartialFeatDlg member initialisation
134  m_OkCancel = NULL;
135 ////@end CExtendPartialFeatDlg member initialisation
136  m_ErrorMessage = "";
137  m_Extend5Btn = NULL;
138  m_Extend3Btn = NULL;
141 }
142 
143 
144 /*!
145  * Control creation for CExtendPartialFeatDlg
146  */
147 
149 {
150 ////@begin CExtendPartialFeatDlg content construction
151  CExtendPartialFeatDlg* itemCBulkCmdDlg1 = this;
152 
153  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
154  itemCBulkCmdDlg1->SetSizer(itemBoxSizer2);
155 
156  m_FeatureType = new CFeatureTypePanel( itemCBulkCmdDlg1, ID_EFL_FEATURETYPE, wxDefaultPosition, wxSize(100, 100), wxSIMPLE_BORDER );
157  itemBoxSizer2->Add(m_FeatureType, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
161 
162  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
163  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
164 
165  m_Extend5Btn = new wxCheckBox( itemCBulkCmdDlg1, wxID_ANY, _("Extend partial 5'"), wxDefaultPosition, wxDefaultSize, 0 );
166  m_Extend5Btn->SetValue(true);
167  itemBoxSizer4->Add(m_Extend5Btn, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
168 
169  m_Extend3Btn = new wxCheckBox( itemCBulkCmdDlg1, wxID_ANY, _("Extend partial 3'"), wxDefaultPosition, wxDefaultSize, 0 );
170  m_Extend3Btn->SetValue(true);
171  itemBoxSizer4->Add(m_Extend3Btn, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
172 
173  wxPanel *container1 = new wxPanel( itemCBulkCmdDlg1, wxID_ANY, wxDefaultPosition, wxSize(800,260), 0 );
174  itemBoxSizer2->Add(container1, 1, wxGROW|wxALL|wxFIXED_MINSIZE, 0);
175 
176  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
177  container1->SetSizer(itemBoxSizer5);
178 
179  vector<CFieldNamePanel::EFieldType> field_types;
180  /*field_types.push_back(CFieldNamePanel::eFieldType_Source);
181  field_types.push_back(CFieldNamePanel::eFieldType_Misc);
182  field_types.push_back(CFieldNamePanel::eFieldType_Feature);
183  field_types.push_back(CFieldNamePanel::eFieldType_CDSGeneProt);
184  field_types.push_back(CFieldNamePanel::eFieldType_RNA);
185  field_types.push_back(CFieldNamePanel::eFieldType_MolInfo);
186  field_types.push_back(CFieldNamePanel::eFieldType_Pub);
187  field_types.push_back(CFieldNamePanel::eFieldType_DBLink);
188  field_types.push_back(CFieldNamePanel::eFieldType_SeqId);
189  */
190  field_types.push_back(CFieldNamePanel::eFieldType_Feature);
191  m_FieldType = new CFieldChoicePanel( container1, field_types, true, false, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
192  itemBoxSizer5->Add(m_FieldType, 1, wxGROW|wxALL|wxFIXED_MINSIZE, 0);
194 
195  wxPanel *container2 = new wxPanel( itemCBulkCmdDlg1, wxID_ANY, wxDefaultPosition, wxSize(800,90), 0 );
196  itemBoxSizer2->Add(container2, 0, wxALIGN_LEFT|wxALL|wxFIXED_MINSIZE, 0);
197 
198  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
199  container2->SetSizer(itemBoxSizer6);
200 
201  m_StringConstraintPanel = new CStringConstraintPanel( container2, false, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
202  itemBoxSizer6->Add(m_StringConstraintPanel, 0, wxALIGN_LEFT|wxALL|wxFIXED_MINSIZE, 0);
203 
204  m_OkCancel = new COkCancelPanel( itemCBulkCmdDlg1, wxID_ANY, wxDefaultPosition, wxSize(100, 100), 0 );
205  itemBoxSizer2->Add(m_OkCancel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
206 
207 ////@end CExtendPartialFeatDlg content construction
208 }
209 
210 
211 /*!
212  * Should we show tooltips?
213  */
214 
216 {
217  return true;
218 }
219 
220 /*!
221  * Get bitmap resources
222  */
223 
224 wxBitmap CExtendPartialFeatDlg::GetBitmapResource( const wxString& name )
225 {
226  // Bitmap retrieval
227 ////@begin CExtendPartialFeatDlg bitmap retrieval
228  wxUnusedVar(name);
229  return wxNullBitmap;
230 ////@end CExtendPartialFeatDlg bitmap retrieval
231 }
232 
233 /*!
234  * Get icon resources
235  */
236 
237 wxIcon CExtendPartialFeatDlg::GetIconResource( const wxString& name )
238 {
239  // Icon retrieval
240 ////@begin CExtendPartialFeatDlg icon retrieval
241  wxUnusedVar(name);
242  return wxNullIcon;
243 ////@end CExtendPartialFeatDlg icon retrieval
244 }
245 
246 
248 {
249  UpdateChildrenFeaturePanels(this->GetSizer());
251 }
252 
253 
254 
256 {
257  return m_ErrorMessage;
258 }
259 
260 
262 {
264 
265  string feat_type = m_FeatureType->GetFieldName();
266  if (NStr::EqualNocase(feat_type, "any")) {
267  feat_type = "";
268  }
269  string field_name = "";
270  if (NStr::IsBlank(feat_type)) {
271  field_name = kPartialStart;
272  } else {
273  field_name = feat_type + " " + kPartialStart;
274  }
275 
276  CRef<CMiscSeqTableColumn> col(new CMiscSeqTableColumn(field_name));
277 
279  string constraint_field = m_FieldType->GetFieldName(false);
280 
281  vector<CConstRef<CObject> > objs = col->GetObjects(m_TopSeqEntry, constraint_field, string_constraint);
282 
283  if (objs.size() == 0) {
284  wxMessageBox(wxT("No features found!"), wxT("Error"),
285  wxOK | wxICON_ERROR, NULL);
286  return cmd;
287  }
288 
289  bool any_change = false;
290  CScope &scope = m_TopSeqEntry.GetScope();
291 
292 
293  bool extend5 = m_Extend5Btn->GetValue();
294  bool extend3 = m_Extend3Btn->GetValue();
295  cmd.Reset(new CCmdComposite("Extend Partial Features"));
296  int offset = 1;
297  bool create_general_only = objects::edit::IsGeneralIdProtPresent(m_TopSeqEntry);
298  ITERATE(vector<CConstRef<CObject> >, it, objs)
299  {
300  const CSeq_feat* f = dynamic_cast<const CSeq_feat* >((*it).GetPointer());
301  if (f)
302  {
303  if (f->IsSetData() && f->GetData().IsCdregion() &&
304  f->IsSetExcept_text() && NStr::Find(f->GetExcept_text(), "RNA editing") != string::npos)
305  {
306  continue;
307  }
308 
309  const CSeq_loc& loc = f->GetLocation();
310  CBioseq_Handle bsh = scope.GetBioseqHandle(loc);
311 
312  CRef<CSeq_feat> new_feat(new CSeq_feat());
313  new_feat->Assign(*f);
314 
315  if (extend5 && f->GetLocation().IsPartialStart(eExtreme_Biological) && !Is5AtStartOfSeq(loc, bsh))
316  {
317  edit::CLocationEditPolicy::Extend5(*new_feat, scope);
318  any_change = true;
319  }
320  if (extend3 && f->GetLocation().IsPartialStop(eExtreme_Biological) && !Is3AtEndOfSeq(loc, bsh))
321  {
322  edit::CLocationEditPolicy::Extend3(*new_feat, scope);
323  any_change = true;
324  }
325  // command to change feature
326  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(scope.GetSeq_featHandle(*f), *new_feat)));
327 
328  // retranslate or resynch if coding region
329  if (new_feat->IsSetProduct() && new_feat->GetData().IsCdregion())
330  {
331  CRef<CCmdComposite> retranslate_cmd = GetRetranslateCDSCommand(scope, *new_feat, offset, create_general_only);
332  if (retranslate_cmd) {
333  cmd->AddCommand(*retranslate_cmd);
334  }
335  }
336 
337  }
338  }
339 
340 
341 
342  if (!any_change) {
343  wxMessageBox(wxT("No effect!"), wxT("Error"),
344  wxOK | wxICON_ERROR, NULL);
345  cmd.Reset(NULL);
346  }
347 
348  return cmd;
349 }
350 
352 {
353  bool rval = false;
354 
355  ENa_strand strand = loc.GetStrand();
356  if (strand == eNa_strand_minus) {
357  if (bsh && loc.GetStart(eExtreme_Biological) == bsh.GetInst_Length() - 1) {
358  rval = true;
359  }
360  } else {
361  if (loc.GetStart(eExtreme_Biological) == 0) {
362  rval = true;
363  }
364  }
365  return rval;
366 }
367 
368 
370 {
371  bool rval = false;
372  ENa_strand strand = loc.GetStrand();
373 
374  if (strand == eNa_strand_minus) {
375  if (loc.GetStop(eExtreme_Biological) == 0) {
376  rval = true;
377  }
378  } else {
379  if (bsh && loc.GetStop(eExtreme_Biological) == bsh.GetInst_Length() - 1) {
380  rval = true;
381  }
382  }
383  return rval;
384 }
385 
386 
388 {
390  m_FeatureType->SetFieldName("Any");
391  m_Extend5Btn->SetValue(true);
392  m_Extend3Btn->SetValue(true);
394  if (cmd)
395  {
397  }
398  Destroy();
399 }
400 
402 {
403  CRef<CCmdComposite> cmd(new CCmdComposite("Extend CDS"));
404  if (!seh)
405  return cmd;
406  CScope& scope = seh.GetScope();
407  int offset = 1;
408  bool create_general_only = objects::edit::IsGeneralIdProtPresent(seh);
410  {
411  const CSeq_loc& loc = fi->GetLocation();
412  CBioseq_Handle bsh = scope.GetBioseqHandle(loc);
413 
414  CRef<CSeq_feat> new_feat(new CSeq_feat());
415  new_feat->Assign(fi->GetOriginalFeature());
416  bool extend_up = (loc.GetStart(eExtreme_Positional) <= 5) && loc.IsPartialStart(eExtreme_Positional);
417  bool extend_down = (bsh.GetInst_Length() - 1 <= loc.GetStop(eExtreme_Positional) + 5) && loc.IsPartialStop(eExtreme_Positional);
418  if (extend_up) {
419  if (loc.IsSetStrand() && loc.GetStrand() == eNa_strand_minus) {
420  edit::CLocationEditPolicy::Extend3(*new_feat, scope);
421  } else {
422  edit::CLocationEditPolicy::Extend5(*new_feat, scope);
423  }
424  }
425  if (extend_down) {
426  if (loc.IsSetStrand() && loc.GetStrand() == eNa_strand_minus) {
427  edit::CLocationEditPolicy::Extend5(*new_feat, scope);
428  } else {
429  edit::CLocationEditPolicy::Extend3(*new_feat, scope);
430  }
431  }
432  if (extend_up || extend_down)
433  {
434  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(fi->GetSeq_feat_Handle(), *new_feat)));
435  cmd->AddCommand(*GetRetranslateCDSCommand(scope, *new_feat, offset, create_general_only));
436  }
437  }
438  return cmd;
439 }
440 
442 
@ eExtreme_Positional
numerical value
Definition: Na_strand.hpp:63
@ eExtreme_Biological
5' and 3'
Definition: Na_strand.hpp:62
#define ID_EFL_FEATURETYPE
bool IsGeneralIdProtPresent(objects::CSeq_entry_Handle tse)
CBioseq_Handle –.
objects::CSeq_entry_Handle m_TopSeqEntry
bool Create(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE, const wxString &name=wxFrameNameStr)
bool GetTopLevelSeqEntryAndProcessor()
ICommandProccessor * m_CmdProccessor
void UpdateChildrenFeaturePanels(wxSizer *sizer)
static CRef< CCmdComposite > ExtendCDS(CSeq_entry_Handle seh)
static bool ShowToolTips()
Should we show tooltips?
virtual CRef< CCmdComposite > GetCommand()
static bool Is3AtEndOfSeq(const CSeq_loc &loc, CBioseq_Handle bsh)
static bool Is5AtStartOfSeq(const CSeq_loc &loc, CBioseq_Handle bsh)
void Init()
Initialises member variables.
bool Create(wxWindow *parent, wxWindowID id=10268, const wxString &caption=_("Extend Partial Features"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(900, 500), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
void ProcessUpdateFeatEvent(wxCommandEvent &event)
CStringConstraintPanel * m_StringConstraintPanel
void CreateControls()
Creates the controls and sizers.
CFeatureTypePanel * m_FeatureType
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CFeat_CI –.
Definition: feat_ci.hpp:64
virtual bool SetFieldName(const string &field)
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
void ListPresentFeaturesFirst(const objects::CSeq_entry_Handle &entry, vector< const objects::CFeatListItem * > *featlist=nullptr)
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
bool SetFieldType(CFieldNamePanel::EFieldType field_type, bool is_pair=false)
vector< CConstRef< CObject > > GetObjects(objects::CBioseq_Handle bsh)
CScope –.
Definition: scope.hpp:92
CSeq_entry_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
CRef< edit::CStringConstraint > GetStringConstraint()
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
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
#define wxFIXED_MINSIZE
USING_SCOPE(ncbi::objects)
const string kPartialStart
#define EVT_UPDATE_FEATURE_LIST(id, fn)
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
bool IsPartialStart(ESeqLocExtremes ext) const
check start or stop of location for e_Lim fuzz
Definition: Seq_loc.cpp:3222
ENa_strand GetStrand(void) const
Get the location's strand.
Definition: Seq_loc.cpp:882
TSeqPos GetStart(ESeqLocExtremes ext) const
Return start and stop positions of the seq-loc.
Definition: Seq_loc.cpp:915
bool IsSetStrand(EIsSetStrand flag=eIsSetStrand_Any) const
Check if strand is set for any/all part(s) of the seq-loc depending on the flag.
Definition: Seq_loc.cpp:858
bool IsPartialStop(ESeqLocExtremes ext) const
Definition: Seq_loc.cpp:3251
TSeqPos GetStop(ESeqLocExtremes ext) const
Definition: Seq_loc.cpp:963
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
CSeq_feat_Handle GetSeq_featHandle(const CSeq_feat &feat, EMissing action=eMissing_Default)
Definition: scope.cpp:200
TInst_Length GetInst_Length(void) const
CScope & GetScope(void) const
Get scope this handle belongs to.
#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
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
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5352
bool IsCdregion(void) const
Check if variant Cdregion is selected.
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
bool IsSetProduct(void) const
product of process Check if a value has been assigned to Product data member.
Definition: Seq_feat_.hpp:1084
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
#define fi
int offset
Definition: replacements.h:160
static static static wxID_ANY
CRef< CCmdComposite > GetRetranslateCDSCommand(objects::CScope &scope, const objects::CSeq_feat &cds, bool create_general_only)
Modified on Fri Dec 01 04:44:50 2023 by modify_doxy.py rev. 669887