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

Go to the SVN repository for this file.

1 /* $Id: edit_seq_ends.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 
29 #include <ncbi_pch.hpp>
30 #include <objmgr/scope.hpp>
32 #include <objmgr/feat_ci.hpp>
33 #include <objmgr/align_ci.hpp>
34 #include <objmgr/bioseq_ci.hpp>
35 #include <objmgr/seq_annot_ci.hpp>
36 #include <objmgr/graph_ci.hpp>
49 #include <objmgr/seq_vector.hpp>
54 
55 
56 // For compilers that support precompilation, includes "wx/wx.h".
57 #include "wx/wxprec.h"
58 
59 #ifdef __BORLANDC__
60 #pragma hdrstop
61 #endif
62 
63 #ifndef WX_PRECOMP
64 #include "wx/wx.h"
65 #endif
66 
67 
69 
70 ////@begin includes
71 ////@end includes
72 
75 
76 
77 ////@begin XPM images
78 ////@end XPM images
79 
80 
81 /*
82  * CEditSequenceEnds type definition
83  */
84 
85 IMPLEMENT_DYNAMIC_CLASS( CEditSequenceEnds, wxDialog )
86 
87 
88 /*
89  * CEditSequenceEnds event table definition
90  */
91 
92 BEGIN_EVENT_TABLE( CEditSequenceEnds, wxDialog )
93 
100 ////@begin CEditSequenceEnds event table entries
101 ////@end CEditSequenceEnds event table entries
102 
104 
105 
106 /*
107  * CEditSequenceEnds constructors
108  */
109 
111 {
112  Init();
113 }
114 
115 CEditSequenceEnds::CEditSequenceEnds( wxWindow* parent, CSeq_entry_Handle seh, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
116  : m_TopSeqEntry(seh)
117 {
118  Init();
119  Create(parent, id, caption, pos, size, style);
120 }
121 
122 
123 /*
124  * CEditSequenceEnds creator
125  */
126 
127 bool CEditSequenceEnds::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
128 {
129 ////@begin CEditSequenceEnds creation
130  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
131  wxDialog::Create( parent, id, caption, pos, size, style );
132 
133  CreateControls();
134  if (GetSizer())
135  {
136  GetSizer()->SetSizeHints(this);
137  }
138  Centre();
139 ////@end CEditSequenceEnds creation
140  return true;
141 }
142 
143 
144 /*
145  * CEditSequenceEnds destructor
146  */
147 
149 {
150 ////@begin CEditSequenceEnds destruction
151 ////@end CEditSequenceEnds destruction
152 }
153 
154 
155 /*
156  * Member initialisation
157  */
158 
160 {
161 ////@begin CEditSequenceEnds member initialisation
162 ////@end CEditSequenceEnds member initialisation
163 }
164 
165 
166 /*
167  * Control creation for CEditSequenceEnds
168  */
169 
171 {
172 ////@begin CEditSequenceEnds content construction
173  // Generated by DialogBlocks, 28/12/2015 13:08:50 (unregistered)
174 
175  CEditSequenceEnds* itemDialog1 = this;
176 
177  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
178  itemDialog1->SetSizer(itemBoxSizer2);
179 
180  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
181  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
182 
183  wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("End"), wxDefaultPosition, wxDefaultSize, 0 );
184  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
185 
186  m_5Prime = new wxRadioButton(itemDialog1, ID_EDITSEQENDS_RADIOBUTTON, _("5'"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
187  m_5Prime->SetValue(true);
188  itemBoxSizer3->Add(m_5Prime, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
189 
190  wxRadioButton* itemRadioButton6 = new wxRadioButton(itemDialog1, ID_EDITSEQENDS_RADIOBUTTON1, _("3'"), wxDefaultPosition, wxDefaultSize, 0);
191  itemRadioButton6->SetValue(false);
192  itemBoxSizer3->Add(itemRadioButton6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
193 
194  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
195  itemBoxSizer2->Add(itemBoxSizer7, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
196 
197  m_Add = new wxRadioButton(itemDialog1, ID_EDITSEQENDS_RADIOBUTTON2, _("Add to end"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
198  m_Add->SetValue(true);
199  itemBoxSizer7->Add(m_Add, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
200 
201  wxRadioButton* itemRadioButton9 = new wxRadioButton(itemDialog1, ID_EDITSEQENDS_RADIOBUTTON3, _("Trim from end"), wxDefaultPosition, wxDefaultSize, 0);
202  itemRadioButton9->SetValue(false);
203  itemBoxSizer7->Add(itemRadioButton9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
204 
205  wxStaticText* itemStaticText10 = new wxStaticText( itemDialog1, wxID_STATIC, _("Sequence"), wxDefaultPosition, wxDefaultSize, 0 );
206  itemBoxSizer2->Add(itemStaticText10, 0, wxALIGN_LEFT|wxALL, 5);
207 
208  m_Seq = new wxTextCtrl(itemDialog1, ID_EDITSEQENDS_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
209  itemBoxSizer2->Add(m_Seq, 0, wxGROW|wxALL, 5);
210 
211  wxBoxSizer* itemBoxSizer12 = new wxBoxSizer(wxHORIZONTAL);
212  itemBoxSizer2->Add(itemBoxSizer12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
213 
214  wxStaticText* itemStaticText13 = new wxStaticText( itemDialog1, wxID_STATIC, _("Optional gene constraint"), wxDefaultPosition, wxDefaultSize, 0 );
215  itemBoxSizer12->Add(itemStaticText13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
216 
217  m_GeneConstraint = new wxTextCtrl(itemDialog1, ID_EDITSEQENDS_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
218  itemBoxSizer12->Add(m_GeneConstraint, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
219 
220  m_ExtendFeatures = new wxCheckBox(itemDialog1, ID_EDITSEQENDS_CHECKBOX, _("Extend features"), wxDefaultPosition, wxDefaultSize, 0);
221  m_ExtendFeatures->SetValue(false);
222  itemBoxSizer2->Add(m_ExtendFeatures, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
223 
224  wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
225  itemBoxSizer2->Add(itemBoxSizer16, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
226 
227  m_TrimSeq = new wxRadioButton(itemDialog1, ID_EDITSEQENDS_RADIOBUTTON4, _("Trim by sequence"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
228  m_TrimSeq->SetValue(true);
229  itemBoxSizer16->Add(m_TrimSeq, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
230 
231  m_TrimCount = new wxRadioButton(itemDialog1, ID_EDITSEQENDS_RADIOBUTTON5, _("Trim by count"), wxDefaultPosition, wxDefaultSize, 0);
232  m_TrimCount->SetValue(false);
233  itemBoxSizer16->Add(m_TrimCount, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
234 
235  wxBoxSizer* itemBoxSizer19 = new wxBoxSizer(wxHORIZONTAL);
236  itemBoxSizer2->Add(itemBoxSizer19, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
237 
238  wxStaticText* itemStaticText20 = new wxStaticText( itemDialog1, wxID_STATIC, _("Trim count"), wxDefaultPosition, wxDefaultSize, 0 );
239  itemBoxSizer19->Add(itemStaticText20, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
240 
241  m_Count = new wxTextCtrl(itemDialog1, ID_EDITSEQENDS_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
242  itemBoxSizer19->Add(m_Count, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
243  m_Count->SetValidator( wxTextValidator( wxFILTER_NUMERIC ) );
244 
245  wxStaticBox* itemStaticBoxSizer22Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Choose Sequences To Edit"));
246  wxStaticBoxSizer* itemStaticBoxSizer22 = new wxStaticBoxSizer(itemStaticBoxSizer22Static, wxVERTICAL);
247  itemBoxSizer2->Add(itemStaticBoxSizer22, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
248 
249  wxArrayString itemCheckListBox23Strings;
250  m_CheckListBox = new wxCheckListBox(itemStaticBoxSizer22->GetStaticBox(), ID_EDITSEQENDS_CHECKLISTBOX, wxDefaultPosition, wxDefaultSize, itemCheckListBox23Strings, wxLB_MULTIPLE | wxLB_NEEDED_SB);
251  itemStaticBoxSizer22->Add(m_CheckListBox, 0, wxGROW|wxALL, 5);
252 
253  wxBoxSizer* itemBoxSizer24 = new wxBoxSizer(wxHORIZONTAL);
254  itemStaticBoxSizer22->Add(itemBoxSizer24, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
255 
256  wxButton* itemButton25 = new wxButton(itemStaticBoxSizer22->GetStaticBox(), ID_EDITSEQENDS_BUTTON, _("Select All"), wxDefaultPosition, wxDefaultSize, 0);
257  itemBoxSizer24->Add(itemButton25, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
258 
259  wxButton* itemButton26 = new wxButton(itemStaticBoxSizer22->GetStaticBox(), ID_EDITSEQENDS_BUTTON1, _("Unselect All"), wxDefaultPosition, wxDefaultSize, 0);
260  itemBoxSizer24->Add(itemButton26, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
261 
262  m_AddCitSub = new wxCheckBox(itemDialog1, ID_EDITSEQENDS_CHECKBOX1, _("Add Cit Subs to edited sequences"), wxDefaultPosition, wxDefaultSize, 0);
263  m_AddCitSub->SetValue(false);
264  itemBoxSizer2->Add(m_AddCitSub, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
265 
266  wxBoxSizer* itemBoxSizer28 = new wxBoxSizer(wxHORIZONTAL);
267  itemBoxSizer2->Add(itemBoxSizer28, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
268 
269  wxButton* itemButton29 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
270  itemBoxSizer28->Add(itemButton29, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
271 
272  wxButton* itemButton30 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
273  itemBoxSizer28->Add(itemButton30, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
274 
275 ////@end CEditSequenceEnds content construction
276  m_TrimSeq->Disable();
277  m_TrimCount->Disable();
278  m_Count->Disable();
279  ReadSequences();
280 }
281 
282 
283 /*
284  * Should we show tooltips?
285  */
286 
288 {
289  return true;
290 }
291 
292 /*
293  * Get bitmap resources
294  */
295 
296 wxBitmap CEditSequenceEnds::GetBitmapResource( const wxString& name )
297 {
298  // Bitmap retrieval
299 ////@begin CEditSequenceEnds bitmap retrieval
300  wxUnusedVar(name);
301  return wxNullBitmap;
302 ////@end CEditSequenceEnds bitmap retrieval
303 }
304 
305 /*
306  * Get icon resources
307  */
308 
309 wxIcon CEditSequenceEnds::GetIconResource( const wxString& name )
310 {
311  // Icon retrieval
312 ////@begin CEditSequenceEnds icon retrieval
313  wxUnusedVar(name);
314  return wxNullIcon;
315 ////@end CEditSequenceEnds icon retrieval
316 }
317 
318 
319 void CEditSequenceEnds::CombineLabels(const CSeq_id &id, vector<string> &labels)
320 {
321  if (id.IsGenbank() && id.GetGenbank().IsSetAccession())
322  labels[0] = id.GetGenbank().GetAccession();
323  if (id.IsGeneral() && id.GetGeneral().IsSetDb() && id.GetGeneral().GetDb() == "BankIt" && id.GetGeneral().IsSetTag() && id.GetGeneral().GetTag().IsStr())
324  labels[1] = id.GetGeneral().GetTag().GetStr();
325  else if (id.IsGeneral() && id.GetGeneral().IsSetDb() && id.GetGeneral().GetDb() == "NCBIFILE" && id.GetGeneral().IsSetTag() && id.GetGeneral().GetTag().IsStr())
326  labels[1] = id.GetGeneral().GetTag().GetStr();
327  else if (id.IsLocal() && id.GetLocal().IsStr())
328  labels[1] = id.GetLocal().GetStr();
329 }
330 
332 {
333  vector<string> labels(2);
334 
335  if (bsh.IsSetId())
336  for (CBioseq_Handle::TId::const_iterator it = bsh.GetId().begin(); it != bsh.GetId().end(); ++it)
337  CombineLabels(*(it->GetSeqId()),labels);
338 
339  for (int i=0; i<labels.size(); i++)
340  if (!labels[i].empty())
341  strs.push_back(labels[i]);
342 }
343 
345 {
346  list<string> strs;
347  CollectLabels(bsh,strs);
348  string label = NStr::Join(strs," ");
349  return label;
350 }
351 
353 {
354  for (CBioseq_CI b_iter(m_TopSeqEntry, objects::CSeq_inst::eMol_na); b_iter; ++b_iter)
355  {
356  string label = GetLabel(*b_iter);
357  long index = m_bioseq.size();
358  m_CheckListBox->Append(wxString(label),(void*)index);
359  m_bioseq.push_back(*b_iter);
360  }
361 }
362 
363 void CEditSequenceEnds::OnSelectAll( wxCommandEvent& event )
364 {
365  for (auto i = 0; i < m_CheckListBox->GetCount(); i++)
366  m_CheckListBox->Check(i, true);
367 }
368 
369 void CEditSequenceEnds::OnUnselectAll( wxCommandEvent& event )
370 {
371  for (auto i = 0; i < m_CheckListBox->GetCount(); i++)
372  m_CheckListBox->Check(i, false);
373 }
374 
375 
377 {
378  CRef<CCmdComposite> cmd(new CCmdComposite("Edit Sequence Ends"));
379  if (m_Add->GetValue()) // Add Sequence
380  {
382  if (m_5Prime->GetValue())
384 
385  string extension = m_Seq->GetValue().ToStdString();
386  if (extension.empty())
387  return cmd;
388 
389  wxString msg;
390  for (auto i = 0; i < m_CheckListBox->GetCount(); i++)
391  if (m_CheckListBox->IsChecked(i))
392  {
393  long index = (long)m_CheckListBox->GetClientData(i);
394  CBioseq_Handle bsh = m_bioseq[index];
395  // if gene constraint is set check that corresponding gene has a locus equal to constraint (no case)
396  string gene_locus = m_GeneConstraint->GetValue().ToStdString();
397  if (!gene_locus.empty())
398  {
399  bool match = false;
400  for (CFeat_CI feat_it(bsh, CSeqFeatData::eSubtype_gene); feat_it; ++feat_it)
401  {
402  const CSeq_feat& gene = feat_it->GetOriginalFeature();
403  if (gene.IsSetData() && gene.GetData().IsGene() && gene.GetData().GetGene().IsSetLocus() &&
404  NStr::EqualNocase(gene.GetData().GetGene().GetLocus(), gene_locus) )
405  {
406  match = true;
407  break;
408  }
409  }
410  if (!match)
411  continue;
412  }
413 
414  CRef<objects::CSeq_inst> new_inst = CSequenceUpdater::s_ExtendOneEndOfSequence(bsh, extension, update_type);
415  TSeqPos inst_length = 0;
416  if (new_inst)
417  {
418  CRef<CCmdChangeBioseqInst> change_inst(new CCmdChangeBioseqInst(bsh, *new_inst));
419  if (change_inst)
420  cmd->AddCommand(*change_inst);
421  if (new_inst->IsSetLength())
422  inst_length = new_inst->GetLength();
423  }
424 
425  if (m_5Prime->GetValue())
426  {
427  for (CFeat_CI feat_it(bsh); feat_it; ++feat_it)
428  {
429  CRef<CSeq_feat> new_feat = CSequenceUpdater::s_OffsetFeature(feat_it->GetOriginalFeature(), static_cast<TSeqPos>(extension.length()));
430  if (new_feat)
431  {
432  if (m_ExtendFeatures->GetValue())
433  {
434  Extend5(*new_feat, inst_length);
435  }
436  CRef< CCmdChangeSeq_feat > cmd_change_feat(new CCmdChangeSeq_feat(feat_it->GetSeq_feat_Handle(),*new_feat));
437  if (cmd_change_feat)
438  {
439  cmd->AddCommand(*cmd_change_feat);
440  }
441  }
442  else
443  {
444  CRef<CCmdDelSeq_feat> cmd_del(new CCmdDelSeq_feat(feat_it->GetSeq_feat_Handle()));
445  if (cmd_del)
446  {
447  cmd->AddCommand(*cmd_del);
448  }
449  }
450  }
451  }
452  else if (m_ExtendFeatures->GetValue())
453  {
454  for (CFeat_CI feat_it(bsh); feat_it; ++feat_it)
455  {
456  CRef<CSeq_feat> new_feat(new CSeq_feat);
457  new_feat->Assign(feat_it->GetOriginalFeature());
458  Extend3(*new_feat, inst_length);
459  CRef< CCmdChangeSeq_feat > cmd_change_feat(new CCmdChangeSeq_feat(feat_it->GetSeq_feat_Handle(),*new_feat));
460  if (cmd_change_feat)
461  {
462  cmd->AddCommand(*cmd_change_feat);
463  }
464  }
465  }
466 
467  if (m_AddCitSub->GetValue())
468  {
469  CConstRef<CSeqdesc> changedSeqdesc;
470  CSeq_entry_Handle seh_for_desc;
471  string msg;
472  CRef<CSeqdesc> changedORadded_citsub = CCitSubUpdater::s_GetCitSubForUpdatedSequence(bsh, msg, changedSeqdesc, seh_for_desc);
473  if (changedORadded_citsub && !NStr::EqualNocase(msg, CCitSubUpdater::sm_ExistingCitSub))
474  {
477  if (bssh && bssh.CanGetClass() && bssh.GetClass() == CBioseq_set::eClass_nuc_prot) // if it is a nuc-prot set go a level higher
478  {
479  seh = bssh.GetParentEntry();
480  }
481 
482  CIRef<IEditCommand> cmdAddDesc(new CCmdCreateDesc(seh, *changedORadded_citsub));
483  cmd->AddCommand(*cmdAddDesc);
484  }
485  }
486  bool graph_deleted = false;
488  CGraph_CI graph_ci(bsh, graph_sel);
489  for (; graph_ci; ++graph_ci)
490  {
491  CIRef<IEditCommand> del_graph(new CCmdDelSeq_graph(graph_ci->GetSeq_graph_Handle()));
492  cmd->AddCommand(*del_graph);
493  graph_deleted = true;
494  }
495  if (graph_deleted)
496  msg += _("quality scores cleared for ") + m_CheckListBox->GetString(i) + _("\n");
497  for (CSeq_annot_CI annot_ci(bsh); annot_ci; ++annot_ci)
498  {
499  if (annot_ci->IsGraph())
500  {
501  CIRef<IEditCommand> del_annot(new CCmdDelSeq_annot(*annot_ci));
502  cmd->AddCommand(*del_annot);
503  }
504  }
505  }
506 
507  if (!msg.IsEmpty())
508  {
509  CGenericReportDlg* report = new CGenericReportDlg(GetParent());
510  report->SetTitle(wxT("Quality Scores Affected"));
511  report->SetText(msg);
512  report->Show(true);
513  }
514  }
515  else // Trim Sequence
516  {
518  CRef<CScope> scope_copy(new CScope(*object_manager));
519 
520  for (auto i = 0; i < m_CheckListBox->GetCount(); i++)
521  if (m_CheckListBox->IsChecked(i))
522  {
523  long index = (long)m_CheckListBox->GetClientData(i);
524  CBioseq_Handle bsh = m_bioseq[index];
525  int before = 0;
526  int after = bsh.GetBioseqLength()-1;
527  if (m_TrimSeq->GetValue())
528  {
530  string seq;
531  seq_vec.GetSeqData(0, bsh.GetBioseqLength(), seq);
532  string str = m_Seq->GetValue().ToStdString();
533  if (m_5Prime->GetValue() && NStr::StartsWith(seq,str, NStr::eNocase))
534  {
535  before += str.length();
536  }
537  else if (!m_5Prime->GetValue() && NStr::EndsWith(seq,str, NStr::eNocase))
538  {
539  after -= str.length();
540  }
541  }
542  else
543  {
544  if (m_5Prime->GetValue())
545  before += wxAtoi(m_Count->GetValue());
546  else
547  after -= wxAtoi(m_Count->GetValue());
548  }
549 
552  CSeq_entry_Handle edited_seh = scope_copy->AddTopLevelSeqEntry(*copy);
553  CEditSeqEndsWithAlign::TrimBeforeAfter(edited_seh.GetSeq(), before, after);
555  cmd->AddCommand(*cmd_bioseq);
557  CEditSeqEndsWithAlign::TrimQualityScores(bsh, before, after, cmd);
558  }
559  }
560  return cmd;
561 }
562 
563 
565 {
566  if (inst_length > 0)
567  {
568  auto start = feat.GetLocation().GetStart(eExtreme_Positional);
569  int diff = 0;
570  if (start > 0)
571  {
573  if (new_loc)
574  {
575  feat.SetLocation().Assign(*new_loc);
576  diff = start;
577  }
578  }
579  ENa_strand strand = feat.GetLocation().GetStrand();
580  if (strand == eNa_strand_minus)
581  return;
582 
583  // adjust frame to maintain consistency
584  if (diff % 3 > 0 && feat.GetData().IsCdregion())
585  {
586  int orig_frame = 1;
587  if (feat.GetData().GetCdregion().IsSetFrame())
588  {
590  {
591  orig_frame = 2;
592  }
593  else if (feat.GetData().GetCdregion().GetFrame() == CCdregion::eFrame_three)
594  {
595  orig_frame = 3;
596  }
597  }
599  switch ((orig_frame + diff % 3) % 3)
600  {
601  case 1:
602  new_frame = CCdregion::eFrame_not_set;
603  break;
604  case 2:
605  new_frame = CCdregion::eFrame_two;
606  break;
607  case 0:
608  new_frame = CCdregion::eFrame_three;
609  break;
610  }
611  feat.SetData().SetCdregion().SetFrame(new_frame);
612  }
613  }
614 }
615 
617 {
618  if (inst_length > 0)
619  {
620  int diff = 0;
621  auto stop = feat.GetLocation().GetStop(eExtreme_Positional);
622  if (stop < inst_length - 1)
623  {
624  CRef<CSeq_loc> new_loc = edit::SeqLocExtend(feat.GetLocation(), inst_length - 1, &m_TopSeqEntry.GetScope());
625  if (new_loc)
626  {
627  feat.SetLocation().Assign(*new_loc);
628  diff = inst_length - 1 - stop;
629  }
630  }
631  ENa_strand strand = feat.GetLocation().GetStrand();
632  if (strand == eNa_strand_minus)
633  {
634  // adjust frame to maintain consistency
635  if (diff % 3 > 0 && feat.GetData().IsCdregion())
636  {
637  int orig_frame = 1;
638  if (feat.GetData().GetCdregion().IsSetFrame())
639  {
641  {
642  orig_frame = 2;
643  }
644  else if (feat.GetData().GetCdregion().GetFrame() == CCdregion::eFrame_three)
645  {
646  orig_frame = 3;
647  }
648  }
650  switch ((orig_frame + diff % 3) % 3)
651  {
652  case 1:
653  new_frame = CCdregion::eFrame_not_set;
654  break;
655  case 2:
656  new_frame = CCdregion::eFrame_two;
657  break;
658  case 0:
659  new_frame = CCdregion::eFrame_three;
660  break;
661  }
662  feat.SetData().SetCdregion().SetFrame(new_frame);
663  }
664  }
665  }
666 }
667 
668 
669 void CEditSequenceEnds::AddOrTrimEnable(wxCommandEvent& event)
670 {
671  if (m_Add->GetValue())
672  {
673  m_Seq->Enable();
674  m_ExtendFeatures->Enable();
675  m_TrimSeq->Disable();
676  m_TrimCount->Disable();
677  m_Count->Disable();
678  }
679  else
680  {
681  if (m_TrimSeq->GetValue())
682  {
683  m_Seq->Enable();
684  m_ExtendFeatures->Disable();
685  m_TrimSeq->Enable();
686  m_TrimCount->Enable();
687  m_Count->Disable();
688  }
689  else
690  {
691  m_Seq->Disable();
692  m_ExtendFeatures->Disable();
693  m_TrimSeq->Enable();
694  m_TrimCount->Enable();
695  m_Count->Enable();
696  }
697  }
698 
699 }
700 
User-defined methods of the data storage class.
@ eExtreme_Positional
numerical value
Definition: Na_strand.hpp:63
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_Handle –.
CBioseq_set_Handle –.
static CRef< objects::CSeqdesc > s_GetCitSubForUpdatedSequence(const objects::CBioseq_Handle &bsh, string &message, CConstRef< objects::CSeqdesc > &changedSeqdesc, objects::CSeq_entry_Handle &seh)
Generates/Creates a Cit-sub publication that will be added to the sequence.
static const char * sm_ExistingCitSub
static void TrimBeforeAfter(CBioseq_Handle edited_bsh, int before, int after)
static void TrimQualityScores(CBioseq_Handle bsh, int before, int after, CRef< CCmdComposite > command)
static void AdjustFeatureLocations(CBioseq_Handle bsh, int before, int after, CRef< CCmdComposite > cmd)
wxCheckListBox * m_CheckListBox
~CEditSequenceEnds()
Destructor.
wxTextCtrl * m_GeneConstraint
void Extend5(CSeq_feat &feat, TSeqPos inst_length)
void CreateControls()
Creates the controls and sizers.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void OnUnselectAll(wxCommandEvent &event)
wxRadioButton * m_Add
string GetLabel(CBioseq_Handle bsh)
void Extend3(CSeq_feat &feat, TSeqPos inst_length)
CSeq_entry_Handle m_TopSeqEntry
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxCheckBox * m_ExtendFeatures
wxTextCtrl * m_Count
void Init()
Initialises member variables.
wxRadioButton * m_5Prime
wxRadioButton * m_TrimSeq
void OnSelectAll(wxCommandEvent &event)
wxCheckBox * m_AddCitSub
void AddOrTrimEnable(wxCommandEvent &event)
wxRadioButton * m_TrimCount
CRef< CCmdComposite > GetCommand()
void CollectLabels(CBioseq_Handle bsh, list< string > &strs)
wxTextCtrl * m_Seq
void CombineLabels(const CSeq_id &id, vector< string > &labels)
vector< CBioseq_Handle > m_bioseq
bool Create(wxWindow *parent, wxWindowID id=32000, const wxString &caption=_("Edit Sequence Ends"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
CEditSequenceEnds()
Constructors.
static bool ShowToolTips()
Should we show tooltips?
CFeat_CI –.
Definition: feat_ci.hpp:64
void SetText(const wxString &text)
CGraph_CI –.
Definition: graph_ci.hpp:234
CScope –.
Definition: scope.hpp:92
CSeqVector –.
Definition: seq_vector.hpp:65
CSeq_annot_CI –.
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
static CRef< objects::CSeq_feat > s_OffsetFeature(const objects::CSeq_feat &feat, const TSeqPos offset, const objects::CSeq_id *newId=NULL)
Offsets the location of the feature.
static CRef< objects::CSeq_inst > s_ExtendOneEndOfSequence(const objects::CBioseq_Handle &bsh, const string &extension, SUpdateSeqParams::ESequenceUpdateType update_type)
Extends the 5' or 3' end of a NA sequence (no alignment is necessary).
Definition: update_seq.cpp:953
@ eSeqUpdateExtend3
extend the 5' end of old sequence with the update
@ eSeqUpdateExtend5
patch old sequence with update in the aligned region
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
USING_SCOPE(objects)
#define ID_EDITSEQENDS_BUTTON1
#define ID_EDITSEQENDS_RADIOBUTTON3
#define ID_EDITSEQENDS_BUTTON
#define ID_EDITSEQENDS_RADIOBUTTON5
#define ID_EDITSEQENDS_CHECKLISTBOX
#define ID_EDITSEQENDS_TEXTCTRL1
#define ID_EDITSEQENDS_TEXTCTRL
#define ID_EDITSEQENDS_TEXTCTRL2
#define ID_EDITSEQENDS_CHECKBOX1
#define ID_EDITSEQENDS_RADIOBUTTON1
#define ID_EDITSEQENDS_RADIOBUTTON2
#define ID_EDITSEQENDS_RADIOBUTTON
#define ID_EDITSEQENDS_RADIOBUTTON4
#define ID_EDITSEQENDS_CHECKBOX
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
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
TSeqPos GetStop(ESeqLocExtremes ext) const
Definition: Seq_loc.cpp:963
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CSeq_entry_Handle AddTopLevelSeqEntry(CSeq_entry &top_entry, TPriority pri=kPriority_Default, EExist action=eExist_Default)
Add seq_entry, default priority is higher than for defaults or loaders Add object to the score with p...
Definition: scope.cpp:522
TClass GetClass(void) const
CBioseq_set_Handle GetParentBioseq_set(void) const
Return a handle for the parent Bioseq-set, or null handle.
bool CanGetClass(void) const
TSeqPos GetBioseqLength(void) const
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Get parent Seq-entry handle.
TSeq GetSeq(void) const
CSeq_entry_Handle GetParentEntry(void) const
Return a handle for the parent seq-entry of the bioseq.
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.
bool IsSetId(void) const
const TId & GetId(void) const
CSeqVector GetSeqVector(EVectorCoding coding, ENa_strand strand=eNa_strand_plus) const
Get sequence: Iupacna or Iupacaa if use_iupac_coding is true.
@ eCoding_Iupac
Set coding to printable coding (Iupacna or Iupacaa)
CSeq_graph_Handle GetSeq_graph_Handle(void) const
Get original graph handle.
Definition: graph_ci.cpp:93
void GetSeqData(TSeqPos start, TSeqPos stop, string &buffer) const
Fill the buffer string with the sequence data for the interval [start, stop).
Definition: seq_vector.cpp:304
#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 EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5430
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
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:5353
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
static const char label[]
bool IsSetLocus(void) const
Official gene symbol Check if a value has been assigned to Locus data member.
Definition: Gene_ref_.hpp:493
const TLocus & GetLocus(void) const
Get the Locus member data.
Definition: Gene_ref_.hpp:505
bool IsSetData(void) const
the specific data Check if a value has been assigned to Data data member.
Definition: Seq_feat_.hpp:913
void SetLocation(TLocation &value)
Assign a value to Location data member.
Definition: Seq_feat_.cpp:131
bool IsCdregion(void) const
Check if variant Cdregion is selected.
const TLocation & GetLocation(void) const
Get the Location member data.
Definition: Seq_feat_.hpp:1117
bool IsGene(void) const
Check if variant Gene 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
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.
const TGene & GetGene(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
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
@ eNa_strand_plus
Definition: Na_strand_.hpp:66
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
const TSeq & GetSeq(void) const
Get the variant data.
Definition: Seq_entry_.cpp:102
@ eClass_nuc_prot
nuc acid and coded proteins
Definition: Bioseq_set_.hpp:99
const TInst & GetInst(void) const
Get the Inst member data.
Definition: Bioseq_.hpp:336
END_EVENT_TABLE()
int i
CRef< CSeq_loc > SeqLocExtend(const CSeq_loc &loc, size_t pos, CScope *scope)
Definition: loc_edit.cpp:546
#define wxT(x)
Definition: muParser.cpp:41
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
The Object manager core.
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)
Definition: pcre_exec.c:513
static static static wxID_ANY
static const char * str(char *buf, int n)
Definition: stats.c:84
SAnnotSelector –.
Modified on Mon Feb 26 04:04:09 2024 by modify_doxy.py rev. 669887