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

Go to the SVN repository for this file.

1 /* $Id: convert_selected_gaps.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>
41 #include <gui/objutils/objects.hpp>
42 #include <objmgr/bioseq_ci.hpp>
43 #include <objmgr/feat_ci.hpp>
45 #include <objects/seq/Seq_ext.hpp>
50 #include <objmgr/align_ci.hpp>
54 #include <objmgr/seq_vector.hpp>
57 
58 #include <wx/textdlg.h>
59 
62 
63 CRef<CCmdComposite> CConvertSelectedGaps::apply(const TConstScopedObjects &objects, bool to_known, bool adjust_features)
64 {
66  bool create_xref_map = true;
67  apply_impl(objects, to_known, adjust_features, old_to_new, create_xref_map);
68  create_xref_map = false;
69  return apply_impl(objects, to_known, adjust_features, old_to_new, create_xref_map);
70 }
71 
73  map<CObject_id::TId, CObject_id::TId> &old_to_new, bool create_xref_map)
74 {
75  CRef<CCmdComposite> composite( new CCmdComposite("Convert Selected Gaps") );
76  map<CBioseq_Handle, pair<CRef<CSeq_inst>, bool> > bsh_to_inst;
77  bool create_general_only = false;
78  CObject_id::TId max_feat_id = 1;
79  bool first = true;
81  {
82  CBioseq_Handle bsh;
83  const CGapEdit* gap_edit = dynamic_cast<const CGapEdit*>((*it).object.GetPointer());
84  if (gap_edit)
85  {
86  bsh = gap_edit->GetBioseq_Handle();
87  }
88  const CSeq_feat* feat = dynamic_cast<const CSeq_feat*>((*it).object.GetPointer());
89  if (feat && feat->IsSetData() && feat->GetData().IsImp() && feat->GetData().GetImp().IsSetKey() && feat->GetData().GetImp().GetKey() == "gap" && feat->IsSetLocation())
90  {
91  CRef<objects::CScope> scope = it->scope;
92  bsh = scope->GetBioseqHandle(feat->GetLocation());
93  }
94 
95  if (!bsh)
96  continue;
97  if (bsh_to_inst.find(bsh) != bsh_to_inst.end())
98  continue;
99  if (!bsh.IsSetInst())
100  continue;
101  if (first)
102  {
104  max_feat_id = CFixFeatureId::s_FindHighestFeatureId(seh);
105  create_general_only = objects::edit::IsGeneralIdProtPresent(seh);
106  first = false;
107  }
108  const CSeq_inst &inst = bsh.GetInst();
109  if (!inst.IsSetExt() || !inst.GetExt().IsDelta())
110  continue;
111 
112  CRef<CSeq_inst> new_inst(new CSeq_inst);
113  new_inst->Assign(inst);
114  bsh_to_inst[bsh] = make_pair(new_inst, false);
115  }
118 
120  {
121  CRef<CScope> scope = it->scope;
122  CBioseq_Handle bsh;
123  TSeqPos from;
124  const CGapEdit* gap_edit = dynamic_cast<const CGapEdit*>((*it).object.GetPointer());
125  if (gap_edit)
126  {
127  bsh = gap_edit->GetBioseq_Handle();
128  from = gap_edit->GetFrom();
129  }
130  const CSeq_feat* feat = dynamic_cast<const CSeq_feat*>((*it).object.GetPointer());
131  if (feat && feat->IsSetData() && feat->GetData().IsImp() && feat->GetData().GetImp().IsSetKey() && feat->GetData().GetImp().GetKey() == "gap" && feat->IsSetLocation())
132  {
133  bsh = scope->GetBioseqHandle(feat->GetLocation());
134  from = feat->GetLocation().GetStart(eExtreme_Positional) + 1;
135  }
136 
137  if (!bsh)
138  continue;
139 
140  for (const auto& d : diffs[bsh])
141  if (d.first < from)
142  {
143  from += d.second;
144  }
145 
146  CRef<CSeq_inst> new_inst = bsh_to_inst[bsh].first;
147  TSeqPos start = 1;
148  NON_CONST_ITERATE(CDelta_ext::Tdata, delta_i, new_inst->SetExt().SetDelta().Set())
149  {
150  if (delta_i->Empty())
151  continue;
152  CDelta_seq& seg = **delta_i;
153 
154  TSeqPos delta_len = 0;
155  if (seg.IsLiteral())
156  {
157  delta_len = seg.GetLiteral().GetLength();
158  }
159  else if (seg.IsLoc())
160  {
161  delta_len = sequence::GetLength (seg.GetLoc(), scope.GetPointer());
162  }
163 
164  if (start == from)
165  {
166  if (to_known)
167  seg.SetLiteral().ResetFuzz();
168  else
169  {
170  seg.SetLiteral().SetFuzz().SetLim(CInt_fuzz::eLim_unk);
171  seg.SetLiteral().SetLength(100);
172  int diff = 100;
173  diff -= delta_len;
174  if (new_inst->IsSetLength())
175  {
176  diffs[bsh][start] = diff;
177  TSeqPos old_length = new_inst->GetLength();
178  new_inst->SetLength(old_length + diff);
179  }
180 
181  {
182  NRawToDeltaSeq::SGap gap;
183  gap.start = start;
184  gap.length = delta_len;
185  gap.is_known = false;
186  gap.is_replace = true;
187  gaps[bsh].push_back(gap);
188  }
189  }
190  bsh_to_inst[bsh].second = true;
191  break;
192  }
193 
194  start += delta_len;
195  }
196 
197  int diff = 0;
198  for (CFeat_CI feat_ci(bsh, CSeqFeatData::eSubtype_gap); feat_ci; ++feat_ci)
199  {
200  const CSeq_feat& orig = feat_ci->GetOriginalFeature();
201  start = orig.GetLocation().GetStart(eExtreme_Positional) + 1;
202  if (start == from)
203  {
204  CRef<CSeq_feat> new_feat(new CSeq_feat());
205  new_feat->Assign(orig);
206  TSeqPos delta_len = new_feat->GetLocation().GetTotalRange().GetLength();
207  if (to_known)
208  {
209  new_feat->AddOrReplaceQualifier("estimated_length", NStr::UIntToString(delta_len));
210  }
211  else
212  {
213  new_feat->AddOrReplaceQualifier("estimated_length", "unknown");
214  diff = 100;
215  diff -= delta_len;
216  if (new_feat->GetLocation().IsInt())
217  {
218  new_feat->SetLocation().SetInt().SetTo(new_feat->GetLocation().GetInt().GetFrom() + 100 - 1);
219  }
220  if (!bsh_to_inst[bsh].second && new_inst->IsSetLength())
221  {
222  diffs[bsh][start] = diff;
223  TSeqPos old_length = new_inst->GetLength();
224  new_inst->SetLength(old_length + diff);
225  {
226  NRawToDeltaSeq::SGap gap;
227  gap.start = start;
228  gap.length = delta_len;
229  gap.is_known = false;
230  gap.is_replace = true;
231  gaps[bsh].push_back(gap);
232  }
233  bsh_to_inst[bsh].second = true;
234  }
235  }
236  composite->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(feat_ci->GetSeq_feat_Handle(), *new_feat)));
237  break;
238  }
239  }
240  if (diff != 0)
241  {
242  for (CFeat_CI feat_ci(bsh, CSeqFeatData::eSubtype_gap); feat_ci; ++feat_ci)
243  {
244  const CSeq_feat& orig = feat_ci->GetOriginalFeature();
245  start = orig.GetLocation().GetStart(eExtreme_Positional) + 1;
246  if (start > from)
247  {
248  CRef<CSeq_feat> new_feat(new CSeq_feat());
249  new_feat->Assign(orig);
250  if (new_feat->GetLocation().IsInt())
251  {
252  new_feat->SetLocation().SetInt().SetFrom(new_feat->GetLocation().GetInt().GetFrom() + diff);
253  new_feat->SetLocation().SetInt().SetTo(new_feat->GetLocation().GetInt().GetTo() + diff);
254  composite->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(feat_ci->GetSeq_feat_Handle(), *new_feat)));
255  }
256  }
257  }
258  }
259  }
260  CRef<CCmdComposite> local_cmd( new CCmdComposite("Seq-inst change to facilitate retranslation") );
261  for (const auto& it : bsh_to_inst)
262  {
263  CBioseq_Handle bsh = it.first;
264  CRef<CSeq_inst> new_inst = it.second.first;
265  bool modified = it.second.second;
266  if (modified)
267  {
269  local_cmd->AddCommand(*cmd);
270  }
271  }
272  composite->AddCommand(*local_cmd);
273  if (adjust_features)
274  {
275  local_cmd->Execute();
276  NRawToDeltaSeq::AdjustFeatureLocations(gaps, composite, false, false, false, create_general_only, max_feat_id, old_to_new, create_xref_map);
277  local_cmd->Unexecute();
278  }
279  return composite;
280 }
281 
282 
283 CRef<CCmdComposite> CConvertGapsBySize::apply(objects::CSeq_entry_Handle seh)
284 {
285  wxTextEntryDialog dlg(NULL, _("Convert gaps longer or equal to"), _("Convert Known Length Gaps to Unknown"), _("100"));
286  dlg.SetTextValidator(wxFILTER_NUMERIC);
287  if (dlg.ShowModal() == wxID_OK)
288  {
289  wxString val = dlg.GetValue();
290  long min_size;
291  if(val.ToLong(&min_size))
292  {
293  CScope &scope = seh.GetScope();
295  CRef<CCmdComposite> composite( new CCmdComposite("Convert Gaps By Size") );
296  for (CBioseq_CI bi(seh, CSeq_inst::eMol_na); bi; ++bi)
297  {
298  CBioseq_Handle bsh = *bi;
299  TSeqPos len = bsh.GetBioseqLength();
300  if (len <= 1)
301  continue;
302  if (!bsh.IsSetInst())
303  continue;
304 
305  const CSeq_inst &inst = bsh.GetInst();
306  if (!inst.IsSetExt() || !inst.GetExt().IsDelta())
307  continue;
308  bool has_loc(false);
309  ITERATE(CDelta_ext::Tdata, iter, inst.GetExt().GetDelta().Get())
310  {
311  if ( (*iter)->IsLoc() )
312  {
313  has_loc = true;
314  break;
315  }
316  }
317  if (has_loc)
318  continue;
319 
320  try
321  {
322  TSeqPos pos = 0;
324  ITERATE (CDelta_ext::Tdata, delta_i, inst.GetExt().GetDelta().Get())
325  {
326  if (delta_i->Empty())
327  continue;
328  const CDelta_seq& seg = **delta_i;
329  auto delta_len = seg.GetLiteral().GetLength();
330  if (sv.IsInGap (pos) && delta_len >= min_size && !(seg.GetLiteral().IsSetFuzz() && seg.GetLiteral().GetFuzz().IsLim() && seg.GetLiteral().GetFuzz().GetLim() == objects::CInt_fuzz::eLim_unk) )
331  {
332  {
333  CRef<CGapEdit> gap(new CGapEdit(bsh, pos + 1, delta_len));
334  SConstScopedObject obj(gap, &scope);
335  objects.push_back(obj);
336  }
337 
338  }
339  pos += delta_len;
340  }
341 
342  } catch (CException ) {} catch (std::exception ) {}
343 
344  }
345  if (!objects.empty())
346  {
347  return CConvertSelectedGaps::apply(objects, false, true);
348  }
349  }
350  }
351  return CRef<CCmdComposite>(NULL);
352 }
353 
354 
356 {
358  bool create_xref_map = true;
359  apply_impl(objects, old_to_new, create_xref_map);
360  create_xref_map = false;
361  return apply_impl(objects, old_to_new, create_xref_map);
362 }
363 
365 {
366  CRef<CCmdComposite> composite;
367 
368  wxTextEntryDialog dlg(NULL, _("Change length to"), _("Change length of selected gaps"), _("100"));
369  dlg.SetTextValidator(wxFILTER_NUMERIC);
370  if (dlg.ShowModal() == wxID_OK)
371  {
372  wxString val = dlg.GetValue();
373  long new_size;
374  if(val.ToLong(&new_size))
375  {
376  composite.Reset( new CCmdComposite("Edit Selected Gaps") );
377 
378  map<CBioseq_Handle, pair<CRef<CSeq_inst>, bool> > bsh_to_inst;
379  bool create_general_only = false;
380  bool first = true;
381  CObject_id::TId max_feat_id = 1;
383  {
384  CBioseq_Handle bsh;
385  const CGapEdit* gap_edit = dynamic_cast<const CGapEdit*>((*it).object.GetPointer());
386  if (gap_edit)
387  {
388  bsh = gap_edit->GetBioseq_Handle();
389  }
390  const CSeq_feat* feat = dynamic_cast<const CSeq_feat*>((*it).object.GetPointer());
391  if (feat && feat->IsSetData() && feat->GetData().IsImp() && feat->GetData().GetImp().IsSetKey() && feat->GetData().GetImp().GetKey() == "gap" && feat->IsSetLocation())
392  {
393  CRef<objects::CScope> scope = it->scope;
394  bsh = scope->GetBioseqHandle(feat->GetLocation());
395  }
396 
397  if (!bsh)
398  continue;
399  if (bsh_to_inst.find(bsh) != bsh_to_inst.end())
400  continue;
401  if (!bsh.IsSetInst())
402  continue;
403  if (first)
404  {
406  max_feat_id = CFixFeatureId::s_FindHighestFeatureId(seh);
407  create_general_only = objects::edit::IsGeneralIdProtPresent(seh);
408  first = false;
409  }
410  const CSeq_inst &inst = bsh.GetInst();
411  if (!inst.IsSetExt() || !inst.GetExt().IsDelta())
412  continue;
413  bool has_loc(false);
414  ITERATE(CDelta_ext::Tdata, iter, inst.GetExt().GetDelta().Get())
415  {
416  if ( (*iter)->IsLoc() )
417  {
418  has_loc = true;
419  break;
420  }
421  }
422  if (has_loc)
423  continue;
424 
425  CRef<CSeq_inst> new_inst(new CSeq_inst);
426  new_inst->Assign(inst);
427  bsh_to_inst[bsh] = make_pair(new_inst, false);
428  }
431 
433  {
434  CRef<CScope> scope = it->scope;
435  CBioseq_Handle bsh;
436  TSeqPos from;
437  const CGapEdit* gap_edit = dynamic_cast<const CGapEdit*>((*it).object.GetPointer());
438  if (gap_edit)
439  {
440  bsh = gap_edit->GetBioseq_Handle();
441  from = gap_edit->GetFrom();
442  }
443  const CSeq_feat* feat = dynamic_cast<const CSeq_feat*>((*it).object.GetPointer());
444  if (feat && feat->IsSetData() && feat->GetData().IsImp() && feat->GetData().GetImp().IsSetKey() && feat->GetData().GetImp().GetKey() == "gap" && feat->IsSetLocation())
445  {
446  bsh = scope->GetBioseqHandle(feat->GetLocation());
447  from = feat->GetLocation().GetStart(eExtreme_Positional) + 1;
448  }
449 
450  if (!bsh)
451  continue;
452 
453  for (const auto& d : diffs[bsh])
454  if (d.first < from)
455  {
456  from += d.second;
457  }
458 
459  CRef<CSeq_inst> new_inst = bsh_to_inst[bsh].first;
460  TSeqPos start = 1;
461  NON_CONST_ITERATE(CDelta_ext::Tdata, delta_i, new_inst->SetExt().SetDelta().Set())
462  {
463  if (delta_i->Empty())
464  continue;
465  CDelta_seq& seg = **delta_i;
466 
467  auto delta_len = seg.GetLiteral().GetLength();
468 
469  if (start == from)
470  {
471  seg.SetLiteral().SetLength(static_cast<CSeq_literal::TLength>(new_size));
472  int diff = static_cast<int>(new_size);
473  diff -= delta_len;
474  if (new_inst->IsSetLength())
475  {
476  diffs[bsh][start] = diff;
477  TSeqPos old_length = new_inst->GetLength();
478  new_inst->SetLength(old_length + diff);
479  }
480 
481  {
482  NRawToDeltaSeq::SGap gap;
483  gap.start = start;
484  gap.length = static_cast<int>(new_size - delta_len);
485  gap.is_known = true;
486  gap.is_replace = false;
487  gaps[bsh].push_back(gap);
488  }
489 
490  bsh_to_inst[bsh].second = true;
491  break;
492  }
493 
494  start += delta_len;
495  }
496 
497  int diff = 0;
498  for (CFeat_CI feat_ci(bsh, CSeqFeatData::eSubtype_gap); feat_ci; ++feat_ci)
499  {
500  const CSeq_feat& orig = feat_ci->GetOriginalFeature();
501  start = orig.GetLocation().GetStart(eExtreme_Positional) + 1;
502  if (start == from)
503  {
504  CRef<CSeq_feat> new_feat(new CSeq_feat());
505  new_feat->Assign(orig);
506  TSeqPos delta_len = new_feat->GetLocation().GetTotalRange().GetLength();
507  new_feat->AddOrReplaceQualifier("estimated_length", NStr::LongToString(new_size));
508 
509  diff = static_cast<int>(new_size);
510  diff -= delta_len;
511  if (new_feat->GetLocation().IsInt())
512  {
513  new_feat->SetLocation().SetInt().SetTo(new_feat->GetLocation().GetInt().GetFrom() + static_cast<CSeq_interval::TTo>(new_size) - 1);
514  }
515  if (!bsh_to_inst[bsh].second && new_inst->IsSetLength())
516  {
517  diffs[bsh][start] = diff;
518  TSeqPos old_length = new_inst->GetLength();
519  new_inst->SetLength(old_length + diff);
520  {
521  NRawToDeltaSeq::SGap gap;
522  gap.start = start;
523  gap.length = static_cast<int>(new_size - delta_len);
524  gap.is_known = true;
525  gap.is_replace = false;
526  gaps[bsh].push_back(gap);
527  }
528  bsh_to_inst[bsh].second = true;
529  }
530 
531  composite->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(feat_ci->GetSeq_feat_Handle(), *new_feat)));
532  break;
533  }
534  }
535  if (diff != 0)
536  {
537  for (CFeat_CI feat_ci(bsh, CSeqFeatData::eSubtype_gap); feat_ci; ++feat_ci)
538  {
539  const CSeq_feat& orig = feat_ci->GetOriginalFeature();
540  start = orig.GetLocation().GetStart(eExtreme_Positional) + 1;
541  if (start > from)
542  {
543  CRef<CSeq_feat> new_feat(new CSeq_feat());
544  new_feat->Assign(orig);
545  if (new_feat->GetLocation().IsInt())
546  {
547  new_feat->SetLocation().SetInt().SetFrom(new_feat->GetLocation().GetInt().GetFrom() + diff);
548  new_feat->SetLocation().SetInt().SetTo(new_feat->GetLocation().GetInt().GetTo() + diff);
549  composite->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(feat_ci->GetSeq_feat_Handle(), *new_feat)));
550  }
551  }
552  }
553  }
554  }
555 
556  CRef<CCmdComposite> local_cmd( new CCmdComposite("Seq-inst change to facilitate retranslation") );
557  for (const auto& it : bsh_to_inst)
558  {
559  CBioseq_Handle bsh = it.first;
560  CRef<CSeq_inst> new_inst = it.second.first;
561  bool modified = it.second.second;
562  if (modified)
563  {
565  local_cmd->AddCommand(*cmd);
566  }
567  }
568  composite->AddCommand(*local_cmd);
569  local_cmd->Execute();
570  NRawToDeltaSeq::AdjustFeatureLocations(gaps, composite, false, false, false, create_general_only, max_feat_id, old_to_new, create_xref_map);
571  local_cmd->Unexecute();
572 
573  if (!diffs.empty())
574  {
575  CSeq_entry_Handle tse = diffs.begin()->first.GetTopLevelEntry();
576  for (objects::CAlign_CI align_ci(tse); align_ci; ++ align_ci)
577  {
578  const objects::CSeq_align& align = *align_ci;
579  CSeq_align_Handle ah = align_ci.GetSeq_align_Handle();
580  int num_rows = align.CheckNumRows();
581  if (num_rows < 2)
582  break;
583  if (!align.IsSetSegs() || !align.GetSegs().IsDenseg() ||
584  !align.GetSegs().GetDenseg().IsSetStarts() || !align.GetSegs().GetDenseg().IsSetLens())
585  continue;
586 
587  vector< TSignedSeqPos > starts(align.GetSegs().GetDenseg().GetStarts());
588  size_t num_segs = align.GetSegs().GetDenseg().GetLens().size();
589  for (size_t s = 0; s < num_segs; s++)
590  for (auto row = 0; row < num_rows; row++)
591  {
592  TSignedSeqPos from = starts[num_rows * s + row];
593  if (from != -1)
594  {
595  const CSeq_id& id = align.GetSeq_id(row);
596  CBioseq_Handle bsh = ah.GetScope().GetBioseqHandle(id);
597  if (!bsh)
598  continue;
599  for (const auto& d : diffs[bsh])
600  if (d.first < from)
601  {
602  from += d.second;
603  }
604  starts[num_rows * s + row] = from;
605  }
606  }
607  CRef<CSeq_align> new_align(new CSeq_align);
608  new_align->Assign(align);
609  new_align->SetSegs().SetDenseg().SetStarts() = starts;
610  new_align->SetSegs().SetDenseg().TrimEndGaps();
611  new_align->SetSegs().SetDenseg().RemovePureGapSegs();
612  new_align->SetSegs().SetDenseg().Compact();
613  CRef<CCmdChangeAlign> cmd (new CCmdChangeAlign(ah, *new_align));
614  composite->AddCommand(*cmd);
615  }
616  }
617  }
618  }
619  return composite;
620 }
621 
622 CRef<CCmdComposite> CCombineAdjacentGaps::apply(objects::CSeq_entry_Handle seh)
623 {
625  bool create_xref_map = true;
626  apply_impl(seh, old_to_new, create_xref_map);
627  create_xref_map = false;
628  return apply_impl(seh, old_to_new, create_xref_map);
629 }
630 
631 CRef<CCmdComposite> CCombineAdjacentGaps::apply_impl(objects::CSeq_entry_Handle seh, map<CObject_id::TId, CObject_id::TId> &old_to_new, bool create_xref_map)
632 {
633  CRef<CCmdComposite> composite( new CCmdComposite("Combine Adjacent Gaps") );
634  bool any_modified = false;
635  bool create_general_only = objects::edit::IsGeneralIdProtPresent(seh);
638  for (CBioseq_CI bi(seh, CSeq_inst::eMol_na); bi; ++bi)
639  {
640  bool bsh_modified = false;
641  CBioseq_Handle bsh = *bi;
642  TSeqPos len = bsh.GetBioseqLength();
643  if (len <= 1)
644  continue;
645  if (!bsh.IsSetInst())
646  continue;
647 
648  const CSeq_inst &inst = bsh.GetInst();
649  if (!inst.IsSetExt() || !inst.GetExt().IsDelta())
650  continue;
651  bool has_loc(false);
652  ITERATE(CDelta_ext::Tdata, iter, inst.GetExt().GetDelta().Get())
653  {
654  if ( (*iter)->IsLoc() )
655  {
656  has_loc = true;
657  break;
658  }
659  }
660  if (has_loc)
661  continue;
662 
663  CRef<CSeq_inst> new_inst(new CSeq_inst);
664  new_inst->Assign(inst);
665  try
666  {
667  vector<pair<int, bool> > gap_len;
668  TSeqPos pos = 0;
670  ITERATE (CDelta_ext::Tdata, delta_i, inst.GetExt().GetDelta().Get())
671  {
672  if (delta_i->Empty())
673  continue;
674  const CDelta_seq& seg = **delta_i;
675  size_t delta_len = seg.GetLiteral().GetLength();
676  if (sv.IsInGap(pos))
677  {
678  bool unknown = (seg.GetLiteral().IsSetFuzz() && seg.GetLiteral().GetFuzz().IsLim() && seg.GetLiteral().GetFuzz().GetLim() == objects::CInt_fuzz::eLim_unk);
679  gap_len.push_back(pair<int, bool> (delta_len, unknown));
680  }
681  else
682  {
683  gap_len.push_back(pair<int, bool> (0, false));
684  }
685  pos += delta_len;
686  }
687 
688  TSeqPos start = 1;
689  size_t i = 0;
690  CDelta_ext::Tdata::iterator delta_i = new_inst->SetExt().SetDelta().Set().begin();
691  while(delta_i != new_inst->SetExt().SetDelta().Set().end())
692  {
693  if (delta_i->Empty())
694  {
695  ++delta_i;
696  continue;
697  }
698  CDelta_seq& seg = **delta_i;
699  size_t orig_len = seg.GetLiteral().GetLength();
700  int delta_len = gap_len[i].first;
701  if (delta_len < 0)
702  {
703  delta_i = new_inst->SetExt().SetDelta().Set().erase(delta_i);
704  i++;
705  start += orig_len;
706  continue;
707  }
708 
709  if (delta_len > 0)
710  {
711  bool unknown = gap_len[i].second;
712  bool modified = false;
713  for (size_t j = i + 1; j < gap_len.size(); j++)
714  {
715  if (gap_len[j].first <= 0)
716  break;
717  delta_len += gap_len[j].first;
718  unknown |= gap_len[j].second;
719  gap_len[j].first = -1;
720  modified = true;
721  }
722  if (modified)
723  {
724  seg.SetLiteral().SetLength(delta_len);
725  if (unknown)
726  {
727  seg.SetLiteral().SetFuzz().SetLim(objects::CInt_fuzz::eLim_unk);
728  seg.SetLiteral().SetLength(100);
729  int diff = 100;
730  diff -= delta_len;
731  if (new_inst->IsSetLength())
732  {
733  TSeqPos old_length = new_inst->GetLength();
734  new_inst->SetLength(old_length + diff);
735  }
736 
737  NRawToDeltaSeq::SGap gap;
738  gap.start = start;
739  gap.length = diff;
740  gap.is_known = true;
741  gap.is_replace = false;
742  gaps[bsh].push_back(gap);
743  }
744  bsh_modified = true;
745  }
746  }
747  ++delta_i;
748  i++;
749  start += orig_len;
750  }
751 
752  } catch (CException ) {} catch (std::exception ) {}
753 
754  if (bsh_modified)
755  {
757  composite->AddCommand(*cmd);
758  any_modified = true;
759  }
760  }
761  if (any_modified)
762  {
763  auto local_cmd = composite;
764  local_cmd->Execute();
765  NRawToDeltaSeq::AdjustFeatureLocations(gaps, composite, false, false, false, create_general_only, max_feat_id, old_to_new, create_xref_map);
766  local_cmd->Unexecute();
767  }
768  else
769  composite.Reset();
770  return composite;
771 }
772 
User-defined methods of the data storage class.
User-defined methods of the 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.
bool IsGeneralIdProtPresent(objects::CSeq_entry_Handle tse)
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_Handle –.
void AddCommand(IEditCommand &command)
virtual void Unexecute()
Undo (opposite to Execute())
virtual void Execute()
Do the editing action.
static CRef< CCmdComposite > apply(objects::CSeq_entry_Handle seh)
static CRef< CCmdComposite > apply_impl(objects::CSeq_entry_Handle seh, map< objects::CObject_id::TId, objects::CObject_id::TId > &old_to_new, bool create_xref_map)
static CRef< CCmdComposite > apply(objects::CSeq_entry_Handle seh)
static CRef< CCmdComposite > apply_impl(const TConstScopedObjects &objects, bool to_known, bool adjust_features, map< objects::CObject_id::TId, objects::CObject_id::TId > &old_to_new, bool create_xref_map)
static CRef< CCmdComposite > apply(const TConstScopedObjects &objects, bool to_known, bool adjust_features=false)
CDelta_seq –.
Definition: Delta_seq.hpp:66
static CRef< CCmdComposite > apply(const TConstScopedObjects &objects)
static CRef< CCmdComposite > apply_impl(const TConstScopedObjects &objects, map< objects::CObject_id::TId, objects::CObject_id::TId > &old_to_new, bool create_xref_map)
CFeat_CI –.
Definition: feat_ci.hpp:64
static TId s_FindHighestFeatureId(const objects::CSeq_entry_Handle &entry)
TSeqPos GetFrom(void) const
Definition: gap_edit.hpp:57
CBioseq_Handle GetBioseq_Handle() const
Definition: gap_edit.hpp:56
CScope –.
Definition: scope.hpp:92
CSeqVector –.
Definition: seq_vector.hpp:65
CSeq_entry_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
void AddOrReplaceQualifier(const string &qual_name, const string &qual_val)
Add a qualifier to this feature, or replace the value for the first one if it already exists.
Definition: Seq_feat.cpp:299
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
bool empty() const
Definition: map.hpp:149
const_iterator find(const key_type &key) const
Definition: map.hpp:153
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)
USING_SCOPE(ncbi::objects)
#define _(proto)
Definition: ct_nlmzip_i.h:78
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
int TSignedSeqPos
Type for signed sequence position.
Definition: ncbimisc.hpp:887
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
TRange GetTotalRange(void) const
Definition: Seq_loc.hpp:913
TSeqPos GetStart(ESeqLocExtremes ext) const
Return start and stop positions of the seq-loc.
Definition: Seq_loc.cpp:915
TSeqPos GetLength(const CSeq_id &id, CScope *scope)
Get sequence length if scope not null, else return max possible TSeqPos.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
CScope & GetScope(void) const
Get scope this handle belongs to.
TSeqPos GetBioseqLength(void) const
bool IsSetInst(void) const
CSeq_entry_Handle GetTopLevelEntry(void) const
Get top level Seq-entry handle.
CSeqVector GetSeqVector(EVectorCoding coding, ENa_strand strand=eNa_strand_plus) const
Get sequence: Iupacna or Iupacaa if use_iupac_coding is true.
const TInst & GetInst(void) const
@ eCoding_Iupac
Set coding to printable coding (Iupacna or Iupacaa)
bool IsInGap(TSeqPos pos) const
true if sequence at 0-based position 'pos' has gap Note: this method is not MT-safe,...
Definition: seq_vector.hpp:277
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
position_type GetLength(void) const
Definition: range.hpp:158
#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 string LongToString(long value, TNumToStringFlags flags=0, int base=10)
Convert Int to string.
Definition: ncbistr.hpp:5141
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
Definition: ncbistr.hpp:5109
bool IsLim(void) const
Check if variant Lim is selected.
Definition: Int_fuzz_.hpp:636
TLim GetLim(void) const
Get the variant data.
Definition: Int_fuzz_.hpp:642
@ eLim_unk
unknown
Definition: Int_fuzz_.hpp:210
void SetSegs(TSegs &value)
Assign a value to Segs data member.
Definition: Seq_align_.cpp:310
const TKey & GetKey(void) const
Get the Key member data.
Definition: Imp_feat_.hpp:259
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 IsImp(void) const
Check if variant Imp is selected.
bool IsSetKey(void) const
Check if a value has been assigned to Key data member.
Definition: Imp_feat_.hpp:247
const TLocation & GetLocation(void) const
Get the Location member data.
Definition: Seq_feat_.hpp:1117
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const TImp & GetImp(void) const
Get the variant data.
bool IsSetLocation(void) const
feature made from Check if a value has been assigned to Location data member.
Definition: Seq_feat_.hpp:1105
TFrom GetFrom(void) const
Get the From member data.
TTo GetTo(void) const
Get the To member data.
bool IsInt(void) const
Check if variant Int is selected.
Definition: Seq_loc_.hpp:528
const TInt & GetInt(void) const
Get the variant data.
Definition: Seq_loc_.cpp:194
TLiteral & SetLiteral(void)
Select the variant.
Definition: Delta_seq_.cpp:130
void SetLength(TLength value)
Assign a value to Length data member.
void SetExt(TExt &value)
Assign a value to Ext data member.
Definition: Seq_inst_.cpp:147
const TLiteral & GetLiteral(void) const
Get the variant data.
Definition: Delta_seq_.cpp:124
bool IsLoc(void) const
Check if variant Loc is selected.
Definition: Delta_seq_.hpp:257
bool IsSetExt(void) const
extensions for special types Check if a value has been assigned to Ext data member.
Definition: Seq_inst_.hpp:826
TLength GetLength(void) const
Get the Length member data.
Definition: Seq_inst_.hpp:659
TLength GetLength(void) const
Get the Length member data.
const TFuzz & GetFuzz(void) const
Get the Fuzz member data.
bool IsSetFuzz(void) const
could be unsure Check if a value has been assigned to Fuzz data member.
bool IsDelta(void) const
Check if variant Delta is selected.
Definition: Seq_ext_.hpp:336
void SetFuzz(TFuzz &value)
Assign a value to Fuzz data member.
bool IsSetLength(void) const
length of sequence in residues Check if a value has been assigned to Length data member.
Definition: Seq_inst_.hpp:640
const TExt & GetExt(void) const
Get the Ext member data.
Definition: Seq_inst_.hpp:838
const TDelta & GetDelta(void) const
Get the variant data.
Definition: Seq_ext_.cpp:180
const TLoc & GetLoc(void) const
Get the variant data.
Definition: Delta_seq_.cpp:102
const Tdata & Get(void) const
Get the member data.
Definition: Delta_ext_.hpp:164
bool IsLiteral(void) const
Check if variant Literal is selected.
Definition: Delta_seq_.hpp:263
void SetLength(TLength value)
Assign a value to Length data member.
Definition: Seq_inst_.hpp:668
list< CRef< CDelta_seq > > Tdata
Definition: Delta_ext_.hpp:89
void ResetFuzz(void)
Reset Fuzz data member.
@ eMol_na
just a nucleic acid
Definition: Seq_inst_.hpp:113
where boath are integers</td > n< td ></td > n</tr > n< tr > n< td > tse</td > n< td > optional</td > n< td > String</td > n< td class=\"description\"> TSE option controls what blob is orig
int i
int len
#define row(bind, expected)
Definition: string_bind.c:73
Modified on Mon May 27 04:40:43 2024 by modify_doxy.py rev. 669887