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

Go to the SVN repository for this file.

1 /* $Id: wrong_illegal_quals.cpp 39111 2017-08-01 15:00:06Z 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>
32 #include <objmgr/feat_ci.hpp>
36 
38 
40 
42 {
43  CRef<CCmdComposite> cmd(new CCmdComposite("Illegal Quals To Note"));
44  bool modified = false;
45  for (CFeat_CI feat_ci(seh); feat_ci; ++feat_ci)
46  {
47  const CSeq_feat& orig = feat_ci->GetOriginalFeature();
48  CRef<CSeq_feat> new_feat(new CSeq_feat());
49  new_feat->Assign(orig);
50  bool changed = false;
51  if (new_feat->IsSetQual())
52  {
53  CSeq_feat::TQual::iterator qual_it = new_feat->SetQual().begin();
54  while (qual_it != new_feat->SetQual().end())
55  {
56  bool to_delete = false;
57  if ((*qual_it)->IsSetQual())
58  {
59  CSeqFeatData::EQualifier gbqual = CSeqFeatData::GetQualifierType((*qual_it)->GetQual());
60  if (gbqual == CSeqFeatData::eQual_bad)
61  {
62  if ((*qual_it)->IsSetVal())
63  {
64  string content = "["+(*qual_it)->GetQual()+"="+(*qual_it)->GetVal()+"]";
65  string prev_value;
66  if (new_feat->IsSetComment())
67  {
68  prev_value = new_feat->GetComment();
69  }
70  if (!prev_value.empty())
71  prev_value += "; ";
72  new_feat->SetComment(prev_value + content);
73  }
74  to_delete = true;
75  changed = true;
76  }
77  }
78  if (to_delete)
79  qual_it = new_feat->SetQual().erase(qual_it);
80  else
81  ++qual_it;
82  }
83  if (new_feat->SetQual().empty())
84  new_feat->ResetQual();
85  }
86 
87  if (changed)
88  {
89  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(feat_ci->GetSeq_feat_Handle(), *new_feat)));
90  modified = true;
91  }
92  }
93 
94  if (modified)
95  {
96  cmd_processor->Execute(cmd);
97  }
98 }
99 
100 
102 {
103  if (subtype == CSeqFeatData::eSubtype_cdregion) {
105  || qual == CSeqFeatData::eQual_codon
108  || qual == CSeqFeatData::eQual_number
113  || qual == CSeqFeatData::eQual_allele
116  return true;
117  }
118  }
119  if (subtype == CSeqFeatData::eSubtype_tRNA )
120  {
121  if (qual == CSeqFeatData::eQual_anticodon)
122  return true;
123  if (qual == CSeqFeatData::eQual_product
124  && !NStr::EqualNocase (value, "tRNA-fMet")
125  && !NStr::EqualNocase (value, "tRNA-iMet"))
126  return true;
127  }
128  return false;
129 }
130 
132 {
133  CRef<CCmdComposite> cmd(new CCmdComposite("Remove Illegal Quals"));
134  bool modified = false;
135  for (CFeat_CI feat_ci(seh); feat_ci; ++feat_ci)
136  {
137  const CSeq_feat& orig = feat_ci->GetOriginalFeature();
138  CRef<CSeq_feat> new_feat(new CSeq_feat());
139  new_feat->Assign(orig);
140  bool changed = false;
141  if (new_feat->IsSetQual())
142  {
143  CSeq_feat::TQual::iterator qual_it = new_feat->SetQual().begin();
144  while (qual_it != new_feat->SetQual().end())
145  {
146  bool to_delete = false;
147  string value;
148  if ((*qual_it)->IsSetVal())
149  value = (*qual_it)->GetVal();
150 
151  if ((*qual_it)->IsSetQual())
152  {
153  CSeqFeatData::EQualifier gbqual = CSeqFeatData::GetQualifierType((*qual_it)->GetQual());
154  if (gbqual == CSeqFeatData::eQual_bad || gbqual == CSeqFeatData::eQual_transl_except ||
155  !CSeqFeatData::IsLegalQualifier(new_feat->GetData().GetSubtype(), gbqual) ||
156  s_SpecialRemove(new_feat->GetData().GetSubtype(), gbqual, value))
157  {
158  to_delete = true;
159  changed = true;
160  }
161  }
162  if (to_delete)
163  qual_it = new_feat->SetQual().erase(qual_it);
164  else
165  ++qual_it;
166  }
167  if (new_feat->SetQual().empty())
168  new_feat->ResetQual();
169  }
170 
171  if (changed)
172  {
173  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(feat_ci->GetSeq_feat_Handle(), *new_feat)));
174  modified = true;
175  }
176  }
177 
178  if (modified)
179  {
180  cmd_processor->Execute(cmd);
181  }
182 }
183 
185 {
186  CRef<CCmdComposite> cmd(new CCmdComposite("Wrong Quals To Note"));
187  bool modified = false;
188  for (CFeat_CI feat_ci(seh); feat_ci; ++feat_ci)
189  {
190  const CSeq_feat& orig = feat_ci->GetOriginalFeature();
191  CRef<CSeq_feat> new_feat(new CSeq_feat());
192  new_feat->Assign(orig);
193  bool changed = false;
194  if (new_feat->IsSetQual())
195  {
196  CSeq_feat::TQual::iterator qual_it = new_feat->SetQual().begin();
197  while (qual_it != new_feat->SetQual().end())
198  {
199  bool to_delete = false;
200  if ((*qual_it)->IsSetQual())
201  {
202  CSeqFeatData::EQualifier gbqual = CSeqFeatData::GetQualifierType((*qual_it)->GetQual());
203  if (gbqual != CSeqFeatData::eQual_bad && !CSeqFeatData::IsLegalQualifier(new_feat->GetData().GetSubtype(), gbqual))
204  {
205  if ((*qual_it)->IsSetVal())
206  {
207  string content = "["+(*qual_it)->GetQual()+"="+(*qual_it)->GetVal()+"]";
208  string prev_value;
209  if (new_feat->IsSetComment())
210  {
211  prev_value = new_feat->GetComment();
212  }
213  if (!prev_value.empty())
214  prev_value += "; ";
215  new_feat->SetComment(prev_value + content);
216  }
217  to_delete = true;
218  changed = true;
219  }
220  }
221  if (to_delete)
222  qual_it = new_feat->SetQual().erase(qual_it);
223  else
224  ++qual_it;
225  }
226  if (new_feat->SetQual().empty())
227  new_feat->ResetQual();
228  }
229 
230  if (changed)
231  {
232  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(feat_ci->GetSeq_feat_Handle(), *new_feat)));
233  modified = true;
234  }
235  }
236 
237  if (modified)
238  {
239  cmd_processor->Execute(cmd);
240  }
241 }
242 
244 {
245  CRef<CCmdComposite> cmd(new CCmdComposite("Remove Wrong Quals"));
246  bool modified = false;
247  for (CFeat_CI feat_ci(seh); feat_ci; ++feat_ci)
248  {
249  const CSeq_feat& orig = feat_ci->GetOriginalFeature();
250  CRef<CSeq_feat> new_feat(new CSeq_feat());
251  new_feat->Assign(orig);
252  bool changed = false;
253  if (new_feat->IsSetQual())
254  {
255  CSeq_feat::TQual::iterator qual_it = new_feat->SetQual().begin();
256  while (qual_it != new_feat->SetQual().end())
257  {
258  bool to_delete = false;
259  if ((*qual_it)->IsSetQual())
260  {
261  CSeqFeatData::EQualifier gbqual = CSeqFeatData::GetQualifierType((*qual_it)->GetQual());
262  if (gbqual != CSeqFeatData::eQual_bad && !CSeqFeatData::IsLegalQualifier(new_feat->GetData().GetSubtype(), gbqual))
263  {
264  to_delete = true;
265  changed = true;
266  }
267  }
268  if (to_delete)
269  qual_it = new_feat->SetQual().erase(qual_it);
270  else
271  ++qual_it;
272  }
273  if (new_feat->SetQual().empty())
274  new_feat->ResetQual();
275  }
276 
277  if (changed)
278  {
279  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(feat_ci->GetSeq_feat_Handle(), *new_feat)));
280  modified = true;
281  }
282  }
283 
284  if (modified)
285  {
286  cmd_processor->Execute(cmd);
287  }
288 }
289 
290 
292 {
293  CRef<CCmdComposite> cmd(new CCmdComposite("Remove Wrong or Illegal Quals"));
294  bool modified = false;
295  for (CFeat_CI feat_ci(seh); feat_ci; ++feat_ci)
296  {
297  const CSeq_feat& orig = feat_ci->GetOriginalFeature();
298  CRef<CSeq_feat> new_feat(new CSeq_feat());
299  new_feat->Assign(orig);
300  bool changed = false;
301  if (new_feat->IsSetQual())
302  {
303  CSeq_feat::TQual::iterator qual_it = new_feat->SetQual().begin();
304  while (qual_it != new_feat->SetQual().end())
305  {
306  bool to_delete = false;
307  if ((*qual_it)->IsSetQual())
308  {
309  CSeqFeatData::EQualifier gbqual = CSeqFeatData::GetQualifierType((*qual_it)->GetQual());
310  if ((gbqual != CSeqFeatData::eQual_bad && !CSeqFeatData::IsLegalQualifier(new_feat->GetData().GetSubtype(), gbqual))
311  || (gbqual == CSeqFeatData::eQual_bad) )
312  {
313  to_delete = true;
314  changed = true;
315  }
316  }
317  if (to_delete)
318  qual_it = new_feat->SetQual().erase(qual_it);
319  else
320  ++qual_it;
321  }
322  if (new_feat->SetQual().empty())
323  new_feat->ResetQual();
324  }
325 
326  if (changed)
327  {
328  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(feat_ci->GetSeq_feat_Handle(), *new_feat)));
329  modified = true;
330  }
331  }
332 
333  if (modified)
334  {
335  cmd_processor->Execute(cmd);
336  }
337 }
338 
CFeat_CI –.
Definition: feat_ci.hpp:64
bool IsLegalQualifier(EQualifier qual) const
Test wheather a certain qualifier is legal for the feature.
EQualifier
List of available qualifiers for feature keys.
ESubtype GetSubtype(void) const
static EQualifier GetQualifierType(CTempString qual)
convert qual string to enumerated value
CSeq_entry_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
static void RmWrongQuals(CSeq_entry_Handle seh, ICommandProccessor *cmd_processor)
static void RmWrongOrIllegalQuals(CSeq_entry_Handle seh, ICommandProccessor *cmd_processor)
static void IllegalQualsToNote(CSeq_entry_Handle seh, ICommandProccessor *cmd_processor)
static void WrongQualsToNote(CSeq_entry_Handle seh, ICommandProccessor *cmd_processor)
static void RmIllegalQuals(CSeq_entry_Handle seh, ICommandProccessor *cmd_processor)
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another 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
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
bool IsSetComment(void) const
Check if a value has been assigned to Comment data member.
Definition: Seq_feat_.hpp:1037
bool IsSetQual(void) const
qualifiers Check if a value has been assigned to Qual data member.
Definition: Seq_feat_.hpp:1135
void SetComment(const TComment &value)
Assign a value to Comment data member.
Definition: Seq_feat_.hpp:1058
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const TComment & GetComment(void) const
Get the Comment member data.
Definition: Seq_feat_.hpp:1049
TQual & SetQual(void)
Assign a value to Qual data member.
Definition: Seq_feat_.hpp:1153
void ResetQual(void)
Reset Qual data member.
Definition: Seq_feat_.cpp:136
where boath are integers</td > n< td ></td > n</tr > n< tr > n< td > tse</td > n< td > optional</td > n< td > String</td > n< td class=\"description\"> TSE option controls what blob is orig
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
USING_SCOPE(ncbi::objects)
bool s_SpecialRemove(CSeqFeatData::ESubtype subtype, CSeqFeatData::EQualifier qual, const string &value)
Modified on Wed Apr 17 13:09:27 2024 by modify_doxy.py rev. 669887