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

Go to the SVN repository for this file.

1 /* $Id: apply_object.cpp 95788 2021-12-23 13:29:04Z stakhovv $
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: Colleen Bollin, NCBI
27 *
28 * File Description:
29 * CApplyObject class
30 */
31 #include <ncbi_pch.hpp>
32 #include <corelib/ncbistd.hpp>
33 #include <corelib/ncbiobj.hpp>
38 #include <objmgr/seq_entry_ci.hpp>
40 #include <objmgr/feat_ci.hpp>
41 #include <objmgr/seq_annot_ci.hpp>
44 
48 
50 {
51  m_SEH = bsh.GetParentEntry();
52  if (!desc.IsMolinfo() && !desc.IsTitle()) {
54  if (bssh && bssh.IsSetClass() && bssh.GetClass() == CBioseq_set::eClass_nuc_prot) {
55  m_SEH = bssh.GetParentEntry();
56  }
57  }
58 
59  m_Original.Reset(&desc);
60  CRef<CSeqdesc> new_desc(new CSeqdesc());
61  new_desc->Assign(desc);
62  m_Editable = new_desc.GetPointer();
63 }
64 
65 
67 {
68  m_SEH = bsh.GetParentEntry();
69  if (subtype != CSeqdesc::e_Molinfo && subtype != CSeqdesc::e_Title) {
71  if (bssh && bssh.IsSetClass() && bssh.GetClass() == CBioseq_set::eClass_nuc_prot) {
72  m_SEH = bssh.GetParentEntry();
73  }
74  }
75 
76  m_Original.Reset();
77  CRef<CSeqdesc> new_desc(new CSeqdesc());
78  new_desc->Select(subtype);
79  m_Editable = new_desc.GetPointer();
80 }
81 
82 
83 CApplyObject::CApplyObject(CBioseq_Handle bsh, const string& user_label) : m_Delete(false)
84 {
85  m_SEH = bsh.GetParentEntry();
87  if (bssh && bssh.IsSetClass() && bssh.GetClass() == CBioseq_set::eClass_nuc_prot) {
88  m_SEH = bssh.GetParentEntry();
89  }
90 
91  m_Original.Reset();
92  CRef<CSeqdesc> new_desc(new CSeqdesc());
93  new_desc->SetUser().SetType().SetStr(user_label);
94  m_Editable = new_desc.GetPointer();
95 }
96 
97 
99 {
100  m_SEH = bsh.GetParentEntry();
101  m_Original.Reset(&feat);
102  CRef<CSeq_feat> new_feat(new CSeq_feat());
103  new_feat->Assign(feat);
104  m_Editable = new_feat.GetPointer();
105 }
106 
107 
109 {
110  m_SEH = bsh.GetParentEntry();
112  CRef<CBioseq> new_seq(new CBioseq());
113  new_seq->Assign(*(bsh.GetCompleteBioseq()));
114  m_Editable = new_seq.GetPointer();
115 }
116 
117 
119 {
120  if (m_Delete) {
121  // deletion
122  if (m_Original) {
123  const CSeqdesc* orig_desc = dynamic_cast<const CSeqdesc * >(m_Original.GetPointer());
124  const CSeq_feat* orig_feat = dynamic_cast<const CSeq_feat * >(m_Original.GetPointer());
125  const CSeq_inst* orig_inst = dynamic_cast<const CSeq_inst * >(m_Original.GetPointer());
126  if (orig_desc) {
128  if (!seh) {
129  seh = m_SEH;
130  }
132  eseh.RemoveSeqdesc(*orig_desc);
133  } else if (orig_feat) {
136  } else if (orig_inst) {
137  // not going to handle this for now
138  }
139  }
140  return;
141  }
142 
143  CSeqdesc* desc = dynamic_cast<CSeqdesc * >(m_Editable.GetPointer());
144  CSeq_feat* feat = dynamic_cast<CSeq_feat * >(m_Editable.GetPointer());
145  CSeq_inst* inst = dynamic_cast<CSeq_inst * >(m_Editable.GetPointer());
146 
147  if (desc) {
148  if (m_Original) {
149  const CSeqdesc* orig_desc = dynamic_cast<const CSeqdesc* >(m_Original.GetPointer());
150  CSeqdesc* change_desc = const_cast<CSeqdesc* >(orig_desc);
151  change_desc->Assign(*desc);
152  } else {
154  eseh.AddSeqdesc(const_cast<CSeqdesc&>(*desc));
155  }
156  } else if (feat) {
157  if (m_Original) {
158  const CSeq_feat* old_feat = dynamic_cast<const CSeq_feat * >(m_Original.GetPointer());
160  // This is necessary, to make sure that we are in "editing mode"
161  const CSeq_annot_Handle& annot_handle = oh.GetAnnot();
162  CSeq_entry_EditHandle eh = annot_handle.GetParentEntry().GetEditHandle();
163 
164  // Now actually edit the feature
165  CSeq_feat_EditHandle feh(oh);
166  CSeq_entry_Handle parent_entry = feh.GetAnnot().GetParentEntry();
167 
168  feh.Replace(*feat);
169  if (feh.IsSetData() && feh.GetData().IsCdregion() && feh.IsSetProduct()) {
170  if (parent_entry.IsSet()
171  && parent_entry.GetSet().IsSetClass()
172  && parent_entry.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot) {
173  // already on nuc-prot set, leave it alone
174  } else {
175  CBioseq_set_Handle nuc_parent = parent_entry.GetParentBioseq_set();
176  if (nuc_parent && nuc_parent.IsSetClass() && nuc_parent.GetClass() == CBioseq_set::eClass_nuc_prot) {
178  CSeq_entry_Handle parent_seh = nuc_parent.GetParentEntry();
179  CSeq_annot_CI annot_ci(parent_seh, CSeq_annot_CI::eSearch_entry);
180  for (; annot_ci; ++annot_ci) {
181  if ((*annot_ci).IsFtable()) {
182  ftable = *annot_ci;
183  break;
184  }
185  }
186 
187  if (!ftable) {
188  CRef<CSeq_annot> new_annot(new CSeq_annot());
189  new_annot->SetData().SetFtable();
190  CSeq_entry_EditHandle eh = parent_seh.GetEditHandle();
191  ftable = eh.AttachAnnot(*new_annot);
192  }
193 
194  CSeq_annot_EditHandle new_annot = ftable.GetEditHandle();
195  new_annot.TakeFeat(feh);
196  }
197  }
198  }
199  } else {
200  if (feat->IsSetData() && feat->GetData().IsCdregion() && feat->IsSetProduct()) {
202  if (bsh) {
203  CBioseq_set_Handle nuc_parent = bsh.GetParentBioseq_set();
204  if (nuc_parent && nuc_parent.IsSetClass() && nuc_parent.GetClass() == CBioseq_set::eClass_nuc_prot) {
205  m_SEH = nuc_parent.GetParentEntry();
206  }
207  }
208  }
211  for (; annot_ci; ++annot_ci) {
212  if ((*annot_ci).IsFtable()) {
213  ftable = *annot_ci;
214  break;
215  }
216  }
217 
219 
220  if (!ftable) {
221  CRef<CSeq_annot> new_annot(new CSeq_annot());
222  ftable = eh.AttachAnnot(*new_annot);
223  }
224 
226  aeh.AddFeat(*feat);
227 
228  }
229 
230  } else if (inst) {
232  beeh.SetInst(*inst);
233  }
234 }
235 
236 
238 {
239  CSeq_entry_Handle seh;
240 
241  if (!scope) {
242  return seh;
243  }
244 
246  scope->GetAllTSEs(tses, CScope::eAllTSEs);
247  ITERATE (CScope::TTSE_Handles, handle, tses) {
248  for (CSeq_entry_CI entry_ci(*handle, CSeq_entry_CI::fRecursive | CSeq_entry_CI::fIncludeGivenEntry); entry_ci; ++entry_ci) {
249  if (entry_ci->IsSetDescr()) {
250  ITERATE (CBioseq::TDescr::Tdata, dit, entry_ci->GetDescr().Get()) {
251  if (dit->GetPointer() == &seq_desc) {
252  return *entry_ci;
253  }
254  }
255  }
256  }
257  }
258  return seh;
259 }
260 
264 
CSeq_entry_Handle GetSeqEntryForSeqdesc(CRef< CScope > scope, const CSeqdesc &seq_desc)
CApplyObject(CSeq_entry_Handle seh, CConstRef< CObject > orig, CRef< CObject > editable)
CSeq_entry_Handle m_SEH
CConstRef< CObject > m_Original
void ApplyChange()
CRef< CObject > m_Editable
CBioseq_EditHandle –.
CBioseq_Handle –.
CBioseq_set_Handle –.
CSeq_annot_CI –.
CSeq_annot_Handle –.
CSeq_entry_CI –.
CSeq_entry_Handle –.
CSeq_entry_Handle –.
CSeq_feat_EditHandle –.
CSeq_feat_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define false
Definition: bool.h:36
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
void GetAllTSEs(TTSE_Handles &tses, enum ETSEKind kind=eManualTSEs)
Definition: scope.cpp:295
CSeq_feat_Handle GetSeq_featHandle(const CSeq_feat &feat, EMissing action=eMissing_Default)
Definition: scope.cpp:200
vector< CSeq_entry_Handle > TTSE_Handles
Definition: scope.hpp:645
@ eAllTSEs
Definition: scope.hpp:643
CConstRef< CBioseq > GetCompleteBioseq(void) const
Get the complete bioseq.
TClass GetClass(void) const
const CSeq_annot_Handle & GetAnnot(void) const
Get handle to seq-annot for this feature.
CRef< CSeqdesc > RemoveSeqdesc(const CSeqdesc &v) const
CBioseq_set_Handle GetParentBioseq_set(void) const
Return a handle for the parent Bioseq-set, or null handle.
CSeq_entry_Handle GetParentEntry(void) const
Get parent Seq-entry handle.
const CSeqFeatData & GetData(void) const
TSet GetSet(void) const
CSeq_annot_EditHandle AttachAnnot(CSeq_annot &annot) const
Attach an annotation.
void Remove(void) const
Remove the feature from Seq-annot.
CSeq_feat_EditHandle AddFeat(const CSeq_feat &new_obj) const
CBioseq_set_Handle GetParentBioseq_set(void) const
Return a handle for the parent Bioseq-set, or null handle.
bool IsSetProduct(void) const
void SetInst(TInst &v) const
CBioseq_set_Handle GetParentBioseq_set(void) const
Get parent bioseq-set handle.
TSeq GetSeq(void) const
CSeq_entry_Handle GetParentEntry(void) const
Get parent Seq-entry handle.
CSeq_entry_EditHandle GetEditHandle(void) const
Get 'edit' version of handle.
CBioseq_EditHandle GetEditHandle(void) const
Get 'edit' version of handle.
CSeq_entry_Handle GetParentEntry(void) const
Return a handle for the parent seq-entry of the bioseq.
bool IsSetClass(void) const
CScope & GetScope(void) const
Get scope this handle belongs to.
CSeq_feat_EditHandle TakeFeat(const CSeq_feat_EditHandle &handle) const
CSeq_annot_EditHandle GetAnnot(void) const
bool IsSet(void) const
void Reset(void)
Reset handle and make it not to point to any seq-entry.
void Replace(const CSeq_feat &new_feat) const
Replace the feature with new Seq-feat object.
bool AddSeqdesc(CSeqdesc &v) const
bool IsSetData(void) const
CSeq_entry_EditHandle GetParentEntry(void) const
Navigate object tree.
@ fIncludeGivenEntry
Include the top (given) entry.
@ fRecursive
Iterate recursively.
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
#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
void SetType(TType &value)
Assign a value to Type data member.
bool IsSetData(void) const
the specific data Check if a value has been assigned to Data data member.
Definition: Seq_feat_.hpp:913
bool IsCdregion(void) const
Check if variant Cdregion is selected.
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const TProduct & GetProduct(void) const
Get the Product member data.
Definition: Seq_feat_.hpp:1096
bool IsSetProduct(void) const
product of process Check if a value has been assigned to Product data member.
Definition: Seq_feat_.hpp:1084
@ eClass_nuc_prot
nuc acid and coded proteins
Definition: Bioseq_set_.hpp:99
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_annot_.cpp:244
list< CRef< CSeqdesc > > Tdata
Definition: Seq_descr_.hpp:91
void Select(E_Choice index, EResetVariant reset=eDoResetVariant)
Select the requested variant if needed.
E_Choice
Choice variants.
Definition: Seqdesc_.hpp:109
TUser & SetUser(void)
Select the variant.
Definition: Seqdesc_.cpp:390
@ e_Molinfo
info on the molecule and techniques
Definition: Seqdesc_.hpp:134
@ e_Title
a title for this sequence
Definition: Seqdesc_.hpp:115
Definition: fix_pub.hpp:45
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
#define ftable
Definition: utilfeat.h:37
#define const
Definition: zconf.h:232
Modified on Wed Jul 17 13:18:47 2024 by modify_doxy.py rev. 669887