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

Go to the SVN repository for this file.

1 /* $Id: append_mod_to_org.cpp 45101 2020-05-29 20:53:24Z asztalos $
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 #include <ncbi_pch.hpp>
32 
36 
39 
40 
42 {
43  if (!tse)
44  return CRef<CCmdComposite>();
45 
46  m_Scope.Reset(&(tse.GetScope()));
47  CRef<CCmdComposite> composite(new CCmdComposite("Strain to sp."));
48  apply_to_seq_and_feat(tse, composite);
49  return composite;
50 }
51 
53 {
54  x_ApplyToDescriptors(*(tse.GetCompleteSeq_entry()), composite);
55 
56  for (CFeat_CI feat_it(tse, SAnnotSelector(CSeqFeatData::e_Biosrc)); feat_it; ++feat_it) {
57  if (m_constraint->Match(*feat_it)) {
58  CRef<CSeq_feat> new_feat(new CSeq_feat());
59  new_feat->Assign(feat_it->GetOriginalFeature());
60  if (x_ApplyToBioSource(new_feat->SetData().SetBiosrc())) {
61  CRef<CCmdChangeSeq_feat> cmd(new CCmdChangeSeq_feat(*feat_it, *new_feat));
62  composite->AddCommand(*cmd);
63  }
64  }
65  }
66 }
67 
69 {
71  if ((*it)->IsSource()) {
72  if (m_constraint->Match(it->GetPointer())) {
73  const CSeqdesc& orig_desc = **it;
74  CRef<CSeqdesc> new_desc(new CSeqdesc);
75  new_desc->Assign(orig_desc);
76  if (x_ApplyToBioSource(new_desc->SetSource())) {
77  CRef<CCmdChangeSeqdesc> cmd(new CCmdChangeSeqdesc(m_Scope->GetSeq_entryHandle(se), orig_desc, *new_desc));
78  composite->AddCommand(*cmd);
79  }
80  }
81  }
82  }
83 
84  if (se.IsSet()) {
86  x_ApplyToDescriptors(**it, composite);
87  }
88  }
89 }
90 
92 {
93  bool modified = false;
94 
95  bool ok_to_add = false;
96  if (!m_Only_sp && !m_Only_cf && !m_Only_aff && !m_Only_nr)
97  ok_to_add = true;
98 
99  if (biosource.IsSetTaxname()) {
100  if (m_EndsWith) {
101  if (m_Only_sp && NStr::EndsWith(biosource.GetTaxname()," sp."))
102  ok_to_add = true;
103 
104  if (m_Only_cf && NStr::EndsWith(biosource.GetTaxname()," cf."))
105  ok_to_add = true;
106 
107  if (m_Only_aff && NStr::EndsWith(biosource.GetTaxname()," aff."))
108  ok_to_add = true;
109 
110  if (m_Only_nr && NStr::EndsWith(biosource.GetTaxname()," nr."))
111  ok_to_add = true;
112  } else {
113  if (m_Only_sp && biosource.GetTaxname().find(" sp.") != string::npos)
114  ok_to_add = true;
115 
116  if (m_Only_cf && biosource.GetTaxname().find(" cf.") != string::npos)
117  ok_to_add = true;
118 
119  if (m_Only_aff && biosource.GetTaxname().find(" aff.") != string::npos)
120  ok_to_add = true;
121 
122  if (m_Only_nr && biosource.GetTaxname().find(" nr.") != string::npos)
123  ok_to_add = true;
124  }
125  }
126 
127  if (m_No_taxid)
128  {
129  if (biosource.IsSetOrg() && biosource.GetOrg().IsSetDb())
130  {
131  COrg_ref::TDb new_db;
132  FOR_EACH_DBXREF_ON_ORGREF(db,biosource.SetOrg())
133  if ((*db)->IsSetDb() && NStr::Equal((*db)->GetDb(),"taxon",NStr::eNocase))
134  ok_to_add = false;
135  }
136  }
137 
138  if (!ok_to_add)
139  return modified;
140 
141 
142 
143  string str_to_add;
144  if (m_IsOrgMod)
145  {
146  if (biosource.IsSetOrg() && biosource.GetOrg().IsSetOrgname() && biosource.GetOrg().GetOrgname().IsSetMod())
147  {
148  FOR_EACH_ORGMOD_ON_BIOSOURCE(orgmod,biosource)
149  if ((*orgmod)->IsSetSubtype() && (*orgmod)->IsSetSubname() && (*orgmod)->GetSubtype() == m_Subtype)
150  {
151  str_to_add = (*orgmod)->GetSubname();
152  }
153  }
154  }
155  else
156  {
157  if (biosource.IsSetSubtype())
158  {
159  FOR_EACH_SUBSOURCE_ON_BIOSOURCE(subsource,biosource)
160  if ((*subsource)->IsSetSubtype() && (*subsource)->IsSetName() && (*subsource)->GetSubtype() == m_Subtype)
161  {
162  str_to_add = (*subsource)->GetName();
163  }
164  }
165  }
166  if (!str_to_add.empty())
167  {
168 
170  {
171  NStr::ReplaceInPlace(str_to_add,":"," ");
172  }
173 
174  bool influenza = false;
175  if (biosource.IsSetOrg() && biosource.GetOrg().IsSetTaxname())
176  {
177  string& taxname = biosource.SetOrg().SetTaxname();
178  if (NStr::Equal(taxname,"Influenza A virus",NStr::eNocase) || NStr::Equal(taxname,"Influenza B virus",NStr::eNocase))
179  influenza = true;
180  }
181 
182  string str;
183  if (biosource.IsSetOrg() && biosource.GetOrg().IsSetTaxname())
184  {
185  string& taxname = biosource.SetOrg().SetTaxname();
186  str = taxname + " ";
187  }
188  if (!m_Abbreviation.empty() && m_Use_Abbreviation)
189  str += m_Abbreviation + " ";
190  if (influenza)
191  str += "(";
192  str += str_to_add;
193  if (influenza)
194  {
195  str += ")";
196  if (NStr::StartsWith(str, "Influenza A virus", NStr::eNocase)) //str = FixInfluenzaVirusName(str);
197  {
198  NStr::ReplaceInPlace (str, " ", " ");
199  NStr::ReplaceInPlace (str, "( ", "(");
200  NStr::ReplaceInPlace (str, " )", ")");
202  }
203  }
204 
205  // SetTaxNameAndRemoveTaxRef (biop->org, str);
206  bool remove_taxref = false;
207  bool is_set_taxname = biosource.IsSetOrg() && biosource.GetOrg().IsSetTaxname();
208  if (!is_set_taxname || str.empty() || str != biosource.GetOrg().GetTaxname())
209  remove_taxref = true;
210  if (biosource.IsSetOrg())
211  {
212  biosource.SetOrg().SetTaxname() = str;
213  modified = true;
214  }
215  if (remove_taxref) {
217  }
218  }
219  return modified;
220 }
221 
USING_SCOPE(objects)
CRef< CEditingActionConstraint > m_constraint
CRef< CCmdComposite > GetCommand(objects::CSeq_entry_Handle tse)
CRef< objects::CScope > m_Scope
bool x_ApplyToBioSource(objects::CBioSource &biosource)
void x_ApplyToDescriptors(const objects::CSeq_entry &se, CCmdComposite *composite)
void apply_to_seq_and_feat(objects::CSeq_entry_Handle tse, CCmdComposite *composite)
const string & GetTaxname(void) const
Definition: BioSource.cpp:340
bool IsSetTaxname(void) const
Definition: BioSource.cpp:335
void AddCommand(IEditCommand &command)
virtual bool Match(const string &value)
CFeat_CI –.
Definition: feat_ci.hpp:64
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static const char * str(char *buf, int n)
Definition: stats.c:84
void CleanupForTaxnameChange(CObjectInfo oi)
Definition: macro_util.cpp:526
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
CConstRef< CSeq_entry > GetCompleteSeq_entry(void) const
Complete and get const reference to the seq-entry.
CScope & GetScope(void) const
Get scope this handle belongs to.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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 EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5430
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3201
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5384
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3405
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
bool IsSetOrg(void) const
Check if a value has been assigned to Org data member.
Definition: BioSource_.hpp:497
bool IsSetSubtype(void) const
Check if a value has been assigned to Subtype data member.
Definition: BioSource_.hpp:527
const TOrg & GetOrg(void) const
Get the Org member data.
Definition: BioSource_.hpp:509
void SetOrg(TOrg &value)
Assign a value to Org data member.
Definition: BioSource_.cpp:108
bool IsSetDb(void) const
ids in taxonomic or culture dbases Check if a value has been assigned to Db data member.
Definition: Org_ref_.hpp:479
vector< CRef< CDbtag > > TDb
Definition: Org_ref_.hpp:101
const TTaxname & GetTaxname(void) const
Get the Taxname member data.
Definition: Org_ref_.hpp:372
bool IsSetMod(void) const
Check if a value has been assigned to Mod data member.
Definition: OrgName_.hpp:827
bool IsSetOrgname(void) const
Check if a value has been assigned to Orgname data member.
Definition: Org_ref_.hpp:529
bool IsSetTaxname(void) const
preferred formal name Check if a value has been assigned to Taxname data member.
Definition: Org_ref_.hpp:360
const TOrgname & GetOrgname(void) const
Get the Orgname member data.
Definition: Org_ref_.hpp:541
@ eSubtype_specimen_voucher
Definition: OrgMod_.hpp:106
@ eSubtype_bio_material
Definition: OrgMod_.hpp:119
@ eSubtype_culture_collection
Definition: OrgMod_.hpp:118
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
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
TSource & SetSource(void)
Select the variant.
Definition: Seqdesc_.cpp:572
#define FOR_EACH_DBXREF_ON_ORGREF(Itr, Var)
FOR_EACH_DBXREF_ON_ORGREF EDIT_EACH_DBXREF_ON_ORGREF.
#define FOR_EACH_ORGMOD_ON_BIOSOURCE(Itr, Var)
FOR_EACH_ORGMOD_ON_BIOSOURCE EDIT_EACH_ORGMOD_ON_BIOSOURCE.
#define FOR_EACH_SUBSOURCE_ON_BIOSOURCE(Itr, Var)
FOR_EACH_SUBSOURCE_ON_BIOSOURCE EDIT_EACH_SUBSOURCE_ON_BIOSOURCE.
#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:08:35 2024 by modify_doxy.py rev. 669887