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

Go to the SVN repository for this file.

1 /* $Id: propagate_descriptors.cpp 43899 2019-09-17 12:09:19Z choi $
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>
33 #include <objmgr/scope.hpp>
35 #include <objmgr/seqdesc_ci.hpp>
36 #include <objmgr/seq_entry_ci.hpp>
40 
42 using namespace objects;
43 
45 {
46  if (!seh.IsSet())
47  return CRef<CCmdComposite>(NULL);
48 
49  CRef<CCmdComposite> cmd(new CCmdComposite("Propagate Descriptors"));
50 
51  CBioseq_set_Handle bioseq_set_h = seh.GetSet();
52  if (bioseq_set_h.IsSetClass() && bioseq_set_h.GetClass() == CBioseq_set::eClass_genbank &&
53  bioseq_set_h.GetCompleteBioseq_set()->IsSetSeq_set() && ! bioseq_set_h.GetCompleteBioseq_set()->GetSeq_set().empty() &&
54  bioseq_set_h.GetCompleteBioseq_set()->GetSeq_set().front()->IsSet())
55  bioseq_set_h = seh.GetScope().GetBioseq_setHandle(bioseq_set_h.GetCompleteBioseq_set()->GetSeq_set().front()->GetSet());
56 
57 
58  vector<CRef<CSeqdesc> > descs;
59  CSeq_entry_Handle pseh = bioseq_set_h.GetParentEntry();
60  for( CSeqdesc_CI desc_ci( pseh, CSeqdesc::e_not_set, 1); desc_ci; ++desc_ci )
61  {
62  if (!ShouldStayInPlace(*desc_ci))
63  {
64  descs.push_back(CRef<CSeqdesc>( SerialClone(*desc_ci) ) );
65  cmd->AddCommand( *CRef<CCmdDelDesc>(new CCmdDelDesc(pseh, *desc_ci)));
66  }
67  }
68 
69 
70  // copy to all immediate children
71  for(CSeq_entry_CI direct_child_ci( bioseq_set_h, CSeq_entry_CI::eNonRecursive ); direct_child_ci; ++direct_child_ci )
72  {
73  CSeq_entry_Handle cseh = *direct_child_ci;
74  for (size_t i = 0; i < descs.size(); i++)
75  {
76  CRef<CSeqdesc> new_desc(new CSeqdesc);
77  new_desc->Assign(*descs[i]);
78  cmd->AddCommand( *CRef<CCmdCreateDesc>(new CCmdCreateDesc(cseh, *new_desc)));
79  }
80  }
81  return cmd;
82 }
83 
85 {
86  if (!seh.IsSet())
87  return CRef<CCmdComposite>(NULL);
88 
89  CRef<CCmdComposite> cmd(new CCmdComposite("Propagate Descriptors"));
90 
91  CBioseq_set_Handle bioseq_set_h = seh.GetSet();
92  if (bioseq_set_h.IsSetClass() && bioseq_set_h.GetClass() == CBioseq_set::eClass_genbank &&
93  bioseq_set_h.GetCompleteBioseq_set()->IsSetSeq_set() && ! bioseq_set_h.GetCompleteBioseq_set()->GetSeq_set().empty() &&
94  bioseq_set_h.GetCompleteBioseq_set()->GetSeq_set().front()->IsSet())
95  bioseq_set_h = seh.GetScope().GetBioseq_setHandle(bioseq_set_h.GetCompleteBioseq_set()->GetSeq_set().front()->GetSet());
96 
97 
98  vector<const CSeqdesc*> descs;
99  // copy from all immediate children
100  CSeq_entry_CI direct_child_ci( bioseq_set_h, CSeq_entry_CI::eNonRecursive );
101  {
102  CSeq_entry_Handle cseh = *direct_child_ci;
103  for( CSeqdesc_CI desc_ci( cseh, CSeqdesc::e_not_set, 1); desc_ci; ++desc_ci )
104  {
105  if (!ShouldStayInPlace(*desc_ci))
106  {
107  descs.push_back(&*desc_ci);
108  }
109  }
110  ++direct_child_ci;
111  }
112  set<size_t> to_delete;
113  for( ; direct_child_ci; ++direct_child_ci )
114  {
115  CSeq_entry_Handle cseh = *direct_child_ci;
116  for (size_t i = 0; i < descs.size(); i++)
117  {
118  bool found = false;
119  for( CSeqdesc_CI desc_ci( cseh, CSeqdesc::e_not_set, 1); desc_ci; ++desc_ci )
120  {
121  if (desc_ci->Equals(*descs[i]))
122  {
123  found = true;
124  }
125  }
126  if (!found)
127  to_delete.insert(i);
128  }
129  }
130  for (set<size_t>::reverse_iterator i = to_delete.rbegin(); i != to_delete.rend(); ++i)
131  {
132  descs.erase(descs.begin() + (*i));
133  }
134 
135  for( CSeq_entry_CI direct_child_ci( bioseq_set_h, CSeq_entry_CI::eNonRecursive ); direct_child_ci; ++direct_child_ci )
136  {
137  CSeq_entry_Handle cseh = *direct_child_ci;
138  for (size_t i = 0; i < descs.size(); i++)
139  {
140  for( CSeqdesc_CI desc_ci( cseh, CSeqdesc::e_not_set, 1); desc_ci; ++desc_ci )
141  {
142  if (desc_ci->Equals(*descs[i]))
143  {
144  cmd->AddCommand( *CRef<CCmdDelDesc>(new CCmdDelDesc(cseh, *desc_ci)));
145  }
146  }
147  }
148  }
149 
150 
151  CSeq_entry_Handle pseh = bioseq_set_h.GetParentEntry();
152  for (size_t i = 0; i < descs.size(); i++)
153  {
154  CRef<CSeqdesc> new_desc(new CSeqdesc);
155  new_desc->Assign(*descs[i]);
156  cmd->AddCommand( *CRef<CCmdCreateDesc>(new CCmdCreateDesc(pseh, *new_desc)));
157  }
158 
159  return cmd;
160 }
161 
163 {
164  bool ret = desc.IsTitle();
165  ret |= desc.IsMolinfo();
166  ret |= desc.IsSource();
167  ret |= desc.IsCreate_date();
168  ret |= desc.IsUpdate_date();
169  ret |= desc.IsUser() && desc.GetUser().GetObjectType() == CUser_object::eObjectType_DBLink;
170  ret |= desc.IsUser() && desc.GetUser().IsSetType() && desc.GetUser().GetType().IsStr() && desc.GetUser().GetType().GetStr() == "GbenchModification";
171 
172  return ret;
173 }
174 
CBioseq_set_Handle –.
static bool ShouldStayInPlace(const objects::CSeqdesc &desc)
static CRef< CCmdComposite > GetPropagateUpCommand(objects::CSeq_entry_Handle seh)
static CRef< CCmdComposite > GetPropagateDownCommand(objects::CSeq_entry_Handle seh)
CSeq_entry_CI –.
CSeq_entry_Handle –.
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
EObjectType GetObjectType() const
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
C * SerialClone(const C &src)
Create on heap a clone of the source object.
Definition: serialbase.hpp:512
CBioseq_set_Handle GetBioseq_setHandle(const CBioseq_set &seqset, EMissing action=eMissing_Default)
Definition: scope.cpp:176
TClass GetClass(void) const
TSet GetSet(void) const
CConstRef< CBioseq_set > GetCompleteBioseq_set(void) const
Return the complete bioseq-set object.
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.
bool IsSet(void) const
@ eNonRecursive
Deprecated.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
bool IsSetType(void) const
type of object within class Check if a value has been assigned to Type data member.
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
const TType & GetType(void) const
Get the Type member data.
bool IsSetSeq_set(void) const
Check if a value has been assigned to Seq_set data member.
const TSeq_set & GetSeq_set(void) const
Get the Seq_set member data.
@ eClass_genbank
converted genbank
const TUser & GetUser(void) const
Get the variant data.
Definition: Seqdesc_.cpp:384
bool IsMolinfo(void) const
Check if variant Molinfo is selected.
Definition: Seqdesc_.hpp:1196
bool IsUpdate_date(void) const
Check if variant Update_date is selected.
Definition: Seqdesc_.hpp:1152
bool IsSource(void) const
Check if variant Source is selected.
Definition: Seqdesc_.hpp:1190
bool IsCreate_date(void) const
Check if variant Create_date is selected.
Definition: Seqdesc_.hpp:1146
bool IsTitle(void) const
Check if variant Title is selected.
Definition: Seqdesc_.hpp:1026
bool IsUser(void) const
Check if variant User is selected.
Definition: Seqdesc_.hpp:1122
@ e_not_set
No variant selected.
Definition: Seqdesc_.hpp:110
int i
Modified on Thu Dec 07 10:11:50 2023 by modify_doxy.py rev. 669887