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

Go to the SVN repository for this file.

1 /* $Id: remove_structured_comment.cpp 29154 2013-11-01 15:17:27Z filippov $
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>
31 #include <objmgr/scope.hpp>
35 
37 using namespace objects;
38 
39 void CRemoveStructuredComment::ApplyToCSeq_entry (objects::CSeq_entry_Handle tse, const CSeq_entry& se, CCmdComposite* composite)
40 {
41 
43  {
44  if ((*it)->IsUser())
45  {
47  bool modified = ApplyToUserObject((*it)->GetUser(),seh);
48  if (modified)
49  {
50  CIRef<IEditCommand> cmdDelDesc(new CCmdDelDesc(seh, **it));
51  composite->AddCommand(*cmdDelDesc);
52  }
53  }
54  }
55 
56  if (se.IsSet()) {
58  ApplyToCSeq_entry (tse, **it, composite);
59  }
60  }
61 }
62 
63 void CRemoveStructuredComment::apply_to_seq_and_feat(objects::CSeq_entry_Handle tse, CCmdComposite* composite)
64 {
65  ApplyToCSeq_entry (tse, *(tse.GetCompleteSeq_entry()), composite);
67  while (feat)
68  {
69  if (feat->IsSetData())
70  {
72  fh = feat->GetSeq_feat_Handle();
73  if (fh)
74  {
75  bool modified = ApplyToUserObject(feat->GetData().GetUser(),fh);
76  if (modified)
77  {
78  CIRef<IEditCommand> mainCmd(new CCmdDelSeq_feat(fh));
79  composite->AddCommand(*mainCmd);
80  }
81  }
82  }
83  ++feat;
84  }
85 }
86 
87 bool CRemoveStructuredComment::apply(objects::CSeq_entry_Handle tse, ICommandProccessor* cmdProcessor, string title)
88 {
89  if (tse) {
90  CRef<CCmdComposite> composite(new CCmdComposite(title));
91  apply_to_seq_and_feat(tse,composite);
92  cmdProcessor->Execute(composite.GetPointer());
93  return true;
94  }
95  else
96  return false;
97 }
98 
100 {
101  bool found = false;
102  if (user.IsSetType() && user.GetType().IsStr() && user.GetType().GetStr() == "StructuredComment") // User-object.type.str
103  {
104  map<CSeq_entry_Handle, vector<const CUser_object *> >::iterator m = m_SeqEntryComments.find(seh);
105  if (m != m_SeqEntryComments.end())
106  {
107  for (unsigned int j=0; j<m->second.size(); ++j)
108  {
109  const CUser_object* u = m->second[j];
110  bool uclass = (u->IsSetClass() && user.IsSetClass() && u->GetClass() == user.GetClass()) || (!u->IsSetClass() && !user.IsSetClass());
111  bool data = (u->IsSetData() && user.IsSetData() && u->GetData().size() == user.GetData().size()) || (!u->IsSetData() && !user.IsSetData());
112  if (u->IsSetData() && user.IsSetData() && u->GetData().size() == user.GetData().size())
113  {
114  for (unsigned int i=0; i<u->GetData().size(); ++i)
115  {
116  CRef< CUser_field > uf1 = u->GetData()[i];
117  CRef< CUser_field > uf2 = user.GetData()[i];
118  data = data && uf1->IsSetData() && uf2->IsSetData() && uf1->GetData().IsStr() && uf2->GetData().IsStr() && uf1->GetData().GetStr() == uf2->GetData().GetStr();
119  }
120  }
121  if (uclass && data) found = true;
122  }
123  }
124  if (!found)
125  m_SeqEntryComments[seh].push_back(&user);
126  }
127 
128  return found;
129 }
130 
132 {
133  bool found = false;
134  if (user.IsSetType() && user.GetType().IsStr() && user.GetType().GetStr() == "StructuredComment") // User-object.type.str
135  {
136  map<CSeq_feat_Handle, vector<const CUser_object *> >::iterator m = m_SeqFeatComments.find(fh);
137  if (m != m_SeqFeatComments.end())
138  {
139  for (unsigned int j=0; j<m->second.size(); ++j)
140  {
141  const CUser_object* u = m->second[j];
142  bool uclass = (u->IsSetClass() && user.IsSetClass() && u->GetClass() == user.GetClass()) || (!u->IsSetClass() && !user.IsSetClass());
143  bool data = (u->IsSetData() && user.IsSetData() && u->GetData().size() == user.GetData().size()) || (!u->IsSetData() && !user.IsSetData());
144  if (u->IsSetData() && user.IsSetData() && u->GetData().size() == user.GetData().size())
145  {
146  for (unsigned int i=0; i<u->GetData().size(); ++i)
147  {
148  CRef< CUser_field > uf1 = u->GetData()[i];
149  CRef< CUser_field > uf2 = user.GetData()[i];
150  data = data && uf1->IsSetData() && uf2->IsSetData() && uf1->GetData().IsStr() && uf2->GetData().IsStr() && uf1->GetData().GetStr() == uf2->GetData().GetStr();
151  }
152  }
153  if (uclass && data) found = true;
154  }
155  }
156  if (!found)
157  m_SeqFeatComments[fh].push_back(&user);
158 
159  }
160 
161  return found;
162 }
163 
165 {
166  bool found = false;
167  if (user.IsSetType() && user.GetType().IsStr() && user.GetType().GetStr() == "StructuredComment") // User-object.type.str
168  found = true;
169  return found;
170 }
171 
173 {
174  bool found = false;
175  if (user.IsSetType() && user.GetType().IsStr() && user.GetType().GetStr() == "StructuredComment") // User-object.type.str
176  found = true;
177  return found;
178 }
179 
181 {
182  bool found = false;
183  if (user.IsSetType() && user.GetType().IsStr() && user.GetType().GetStr() == "StructuredComment") // User-object.type.str
184  {
185  if (!user.IsSetData() || user.GetData().empty())
186  found = true;
187  else
188  {
189  bool nonempty = false;
190  for (unsigned int i=0; i<user.GetData().size(); ++i)
191  {
192  CRef< CUser_field > uf = user.GetData()[i];
193  if (uf->IsSetData()) nonempty = true;
194  }
195  found = !nonempty;
196  }
197  }
198  return found;
199 }
200 
202 {
203  bool found = false;
204  if (user.IsSetType() && user.GetType().IsStr() && user.GetType().GetStr() == "StructuredComment") // User-object.type.str
205  {
206  if (!user.IsSetData() || user.GetData().empty())
207  found = true;
208  else
209  {
210  bool nonempty = false;
211  for (unsigned int i=0; i<user.GetData().size(); ++i)
212  {
213  CRef< CUser_field > uf = user.GetData()[i];
214  if (uf->IsSetData()) nonempty = true;
215  }
216  found = !nonempty;
217  }
218  }
219  return found;
220 }
221 
void AddCommand(IEditCommand &command)
CFeat_CI –.
Definition: feat_ci.hpp:64
bool ApplyToUserObject(const CUser_object &user, CSeq_entry_Handle seh)
bool ApplyToUserObject(const CUser_object &user, CSeq_entry_Handle seh)
bool ApplyToUserObject(const CUser_object &user, CSeq_entry_Handle seh)
void ApplyToCSeq_entry(CSeq_entry_Handle tse, const CSeq_entry &se, CCmdComposite *composite)
bool apply(CSeq_entry_Handle tse, ICommandProccessor *cmdProcessor, string title)
void apply_to_seq_and_feat(CSeq_entry_Handle tse, CCmdComposite *composite)
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
CSeq_feat_Handle –.
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
size_type size() const
Definition: map.hpp:148
const_iterator end() const
Definition: map.hpp:152
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: map.hpp:338
char data[12]
Definition: iconv.c:80
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
const CSeqFeatData & GetData(void) const
CScope & GetScope(void) const
Get scope this handle belongs to.
bool IsSetData(void) const
const CSeq_feat_Handle & GetSeq_feat_Handle(void) const
Get original feature handle.
Definition: mapped_feat.hpp:71
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const TStr & GetStr(void) const
Get the variant data.
bool IsSetData(void) const
the object itself Check if a value has been assigned to Data data member.
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 TData & GetData(void) const
Get the Data member data.
bool IsSetClass(void) const
endeavor which designed this object Check if a value has been assigned to Class data member.
const TClass & GetClass(void) const
Get the Class member data.
bool IsStr(void) const
Check if variant Str is selected.
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
const TData & GetData(void) const
Get the Data member data.
const TType & GetType(void) const
Get the Type member data.
bool IsSetData(void) const
Check if a value has been assigned to Data data member.
const TUser & GetUser(void) const
Get the variant data.
@ e_User
user defined structure
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
#define FOR_EACH_SEQENTRY_ON_SEQSET(Itr, Var)
FOR_EACH_SEQENTRY_ON_SEQSET EDIT_EACH_SEQENTRY_ON_SEQSET.
#define FOR_EACH_SEQDESC_ON_SEQENTRY(Itr, Var)
FOR_EACH_SEQDESC_ON_SEQENTRY EDIT_EACH_SEQDESC_ON_SEQENTRY.
SAnnotSelector –.
Modified on Wed Apr 17 13:10:46 2024 by modify_doxy.py rev. 669887