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

Go to the SVN repository for this file.

1 /* $Id: raw_seq_to_delta_by_loc.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 
30 #include <ncbi_pch.hpp>
31 
32 // For compilers that support precompilation, includes "wx/wx.h".
33 #include "wx/wxprec.h"
34 
35 #ifdef __BORLANDC__
36 #pragma hdrstop
37 #endif
38 
39 #ifndef WX_PRECOMP
40 #include "wx/wx.h"
41 #endif
42 
43 ////@begin includes
44 ////@end includes
45 
47 #include <objects/seq/Seq_data.hpp>
48 #include <objects/seq/Seq_gap.hpp>
52 #include <objmgr/scope.hpp>
56 #include <objects/seq/Seq_ext.hpp>
60 #include <objects/seq/IUPACna_.hpp>
64 #include <objmgr/feat_ci.hpp>
65 #include <objmgr/graph_ci.hpp>
66 #include <objmgr/align_ci.hpp>
67 #include <objmgr/util/sequence.hpp>
68 #include <objmgr/util/feature.hpp>
70 #include <objects/seq/Seq_inst.hpp>
86 
87 
88 ////@begin XPM images
89 ////@end XPM images
90 
92 
93 
94 /*
95  * CRawSeqToDeltaSeqByLoc type definition
96  */
97 
98 IMPLEMENT_DYNAMIC_CLASS( CRawSeqToDeltaSeqByLoc, wxDialog )
99 
100 
101 /*
102  * CRawSeqToDeltaSeqByLoc event table definition
103  */
104 
105 BEGIN_EVENT_TABLE( CRawSeqToDeltaSeqByLoc, wxDialog )
106 
107 ////@begin CRawSeqToDeltaSeqByLoc event table entries
108 ////@end CRawSeqToDeltaSeqByLoc event table entries
109 
111 
112 
113 /*
114  * CRawSeqToDeltaSeqByLoc constructors
115  */
116 
118 {
119  Init();
120 }
121 
122 CRawSeqToDeltaSeqByLoc::CRawSeqToDeltaSeqByLoc( wxWindow* parent, objects::CSeq_entry_Handle tse, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
123  : m_TopSeqEntry(tse)
124 {
125  Init();
126  Create(parent, id, caption, pos, size, style);
127 }
128 
129 
130 /*
131  * CRawSeqToDeltaSeqByLoc creator
132  */
133 
134 bool CRawSeqToDeltaSeqByLoc::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
135 {
136 ////@begin CRawSeqToDeltaSeqByLoc creation
137  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
138  wxDialog::Create( parent, id, caption, pos, size, style );
139 
140  CreateControls();
141  if (GetSizer())
142  {
143  GetSizer()->SetSizeHints(this);
144  }
145  Centre();
146 ////@end CRawSeqToDeltaSeqByLoc creation
147  return true;
148 }
149 
150 
151 /*
152  * CRawSeqToDeltaSeqByLoc destructor
153  */
154 
156 {
157 ////@begin CRawSeqToDeltaSeqByLoc destruction
158 ////@end CRawSeqToDeltaSeqByLoc destruction
159 }
160 
161 
162 /*
163  * Member initialisation
164  */
165 
167 {
168 ////@begin CRawSeqToDeltaSeqByLoc member initialisation
170  m_CoordSeq = NULL;
171  m_AdjustCDS = NULL;
172 ////@end CRawSeqToDeltaSeqByLoc member initialisation
173 }
174 
175 
176 /*
177  * Control creation for CRawSeqToDeltaSeqByLoc
178  */
179 
181 {
182 ////@begin CRawSeqToDeltaSeqByLoc content construction
183  // Generated by DialogBlocks, 16/09/2015 11:34:00 (unregistered)
184 
185  CRawSeqToDeltaSeqByLoc* itemDialog1 = this;
186 
187  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
188  itemDialog1->SetSizer(itemBoxSizer2);
189 
190  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
191  itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxLEFT, 40);
192 
193  wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("Start"), wxDefaultPosition, wxDefaultSize, 0 );
194  itemBoxSizer3->Add(itemStaticText4, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
195 
196  wxStaticText* itemStaticText5 = new wxStaticText( itemDialog1, wxID_STATIC, _("Type"), wxDefaultPosition, wxDefaultSize, 0 );
197  itemBoxSizer3->Add(itemStaticText5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
198 
199  wxStaticText* itemStaticText6 = new wxStaticText( itemDialog1, wxID_STATIC, _("Length"), wxDefaultPosition, wxDefaultSize, 0 );
200  itemBoxSizer3->Add(itemStaticText6, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
201 
202  wxStaticText* itemStaticText7 = new wxStaticText( itemDialog1, wxID_STATIC, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
203  itemBoxSizer3->Add(itemStaticText7, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
204 
205  wxScrolledWindow* itemScrolledWindow8 = new wxScrolledWindow(itemDialog1, ID_CRAWTODELTA_SCROLLEDWINDOW, wxDefaultPosition, wxSize(-1, 120), wxSUNKEN_BORDER | wxHSCROLL | wxVSCROLL);
206  itemBoxSizer2->Add(itemScrolledWindow8, 0, wxGROW|wxALL, 5);
207  itemScrolledWindow8->SetScrollbars(0, 1, 0, 30);
208  m_ScrollSizer = new wxBoxSizer(wxVERTICAL);
209  itemScrolledWindow8->SetSizer(m_ScrollSizer);
210 
211  wxArrayString itemChoice12Strings;
212  itemChoice12Strings.Add(_("Unknown length"));
213  itemChoice12Strings.Add(_("Known length"));
214  wxArrayString itemChoice14Strings;
215  itemChoice14Strings.Add(_("Insert"));
216  itemChoice14Strings.Add(_("Replace"));
217  for (size_t i = 0; i < 4; i++)
218  {
219  wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
220  m_ScrollSizer->Add(itemBoxSizer10, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT, 5);
221 
222  m_LastStart = new wxTextCtrl( itemScrolledWindow8, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
223  itemBoxSizer10->Add(m_LastStart, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
224  m_LastStart->SetValidator( wxTextValidator( wxFILTER_NUMERIC ) );
225 
226  wxChoice* itemChoice12 = new wxChoice( itemScrolledWindow8, wxID_ANY, wxDefaultPosition, wxDefaultSize, itemChoice12Strings, 0 );
227  itemChoice12->SetStringSelection(_("Unknown length"));
228  itemBoxSizer10->Add(itemChoice12, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
229 
230  m_LastLength = new wxTextCtrl( itemScrolledWindow8, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
231  itemBoxSizer10->Add(m_LastLength, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
232  m_LastLength->SetValidator( wxTextValidator( wxFILTER_NUMERIC ) );
233 
234  wxChoice* itemChoice14 = new wxChoice( itemScrolledWindow8, wxID_ANY, wxDefaultPosition, wxDefaultSize, itemChoice14Strings, 0 );
235  itemChoice14->SetStringSelection(_("Insert"));
236  itemBoxSizer10->Add(itemChoice14, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
237  }
238  m_LastStart->Bind(wxEVT_TEXT, &CRawSeqToDeltaSeqByLoc::OnNewText, this);
239  m_LastLength->Bind(wxEVT_TEXT, &CRawSeqToDeltaSeqByLoc::OnNewText, this);
240  itemScrolledWindow8->FitInside();
241 
242  wxStaticBox* itemStaticBoxSizer30Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Coordinates"));
243  wxStaticBoxSizer* itemStaticBoxSizer30 = new wxStaticBoxSizer(itemStaticBoxSizer30Static, wxHORIZONTAL);
244  itemBoxSizer2->Add(itemStaticBoxSizer30, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
245 
246  m_CoordSeq = new wxRadioButton(itemStaticBoxSizer30->GetStaticBox(), ID_CRAWTODELTA_RADIOBUTTON, _("Sequence"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
247  m_CoordSeq->SetValue(true);
248  itemStaticBoxSizer30->Add(m_CoordSeq, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
249 
250  wxRadioButton* itemRadioButton32 = new wxRadioButton(itemStaticBoxSizer30->GetStaticBox(), ID_CRAWTODELTA_RADIOBUTTON1, _("Alignment"), wxDefaultPosition, wxDefaultSize, 0);
251  itemRadioButton32->SetValue(false);
252  itemStaticBoxSizer30->Add(itemRadioButton32, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
253 
254  objects::CAlign_CI align_ci(m_TopSeqEntry, objects::CSeq_annot::C_Data::e_Align);
255  if (align_ci)
256  {
257  m_CoordSeq->Enable();
258  itemRadioButton32->Enable();
259  }
260  else
261  {
262  m_CoordSeq->Disable();
263  itemRadioButton32->Disable();
264  }
265 
266  m_AdjustCDS = new wxCheckBox(itemDialog1, ID_CRAWTODELTA_CHECKBOX, _("Adjust CDS location for gaps"), wxDefaultPosition, wxDefaultSize, 0);
267  m_AdjustCDS->SetValue(true);
268  itemBoxSizer2->Add(m_AdjustCDS, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
269 
270  wxBoxSizer* itemBoxSizer34 = new wxBoxSizer(wxHORIZONTAL);
271  itemBoxSizer2->Add(itemBoxSizer34, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
272 
273  wxButton* itemButton35 = new wxButton( itemDialog1, wxID_OK, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
274  itemBoxSizer34->Add(itemButton35, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
275 
276  wxButton* itemButton36 = new wxButton( itemDialog1, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
277  itemBoxSizer34->Add(itemButton36, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
278 
279 ////@end CRawSeqToDeltaSeqByLoc content construction
280 }
281 
282 void CRawSeqToDeltaSeqByLoc::OnNewText(wxCommandEvent& event)
283 {
284  m_LastStart->Unbind(wxEVT_TEXT, &CRawSeqToDeltaSeqByLoc::OnNewText, this);
285  m_LastLength->Unbind(wxEVT_TEXT, &CRawSeqToDeltaSeqByLoc::OnNewText, this);
286 
287  wxArrayString itemChoice12Strings;
288  itemChoice12Strings.Add(_("Unknown length"));
289  itemChoice12Strings.Add(_("Known length"));
290  wxArrayString itemChoice14Strings;
291  itemChoice14Strings.Add(_("Insert"));
292  itemChoice14Strings.Add(_("Replace"));
293 
294  wxWindow* parent = m_ScrollSizer->GetContainingWindow();
295 
296  wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
297  m_ScrollSizer->Add(itemBoxSizer10, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT, 5);
298 
299  m_LastStart = new wxTextCtrl( parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
300  itemBoxSizer10->Add(m_LastStart, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
301  m_LastStart->SetValidator( wxTextValidator( wxFILTER_NUMERIC ) );
302 
303  wxChoice* itemChoice12 = new wxChoice( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, itemChoice12Strings, 0 );
304  itemChoice12->SetStringSelection(_("Unknown length"));
305  itemBoxSizer10->Add(itemChoice12, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
306 
307  m_LastLength = new wxTextCtrl( parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
308  itemBoxSizer10->Add(m_LastLength, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
309  m_LastLength->SetValidator( wxTextValidator( wxFILTER_NUMERIC ) );
310 
311  wxChoice* itemChoice14 = new wxChoice( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, itemChoice14Strings, 0 );
312  itemChoice14->SetStringSelection(_("Insert"));
313  itemBoxSizer10->Add(itemChoice14, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
314 
315  m_LastStart->Bind(wxEVT_TEXT, &CRawSeqToDeltaSeqByLoc::OnNewText, this);
316  m_LastLength->Bind(wxEVT_TEXT, &CRawSeqToDeltaSeqByLoc::OnNewText, this);
317 
318  parent->FitInside();
319 }
320 
321 /*
322  * Should we show tooltips?
323  */
324 
326 {
327  return true;
328 }
329 
330 /*
331  * Get bitmap resources
332  */
333 
334 wxBitmap CRawSeqToDeltaSeqByLoc::GetBitmapResource( const wxString& name )
335 {
336  // Bitmap retrieval
337 ////@begin CRawSeqToDeltaSeqByLoc bitmap retrieval
338  wxUnusedVar(name);
339  return wxNullBitmap;
340 ////@end CRawSeqToDeltaSeqByLoc bitmap retrieval
341 }
342 
343 /*
344  * Get icon resources
345  */
346 
347 wxIcon CRawSeqToDeltaSeqByLoc::GetIconResource( const wxString& name )
348 {
349  // Icon retrieval
350 ////@begin CRawSeqToDeltaSeqByLoc icon retrieval
351  wxUnusedVar(name);
352  return wxNullIcon;
353 ////@end CRawSeqToDeltaSeqByLoc icon retrieval
354 }
355 
357 {
359  bool create_xref_map = true;
360  apply_impl(title, old_to_new, create_xref_map);
361  create_xref_map = false;
362  return apply_impl(title, old_to_new, create_xref_map);
363 }
364 
366 {
367  vector<NRawToDeltaSeq::SGap> orig_gaps;
368  wxSizerItemList::iterator node = m_ScrollSizer->GetChildren().begin();
369  while (node != m_ScrollSizer->GetChildren().end())
370  {
371  if ((*node)->IsSizer())
372  {
373  wxTextCtrl *start_ctrl = dynamic_cast<wxTextCtrl*>((*node)->GetSizer()->GetItem((size_t)0)->GetWindow());
374  wxChoice *unknown_known_ctrl = dynamic_cast<wxChoice*>((*node)->GetSizer()->GetItem((size_t)1)->GetWindow());
375  wxTextCtrl *length_ctrl = dynamic_cast<wxTextCtrl*>((*node)->GetSizer()->GetItem((size_t)2)->GetWindow());
376  wxChoice *insert_replace_ctrl = dynamic_cast<wxChoice*>((*node)->GetSizer()->GetItem((size_t)3)->GetWindow());
377  if (start_ctrl && unknown_known_ctrl && length_ctrl && insert_replace_ctrl && !start_ctrl->GetValue().IsEmpty() && !length_ctrl->GetValue().IsEmpty())
378  {
379  NRawToDeltaSeq::SGap gap;
380  gap.start = wxAtoi(start_ctrl->GetValue()) - 1;
381  gap.length = wxAtoi(length_ctrl->GetValue());
382  gap.is_known = false;
383  if (unknown_known_ctrl->GetSelection() != wxNOT_FOUND)
384  gap.is_known = (unknown_known_ctrl->GetString(unknown_known_ctrl->GetSelection()) == _("Known length"));
385  gap.is_replace = false;
386  if (insert_replace_ctrl->GetSelection() != wxNOT_FOUND)
387  gap.is_replace = (insert_replace_ctrl->GetString(insert_replace_ctrl->GetSelection()) == _("Replace"));
388 
389  orig_gaps.push_back(gap);
390  }
391  }
392  ++node;
393  }
394  sort(orig_gaps.begin(), orig_gaps.end());
395  if (!m_TopSeqEntry)
396  return CRef<CCmdComposite>(nullptr);
397 
398  objects::CScope &scope = m_TopSeqEntry.GetScope();
399  bool create_general_only = objects::edit::IsGeneralIdProtPresent(m_TopSeqEntry);
401  CRef<CCmdComposite> composite(new CCmdComposite(title));
402  bool alignment_affected = false;
404  for( objects::CBioseq_CI bi(m_TopSeqEntry, objects::CSeq_inst::eMol_na); bi; ++bi)
405  {
406  objects::CBioseq_Handle bsh = *bi;
407  vector<NRawToDeltaSeq::SGap> gaps(orig_gaps);
408  if ( m_CoordSeq->IsEnabled() && !m_CoordSeq->GetValue())
409  {
410  UseAlignCoords(bsh, gaps);
411  }
412  if (gaps.empty())
413  continue;
414  map_gaps[bsh] = gaps;
415  CRef<objects::CBioseq> bseq( new objects::CBioseq );
416  bseq->Assign(*bsh.GetCompleteBioseq());
417  objects::CSeq_inst& inst = bseq->SetInst();
418  // can only convert if starting as raw
419  if (!inst.IsSetRepr() || inst.GetRepr() != objects::CSeq_inst::eRepr_raw
420  || !inst.IsSetSeq_data()) {
421  continue;
422  }
423 
424  string iupacna;
425  switch(inst.GetSeq_data().Which()) {
426  case objects::CSeq_data::e_Iupacna:
427  iupacna = inst.GetSeq_data().GetIupacna();
428  break;
429  case objects::CSeq_data::e_Ncbi2na:
430  CSeqConvert::Convert(inst.GetSeq_data().GetNcbi2na().Get(), CSeqUtil::e_Ncbi2na,
431  0, inst.GetLength(), iupacna, CSeqUtil::e_Iupacna);
432  break;
433  case objects::CSeq_data::e_Ncbi4na:
434  CSeqConvert::Convert(inst.GetSeq_data().GetNcbi4na().Get(), CSeqUtil::e_Ncbi4na,
435  0, inst.GetLength(), iupacna, CSeqUtil::e_Iupacna);
436  break;
437  case objects::CSeq_data::e_Ncbi8na:
438  CSeqConvert::Convert(inst.GetSeq_data().GetNcbi8na().Get(), CSeqUtil::e_Ncbi8na,
439  0, inst.GetLength(), iupacna, CSeqUtil::e_Iupacna);
440  break;
441  default:
442  return CRef<CCmdComposite>(NULL);
443  break;
444  }
445  int literal_start = 0;
446  inst.ResetSeq_data();
447  inst.SetRepr(objects::CSeq_inst::eRepr_delta);
448  CSeq_inst::TLength total_length = static_cast<CSeq_inst::TLength>(iupacna.length());
449  if (inst.IsSetLength())
450  total_length = inst.GetLength();
451  for (size_t i = 0; i < gaps.size(); i++)
452  {
453  int literal_length = gaps[i].start - literal_start;
454  if (literal_length < 0 || gaps[i].start > iupacna.size())
455  {
456  wxMessageBox(_("Inconsistent gap intervals"), _("Error in gap interval specification"), wxOK|wxICON_ERROR);
457  return CRef<CCmdComposite>(nullptr);
458  }
459  if (literal_length > 0)
460  {
461  string literal = iupacna.substr(literal_start, literal_length);
462  CRef<objects::CDelta_seq> ds(new objects::CDelta_seq());
463  ds->SetLiteral().SetSeq_data().SetIupacna().Set(literal);
464  ds->SetLiteral().SetLength(static_cast<CSeq_literal::TLength>(literal.length()));
465  inst.SetExt().SetDelta().Set().push_back(ds);
466  }
467 
468  CRef<objects::CDelta_seq> gap(new objects::CDelta_seq());
469  if (!gaps[i].is_known)
470  {
471  gap->SetLiteral().SetFuzz().SetLim(objects::CInt_fuzz::eLim_unk);
472  }
473  gap->SetLiteral().SetLength(gaps[i].length);
474  inst.SetExt().SetDelta().Set().push_back(gap);
475  literal_start = gaps[i].start;
476  if (gaps[i].is_replace)
477  literal_start += gaps[i].length;
478  else
479  total_length += gaps[i].length;
480  }
481  if (literal_start < iupacna.size())
482  {
483  string literal = iupacna.substr(literal_start);
484  CRef<objects::CDelta_seq> ds(new objects::CDelta_seq());
485  ds->SetLiteral().SetSeq_data().SetIupacna().Set(literal);
486  ds->SetLiteral().SetLength(static_cast<CSeq_literal::TLength>(literal.length()));
487  inst.SetExt().SetDelta().Set().push_back(ds);
488  }
489  inst.SetLength(total_length);
491  CRef<CCmdChangeBioseqInst> cmd(new CCmdChangeBioseqInst(bsh, bseq->SetInst()));
492  composite->AddCommand(*cmd);
493  }
494  auto local_cmd = composite;
495  local_cmd->Execute();
496  NRawToDeltaSeq::AdjustFeatureLocations(map_gaps, composite, false, m_AdjustCDS->GetValue(), false, create_general_only, max_feat_id, old_to_new, create_xref_map);
497  local_cmd->Unexecute();
498  UpdateDensegAlignment( m_TopSeqEntry, composite, orig_gaps, ( m_CoordSeq->IsEnabled() && !m_CoordSeq->GetValue()));
499 
500  return composite;
501 }
502 
503 void CRawSeqToDeltaSeqByLoc::UseAlignCoords(objects::CBioseq_Handle bsh, vector<NRawToDeltaSeq::SGap> &gaps)
504 {
505  for (size_t i = 0; i < gaps.size(); i++)
506  {
507  int start = gaps[i].start;
508  int stop = gaps[i].start + gaps[i].length - 1;
509  int real_start = -1;
510  int real_stop = -1;
511  ComputeAlignCoords(bsh, start, stop, real_start, real_stop);
512  if (real_start >= 0 && real_stop >= 0)
513  {
514  gaps[i].start = real_start;
515  gaps[i].length = real_stop - real_start + 1;
516  }
517  }
518 }
519 
520 void CRawSeqToDeltaSeqByLoc::ComputeAlignCoords(objects::CBioseq_Handle bsh, int before, int after, int &real_before, int &real_after)
521 {
522  objects::CAlign_CI align_ci(bsh);
523  if (align_ci)
524  {
525  const objects::CSeq_align& align = *align_ci;
526  int row = CEditSeqEndsWithAlign::FindRow(bsh, align);
527  if (row >= 0)
528  {
529  real_before = CEditSeqEndsWithAlign::FindPosition(align,row,before);
530  if (real_before < 0)
531  {
532  before++;
533  while (real_before < 0 && before < bsh.GetBioseqLength())
534  {
535  real_before = CEditSeqEndsWithAlign::FindPosition(align,row,before);
536  before++;
537  }
538  }
539  real_after = CEditSeqEndsWithAlign::FindPosition(align,row,after);
540  if (real_after < 0)
541  {
542  after--;
543  while (real_after < 0 && after >= 0)
544  {
545  real_after = CEditSeqEndsWithAlign::FindPosition(align,row,after);
546  after--;
547  }
548  }
549  }
550  }
551 }
552 
553 
554 void CRawSeqToDeltaSeqByLoc::UpdateDensegAlignment( const CSeq_entry_Handle& tse, CRef<CCmdComposite> composite, const vector<NRawToDeltaSeq::SGap> &gaps, const bool use_align_coords)
555 {
556  for (objects::CAlign_CI align_ci(tse); align_ci; ++ align_ci)
557  {
558  const objects::CSeq_align& align = *align_ci;
559  int num_rows = align.CheckNumRows();
560  if (num_rows < 2)
561  break;
562  if (!align.IsSetSegs() || !align.GetSegs().IsDenseg() ||
563  !align.GetSegs().GetDenseg().IsSetStarts() || !align.GetSegs().GetDenseg().IsSetLens())
564  continue;
565 
566  vector< TSignedSeqPos > starts(align.GetSegs().GetDenseg().GetStarts()); // TODO take into account strand
567  vector< TSeqPos > lens(align.GetSegs().GetDenseg().GetLens());
568 
569  vector< ENa_strand > strands;
570  vector<vector<vector< ENa_strand > > > all_new_strands;
571  if (align.GetSegs().GetDenseg().IsSetStrands())
572  strands = align.GetSegs().GetDenseg().GetStrands();
573 
574  vector< CRef< CScore > > scores;
575  vector< vector< CRef< CScore > > > all_new_scores;
576  if (align.GetSegs().GetDenseg().IsSetScores())
577  scores = align.GetSegs().GetDenseg().GetScores();
578 
579  vector< vector< vector<TSignedSeqPos> > > all_new_starts;
580  vector< vector<TSeqPos> > all_new_lens;
581 
582  x_UpdateRows(num_rows, gaps, starts, lens, strands, scores, all_new_starts, all_new_lens, all_new_strands, all_new_scores, use_align_coords, align);
583 
584  // TODO use align coords
585  CSeq_align_Handle ah = align_ci.GetSeq_align_Handle();
586  if (all_new_lens.empty())
587  {
588  CRef<objects::CCmdDelSeq_align> cmd(new objects::CCmdDelSeq_align(ah));
589  composite->AddCommand(*cmd);
590  }
591  else
592  {
593  CRef<CSeq_align> new_align = x_GetNewAlign(0, align, num_rows, all_new_starts, all_new_lens, all_new_strands, all_new_scores);
594  CRef<CCmdChangeAlign> cmd (new CCmdChangeAlign(ah, *new_align));
595  composite->AddCommand(*cmd);
596 
597  for (size_t block = 1; block < all_new_lens.size(); block++)
598  {
599  CRef<CSeq_align> add_align = x_GetNewAlign(block, align, num_rows, all_new_starts, all_new_lens, all_new_strands, all_new_scores);
601  CRef<CCmdCreateAlign> add_cmd(new CCmdCreateAlign(seh, *add_align));
602  composite->AddCommand(*add_cmd);
603  }
604  }
605  }
606 }
607 
608 void CRawSeqToDeltaSeqByLoc::x_UpdateRows(const size_t num_rows, const vector<NRawToDeltaSeq::SGap> &gaps, const vector< TSignedSeqPos > &orig_starts, const vector< TSeqPos > &lens,
609  const vector< ENa_strand > &strands, const vector< CRef< CScore > > &scores,
610  vector < vector< vector<TSignedSeqPos> > > &all_new_starts, vector < vector<TSeqPos> > &all_new_lens,
611  vector< vector< vector< ENa_strand > > > &all_new_strands, vector< vector< CRef< CScore > > > &all_new_scores,
612  const bool use_align_coords, const objects::CSeq_align& align)
613 {
614  vector< vector<TSignedSeqPos> > new_starts(num_rows);
615  vector<TSeqPos> new_lens;
616  vector< vector< ENa_strand > > new_strands(num_rows);
617  vector< CRef< CScore > > new_scores;
618 
619  vector< TSignedSeqPos > starts(orig_starts);
620  vector< TSignedSeqPos > stops(orig_starts);
621  size_t num_segs = lens.size();
622  for (size_t s = 0; s < num_segs; s++)
623  for (size_t row = 0; row < num_rows; row++)
624  if (starts[num_rows * s + row] != -1)
625  stops[num_rows * s + row] += lens[s] - 1;
626 
627  vector<TSeqPos> offset(num_rows, 0);
628  size_t i = 0;
629  size_t j = 0;
630  vector<bool> next_segment(num_rows, false);
631  vector<bool> next_gap(num_rows, false);
632  set<TSeqPos> break_aligns;
633  set<TSeqPos> break_aligns_before;
635  map<TSeqPos,TSeqPos> lengths;
636  set<size_t> delete_segs;
637  set<size_t> before_segs;
638  while ( j < num_segs )
639  {
640  for (size_t row = 0; row < num_rows; row++)
641  {
642  if (next_segment[row] || next_gap[row])
643  continue;
644 
645  TSignedSeqPos orig_seg_start = orig_starts[num_rows*j+row];
646  TSignedSeqPos seg_start = starts[num_rows*j+row];
647  if (seg_start < 0)
648  {
649  next_segment[row] = true;
650  continue;
651  }
652  TSignedSeqPos seg_stop = stops[num_rows*j+row];
653 
654  int gap_start = 0;
655  if (i < gaps.size())
656  {
657  gap_start = gaps[i].start;
658  if (use_align_coords)
659  {
660  int total_len = 0;
661  for (size_t s = 0; s < lens.size(); s++)
662  total_len += lens[s];
663  int real_before = CEditSeqEndsWithAlign::FindPosition(align,static_cast<int>(row),gap_start);
664  if (real_before < 0)
665  {
666  gap_start++;
667  while (real_before < 0 && gap_start < total_len)
668  {
669  real_before = CEditSeqEndsWithAlign::FindPosition(align,static_cast<int>(row),gap_start);
670  gap_start++;
671  }
672  }
673  gap_start = real_before;
674  }
675  }
676 
677  if ( i >= gaps.size() || seg_stop < gap_start) // no inserts or replaces in this interval
678  {
679  next_segment[row] = true;
680  }
681  else if (!gaps[i].is_replace && gap_start <= seg_start) // insert before the interval
682  {
683  if (gaps[i].is_known)
684  offset[row] += gaps[i].length;
685  else
686  offset[row] += 100;
687  next_gap[row] = true;
688  }
689  else if (gaps[i].is_replace && gaps[i].is_known && gap_start + gaps[i].length <= seg_start) // known replace before the interval
690  {
691  next_gap[row] = true;
692  }
693  else if (gaps[i].is_replace && !gaps[i].is_known && gap_start + 100 <= seg_start) // unknown replace before the interval
694  {
695  offset[row] += 100 - gaps[i].length;
696  next_gap[row] = true;
697  }
698  else if (!gaps[i].is_replace && gaps[i].is_known && gap_start > seg_start && gap_start <= seg_stop) // known insert
699  {
700  TSeqPos new_stop = gap_start + offset[row] - 1;
701 
702  breaks[gap_start - orig_seg_start].push_back(pair<TSeqPos, size_t>(new_stop + 1, row));
703  lengths[gap_start - orig_seg_start] = gaps[i].length;
704 
705  starts[num_rows*j+row] = gap_start; // no offset here because we are processing the current interval again.
706  offset[row] += gaps[i].length;
707  next_gap[row] = true;
708  }
709  else if (!gaps[i].is_replace && !gaps[i].is_known && gap_start > seg_start && gap_start <= seg_stop) // unknown insert
710  {
711  TSeqPos new_stop = gap_start + offset[row] - 1;
712 
713  breaks[gap_start - orig_seg_start].push_back(pair<TSeqPos, size_t>(new_stop + 1, row) );
714  lengths[gap_start - orig_seg_start] = 100;
715 
716  starts[num_rows*j+row] = gap_start; // no offset here because we are processing the current interval again.
717  offset[row] += 100;
718  next_gap[row] = true;
719  break_aligns.insert(gap_start - orig_seg_start);
720  }
721  else if (gaps[i].is_replace && gaps[i].is_known && gap_start >= seg_start && gap_start + gaps[i].length - 1 <= seg_stop) // known replace
722  {
723  next_gap[row] = true;
724  }
725  else if (gaps[i].is_replace && !gaps[i].is_known && gap_start <= seg_start && gap_start + gaps[i].length - 1 < seg_stop) // unknown replace on the left edge
726  {
727  offset[row] += 100 - gaps[i].length;
728 
729  starts[num_rows*j+row] = gap_start + gaps[i].length;
730  next_gap[row] = true;
731  if (j != 0) // check if it is the very first interval, otherwise create a new feat
732  {
733  break_aligns_before.insert(gap_start + gaps[i].length - orig_seg_start);
734  }
735  }
736  else if (gaps[i].is_replace && !gaps[i].is_known && gap_start <= seg_start && gap_start + gaps[i].length - 1 >= seg_stop) // unknown replace of the whole interval
737  {
738  next_segment[row] = true;
739  break_aligns_before.insert(gap_start - orig_seg_start);
740  }
741  else if (gaps[i].is_replace && !gaps[i].is_known && gap_start > seg_start && gap_start <= seg_stop && gap_start + gaps[i].length - 1 > seg_stop) // unknown replace on the right edge
742  {
743  offset[row] += 100 - gaps[i].length;
744 
745  if (j != num_segs - 1 ) // check if it is the very last interval, otherwise create a new feat
746  {
747  break_aligns_before.insert(gap_start - orig_seg_start);
748  }
749  next_segment[row] = true;
750  }
751  else if (gaps[i].is_replace && !gaps[i].is_known && gap_start > seg_start && gap_start <= seg_stop && gap_start + gaps[i].length - 1 <= seg_stop) // unknwon replace
752  {
753  offset[row] += 100 - gaps[i].length;
754 
755  starts[num_rows*j+row] = gap_start + gaps[i].length; // no offset here because we are processing the current interval again.
756  next_gap[row] = true;
757  break_aligns_before.insert(gap_start - orig_seg_start);
758  }
759  else
760  next_gap[row] = true;
761  }
762 
763  bool all_next_segment = true;
764  bool all_next_gap = true;
765  for (size_t row = 0; row < num_rows; row++)
766  {
767  all_next_segment &= next_segment[row];
768  all_next_gap &= next_gap[row];
769  }
770  set<TSeqPos>::const_iterator bai = break_aligns_before.begin();
771  if (all_next_segment)
772  {
773  vector< TSignedSeqPos > current_starts(orig_starts);
774  TSeqPos prev_break = 0;
775  for (map<TSeqPos, vector<pair<TSeqPos, size_t> > >::const_iterator b = breaks.begin(); b != breaks.end(); ++b)
776  {
777  TSeqPos start = b->first;
778  for (size_t row = 0; row < num_rows; row++)
779  {
780  TSignedSeqPos seg_start = current_starts[num_rows*j+row];
781  new_starts[row].push_back(seg_start);
782  current_starts[num_rows*j+row] += start - prev_break;
783  new_starts[row].push_back(-1);
784  if (!strands.empty())
785  {
786  new_strands[row].push_back(strands[num_rows*j+row]);
787  new_strands[row].push_back(strands[num_rows*j+row]);
788  }
789  }
790  new_lens.push_back(start - prev_break);
791 
792  if (!scores.empty())
793  {
794  CRef<CScore> score(new CScore);
795  score->Assign(*scores[j]);
796  new_scores.push_back(score);
797  }
798 
799  if (break_aligns.find(start) != break_aligns.end())
800  delete_segs.insert(new_lens.size());
801  if (bai != break_aligns_before.end() && start > *bai)
802  {
803  before_segs.insert(new_lens.size());
804  ++bai;
805  }
806  for (size_t r = 0; r < b->second.size(); r++)
807  {
808  size_t row = b->second[r].second;
809  new_starts[row].back() = b->second[r].first;
810  current_starts[num_rows*j+row] += lengths[start];
811  }
812  new_lens.push_back(lengths[start]);
813  if (!scores.empty())
814  {
815  CRef<CScore> score(new CScore);
816  score->Assign(*scores[j]);
817  new_scores.push_back(score);
818  }
819  prev_break = start;
820  }
821 
822  TSignedSeqPos len = lens[j];
823  len -= prev_break;
824  if (len > 0)
825  {
826  for (size_t row = 0; row < num_rows; row++)
827  {
828  TSignedSeqPos seg_start = current_starts[num_rows*j+row];
829  new_starts[row].push_back(seg_start);
830  if (!strands.empty())
831  new_strands[row].push_back(strands[num_rows*j+row]);
832  }
833  if (bai != break_aligns_before.end() && prev_break < *bai)
834  {
835  before_segs.insert(new_lens.size());
836  }
837  new_lens.push_back(len);
838  if (!scores.empty())
839  {
840  CRef<CScore> score(new CScore);
841  score->Assign(*scores[j]);
842  new_scores.push_back(score);
843  }
844  }
845 
846  breaks.clear();
847  lengths.clear();
848  break_aligns.clear();
849  break_aligns_before.clear();
850  if (all_next_segment)
851  {
852  for (size_t row = 0; row < num_rows; row++)
853  next_segment[row] = false;
854  j++;
855  }
856  }
857 
858  if (all_next_gap)
859  {
860  for (size_t row = 0; row < num_rows; row++)
861  next_gap[row] = false;
862  i++;
863  }
864  }
865 
866  vector< vector<TSignedSeqPos> > block_starts(num_rows);
867  vector<TSeqPos> block_lens;
868  vector< vector< ENa_strand > > block_strands(num_rows);
869  vector< CRef< CScore > > block_scores;
870  for (size_t seg = 0; seg < new_lens.size(); seg++)
871  {
872  if (delete_segs.find(seg) != delete_segs.end() || before_segs.find(seg) != before_segs.end())
873  {
874  all_new_starts.push_back(block_starts);
875  all_new_lens.push_back(block_lens);
876  all_new_strands.push_back(block_strands);
877  all_new_scores.push_back(block_scores);
878  block_starts.clear();
879  block_starts.resize(num_rows);
880  block_lens.clear();
881  block_strands.clear();
882  block_strands.resize(num_rows);
883  block_scores.clear();
884  }
885  if (delete_segs.find(seg) != delete_segs.end())
886  continue;
887  for (size_t row = 0; row < num_rows; row++)
888  {
889  block_starts[row].push_back(new_starts[row][seg]);
890  if (!strands.empty())
891  block_strands[row].push_back(new_strands[row][seg]);
892  }
893  block_lens.push_back(new_lens[seg]);
894  if (!scores.empty())
895  block_scores.push_back(new_scores[seg]);
896  }
897  if (!block_lens.empty())
898  {
899  all_new_starts.push_back(block_starts);
900  all_new_lens.push_back(block_lens);
901  all_new_strands.push_back(block_strands);
902  all_new_scores.push_back(block_scores);
903  }
904 }
905 
906 CRef<CSeq_align> CRawSeqToDeltaSeqByLoc::x_GetNewAlign(const size_t block, const objects::CSeq_align& align, const size_t num_rows,
907  const vector < vector< vector<TSignedSeqPos> > > &all_new_starts, const vector < vector<TSeqPos> > &all_new_lens,
908  const vector< vector< vector< ENa_strand > > > &all_new_strands, const vector< vector< CRef< CScore > > > &all_new_scores)
909 {
910  vector< TSignedSeqPos > starts_vec(num_rows * all_new_lens[block].size());
911  for (size_t i = 0; i < all_new_lens[block].size(); i++)
912  for (size_t row = 0; row < num_rows; ++row)
913  starts_vec[i * num_rows + row] = all_new_starts[block][row][i];
914 
915  CRef<CSeq_align> new_align(new CSeq_align);
916  new_align->Assign(align);
917  new_align->SetSegs().SetDenseg().SetStarts() = starts_vec;
918  new_align->SetSegs().SetDenseg().SetLens() = all_new_lens[block];
919  new_align->SetSegs().SetDenseg().SetNumseg(static_cast<CDense_seg::TNumseg>(all_new_lens[block].size()));
920  if (!all_new_strands.empty() && all_new_strands[block].size() == num_rows && !all_new_strands[block].front().empty())
921  {
922  vector< ENa_strand > strands_vec(num_rows * all_new_lens[block].size());
923  for (size_t i = 0; i < all_new_lens[block].size(); i++)
924  for (size_t row = 0; row < num_rows; ++row)
925  strands_vec[i * num_rows + row] = all_new_strands[block][row][i];
926  new_align->SetSegs().SetDenseg().SetStrands() = strands_vec;
927  }
928  else
929  new_align->SetSegs().SetDenseg().ResetStrands();
930 
931  if (!all_new_scores[block].empty())
932  new_align->SetSegs().SetDenseg().SetScores() = all_new_scores[block];
933  else
934  new_align->SetSegs().SetDenseg().ResetScores();
935 
936  new_align->SetSegs().SetDenseg().TrimEndGaps();
937  new_align->SetSegs().SetDenseg().RemovePureGapSegs();
938  new_align->SetSegs().SetDenseg().Compact();
939  return new_align;
940 }
941 
943 {
945  bool create_xref_map = true;
946  ByAssemblyGapFeatures_impl(seh, old_to_new, create_xref_map);
947  create_xref_map = false;
948  return ByAssemblyGapFeatures_impl(seh, old_to_new, create_xref_map);
949 }
950 
952 {
953  if (!seh)
954  return CRef<CCmdComposite>(nullptr);
955 
956  objects::CScope &scope = seh.GetScope();
957  bool create_general_only = objects::edit::IsGeneralIdProtPresent(seh.GetTopLevelEntry());
958  CObject_id::TId max_feat_id = CFixFeatureId::s_FindHighestFeatureId(seh.GetTopLevelEntry());
959  CRef<CCmdComposite> composite(new CCmdComposite("Raw Seq to Delta Seq By Assembly_Gap Features"));
960  bool alignment_affected = false;
961  vector<NRawToDeltaSeq::SGap> all_gaps;
963  for( objects::CBioseq_CI bi(seh, objects::CSeq_inst::eMol_na); bi; ++bi)
964  {
965  objects::CBioseq_Handle bsh = *bi;
966  TSeqPos seq_start = bsh.GetRangeSeq_loc(0,0)->GetStart(objects::eExtreme_Positional);
967  vector<NRawToDeltaSeq::SGap> gaps;
968  for (CFeat_CI feat_it(bsh, SAnnotSelector(CSeqFeatData::eSubtype_assembly_gap)); feat_it; ++feat_it)
969  {
970  const CSeq_loc& feat_loc = feat_it->GetLocation();
971  for(CSeq_loc_CI loc_it(feat_loc, CSeq_loc_CI::eEmpty_Skip, CSeq_loc_CI::eOrder_Positional); loc_it; ++loc_it)
972  {
973  CSeq_loc_CI::TRange feat_range = loc_it.GetRange();
974  NRawToDeltaSeq::SGap gap;
975  gap.start = feat_range.GetFrom() - seq_start;
976  gap.length = feat_range.GetTo() - seq_start - gap.start + 1;
977  gap.is_known = true;
978  if (feat_it->GetNamedQual("estimated_length") == "unknown")
979  gap.is_known = false;
980  gap.gap_type = objects::CSeq_gap::eType_unknown;
981  string gap_type_str = feat_it->GetNamedQual("gap_type");
982  if (!gap_type_str.empty())
983  {
984  if (objects::CSeq_gap::ENUM_METHOD_NAME(EType)()->IsValidName(gap_type_str))
985  gap.gap_type = objects::CSeq_gap::ENUM_METHOD_NAME(EType)()->FindValue(gap_type_str);
986  else
987  {
988  const objects::CSeq_gap::SGapTypeInfo *gap_type_info = objects::CSeq_gap::NameToGapTypeInfo(gap_type_str); // NameToGapTypeInfo does not recognize all gap types
989  if (gap_type_info)
990  gap.gap_type = gap_type_info->m_eType;
991  }
992  }
993  gap.linkage = objects::CSeq_gap::eLinkage_unlinked;
994  gap.linkage_evidence = -1;
995  string linkage_evidence_str = feat_it->GetNamedQual("linkage_evidence");
996  if ( gap.gap_type == objects::CSeq_gap::eType_repeat || gap.gap_type == objects::CSeq_gap::eType_scaffold || gap.gap_type == objects::CSeq_gap::eType_contamination)
997  {
998  gap.linkage = objects::CSeq_gap::eLinkage_linked;
999  if (!linkage_evidence_str.empty() && objects::CLinkage_evidence::ENUM_METHOD_NAME(EType)()->IsValidName(linkage_evidence_str))
1000  gap.linkage_evidence = objects::CLinkage_evidence::ENUM_METHOD_NAME(EType)()->FindValue(linkage_evidence_str);
1001  }
1002  gap.is_replace = true;
1003  gaps.push_back(gap);
1004  all_gaps.push_back(gap);
1005  }
1006  }
1007  if (gaps.empty())
1008  continue;
1009  sort(gaps.begin(), gaps.end());
1010  map_gaps[bsh] = gaps;
1011  CRef<objects::CBioseq> bseq( new objects::CBioseq );
1012  bseq->Assign(*bsh.GetCompleteBioseq());
1013  objects::CSeq_inst& inst = bseq->SetInst();
1014  // can only convert if starting as raw
1015  if (!inst.IsSetRepr() || inst.GetRepr() != objects::CSeq_inst::eRepr_raw
1016  || !inst.IsSetSeq_data()) {
1017  continue;
1018  }
1019 
1020  string iupacna;
1021  switch(inst.GetSeq_data().Which()) {
1022  case objects::CSeq_data::e_Iupacna:
1023  iupacna = inst.GetSeq_data().GetIupacna();
1024  break;
1025  case objects::CSeq_data::e_Ncbi2na:
1026  CSeqConvert::Convert(inst.GetSeq_data().GetNcbi2na().Get(), CSeqUtil::e_Ncbi2na,
1027  0, inst.GetLength(), iupacna, CSeqUtil::e_Iupacna);
1028  break;
1029  case objects::CSeq_data::e_Ncbi4na:
1030  CSeqConvert::Convert(inst.GetSeq_data().GetNcbi4na().Get(), CSeqUtil::e_Ncbi4na,
1031  0, inst.GetLength(), iupacna, CSeqUtil::e_Iupacna);
1032  break;
1033  case objects::CSeq_data::e_Ncbi8na:
1034  CSeqConvert::Convert(inst.GetSeq_data().GetNcbi8na().Get(), CSeqUtil::e_Ncbi8na,
1035  0, inst.GetLength(), iupacna, CSeqUtil::e_Iupacna);
1036  break;
1037  default:
1038  return CRef<CCmdComposite>(NULL);
1039  break;
1040  }
1041  int literal_start = 0;
1042  inst.ResetSeq_data();
1043  inst.SetRepr(objects::CSeq_inst::eRepr_delta);
1044  CSeq_inst::TLength total_length = static_cast<CSeq_inst::TLength>(iupacna.length());
1045  if (inst.IsSetLength())
1046  total_length = inst.GetLength();
1047  for (size_t i = 0; i < gaps.size(); i++)
1048  {
1049  int literal_length = gaps[i].start - literal_start;
1050  if (literal_length < 0 || gaps[i].start > iupacna.size())
1051  {
1052  if (create_xref_map)
1053  wxMessageBox(_("Inconsistent gap intervals"), _("Error in gap interval specification"), wxOK|wxICON_ERROR);
1054  return CRef<CCmdComposite>(nullptr);
1055  }
1056  if (literal_length > 0)
1057  {
1058  string literal = iupacna.substr(literal_start, literal_length);
1059  CRef<objects::CDelta_seq> ds(new objects::CDelta_seq());
1060  ds->SetLiteral().SetSeq_data().SetIupacna().Set(literal);
1061  ds->SetLiteral().SetLength(static_cast<CSeq_literal::TLength>(literal.length()));
1062  inst.SetExt().SetDelta().Set().push_back(ds);
1063  }
1064 
1065  CRef<objects::CDelta_seq> gap(new objects::CDelta_seq());
1066  if (!gaps[i].is_known)
1067  {
1068  gap->SetLiteral().SetFuzz().SetLim(objects::CInt_fuzz::eLim_unk);
1069  }
1070  gap->SetLiteral().SetLength(gaps[i].length);
1071  gap->SetLiteral().SetSeq_data().SetGap().SetType(gaps[i].gap_type);
1072  gap->SetLiteral().SetSeq_data().SetGap().SetLinkage(gaps[i].linkage);
1073  if (gaps[i].linkage_evidence >= 0)
1074  {
1076  link_ev->SetType(gaps[i].linkage_evidence);
1077  gap->SetLiteral().SetSeq_data().SetGap().SetLinkage_evidence().push_back(link_ev);
1078  }
1079 
1080  inst.SetExt().SetDelta().Set().push_back(gap);
1081  literal_start = gaps[i].start;
1082  if (gaps[i].is_replace)
1083  literal_start += gaps[i].length;
1084  else
1085  total_length += gaps[i].length;
1086  }
1087  if (literal_start < iupacna.size())
1088  {
1089  string literal = iupacna.substr(literal_start);
1090  CRef<objects::CDelta_seq> ds(new objects::CDelta_seq());
1091  ds->SetLiteral().SetSeq_data().SetIupacna().Set(literal);
1092  ds->SetLiteral().SetLength(static_cast<CSeq_literal::TLength>(literal.length()));
1093  inst.SetExt().SetDelta().Set().push_back(ds);
1094  }
1095  inst.SetLength(total_length);
1096  //objects::edit::NormalizeUnknownLengthGaps(inst);
1097  CRef<CCmdChangeBioseqInst> cmd(new CCmdChangeBioseqInst(bsh, bseq->SetInst()));
1098  composite->AddCommand(*cmd);
1099 
1100  for (CFeat_CI feat_it(bsh, SAnnotSelector(CSeqFeatData::eSubtype_assembly_gap)); feat_it; ++feat_it)
1101  {
1102  composite->AddCommand(*CRef<CCmdDelSeq_feat>(new CCmdDelSeq_feat(feat_it->GetSeq_feat_Handle())));
1103  }
1104  }
1105  auto local_cmd = composite;
1106  local_cmd->Execute();
1107  NRawToDeltaSeq::AdjustFeatureLocations(map_gaps, composite, false, true, false, create_general_only, max_feat_id, old_to_new, create_xref_map);
1108  local_cmd->Unexecute();
1109  UpdateDensegAlignment( seh, composite, all_gaps, false);
1110 
1111  return composite;
1112 }
1113 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
Data storage class.
User-defined methods of the data storage class.
@ eExtreme_Positional
numerical value
Definition: Na_strand.hpp:63
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
bool IsGeneralIdProtPresent(objects::CSeq_entry_Handle tse)
void AddCommand(IEditCommand &command)
virtual void Execute()
Do the editing action.
static int FindRow(const CBioseq_Handle &bsh, const CSeq_align &align)
static int FindPosition(const CSeq_align &align, int row, int after)
CFeat_CI –.
Definition: feat_ci.hpp:64
static TId s_FindHighestFeatureId(const objects::CSeq_entry_Handle &entry)
CRef< CCmdComposite > apply_impl(string title, map< objects::CObject_id::TId, objects::CObject_id::TId > &old_to_new, bool create_xref_map)
void ComputeAlignCoords(objects::CBioseq_Handle bsh, int before, int after, int &real_before, int &real_after)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void OnNewText(wxCommandEvent &event)
void Init()
Initialises member variables.
static void x_UpdateRows(size_t num_rows, const vector< NRawToDeltaSeq::SGap > &gaps, const vector< TSignedSeqPos > &orig_starts, const vector< TSeqPos > &lens, const vector< objects::ENa_strand > &strands, const vector< CRef< objects::CScore > > &scores, vector< vector< vector< TSignedSeqPos > > > &all_new_starts, vector< vector< TSeqPos > > &all_new_lens, vector< vector< vector< objects::ENa_strand > > > &all_new_strands, vector< vector< CRef< objects::CScore > > > &all_new_scores, const bool use_align_coords, const objects::CSeq_align &align)
void CreateControls()
Creates the controls and sizers.
static bool ShowToolTips()
Should we show tooltips?
objects::CSeq_entry_Handle m_TopSeqEntry
static CRef< objects::CSeq_align > x_GetNewAlign(const size_t block, const objects::CSeq_align &align, const size_t num_rows, const vector< vector< vector< TSignedSeqPos > > > &all_new_starts, const vector< vector< TSeqPos > > &all_new_lens, const vector< vector< vector< objects::ENa_strand > > > &all_new_strands, const vector< vector< CRef< objects::CScore > > > &all_new_scores)
CRef< CCmdComposite > apply(string title)
void UseAlignCoords(objects::CBioseq_Handle bsh, vector< NRawToDeltaSeq::SGap > &gaps)
static CRef< CCmdComposite > ByAssemblyGapFeatures_impl(objects::CSeq_entry_Handle seh, map< objects::CObject_id::TId, objects::CObject_id::TId > &old_to_new, bool create_xref_map)
static void UpdateDensegAlignment(const objects::CSeq_entry_Handle &tse, CRef< CCmdComposite > composite, const vector< NRawToDeltaSeq::SGap > &gaps, const bool use_align_coords)
static CRef< CCmdComposite > ByAssemblyGapFeatures(objects::CSeq_entry_Handle seh)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool Create(wxWindow *parent, wxWindowID id=10000, const wxString &caption=_("Convert Raw Sequence to Delta Sequence"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
Definition: Score.hpp:57
static SIZE_TYPE Convert(const CTempString &src, TCoding src_coding, TSeqPos pos, TSeqPos length, string &dst, TCoding dst_coding)
@ e_Ncbi8na
Definition: sequtil.hpp:52
@ e_Iupacna
Definition: sequtil.hpp:47
@ e_Ncbi4na
Definition: sequtil.hpp:50
@ e_Ncbi2na
Definition: sequtil.hpp:48
CSeq_entry_Handle –.
Seq-loc iterator class – iterates all intervals from a seq-loc in the correct order.
Definition: Seq_loc.hpp:453
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
void clear()
Definition: set.hpp:153
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
void AdjustFeatureLocations(const map< objects::CBioseq_Handle, vector< SGap >> &map_gaps, CRef< CCmdComposite > composite, bool split_gene_locations, bool break_features, bool keep_gap_length, bool create_general_only, objects::CObject_id::TId &max_feat_id, map< objects::CObject_id::TId, objects::CObject_id::TId > &old_to_new, bool create_xref_map)
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
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
int TSignedSeqPos
Type for signed sequence position.
Definition: ncbimisc.hpp:887
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
#define ENUM_METHOD_NAME(EnumName)
Definition: serialbase.hpp:994
@ eOrder_Positional
Definition: Seq_loc.hpp:461
CSeq_entry_Handle GetParentEntry(void) const
Get parent Seq-entry handle.
const CSeq_annot_Handle & GetAnnot(void) const
Get handle to the seq-annot.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
CTempString literal(const char(&str)[Size])
Templatized initialization from a string literal.
Definition: tempstr.hpp:441
size_type length(void) const
Return the length of the represented array.
Definition: tempstr.hpp:320
CTempString substr(size_type pos) const
Obtain a substring from this string, beginning at a given offset.
Definition: tempstr.hpp:776
TTo GetTo(void) const
Get the To member data.
Definition: Range_.hpp:269
TFrom GetFrom(void) const
Get the From member data.
Definition: Range_.hpp:222
void SetSegs(TSegs &value)
Assign a value to Segs data member.
Definition: Seq_align_.cpp:310
TSeqPos TLength
Definition: Seq_inst_.hpp:147
END_EVENT_TABLE()
int i
int len
constexpr auto sort(_Init &&init)
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
The Object manager core.
#define ID_CRAWTODELTA_RADIOBUTTON1
#define ID_CRAWTODELTA_CHECKBOX
#define ID_CRAWTODELTA_RADIOBUTTON
#define ID_CRAWTODELTA_SCROLLEDWINDOW
int offset
Definition: replacements.h:160
TLocAdjustmentVector NormalizeUnknownLengthGaps(CSeq_inst &inst, TSeqPos unknown_length=100)
NormalizeUnknownLengthGaps A function to adjust the length of unknown-length gaps to a specific lengt...
static static static wxID_ANY
SAnnotSelector –.
Modified on Thu Nov 30 04:52:25 2023 by modify_doxy.py rev. 669887