1 /*  $Id: seq_entry_handle.cpp 590492 2019-07-30 16:13:15Z vasilche $
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 * Author: Aleksey Grichenko, Eugene Vasilchenko
27 *
28 * File Description:
29 *    Handle to Seq-entry object
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include <objmgr/seq_entry_handle.hpp>
35 #include <objmgr/seq_entry_ci.hpp>
36 #include <objmgr/seq_annot_ci.hpp>
37 #include <objmgr/bioseq_handle.hpp>
38 #include <objmgr/bioseq_set_handle.hpp>
39 #include <objmgr/scope.hpp>
40 #include <objmgr/bio_object_id.hpp>
41 
42 #include <objmgr/impl/seq_entry_info.hpp>
43 #include <objmgr/impl/scope_impl.hpp>
44 #include <objmgr/impl/tse_info.hpp>
45 #include <objmgr/impl/bioseq_set_info.hpp>
46 #include <objmgr/impl/bioseq_info.hpp>
47 #include <objmgr/impl/seq_annot_info.hpp>
48 #include <objmgr/impl/seq_entry_edit_commands.hpp>
49 
50 #include <objects/seqset/Bioseq_set.hpp>
51 #include <objects/seq/Seqdesc.hpp>
52 
53 
54 BEGIN_NCBI_SCOPE
BEGIN_SCOPE(objects)55 BEGIN_SCOPE(objects)
56 
57 
58 CSeq_entry_Handle::CSeq_entry_Handle(const CTSE_Handle& tse)
59     : m_Info(tse.x_GetScopeInfo().GetScopeLock(tse, tse.x_GetTSE_Info()))
60 {
61 }
62 
63 
CSeq_entry_Handle(const CSeq_entry_Info & info,const CTSE_Handle & tse)64 CSeq_entry_Handle::CSeq_entry_Handle(const CSeq_entry_Info& info,
65                                      const CTSE_Handle& tse)
66     : m_Info(tse.x_GetScopeInfo().GetScopeLock(tse, info))
67 {
68 }
69 
70 
Swap(CSeq_entry_Handle & h)71 void CSeq_entry_Handle::Swap(CSeq_entry_Handle& h)
72 {
73     m_Info.Swap(h.m_Info);
74 }
75 
76 
Reset(void)77 void CSeq_entry_Handle::Reset(void)
78 {
79     m_Info.Reset();
80 }
81 
GetBioObjectId(void) const82 const CBioObjectId& CSeq_entry_Handle::GetBioObjectId(void) const
83 {
84     return x_GetInfo().GetBioObjectId();
85 }
86 
x_GetInfo(void) const87 const CSeq_entry_Info& CSeq_entry_Handle::x_GetInfo(void) const
88 {
89     return m_Info->GetObjectInfo();
90 }
91 
92 
Which(void) const93 CSeq_entry::E_Choice CSeq_entry_Handle::Which(void) const
94 {
95     return x_GetInfo().Which();
96 }
97 
98 
GetCompleteSeq_entry(void) const99 CConstRef<CSeq_entry> CSeq_entry_Handle::GetCompleteSeq_entry(void) const
100 {
101     return x_GetInfo().GetCompleteSeq_entry();
102 }
103 
104 
GetSeq_entryCore(void) const105 CConstRef<CSeq_entry> CSeq_entry_Handle::GetSeq_entryCore(void) const
106 {
107     return x_GetInfo().GetSeq_entryCore();
108 }
109 
110 
HasParentEntry(void) const111 bool CSeq_entry_Handle::HasParentEntry(void) const
112 {
113     return *this  &&  x_GetInfo().HasParent_Info();
114 }
115 
116 
GetParentEntry(void) const117 CSeq_entry_Handle CSeq_entry_Handle::GetParentEntry(void) const
118 {
119     CSeq_entry_Handle ret;
120     const CSeq_entry_Info& info = x_GetInfo();
121     if ( info.HasParent_Info() ) {
122         ret = CSeq_entry_Handle(info.GetParentSeq_entry_Info(),
123                                 GetTSE_Handle());
124     }
125     return ret;
126 }
127 
128 
IsTopLevelEntry(void) const129 bool CSeq_entry_Handle::IsTopLevelEntry(void) const
130 {
131     return !x_GetInfo().HasParent_Info();
132 }
133 
134 
GetTopLevelEntry(void) const135 CSeq_entry_Handle CSeq_entry_Handle::GetTopLevelEntry(void) const
136 {
137     return GetTSE_Handle();
138 }
139 
140 
IsTopLevelSeq_submit(void) const141 bool CSeq_entry_Handle::IsTopLevelSeq_submit(void) const
142 {
143     return IsTopLevelEntry() && GetTSE_Handle().IsTopLevelSeq_submit();
144 }
145 
146 
GetTopLevelSeq_submit() const147 const CSeq_submit& CSeq_entry_Handle::GetTopLevelSeq_submit() const
148 {
149     return GetTSE_Handle().GetTopLevelSeq_submit();
150 }
151 
152 
GetTopLevelSubmit_block() const153 const CSubmit_block& CSeq_entry_Handle::GetTopLevelSubmit_block() const
154 {
155     return GetTSE_Handle().GetTopLevelSubmit_block();
156 }
157 
158 
GetBioseqHandle(const CSeq_id & id) const159 CBioseq_Handle CSeq_entry_Handle::GetBioseqHandle(const CSeq_id& id) const
160 {
161     return GetTSE_Handle().GetBioseqHandle(id);
162 }
163 
164 
GetBioseqHandle(const CSeq_id_Handle & id) const165 CBioseq_Handle CSeq_entry_Handle::GetBioseqHandle(const CSeq_id_Handle& id) const
166 {
167     return GetTSE_Handle().GetBioseqHandle(id);
168 }
169 
170 
GetSingleSubEntry(void) const171 CSeq_entry_Handle CSeq_entry_Handle::GetSingleSubEntry(void) const
172 {
173     if ( !IsSet() ) {
174         NCBI_THROW(CObjMgrException, eModifyDataError,
175                    "CSeq_entry_Handle::GetSingleSubEntry: "
176                    "Seq-entry is not Bioseq-set");
177     }
178     CSeq_entry_CI iter(*this);
179     if ( !iter ) {
180         NCBI_THROW(CObjMgrException, eModifyDataError,
181                    "CSeq_entry_Handle::GetSingleSubEntry: "
182                    "Seq-entry is empty");
183     }
184     CSeq_entry_Handle entry = *iter;
185     if ( ++iter ) {
186         NCBI_THROW(CObjMgrException, eModifyDataError,
187                    "CSeq_entry_Handle::GetSingleSubEntry: "
188                    "Seq-entry contains more than one sub entry");
189     }
190     return entry;
191 }
192 
193 
GetEditHandle(void) const194 CSeq_entry_EditHandle CSeq_entry_Handle::GetEditHandle(void) const
195 {
196     return GetScope().GetEditHandle(*this);
197 }
198 
199 
GetParentBioseq_set(void) const200 CBioseq_set_Handle CSeq_entry_Handle::GetParentBioseq_set(void) const
201 {
202     CBioseq_set_Handle ret;
203     const CSeq_entry_Info& info = x_GetInfo();
204     if ( info.HasParent_Info() ) {
205         ret = CBioseq_set_Handle(info.GetParentBioseq_set_Info(),
206                                  GetTSE_Handle());
207     }
208     return ret;
209 }
210 
211 
GetSeq(void) const212 CBioseq_Handle CSeq_entry_Handle::GetSeq(void) const
213 {
214     return x_GetScopeImpl().GetBioseqHandle(x_GetInfo().GetSeq(),
215                                             GetTSE_Handle());
216 }
217 
218 
GetSet(void) const219 CBioseq_set_Handle CSeq_entry_Handle::GetSet(void) const
220 {
221     return CBioseq_set_Handle(x_GetInfo().GetSet(),
222                               GetTSE_Handle());
223 }
224 
225 
IsSetDescr(void) const226 bool CSeq_entry_Handle::IsSetDescr(void) const
227 {
228     return x_GetInfo().IsSetDescr();
229 }
230 
231 
GetDescr(void) const232 const CSeq_descr& CSeq_entry_Handle::GetDescr(void) const
233 {
234     return x_GetInfo().GetDescr();
235 }
236 
237 
GetBlobId(void) const238 CSeq_entry_Handle::TBlobId CSeq_entry_Handle::GetBlobId(void) const
239 {
240     return x_GetInfo().GetTSE_Info().GetBlobId();
241 }
242 
243 
GetBlobVersion(void) const244 CSeq_entry_Handle::TBlobVersion CSeq_entry_Handle::GetBlobVersion(void) const
245 {
246     return x_GetInfo().GetTSE_Info().GetBlobVersion();
247 }
248 
249 
250 /////////////////////////////////////////////////////////////////////////////
251 // CSeq_entry_EditHandle
252 
253 
CSeq_entry_EditHandle(const CSeq_entry_Handle & h)254 CSeq_entry_EditHandle::CSeq_entry_EditHandle(const CSeq_entry_Handle& h)
255     : CSeq_entry_Handle(h)
256 {
257     if ( !h.GetTSE_Handle().CanBeEdited() ) {
258         NCBI_THROW(CObjMgrException, eInvalidHandle,
259                    "object is not in editing mode");
260     }
261 }
262 
263 
CSeq_entry_EditHandle(CSeq_entry_Info & info,const CTSE_Handle & tse)264 CSeq_entry_EditHandle::CSeq_entry_EditHandle(CSeq_entry_Info& info,
265                                              const CTSE_Handle& tse)
266     : CSeq_entry_Handle(info, tse)
267 {
268 }
269 
270 
SetTopLevelSubmit_block(void) const271 CSubmit_block& CSeq_entry_EditHandle::SetTopLevelSubmit_block(void) const
272 {
273     return GetTSE_Handle().SetTopLevelSubmit_block();
274 }
275 
276 
SetTopLevelSubmit_block(CSubmit_block & sub) const277 void CSeq_entry_EditHandle::SetTopLevelSubmit_block(CSubmit_block& sub) const
278 {
279     GetTSE_Handle().SetTopLevelSubmit_block(sub);
280 }
281 
282 
GetParentEntry(void) const283 CSeq_entry_EditHandle CSeq_entry_EditHandle::GetParentEntry(void) const
284 {
285     CSeq_entry_EditHandle ret;
286     CSeq_entry_Info& info = x_GetInfo();
287     if ( info.HasParent_Info() ) {
288         ret = CSeq_entry_EditHandle(info.GetParentSeq_entry_Info(),
289                                     GetTSE_Handle());
290     }
291     return ret;
292 }
293 
294 
GetSingleSubEntry(void) const295 CSeq_entry_EditHandle CSeq_entry_EditHandle::GetSingleSubEntry(void) const
296 {
297     return CSeq_entry_Handle::GetSingleSubEntry().GetEditHandle();
298 }
299 
300 
GetParentBioseq_set(void) const301 CBioseq_set_EditHandle CSeq_entry_EditHandle::GetParentBioseq_set(void) const
302 {
303     CBioseq_set_EditHandle ret;
304     CSeq_entry_Info& info = x_GetInfo();
305     if ( info.HasParent_Info() ) {
306         ret = CBioseq_set_EditHandle(info.GetParentBioseq_set_Info(),
307                                      GetTSE_Handle());
308     }
309     return ret;
310 }
311 
312 
x_GetInfo(void) const313 CSeq_entry_Info& CSeq_entry_EditHandle::x_GetInfo(void) const
314 {
315     return const_cast<CSeq_entry_Info&>(CSeq_entry_Handle::x_GetInfo());
316 }
317 
318 
SetSet(void) const319 CBioseq_set_EditHandle CSeq_entry_EditHandle::SetSet(void) const
320 {
321     return CBioseq_set_EditHandle(x_GetInfo().SetSet(),
322                                   GetTSE_Handle());
323 
324 }
325 
326 
SetSeq(void) const327 CBioseq_EditHandle CSeq_entry_EditHandle::SetSeq(void) const
328 {
329     return x_GetScopeImpl().GetBioseqHandle(x_GetInfo().SetSeq(),
330                                             GetTSE_Handle()).GetEditHandle();
331 
332 }
333 
334 
SetDescr(TDescr & v) const335 void CSeq_entry_EditHandle::SetDescr(TDescr& v) const
336 {
337     typedef CSetValue_EditCommand<CSeq_entry_EditHandle,TDescr> TCommand;
338     CCommandProcessor processor(x_GetScopeImpl());
339     processor.run(new TCommand(*this, v));
340 }
341 
342 
SetDescr(void) const343 CSeq_entry_EditHandle::TDescr& CSeq_entry_EditHandle::SetDescr(void) const
344 {
345     if (x_GetScopeImpl().IsTransactionActive()
346         || GetTSE_Handle().x_GetTSE_Info().GetEditSaver() ) {
347         NCBI_THROW(CObjMgrException, eTransaction,
348                        "TDescr& CSeq_entry_EditHandle::SetDescr(): "
349                        "method can not be called if a transaction is required");
350     }
351     return x_GetInfo().SetDescr();
352 }
353 
354 
AddDescr(TDescr & v) const355 void CSeq_entry_EditHandle::AddDescr(TDescr& v) const
356 {
357     typedef CAddDescr_EditCommand<CSeq_entry_EditHandle> TCommand;
358     CCommandProcessor processor(x_GetScopeImpl());
359     processor.run(new TCommand(*this, v));
360 }
361 
362 
ResetDescr(void) const363 void CSeq_entry_EditHandle::ResetDescr(void) const
364 {
365     typedef CResetValue_EditCommand<CSeq_entry_EditHandle,TDescr> TCommand;
366     CCommandProcessor processor(x_GetScopeImpl());
367     processor.run(new TCommand(*this));
368 }
369 
370 
AddSeqdesc(CSeqdesc & v) const371 bool CSeq_entry_EditHandle::AddSeqdesc(CSeqdesc& v) const
372 {
373     typedef CDesc_EditCommand<CSeq_entry_EditHandle,true> TCommand;
374     CCommandProcessor processor(x_GetScopeImpl());
375     return processor.run(new TCommand(*this, v));
376 }
377 
378 
RemoveSeqdesc(const CSeqdesc & v) const379 CRef<CSeqdesc> CSeq_entry_EditHandle::RemoveSeqdesc(const CSeqdesc& v) const
380 {
381     typedef CDesc_EditCommand<CSeq_entry_EditHandle,false> TCommand;
382     CCommandProcessor processor(x_GetScopeImpl());
383     return processor.run(new TCommand(*this, v));
384 }
385 
386 
ReplaceSeqdesc(const CSeqdesc & old_desc,CSeqdesc & new_desc) const387 CRef<CSeqdesc> CSeq_entry_EditHandle::ReplaceSeqdesc(const CSeqdesc& old_desc, CSeqdesc& new_desc) const
388 {
389     return x_RealReplaceSeqdesc(old_desc, new_desc);
390 }
391 
392 
393 CBioseq_EditHandle
AttachBioseq(CBioseq & seq,int index) const394 CSeq_entry_EditHandle::AttachBioseq(CBioseq& seq, int index) const
395 {
396     return SetSet().AttachBioseq(seq, index);
397 }
398 
399 
400 CBioseq_EditHandle
CopyBioseq(const CBioseq_Handle & seq,int index) const401 CSeq_entry_EditHandle::CopyBioseq(const CBioseq_Handle& seq,
402                                   int index) const
403 {
404     return SetSet().CopyBioseq(seq, index);
405 }
406 
407 
408 CBioseq_EditHandle
TakeBioseq(const CBioseq_EditHandle & seq,int index) const409 CSeq_entry_EditHandle::TakeBioseq(const CBioseq_EditHandle& seq,
410                                   int index) const
411 {
412     return SetSet().TakeBioseq(seq, index);
413 }
414 
415 
416 CSeq_entry_EditHandle
AttachEntry(CSeq_entry & entry,int index) const417 CSeq_entry_EditHandle::AttachEntry(CSeq_entry& entry, int index) const
418 {
419     return SetSet().AttachEntry(entry, index);
420 }
421 
422 
423 CSeq_entry_EditHandle
CopyEntry(const CSeq_entry_Handle & entry,int index) const424 CSeq_entry_EditHandle::CopyEntry(const CSeq_entry_Handle& entry,
425                                  int index) const
426 {
427     return SetSet().CopyEntry(entry, index);
428 }
429 
430 
431 CSeq_entry_EditHandle
TakeEntry(const CSeq_entry_EditHandle & entry,int index) const432 CSeq_entry_EditHandle::TakeEntry(const CSeq_entry_EditHandle& entry,
433                                  int index) const
434 {
435     return SetSet().TakeEntry(entry, index);
436 }
437 
438 
439 CSeq_entry_EditHandle
AttachEntry(const CSeq_entry_EditHandle & entry,int index) const440 CSeq_entry_EditHandle::AttachEntry(const CSeq_entry_EditHandle& entry,
441                                    int index) const
442 {
443     return SetSet().AttachEntry(entry, index);
444 }
445 
446 
447 CSeq_annot_EditHandle
AttachAnnot(CSeq_annot & annot) const448 CSeq_entry_EditHandle::AttachAnnot(CSeq_annot& annot) const
449 {
450     return AttachAnnot(Ref(new CSeq_annot_Info(annot)));
451     //    return x_GetScopeImpl().AttachAnnot(*this, annot);
452 }
453 
454 CSeq_annot_EditHandle
AttachAnnot(CRef<CSeq_annot_Info> annot) const455 CSeq_entry_EditHandle::AttachAnnot(CRef<CSeq_annot_Info> annot) const
456 {
457     typedef CAttachAnnot_EditCommand<CRef<CSeq_annot_Info> > TCommand;
458     CCommandProcessor processor(x_GetScopeImpl());
459     return processor.run(new TCommand(*this, annot, x_GetScopeImpl()));
460 }
461 
462 
463 CSeq_annot_EditHandle
CopyAnnot(const CSeq_annot_Handle & annot) const464 CSeq_entry_EditHandle::CopyAnnot(const CSeq_annot_Handle& annot) const
465 {
466     return AttachAnnot(Ref(new CSeq_annot_Info(annot.x_GetInfo(), 0)));
467     //    return x_GetScopeImpl().CopyAnnot(*this, annot);
468 }
469 
470 
471 CSeq_annot_EditHandle
TakeAnnot(const CSeq_annot_EditHandle & annot) const472 CSeq_entry_EditHandle::TakeAnnot(const CSeq_annot_EditHandle& annot) const
473 {
474     CRef<IScopeTransaction_Impl> tr(x_GetScopeImpl().CreateTransaction());
475     annot.Remove();
476     CSeq_annot_EditHandle handle = AttachAnnot(annot);
477     tr->Commit();
478     return handle;
479     //    return x_GetScopeImpl().TakeAnnot(*this, annot);
480 }
481 
482 
483 CSeq_annot_EditHandle
AttachAnnot(const CSeq_annot_EditHandle & annot) const484 CSeq_entry_EditHandle::AttachAnnot(const CSeq_annot_EditHandle& annot) const
485 {
486     typedef CAttachAnnot_EditCommand<CSeq_annot_EditHandle> TCommand;
487     CCommandProcessor processor(x_GetScopeImpl());
488     return processor.run(new TCommand(*this, annot, x_GetScopeImpl()));
489     //return x_GetScopeImpl().AttachAnnot(*this, annot);
490 }
491 
492 
493 void
TakeAllAnnots(const CSeq_entry_EditHandle & entry) const494 CSeq_entry_EditHandle::TakeAllAnnots(const CSeq_entry_EditHandle& entry) const
495 {
496     vector<CSeq_annot_EditHandle> annots;
497     // we have to copy all handles as moving annots directly could break iter
498     for ( CSeq_annot_CI it(entry, CSeq_annot_CI::eSearch_entry); it; ++it ) {
499         annots.push_back(it->GetEditHandle());
500     }
501     ITERATE ( vector<CSeq_annot_EditHandle>, it, annots ) {
502         TakeAnnot(*it);
503     }
504 }
505 
TakeAllDescr(const CSeq_entry_EditHandle & entry) const506 void CSeq_entry_EditHandle::TakeAllDescr(const CSeq_entry_EditHandle& entry) const
507 {
508     if (entry.IsSetDescr()) {
509         CRef<IScopeTransaction_Impl> tr(x_GetScopeImpl().CreateTransaction());
510         TDescr& descr = const_cast<TDescr&>(entry.GetDescr());
511         AddDescr(descr);
512         entry.ResetDescr();
513         tr->Commit();
514     }
515         //    x_GetInfo().AddDescr(entry.x_GetInfo());
516         //    entry.ResetDescr();
517 
518 }
519 
Remove(void) const520 void CSeq_entry_EditHandle::Remove(void) const
521 {
522     if( !GetParentEntry() ) {
523         typedef CRemoveTSE_EditCommand TCommand;
524         CCommandProcessor processor(x_GetScopeImpl());
525         processor.run(new TCommand(*this, x_GetScopeImpl()));
526     } else {
527         typedef CSeq_entry_Remove_EditCommand TCommand;
528         CCommandProcessor processor(x_GetScopeImpl());
529         processor.run(new TCommand(*this, x_GetScopeImpl()));
530         //    x_GetScopeImpl().RemoveEntry(*this);
531     }
532 }
533 
534 
SelectSet(TClass set_class) const535 CBioseq_set_EditHandle CSeq_entry_EditHandle::SelectSet(TClass set_class) const
536 {
537     CRef<IScopeTransaction_Impl> tr(x_GetScopeImpl().CreateTransaction());
538     CBioseq_set_EditHandle seqset = SelectSet(*new CBioseq_set);
539     if ( set_class != CBioseq_set::eClass_not_set ) {
540         seqset.SetClass(set_class);
541     }
542     tr->Commit();
543     return seqset;
544 }
545 
546 
SelectNone(void) const547 void CSeq_entry_EditHandle::SelectNone(void) const
548 {
549     typedef CSeq_entry_SelectNone_EditCommand TCommand;
550     CCommandProcessor processor(x_GetScopeImpl());
551     processor.run(new TCommand(*this, x_GetScopeImpl()));
552     //x_GetScopeImpl().SelectNone(*this);
553 }
554 
555 
556 CBioseq_set_EditHandle
SelectSet(CBioseq_set & seqset) const557 CSeq_entry_EditHandle::SelectSet(CBioseq_set& seqset) const
558 {
559     return SelectSet(Ref(new CBioseq_set_Info(seqset)));
560     //return x_GetScopeImpl().SelectSet(*this, seqset);
561 }
562 
563 CBioseq_set_EditHandle
SelectSet(CRef<CBioseq_set_Info> seqset) const564 CSeq_entry_EditHandle::SelectSet(CRef<CBioseq_set_Info> seqset) const
565 {
566     typedef CSeq_entry_Select_EditCommand
567                  <CBioseq_set_EditHandle,CRef<CBioseq_set_Info> > TCommand;
568     CCommandProcessor processor(x_GetScopeImpl());
569     return processor.run(new TCommand(*this, seqset, x_GetScopeImpl()));
570 }
571 
572 
573 CBioseq_set_EditHandle
CopySet(const CBioseq_set_Handle & seqset) const574 CSeq_entry_EditHandle::CopySet(const CBioseq_set_Handle& seqset) const
575 {
576     return SelectSet(Ref(new CBioseq_set_Info(seqset.x_GetInfo(),0)));
577     //return x_GetScopeImpl().CopySet(*this, seqset);
578 }
579 
580 
581 CBioseq_set_EditHandle
TakeSet(const CBioseq_set_EditHandle & seqset) const582 CSeq_entry_EditHandle::TakeSet(const CBioseq_set_EditHandle& seqset) const
583 {
584     CRef<IScopeTransaction_Impl> tr(x_GetScopeImpl().CreateTransaction());
585     seqset.Remove(CBioseq_set_EditHandle::eKeepSeq_entry);
586     CBioseq_set_EditHandle handle = SelectSet(seqset);
587     tr->Commit();
588     return handle;
589     //return x_GetScopeImpl().TakeSet(*this, seqset);
590 }
591 
592 
593 CBioseq_set_EditHandle
SelectSet(const CBioseq_set_EditHandle & seqset) const594 CSeq_entry_EditHandle::SelectSet(const CBioseq_set_EditHandle& seqset) const
595 {
596     typedef CSeq_entry_Select_EditCommand
597                    <CBioseq_set_EditHandle,CBioseq_set_EditHandle> TCommand;
598     CCommandProcessor processor(x_GetScopeImpl());
599     return processor.run(new TCommand(*this, seqset, x_GetScopeImpl()));
600     //    return x_GetScopeImpl().SelectSet(*this, seqset);
601 }
602 
603 
SelectSeq(CBioseq & seq) const604 CBioseq_EditHandle CSeq_entry_EditHandle::SelectSeq(CBioseq& seq) const
605 {
606     return SelectSeq(Ref(new CBioseq_Info(seq)));
607     //    return x_GetScopeImpl().SelectSeq(*this, seq);
608 }
609 
610 CBioseq_EditHandle
SelectSeq(CRef<CBioseq_Info> seq) const611 CSeq_entry_EditHandle::SelectSeq(CRef<CBioseq_Info> seq) const
612 {
613     typedef CSeq_entry_Select_EditCommand
614                  <CBioseq_EditHandle,CRef<CBioseq_Info> > TCommand;
615     CCommandProcessor processor(x_GetScopeImpl());
616     return processor.run(new TCommand(*this, seq, x_GetScopeImpl()));
617 }
618 
619 CBioseq_EditHandle
CopySeq(const CBioseq_Handle & seq) const620 CSeq_entry_EditHandle::CopySeq(const CBioseq_Handle& seq) const
621 {
622     return SelectSeq(Ref(new CBioseq_Info(seq.x_GetInfo(),0)));
623     //    return x_GetScopeImpl().CopySeq(*this, seq);
624 }
625 
626 
627 CBioseq_EditHandle
TakeSeq(const CBioseq_EditHandle & seq) const628 CSeq_entry_EditHandle::TakeSeq(const CBioseq_EditHandle& seq) const
629 {
630     CRef<IScopeTransaction_Impl> tr(x_GetScopeImpl().CreateTransaction());
631     seq.Remove(CBioseq_EditHandle::eKeepSeq_entry);
632     CBioseq_EditHandle handle = SelectSeq(seq);
633     tr->Commit();
634     return handle;
635     //    return x_GetScopeImpl().TakeSeq(*this, seq);
636 }
637 
638 
639 CBioseq_EditHandle
SelectSeq(const CBioseq_EditHandle & seq) const640 CSeq_entry_EditHandle::SelectSeq(const CBioseq_EditHandle& seq) const
641 {
642     typedef CSeq_entry_Select_EditCommand
643                    <CBioseq_EditHandle,CBioseq_EditHandle> TCommand;
644     CCommandProcessor processor(x_GetScopeImpl());
645     return processor.run(new TCommand(*this, seq, x_GetScopeImpl()));
646     //    return x_GetScopeImpl().SelectSeq(*this, seq);
647 }
648 
649 
650 CBioseq_set_EditHandle
ConvertSeqToSet(TClass set_class) const651 CSeq_entry_EditHandle::ConvertSeqToSet(TClass set_class) const
652 {
653     if ( !IsSeq() ) {
654         NCBI_THROW(CObjMgrException, eModifyDataError,
655                    "CSeq_entry_EditHandle::ConvertSeqToSet: "
656                    "Seq-entry is not in 'seq' state");
657     }
658     CBioseq_EditHandle seq = SetSeq();
659     CRef<IScopeTransaction_Impl> tr(x_GetScopeImpl().CreateTransaction());
660     SelectNone();
661     _ASSERT(Which() == CSeq_entry::e_not_set);
662     _ASSERT(seq.IsRemoved());
663     _ASSERT(!seq);
664     CBioseq_set_EditHandle seqset = SelectSet(set_class);
665     seqset.AddNewEntry(-1).SelectSeq(seq);
666     _ASSERT(seq);
667     tr->Commit();
668     return seqset;
669 }
670 
671 
CollapseSet(void) const672 void CSeq_entry_EditHandle::CollapseSet(void) const
673 {
674     CSeq_entry_EditHandle entry = GetSingleSubEntry();
675     if ( entry.Which() == CSeq_entry::e_not_set ) {
676         NCBI_THROW(CObjMgrException, eModifyDataError,
677                    "CSeq_entry_EditHandle::CollapseSet: "
678                    "sub entry should be non-empty");
679     }
680     CRef<IScopeTransaction_Impl> tr(x_GetScopeImpl().CreateTransaction());
681     entry.TakeAllDescr(*this);
682     entry.TakeAllAnnots(*this);
683     if ( entry.IsSet() ) {
684         CBioseq_set_EditHandle seqset = entry.SetSet();
685         entry.SelectNone();
686         SelectNone();
687         _ASSERT(seqset.IsRemoved());
688         _ASSERT(!seqset);
689         SelectSet(seqset);
690         _ASSERT(seqset);
691     }
692     else {
693         CBioseq_EditHandle seq = entry.SetSeq();
694         entry.SelectNone();
695         SelectNone();
696         _ASSERT(seq.IsRemoved());
697         _ASSERT(!seq);
698         SelectSeq(seq);
699         _ASSERT(seq);
700     }
701     tr->Commit();
702 }
703 
704 CBioseq_EditHandle
ConvertSetToSeq(void) const705 CSeq_entry_EditHandle::ConvertSetToSeq(void) const
706 {
707     CSeq_entry_EditHandle entry = GetSingleSubEntry();
708     if ( !entry.IsSeq() ) {
709         NCBI_THROW(CObjMgrException, eModifyDataError,
710                    "CSeq_entry_EditHandle::ConvertSetToSeq: "
711                    "sub entry should contain Bioseq");
712     }
713     CRef<IScopeTransaction_Impl> tr(x_GetScopeImpl().CreateTransaction());
714     entry.TakeAllDescr(*this);
715     entry.TakeAllAnnots(*this);
716     CBioseq_EditHandle seq = entry.SetSeq();
717     entry.SelectNone();
718     SelectNone();
719     _ASSERT(seq.IsRemoved());
720     _ASSERT(!seq);
721     SelectSeq(seq);
722     _ASSERT(seq);
723     tr->Commit();
724     return seq;
725 }
726 
727 ////////////////////////////////////////////////////////////////////////
x_RealSetDescr(TDescr & v) const728 void CSeq_entry_EditHandle::x_RealSetDescr(TDescr& v) const
729 {
730     x_GetInfo().SetDescr(v);
731 }
732 
733 
x_RealResetDescr(void) const734 void CSeq_entry_EditHandle::x_RealResetDescr(void) const
735 {
736     x_GetInfo().ResetDescr();
737 }
738 
739 
x_RealAddSeqdesc(CSeqdesc & v) const740 bool CSeq_entry_EditHandle::x_RealAddSeqdesc(CSeqdesc& v) const
741 {
742     return x_GetInfo().AddSeqdesc(v);
743 }
744 
745 
x_RealRemoveSeqdesc(const CSeqdesc & v) const746 CRef<CSeqdesc> CSeq_entry_EditHandle::x_RealRemoveSeqdesc(const CSeqdesc& v) const
747 {
748     return x_GetInfo().RemoveSeqdesc(v);
749 }
750 
751 
x_RealReplaceSeqdesc(const CSeqdesc & old_desc,CSeqdesc & new_desc) const752 CRef<CSeqdesc> CSeq_entry_EditHandle::x_RealReplaceSeqdesc(const CSeqdesc& old_desc, CSeqdesc& new_desc) const
753 {
754     return x_GetInfo().ReplaceSeqdesc(old_desc, new_desc);
755 }
756 
757 
x_RealAddSeq_descr(TDescr & v) const758 void CSeq_entry_EditHandle::x_RealAddSeq_descr(TDescr& v) const
759 {
760     x_GetInfo().AddSeq_descr(v);
761 }
762 
763 
UpdateAnnotations(void) const764 void CSeq_entry_EditHandle::UpdateAnnotations(void) const
765 {
766     x_GetInfo();
767 }
768 
769 
770 END_SCOPE(objects)
771 END_NCBI_SCOPE
772