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

Go to the SVN repository for this file.

1 /* $Id: seq_map_ci.cpp 74559 2016-09-13 11:58:16Z ivanov $
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:
27 * Eugene Vasilchenko
28 *
29 * File Description:
30 * Sequence map for the Object Manager. Describes sequence as a set of
31 * segments of different types (data, reference, gap or end).
32 *
33 */
34 
35 #include <ncbi_pch.hpp>
36 #include <objmgr/seq_map_ci.hpp>
37 #include <objmgr/seq_map.hpp>
38 #include <objmgr/tse_handle.hpp>
40 #include <objmgr/scope.hpp>
41 #include <objmgr/seq_vector.hpp>
42 #include <objmgr/bioseq_handle.hpp>
46 
49 
50 
51 /////////////////////////////////////////////////////////////////////////////
52 // SSeqMapSelector
53 /////////////////////////////////////////////////////////////////////////////
54 
55 
57  : m_Position(0),
58  m_Length(kInvalidSeqPos),
59  m_MinusStrand(false),
60  m_LinkUsedTSE(true),
61  m_MaxResolveCount(0),
62  m_Flags(CSeqMap::fDefaultFlags),
63  m_UsedTSEs(0)
64 {
65 }
66 
67 
69  : m_Position(0),
70  m_Length(kInvalidSeqPos),
71  m_MinusStrand(false),
72  m_LinkUsedTSE(true),
73  m_MaxResolveCount(resolve_count),
74  m_Flags(flags),
75  m_UsedTSEs(0)
76 {
77 }
78 
79 
81 {
82  m_LimitTSE = tse.GetTSE_Handle();
83  return *this;
84 }
85 
86 
88 {
90  return m_LimitTSE;
91 }
92 
93 
95 {
96  if ( m_UsedTSEs ) {
97  m_UsedTSEs->push_back(tse);
98  }
99 }
100 
101 
102 ////////////////////////////////////////////////////////////////////
103 // CSeqMap_CI_SegmentInfo
104 
105 
106 bool CSeqMap_CI_SegmentInfo::x_Move(bool minusStrand, CScope* scope)
107 {
108  const CSeqMap& seqMap = *m_SeqMap;
109  size_t index = m_Index;
110  const CSeqMap::CSegment& old_seg = seqMap.x_GetSegment(index);
111  if ( !minusStrand ) {
112  if ( old_seg.m_Position > m_LevelRangeEnd ||
113  index >= seqMap.x_GetLastEndSegmentIndex() )
114  return false;
115  m_Index = ++index;
116  seqMap.x_GetSegmentLength(index, scope); // Update length of segment
117  return seqMap.x_GetSegmentPosition(index, scope) < m_LevelRangeEnd;
118  }
119  else {
120  if ( old_seg.m_Position + old_seg.m_Length < m_LevelRangePos ||
121  index <= seqMap.x_GetFirstEndSegmentIndex() )
122  return false;
123  m_Index = --index;
124  return old_seg.m_Position > m_LevelRangePos;
125  }
126 }
127 
128 
129 
130 ////////////////////////////////////////////////////////////////////
131 // CSeqMap_CI
132 
133 inline
135 {
136  return x_Push(pos, m_Selector.CanResolve());
137 }
138 
139 
141  : m_SearchPos(0),
142  m_SearchEnd(kInvalidSeqPos),
143  m_FeaturePolicyWasApplied(false)
144 {
146 }
147 
148 
150  CScope* scope,
151  const SSeqMapSelector& sel,
152  TSeqPos pos)
153  : m_Scope(scope),
154  m_SearchPos(0),
155  m_SearchEnd(kInvalidSeqPos),
156  m_FeaturePolicyWasApplied(false)
157 {
158  x_Select(seqMap, sel, pos);
159 }
160 
161 
163  CScope* scope,
164  const SSeqMapSelector& sel,
165  const CRange<TSeqPos>& range)
166  : m_Scope(scope),
167  m_SearchPos(range.GetFrom()),
168  m_SearchEnd(range.GetToOpen()),
169  m_FeaturePolicyWasApplied(false)
170 {
171  x_Select(seqMap, sel, range.GetFrom());
172 }
173 
174 
176  const SSeqMapSelector& sel,
177  TSeqPos pos)
178  : m_Scope(&bioseq.GetScope()),
179  m_SearchPos(0),
180  m_SearchEnd(kInvalidSeqPos),
181  m_FeaturePolicyWasApplied(false)
182 {
183  SSeqMapSelector tse_sel(sel);
184  tse_sel.SetLinkUsedTSE(bioseq.GetTSE_Handle());
185  x_Select(ConstRef(&bioseq.GetSeqMap()), tse_sel, pos);
186 }
187 
188 
190  const SSeqMapSelector& sel,
191  const CRange<TSeqPos>& range)
192  : m_Scope(&bioseq.GetScope()),
193  m_SearchPos(range.GetFrom()),
194  m_SearchEnd(range.GetToOpen()),
195  m_FeaturePolicyWasApplied(false)
196 {
197  SSeqMapSelector tse_sel(sel);
198  tse_sel.SetLinkUsedTSE(bioseq.GetTSE_Handle());
199  x_Select(ConstRef(&bioseq.GetSeqMap()), tse_sel, range.GetFrom());
200 }
201 
202 
204  const CSeqMap& seqmap,
205  size_t index,
206  TSeqPos pos)
207  : m_Scope(base.m_Scope),
208  m_Stack(1, base.m_Stack.back()),
209  m_SearchPos(0),
210  m_SearchEnd(kInvalidSeqPos),
211  m_FeaturePolicyWasApplied(false)
212 {
214  if ( &info.x_GetSeqMap() != &seqmap ||
215  info.x_GetIndex() != index ) {
216  NCBI_THROW(CSeqMapException, eInvalidIndex,
217  "Invalid argument");
218  }
219  info.m_LevelRangePos = 0;
220  info.m_LevelRangeEnd = kInvalidSeqPos;
221  info.m_MinusStrand = 0;
222  const CSeqMap::CSegment& seg = info.x_GetSegment();
223  if ( seg.m_Position != pos ) {
224  NCBI_THROW(CSeqMapException, eInvalidIndex,
225  "Invalid argument");
226  }
227  m_Selector.m_Position = pos;
228  m_Selector.m_Length = info.x_CalcLength();
229 }
230 
231 
233 {
234 }
235 
236 
238  const SSeqMapSelector& selector,
239  TSeqPos pos)
240 {
241  m_Selector = selector;
243  TSeqPos len = seqMap->GetLength(GetScope());
246  }
247  if ( pos < m_Selector.m_Position ) {
248  pos = m_Selector.m_Position;
249  }
250  else if ( pos > m_Selector.m_Position + m_Selector.m_Length ) {
252  }
253  x_Push(seqMap, m_Selector.m_TopTSE,
257  pos - m_Selector.m_Position);
258  while ( !x_Found() && GetPosition() < m_SearchEnd ) {
259  if ( !x_Push(pos - m_Selector.m_Position) ) {
260  x_SettleNext();
261  break;
262  }
263  }
264 }
265 
266 
267 const CSeq_data& CSeqMap_CI::GetData(void) const
268 {
269  if ( !*this ) {
270  NCBI_THROW(CSeqMapException, eOutOfRange,
271  "Iterator out of range");
272  }
273  if ( GetRefPosition() != 0 || GetRefMinusStrand() ) {
274  NCBI_THROW(CSeqMapException, eDataError,
275  "Non standard Seq_data: use methods "
276  "GetRefData/GetRefPosition/GetRefMinusStrand");
277  }
278  return GetRefData();
279 }
280 
281 
283 {
284  if ( !*this ) {
285  NCBI_THROW(CSeqMapException, eOutOfRange,
286  "Iterator out of range");
287  }
289 }
290 
291 
293 {
294  if ( !*this ) {
295  NCBI_THROW(CSeqMapException, eOutOfRange,
296  "Iterator out of range");
297  }
299 }
300 
301 
303 {
304  if ( !*this ) {
305  NCBI_THROW(CSeqMapException, eOutOfRange,
306  "Iterator out of range");
307  }
308  return x_GetSegment().m_UnknownLength;
309 }
310 
311 
313 {
314  if ( !*this ) {
315  NCBI_THROW(CSeqMapException, eOutOfRange,
316  "Iterator out of range");
317  }
318  return CSeq_id_Handle::
319  GetHandle(x_GetSeqMap().x_GetRefSeqid(x_GetSegment()));
320 }
321 
322 
324 {
325  if ( !InRange() ) {
326  NCBI_THROW(CSeqMapException, eOutOfRange,
327  "Iterator out of range");
328  }
329  const CSeqMap::CSegment& seg = x_GetSegment();
330  TSeqPos skip;
331  if ( !seg.m_RefMinusStrand ) {
332  skip = m_LevelRangePos >= seg.m_Position ?
333  m_LevelRangePos - seg.m_Position : 0;
334  }
335  else {
336  TSeqPos seg_end = seg.m_Position + seg.m_Length;
337  skip = seg_end > m_LevelRangeEnd ?
338  seg_end - m_LevelRangeEnd : 0;
339  }
340  return seg.m_RefPosition + skip;
341 }
342 
343 
345 {
346  if ( !m_MinusStrand ) {
348  return min_pos > m_LevelRangePos ? min_pos - m_LevelRangePos : 0;
349  }
351  return m_LevelRangeEnd > max_pos ? m_LevelRangeEnd - max_pos : 0;
352 }
353 
354 
356 {
357  if ( m_SequenceClass == -1 ) {
359  }
360  return m_SequenceClass;
361 }
362 
363 
365 {
366  return x_GetSegmentInfo().x_GetTopOffset();
367 }
368 
369 
371 {
375  GetHandle(x_GetSeqMap().x_GetRefSeqid(seg));
377 }
378 
379 
380 inline
382 {
383  return m_Selector.CanResolve() &&
385 }
386 
387 
389 {
390  CBioseq_Handle bh;
391  if ( m_Selector.x_HasLimitTSE() ) {
392  // Check TSE limit
394  }
395  else {
396  if ( !GetScope() ) {
397  NCBI_THROW(CSeqMapException, eNullPointer,
398  "Cannot resolve "+
399  seq_id.AsFastaString()+": null scope pointer");
400  }
401  bh = GetScope()->GetBioseqHandle(seq_id);
402  if ( !bh && !(GetFlags() & CSeqMap::fIgnoreUnresolved) ) {
404  "Cannot resolve "+
405  seq_id.AsFastaString()+": unknown");
406  }
407  }
408  return bh;
409 }
410 
411 
412 bool CSeqMap_CI::x_Push(TSeqPos pos, bool resolveExternal)
413 {
415  if ( !info.InRange() ) {
416  return false;
417  }
418  const CSeqMap::CSegment& seg = info.x_GetSegment();
420 
421  switch ( type ) {
422  case CSeqMap::eSeqSubMap:
423  {{
424  CConstRef<CSeqMap> push_map
425  (static_cast<const CSeqMap*>(info.m_SeqMap->x_GetObject(seg)));
426  // We have to copy the info.m_TSE into local variable push_tse because
427  // of TSegmentInfo referenced by info can be moved inside x_Push() call.
428  CTSE_Handle push_tse = info.m_TSE;
429  x_Push(push_map, info.m_TSE,
431  break;
432  }}
433  case CSeqMap::eSeqRef:
434  {{
435  if ( !resolveExternal ) {
436  return false;
437  }
438  const CSeq_id& seq_id = info.m_SeqMap->x_GetRefSeqid(seg);
439  CBioseq_Handle bh = x_GetBioseq(seq_id);
440  if ( !bh ) {
441  return false;
442  }
443  if ( (GetFlags() & CSeqMap::fByFeaturePolicy) ) {
445  if ( p != bh.eFeatureFetchPolicy_default ) {
447  }
448  if ( p == bh.eFeatureFetchPolicy_only_near ) {
449  return false;
450  }
451  }
452  if ( info.m_TSE ) {
453  if ( !info.m_TSE.AddUsedTSE(bh.GetTSE_Handle()) ) {
455  }
456  }
457  size_t depth = m_Stack.size();
458  x_Push(ConstRef(&bh.GetSeqMap()), bh.GetTSE_Handle(),
460  if (m_Stack.size() == depth) {
461  return false;
462  }
464  if ( (m_Stack.size() & 63) == 0 ) {
465  // check for self-recursion every 64'th stack frame
466  const CSeqMap* top_seq_map = &m_Stack.back().x_GetSeqMap();
467  for ( int i = int(m_Stack.size())-2; i >= 0; --i ) {
468  if ( &m_Stack[i].x_GetSeqMap() == top_seq_map ) {
469  NCBI_THROW(CSeqMapException, eSelfReference,
470  "Self-reference in CSeqMap");
471  }
472  }
473  }
474  break;
475  }}
476  default:
477  return false;
478  }
479  return true;
480 }
481 
482 
484  const CTSE_Handle& tse,
485  TSeqPos from, TSeqPos length,
486  bool minusStrand,
487  TSeqPos pos)
488 {
490  push.m_SeqMap = seqMap;
491  push.m_TSE = tse;
492  push.m_LevelRangePos = from;
493  push.m_LevelRangeEnd = from + length;
494  if (push.m_LevelRangeEnd < push.m_LevelRangePos) {
495  // Detect (from + length) overflow
496  NCBI_THROW(CSeqMapException, eDataError,
497  "Sequence position overflow");
498  }
499  push.m_MinusStrand = minusStrand;
500  TSeqPos findOffset = !minusStrand? pos: length - 1 - pos;
501  push.m_Index = seqMap->x_FindSegment(from + findOffset, GetScope());
502  if ( push.m_Index == size_t(-1) ) {
503  if ( !m_Stack.empty() ) {
504  return;
505  }
506  push.m_Index = !minusStrand?
507  seqMap->x_GetLastEndSegmentIndex():
508  seqMap->x_GetFirstEndSegmentIndex();
509  }
510  else {
511  _ASSERT(push.m_Index > seqMap->x_GetFirstEndSegmentIndex() &&
512  push.m_Index < seqMap->x_GetLastEndSegmentIndex());
513  if ( pos >= length ) {
514  if ( !minusStrand ) {
515  if ( seqMap->x_GetSegmentPosition(push.m_Index, 0) <
516  push.m_LevelRangeEnd ) {
517  ++push.m_Index;
518  _ASSERT(seqMap->x_GetSegmentPosition(push.m_Index, 0) >=
519  push.m_LevelRangeEnd);
520  }
521  }
522  else {
523  if ( seqMap->x_GetSegmentEndPosition(push.m_Index, 0) >
524  push.m_LevelRangePos ) {
525  --push.m_Index;
526  _ASSERT(seqMap->x_GetSegmentEndPosition(push.m_Index, 0) <=
527  push.m_LevelRangePos);
528  }
529  }
530  }
531  }
532  // update length of current segment
533  seqMap->x_GetSegmentLength(push.m_Index, GetScope());
534  m_Stack.push_back(push);
535  // update position
537  // update length
538  m_Selector.m_Length = push.x_CalcLength();
539 }
540 
541 
543 {
544  if ( m_Stack.size() <= 1 ) {
545  return false;
546  }
547 
549  m_Stack.pop_back();
550  if ( x_GetSegment().m_SegType == CSeqMap::eSeqRef ) {
552  }
553  x_UpdateLength();
554  return true;
555 }
556 
557 
559 {
562  if ( !top.x_Move(top.m_MinusStrand, GetScope()) ) {
563  m_Selector.m_Length = 0;
564  return false;
565  }
566  else {
567  x_UpdateLength();
568  return true;
569  }
570 }
571 
572 
574 {
576  if ( !top.x_Move(!top.m_MinusStrand, GetScope()) ) {
577  m_Selector.m_Length = 0;
578  return false;
579  }
580  else {
581  x_UpdateLength();
583  return true;
584  }
585 }
586 
587 
588 inline
590 {
591  return x_Next(m_Selector.CanResolve());
592 }
593 
594 
595 bool CSeqMap_CI::x_Next(bool resolveExternal)
596 {
597  TSeqPos search_pos = m_SearchPos;
598  TSeqPos level_pos = GetPosition();
599  TSeqPos offset = search_pos > level_pos? search_pos - level_pos: 0;
600  if ( x_Push(offset, resolveExternal) ) {
601  return true;
602  }
603  do {
604  if ( x_TopNext() )
605  return true;
606  } while ( x_Pop() );
607  return false;
608 }
609 
610 
612 {
613  if ( !x_TopPrev() )
614  return x_Pop();
615  for ( ;; ) {
616  TSeqPos search_end = m_SearchEnd;
617  TSeqPos level_end = GetEndPosition();
618  TSeqPos end_offset = search_end < level_end? level_end - search_end: 0;
619  if ( !x_Push(m_Selector.m_Length-end_offset-1) ) {
620  break;
621  }
622  }
623  return true;
624 }
625 
626 
627 bool CSeqMap_CI::x_Found(void) const
628 {
629  if ( (GetFlags() & CSeqMap::fFindExactLevel) &&
630  m_Selector.GetResolveCount() != 0 ) {
631  return false;
632  }
634  const CSeqMap::CSegment& seg = info.x_GetSegment();
635  switch ( seg.m_SegType ) {
636  case CSeqMap::eSeqRef:
637  if ( (GetFlags() & CSeqMap::fFindLeafRef) != 0 ) {
638  if ( (GetFlags() & CSeqMap::fFindInnerRef) != 0 ) {
639  // both leaf and inner segments are accepted
640  }
641  else {
642  // leaf only are accepted
643  if ( x_CanResolve(seg) ) {
644  // this is not a leaf segment
645  return false;
646  }
647  }
648  }
649  else {
650  if ( (GetFlags() & CSeqMap::fFindInnerRef) != 0 ) {
651  // inner only are accepted
652  if ( !x_CanResolve(seg) ) {
653  // this is a leaf segment
654  return false;
655  }
656  }
657  else {
658  // none reference segments are accepted
659  return false;
660  }
661  }
662  if ( (GetFlags() & CSeqMap::fBySequenceClass) ) {
663  int p_class = x_GetSequenceClass();
664  if ( p_class != CBioseq_Handle::eSequenceClass_none ) {
665  const CSeq_id& seq_id = info.m_SeqMap->x_GetRefSeqid(seg);
666  CBioseq_Handle bh = x_GetBioseq(seq_id);
667  if ( bh && p_class != bh.GetSequenceClass() ) {
668  return false;
669  }
670  }
671  }
672  return true;
673  case CSeqMap::eSeqData:
674  return (GetFlags() & CSeqMap::fFindData) != 0;
675  case CSeqMap::eSeqGap:
676  return (GetFlags() & CSeqMap::fFindGap) != 0;
677  case CSeqMap::eSeqSubMap:
678  return false; // always skip submaps
679  default:
680  return false;
681  }
682 }
683 
684 
686 {
687  while ( !x_Found() && GetPosition() < m_SearchEnd ) {
688  if ( !x_Next() )
689  return false;
690  }
691  return true;
692 }
693 
694 
696 {
697  while ( !x_Found() ) {
698  if ( !x_Prev() )
699  return false;
700  }
701  return true;
702 }
703 
704 
705 bool CSeqMap_CI::Next(bool resolveCurrentExternal)
706 {
707  return x_Next(resolveCurrentExternal && m_Selector.CanResolve()) &&
708  x_SettleNext();
709 }
710 
711 
713 {
714  return x_Prev() && x_SettlePrev();
715 }
716 
717 
719 {
721 }
722 
723 
724 bool CSeqMap_CI::IsValid(void) const
725 {
726  return GetPosition() < m_SearchEnd &&
727  !m_Stack.empty() &&
728  m_Stack.front().InRange() &&
729  m_Stack.front().GetType() != CSeqMap::eSeqEnd;
730 }
731 
732 
734 {
736 }
737 
738 
740 {
742 }
743 
744 
745 ////////////////////////////////////////////////////////////////////
746 // CSeqMap_I
747 
748 
750 {
751 }
752 
753 
755  const SSeqMapSelector& selector,
756  TSeqPos pos)
757  : CSeqMap_CI(ConstRef(&bioseq.GetSeqMap()),
758  &bioseq.GetScope(),
759  sx_AdjustSelector(selector),
760  pos),
761  m_SeqMap(&bioseq.SetSeqMap())
762 {
763 }
764 
765 
767  const SSeqMapSelector& selector,
768  const CRange<TSeqPos>& range)
769  : CSeqMap_CI(ConstRef(&bioseq.GetSeqMap()),
770  &bioseq.GetScope(),
771  sx_AdjustSelector(selector),
772  range),
773  m_SeqMap(&bioseq.SetSeqMap())
774 {
775 }
776 
777 
779  CScope* scope,
780  const SSeqMapSelector& selector,
781  TSeqPos pos)
782  : CSeqMap_CI(seqmap,
783  scope,
784  sx_AdjustSelector(selector),
785  pos),
786  m_SeqMap(seqmap)
787 {
788 }
789 
790 
792  CScope* scope,
793  const SSeqMapSelector& selector,
794  const CRange<TSeqPos>& range)
795  : CSeqMap_CI(seqmap,
796  scope,
797  sx_AdjustSelector(selector),
798  range),
799  m_SeqMap(seqmap)
800 {
801 }
802 
803 
805 {
806 }
807 
808 
809 inline
811 {
812  SSeqMapSelector sel_copy = selector;
813  sel_copy.SetResolveCount(0);
814  return sel_copy;
815 }
816 
817 
818 void CSeqMap_I::SetGap(TSeqPos length, CSeq_data* gap_data)
819 {
820  if ( gap_data ) {
821  m_SeqMap->SetSegmentGap(*this, length, *gap_data);
822  }
823  else {
824  m_SeqMap->SetSegmentGap(*this, length);
825  }
826 }
827 
828 
830  TSeqPos ref_pos,
831  TSeqPos ref_length,
832  bool ref_minus_strand)
833 {
835  *this, ref_length, ref_id, ref_pos, ref_minus_strand);
836 
837 }
838 
839 
841 {
842  m_SeqMap->SetSegmentData(*this, length, data);
843 }
844 
845 
847 {
848  CSeqMap_CI it = m_SeqMap->InsertSegmentGap(*this, length);
849  if ( gap_data ) {
850  SetGap(length, gap_data);
851  }
852  CSeqMap_CI::operator=(it);
853  return *this;
854 }
855 
856 
858  TSeqPos ref_pos,
859  TSeqPos ref_length,
860  bool ref_minus_strand)
861 {
862  CSeqMap_CI it = InsertGap(0);
864  *this, ref_length, ref_id, ref_pos, ref_minus_strand);
865  CSeqMap_CI::operator=(it);
866  x_UpdateLength();
867  return *this;
868 }
869 
870 
872 {
873  CSeqMap_CI it = InsertGap(0);
874  m_SeqMap->SetSegmentData(*this, length, data);
875  CSeqMap_CI::operator=(it);
876  x_UpdateLength();
877  return *this;
878 }
879 
880 
882  CSeqUtil::ECoding buffer_coding,
883  CSeq_data::E_Choice seq_data_coding)
884 {
886  InsertData(0, *data);
887  SetSequence(buffer, buffer_coding, seq_data_coding);
888  x_UpdateLength();
889  return *this;
890 }
891 
892 
894 {
895  CSeqMap_CI it = m_SeqMap->RemoveSegment(*this);
896  CSeqMap_CI::operator=(it);
897  return *this;
898 }
899 
900 
902  CSeqUtil::ECoding buffer_coding) const
903 {
905  CSeq_data::E_Choice src_coding = data->Which();
906 
907 #define CODING_UNPACK_CASE(coding) \
908  case CSeq_data::e_##coding: \
909  CSeqConvert::Convert( \
910  data->Get##coding().Get(), \
911  CSeqUtil::e_##coding, \
912  0, GetLength(), \
913  buffer, buffer_coding); \
914  break
915 
916  // Unpack and return
917  switch ( src_coding ) {
918  CODING_UNPACK_CASE(Iupacna);
919  CODING_UNPACK_CASE(Iupacaa);
920  CODING_UNPACK_CASE(Ncbi2na);
921  CODING_UNPACK_CASE(Ncbi4na);
922  CODING_UNPACK_CASE(Ncbi8na);
923  // CODING_UNPACK_CASE(Ncbipna);
924  CODING_UNPACK_CASE(Ncbi8aa);
925  CODING_UNPACK_CASE(Ncbieaa);
926  // CODING_UNPACK_CASE(Ncbipaa);
927  CODING_UNPACK_CASE(Ncbistdaa);
928  default:
929  NCBI_THROW(CSeqMapException, eUnimplemented,
930  "Unsupported seq-data type: " +
931  CSeq_data::SelectionName(src_coding));
932  break;
933  }
934 }
935 
936 
937 void CSeqMap_I::SetSequence(const string& buffer,
938  CSeqUtil::ECoding buffer_coding,
939  CSeq_data::E_Choice seq_data_coding)
940 {
941  CRef<CSeq_data> new_data(new CSeq_data);
942 
943 #define CODING_PACK_CASE(coding) \
944  case CSeq_data::e_##coding: \
945  CSeqConvert::Convert( \
946  buffer, buffer_coding, \
947  0, TSeqPos(buffer.size()), \
948  new_data->Set##coding().Set(), \
949  CSeqUtil::e_##coding); \
950  break
951 
952  switch ( seq_data_coding ) {
953  CODING_PACK_CASE(Iupacna);
954  CODING_PACK_CASE(Iupacaa);
955  CODING_PACK_CASE(Ncbi2na);
956  CODING_PACK_CASE(Ncbi4na);
957  CODING_PACK_CASE(Ncbi8na);
958  // CODING_PACK_CASE(Ncbipna);
959  CODING_PACK_CASE(Ncbi8aa);
960  CODING_PACK_CASE(Ncbieaa);
961  // CODING_PACK_CASE(Ncbipaa);
962  CODING_PACK_CASE(Ncbistdaa);
963  default:
964  NCBI_THROW(CSeqMapException, eUnimplemented,
965  "Unsupported seq-data type: " +
966  CSeq_data::SelectionName(seq_data_coding));
967  break;
968  }
969  SetSeq_data(TSeqPos(buffer.size()), *new_data);
970  x_UpdateLength();
971 }
972 
973 
static CRef< CScope > m_Scope
User-defined methods of the data storage class.
CBioseq_EditHandle –.
CBioseq_Handle –.
CScope –.
Definition: scope.hpp:92
SeqMap related exceptions.
Iterator over CSeqMap.
Definition: seq_map_ci.hpp:252
Non-const iterator over CSeqMap (allows to edit the sequence).
Definition: seq_map_ci.hpp:407
CSeqMap –.
Definition: seq_map.hpp:93
CSeq_entry_Handle –.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id) const
Get Bioseq handle from this TSE.
Definition: tse_handle.cpp:217
static uch flags
static unsigned char depth[2 *(256+1+29)+1]
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
int offset
Definition: replacements.h:160
char data[12]
Definition: iconv.c:80
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:878
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
const string AsFastaString(void) const
Definition: Seq_id.cpp:2266
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
EFeatureFetchPolicy GetFeatureFetchPolicy(void) const
const CTSE_Handle & GetTSE_Handle(void) const
Get CTSE_Handle of containing TSE.
const CTSE_Handle & GetTSE_Handle(void) const
EFeatureFetchPolicy
Feature fetch policy describes when to look for features on sequence segments.
const CSeqMap & GetSeqMap(void) const
Get sequence map.
ESequenceClass GetSequenceClass(void) const
CSeqMap_I & Remove(void)
Remove current segment.
Definition: seq_map_ci.cpp:893
TSeqPos x_GetLevelRealPos(void) const
Definition: seq_map_ci.hpp:511
CSeqMap_I & InsertRef(const CSeq_id_Handle &ref_id, TSeqPos ref_pos, TSeqPos ref_length, bool ref_minus_strand=false)
Insert reference. On return the iterator points to the new segment.
Definition: seq_map_ci.cpp:857
TSeqPos GetEndPosition(void) const
return end position of current segment in sequence (exclusive)
Definition: seq_map_ci.hpp:679
int x_GetSequenceClass(void) const
Definition: seq_map_ci.cpp:739
void PushResolve(void)
Definition: seq_map_ci.hpp:206
SSeqMapSelector & SetResolveCount(size_t res_cnt)
Set max depth of resolving seq-map.
Definition: seq_map_ci.hpp:151
bool x_Next(void)
Definition: seq_map_ci.cpp:589
size_t GetResolveCount(void) const
Definition: seq_map_ci.hpp:197
const CSeqMap::CSegment & x_GetSegment(void) const
Definition: seq_map_ci.hpp:637
const CSeq_data & GetRefData(void) const
will allow any data segments, user should check for position and strand
Definition: seq_map_ci.cpp:282
void x_Select(const CConstRef< CSeqMap > &seqMap, const SSeqMapSelector &selector, TSeqPos pos)
Definition: seq_map_ci.cpp:237
bool CanResolve(void) const
Definition: seq_map_ci.hpp:201
~CSeqMap_CI(void)
Definition: seq_map_ci.cpp:232
TStack m_Stack
Definition: seq_map_ci.hpp:389
void AddUsedTSE(const CTSE_Handle &tse) const
Definition: seq_map_ci.cpp:94
bool Next(bool resolveExternal=true)
go to next/next segment, return false if no more segments if no_resolve_current == true,...
Definition: seq_map_ci.cpp:705
SSeqMapSelector & SetLinkUsedTSE(bool link=true)
Definition: seq_map_ci.hpp:157
TSeqPos x_GetTopOffset(void) const
Definition: seq_map_ci.cpp:344
TSeqPos x_CalcLength(void) const
Definition: seq_map_ci.hpp:560
void GetSequence(string &buffer, CSeqUtil::ECoding buffer_coding) const
Get current sequence as a string with the selected encoding.
Definition: seq_map_ci.cpp:901
CRef< CSeqMap > m_SeqMap
Definition: seq_map_ci.hpp:471
SSeqMapSelector m_Selector
Definition: seq_map_ci.hpp:391
TSeqPos GetRefPosition(void) const
Definition: seq_map_ci.hpp:693
void SetSeq_data(TSeqPos length, CSeq_data &data)
Change current segment to data.
Definition: seq_map_ci.cpp:840
SSeqMapSelector & SetPosition(TSeqPos pos)
Find segment containing the position.
Definition: seq_map_ci.hpp:120
TSeqPos m_Position
Definition: seq_map_ci.hpp:230
bool x_SettleNext(void)
Definition: seq_map_ci.cpp:685
CSeqMap_I & InsertGap(TSeqPos length, CSeq_data *gap_data=0)
Insert gap. On return the iterator points to the new segment.
Definition: seq_map_ci.cpp:846
const TSegmentInfo & x_GetSegmentInfo(void) const
Definition: seq_map_ci.hpp:609
CSeqMap_I(void)
Definition: seq_map_ci.cpp:749
const CSeq_data & GetData(void) const
will allow only regular data segments (whole, plus strand)
Definition: seq_map_ci.cpp:267
void SetRef(const CSeq_id_Handle &ref_id, TSeqPos ref_pos, TSeqPos ref_length, bool ref_minus_strand=false)
Change current segment to reference.
Definition: seq_map_ci.cpp:829
CScope * GetScope(void) const
Definition: seq_map_ci.hpp:644
bool x_SettlePrev(void)
Definition: seq_map_ci.cpp:695
SSeqMapSelector & SetFlags(TFlags flags)
Select segment type(s)
Definition: seq_map_ci.hpp:179
void SetSequence(const string &buffer, CSeqUtil::ECoding buffer_coding, CSeq_data::E_Choice seq_data_coding)
Set sequence data.
Definition: seq_map_ci.cpp:937
bool x_Found(void) const
Definition: seq_map_ci.cpp:627
CConstRef< CSeqMap > m_SeqMap
Definition: seq_map_ci.hpp:96
const CTSE_Handle & x_GetLimitTSE(CScope *scope=0) const
Definition: seq_map_ci.cpp:87
TSeqPos x_GetTopOffset(void) const
Definition: seq_map_ci.cpp:364
TSeqPos m_SearchEnd
Definition: seq_map_ci.hpp:394
CSeqMap::TFlags TFlags
Definition: seq_map_ci.hpp:114
const CSeqMap::CSegment & x_GetSegment(void) const
Definition: seq_map_ci.hpp:494
TSeqPos GetRefPosition(void) const
Definition: seq_map_ci.cpp:323
CTSE_Handle m_TopTSE
Definition: seq_map_ci.hpp:238
~CSeqMap_I(void)
Definition: seq_map_ci.cpp:804
CSeqMap_CI(void)
Definition: seq_map_ci.cpp:140
bool x_RefTSEMatch(const CSeqMap::CSegment &seg) const
Definition: seq_map_ci.cpp:370
bool IsValid(void) const
Definition: seq_map_ci.cpp:724
const CSeqMap & x_GetSeqMap(void) const
Definition: seq_map_ci.hpp:623
bool x_TopNext(void)
Definition: seq_map_ci.cpp:558
void SetGap(TSeqPos length, CSeq_data *gap_data=0)
Change current segment to gap.
Definition: seq_map_ci.cpp:818
bool GetRefMinusStrand(void) const
Definition: seq_map_ci.hpp:700
CSeqMap_I & InsertData(TSeqPos length, CSeq_data &data)
Insert data. On return the iterator points to the new segment.
Definition: seq_map_ci.cpp:871
SSeqMapSelector(void)
Definition: seq_map_ci.cpp:56
bool x_TopPrev(void)
Definition: seq_map_ci.cpp:573
TSeqPos m_SearchPos
Definition: seq_map_ci.hpp:393
bool x_CanResolve(const CSeqMap::CSegment &seg) const
Definition: seq_map_ci.cpp:381
CBioseq_Handle x_GetBioseq(const CSeq_id &seq_id) const
Definition: seq_map_ci.cpp:388
void x_UpdateLength(void)
Definition: seq_map_ci.cpp:733
SSeqMapSelector & SetLimitTSE(const CSeq_entry_Handle &tse)
Limit TSE to resolve references.
Definition: seq_map_ci.cpp:80
bool m_FeaturePolicyWasApplied
Definition: seq_map_ci.hpp:396
void SetFlags(TFlags flags)
Definition: seq_map_ci.cpp:718
CSeq_id_Handle GetRefSeqid(void) const
The following function makes sense only when the segment is a reference to another seq.
Definition: seq_map_ci.cpp:312
bool IsUnknownLength(void) const
return true if current segment is a gap of unknown length
Definition: seq_map_ci.cpp:302
SSeqMapSelector::TFlags TFlags
Definition: seq_map_ci.hpp:254
static SSeqMapSelector sx_AdjustSelector(const SSeqMapSelector &selector)
Definition: seq_map_ci.cpp:810
bool x_Move(bool minusStrand, CScope *scope)
Definition: seq_map_ci.cpp:106
void PopResolve(void)
Definition: seq_map_ci.hpp:211
bool InRange(void) const
Definition: seq_map_ci.hpp:574
CTSE_Handle m_LimitTSE
Definition: seq_map_ci.hpp:242
bool x_Pop(void)
Definition: seq_map_ci.cpp:542
TFlags GetFlags(void) const
Definition: seq_map_ci.hpp:785
vector< CTSE_Handle > * m_UsedTSEs
Definition: seq_map_ci.hpp:246
bool x_Push(TSeqPos offset, bool resolveExternal)
Definition: seq_map_ci.cpp:412
TSeqPos x_GetLevelRealEnd(void) const
Definition: seq_map_ci.hpp:518
TSeqPos GetPosition(void) const
return position of current segment in sequence
Definition: seq_map_ci.hpp:665
int x_GetSequenceClass(void) const
Definition: seq_map_ci.cpp:355
TSeqPos GetLength(void) const
return length of current segment
Definition: seq_map_ci.hpp:672
bool x_HasLimitTSE(void) const
Definition: seq_map_ci.hpp:223
CConstRef< CSeq_literal > GetRefGapLiteral(void) const
return CSeq_literal with gap data, or null if either the segment is not a gap, or an unspecified gap
Definition: seq_map_ci.cpp:292
bool Prev(void)
Definition: seq_map_ci.cpp:712
bool x_Prev(void)
Definition: seq_map_ci.cpp:611
void SetSegmentRef(const CSeqMap_CI &seg, TSeqPos length, const CSeq_id_Handle &ref_id, TSeqPos ref_pos, bool ref_minus_strand)
Definition: seq_map.cpp:682
void SetSegmentGap(const CSeqMap_CI &seg, TSeqPos length)
Definition: seq_map.cpp:694
size_t x_FindSegment(TSeqPos position, CScope *scope) const
Definition: seq_map.cpp:403
atomic< TSeqPos > m_Position
Definition: seq_map.hpp:253
CConstRef< CSeq_literal > x_GetSeq_literal(const CSegment &seg) const
Definition: seq_map.cpp:563
int x_GetSequenceClass(void) const
Definition: seq_map.cpp:588
const CSegment & x_GetSegment(size_t index) const
Definition: seq_map.hpp:447
TSeqPos m_RefPosition
Definition: seq_map.hpp:264
size_t x_GetLastEndSegmentIndex(void) const
Definition: seq_map.hpp:433
TSeqPos x_GetSegmentLength(size_t index, CScope *scope) const
Definition: seq_map.hpp:464
size_t x_GetFirstEndSegmentIndex(void) const
Definition: seq_map.hpp:440
TSeqPos x_GetSegmentPosition(size_t index, CScope *scope) const
Definition: seq_map.hpp:455
TSeqPos x_GetSegmentEndPosition(size_t index, CScope *scope) const
Definition: seq_map.hpp:475
CSeqMap_CI RemoveSegment(const CSeqMap_CI &seg)
Delete segment from sequence map.
Definition: seq_map.cpp:740
void SetSegmentData(const CSeqMap_CI &seg, TSeqPos length, CSeq_data &data)
Definition: seq_map.cpp:713
CSeqMap_CI InsertSegmentGap(const CSeqMap_CI &seg, TSeqPos length)
Insert new gap into sequence map.
Definition: seq_map.cpp:723
atomic< TSeqPos > m_Length
Definition: seq_map.hpp:255
TSeqPos GetLength(CScope *scope) const
Definition: seq_map.hpp:482
const CSeq_data & x_GetSeq_data(const CSegment &seg) const
Definition: seq_map.cpp:544
ESegmentType
Definition: seq_map.hpp:96
@ fBySequenceClass
Definition: seq_map.hpp:136
@ fFindGap
Definition: seq_map.hpp:130
@ fFindLeafRef
Definition: seq_map.hpp:131
@ fFindInnerRef
Definition: seq_map.hpp:132
@ fByFeaturePolicy
Definition: seq_map.hpp:135
@ fFindData
Definition: seq_map.hpp:129
@ fFindExactLevel
Definition: seq_map.hpp:133
@ fIgnoreUnresolved
Definition: seq_map.hpp:134
@ eSeqEnd
Definition: seq_map.hpp:101
@ eSeqData
real sequence data
Definition: seq_map.hpp:98
@ eSeqSubMap
sub seqmap
Definition: seq_map.hpp:99
@ eSeqGap
gap
Definition: seq_map.hpp:97
@ eSeqRef
reference to Bioseq
Definition: seq_map.hpp:100
CConstRef< C > ConstRef(const C *object)
Template function for conversion of const object pointer to CConstRef.
Definition: ncbiobj.hpp:2024
int8_t Int1
1-byte (8-bit) signed integer
Definition: ncbitype.h:98
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
E_Choice
Choice variants.
Definition: Seq_data_.hpp:102
static string SelectionName(E_Choice index)
Retrieve selection name (for diagnostic purposes).
Definition: Seq_data_.cpp:156
int i
int len
static MDB_envinfo info
Definition: mdb_load.c:37
range(_Ty, _Ty) -> range< _Ty >
list< Ts... > push
T max(T x_, T y_)
T min(T x_, T y_)
static uint8_t * buffer
Definition: pcre2test.c:1016
#define CODING_PACK_CASE(coding)
#define CODING_UNPACK_CASE(coding)
Selector used in CSeqMap methods returning iterators.
Definition: seq_map_ci.hpp:113
Definition: type.c:6
#define _ASSERT
CScope & GetScope()
Modified on Fri Sep 20 14:58:26 2024 by modify_doxy.py rev. 669887