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

Go to the SVN repository for this file.

1 /* $Id: cmd_insert_bioseq_set.cpp 31019 2014-08-20 13:08:23Z bollin $
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: Colleen Bollin and Roman Katargin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
33 #include <objmgr/seq_entry_ci.hpp>
35 #include <objmgr/seq_annot_ci.hpp>
37 
40 
42  : m_seh(seh), m_Class(new_class)
43 {
44 }
45 
47 {
48  CSeq_entry_EditHandle edit = m_seh.GetEditHandle();
49 
50  if (m_seh.IsSet()) {
51  size_t num_in_set = 0;
52  CConstRef<CBioseq_set> old_set = m_seh.GetSet().GetCompleteBioseq_set();
53  if (!m_seh.GetSet().IsEmptySeq_set()) {
54  num_in_set = old_set->GetSeq_set().size();
55  }
56  CRef<CSeq_entry> new_set(new CSeq_entry());
57  new_set->SetSet().SetClass(m_Class);
58  CSeq_entry_EditHandle new_set_edit = edit.AttachEntry(*new_set);
59  new_set_edit.TakeAllAnnots(edit);
60  new_set_edit.TakeAllDescr(edit);
61  x_TransferSeqSet(new_set_edit, edit, num_in_set);
62  } else {
63  edit.ConvertSeqToSet(m_Class);
64  }
65 
66 }
67 
69 {
70  CSeq_entry_EditHandle edit = m_seh.GetEditHandle();
71  CConstRef<CSeq_entry> entry = m_seh.GetSet().GetCompleteBioseq_set()->GetSeq_set().front();
72  CSeq_entry_Handle e = edit.GetScope().GetSeq_entryHandle(*entry);
73  CSeq_entry_EditHandle new_set_edit = e.GetEditHandle();
74  edit.TakeAllAnnots(new_set_edit);
75  edit.TakeAllDescr(new_set_edit);
76  if (entry->IsSet()) {
77  size_t num_in_set = 0;
78  if (entry->GetSet().IsSetSeq_set()) {
79  num_in_set = entry->GetSet().GetSeq_set().size();
80  }
81  x_TransferSeqSet(edit, new_set_edit, num_in_set);
82  new_set_edit.Remove();
83  } else {
84  edit.ConvertSetToSeq();
85  }
86 }
87 
88 
90 {
91  return "Insert Set";
92 }
93 
94 
96 {
97  CScope& scope = src.GetScope();
99  for (size_t i = 0; i < num_in_set; i++) {
100  CConstRef<CSeq_entry> entry = old_set->GetSeq_set().front();
101  CSeq_entry_Handle e = scope.GetSeq_entryHandle(*entry);
103  dst.TakeEntry(take);
104  }
105 }
106 
107 
CCmdInsertBioseqSet(objects::CSeq_entry_Handle seh, const objects::CBioseq_set::TClass new_class)
objects::CBioseq_set::TClass m_Class
virtual void Execute()
Do the editing action.
void x_TransferSeqSet(objects::CSeq_entry_EditHandle dst, objects::CSeq_entry_EditHandle src, size_t num_in_set)
objects::CSeq_entry_Handle m_seh
virtual void Unexecute()
Undo (opposite to Execute())
CScope –.
Definition: scope.hpp:92
CSeq_entry_Handle –.
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
USING_SCOPE(objects)
CSeq_entry_Handle GetSeq_entryHandle(CDataLoader *loader, const TBlobId &blob_id, EMissing action=eMissing_Default)
Get Seq-entry handle by its blob-id, with possible loading.
Definition: scope.cpp:113
TSet GetSet(void) const
void Remove(void) const
Remove this Seq-entry from parent, or scope if it's top level Seq-entry.
void TakeAllAnnots(const CSeq_entry_EditHandle &src_entry) const
Remove all the annotation from seq-entry and attach to current one.
CConstRef< CBioseq_set > GetCompleteBioseq_set(void) const
Return the complete bioseq-set object.
CSeq_entry_EditHandle GetEditHandle(void) const
Get 'edit' version of handle.
CScope & GetScope(void) const
Get scope this handle belongs to.
CSeq_entry_EditHandle TakeEntry(const CSeq_entry_EditHandle &entry, int index=-1) const
Remove seq-entry from its location and attach to current one.
void TakeAllDescr(const CSeq_entry_EditHandle &src_entry) const
Remove all the descritions from seq-entry and attach to current one.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TSet & SetSet(void)
Select the variant.
Definition: Seq_entry_.cpp:130
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
bool IsSetSeq_set(void) const
Check if a value has been assigned to Seq_set data member.
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
const TSeq_set & GetSeq_set(void) const
Get the Seq_set member data.
void SetClass(TClass value)
Assign a value to Class data member.
int i
Definition: fix_pub.hpp:45
Modified on Wed Feb 21 09:57:57 2024 by modify_doxy.py rev. 669887