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

Go to the SVN repository for this file.

1 /* $Id: citsub_updater.cpp 41956 2018-11-20 18:42:42Z 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: Andrea Asztalos
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 #include <objects/seq/Seqdesc.hpp>
32 #include <objects/seq/Pubdesc.hpp>
33 #include <objects/pub/Pub.hpp>
35 #include <objects/general/Date.hpp>
36 #include <objmgr/seqdesc_ci.hpp>
37 
40 
43 
44 const char* CCitSubUpdater::sm_SubmitterUpdateText = "Sequence update by submitter";
45 const char* CCitSubUpdater::sm_NoEarlierCitSub = "There is no earlier Cit-sub template";
46 const char* CCitSubUpdater::sm_ChangeExistingCitSub = "Adding update indication to existing cit-sub";
47 const char* CCitSubUpdater::sm_ExistingCitSub = "There already exists an update on today's date";
48 const char* CCitSubUpdater::sm_AddedCitSub = "The update Cit-sub has been placed on the top Seq-entry";
49 const char* CCitSubUpdater::sm_DifferentCitSub = "There already exists a Cit-sub having today's date with a description different than update";
50 
51 const char* CCitSubUpdater::sm_TrimmedText = "Sequence update by database staff to remove vector contamination";
52 
53 static const CDate* s_GetLaterDate(const CDate* d1, const CDate* d2)
54 {
55  if (d1 == 0 || d1->Which() == CDate::e_Str) {
56  return d2;
57  }
58 
59  if (d2 == 0 || d2->Which() == CDate::e_Str) {
60  return d1;
61  }
62 
63  return (d1->Compare(*d2) == CDate::eCompare_after) ? d1 : d2;
64 }
65 
66 static bool s_FindLatestCitSub(const CPubdesc& pubdesc,
67  CConstRef<CDate>& latestDate,
68  CConstRef<CCit_sub>& latestCitSub,
69  CConstRef<CPub>& latestPub)
70 {
71  bool found = false;
72  FOR_EACH_PUB_ON_PUBDESC(pub_iter, pubdesc) {
73  const CPub& pub = **pub_iter;
74  if (pub.IsSub() && pub.GetSub().IsSetDate()) {
75  latestDate = s_GetLaterDate(latestDate, &pub.GetSub().GetDate());
76  if (latestDate == &pub.GetSub().GetDate()) {
77  latestCitSub.Reset(&pub.GetSub());
78  latestPub.Reset(&pub);
79  found = true;
80  }
81  }
82  }
83  return found;
84 }
85 
87 {
88  return sx_GetCitSubForSequence(bsh, message, changedSeqdesc, seh, sm_SubmitterUpdateText);
89 }
90 
92 {
93  return sx_GetCitSubForSequence(bsh, message, changedSeqdesc, seh, sm_TrimmedText);
94 }
95 
97  string& message, CConstRef<CSeqdesc>& changedSeqdesc, CSeq_entry_Handle& seh, const CTempString& text)
98 {
99  message.clear();
100  changedSeqdesc.Reset();
101  seh.Reset();
102 
103  CConstRef<CDate> latestDate;
104  CConstRef<CCit_sub> latestCitSub;
105  CConstRef<CSeqdesc> latestSeqdesc;
106  CConstRef<CPub> latestPub;
107 
108  for (CSeqdesc_CI desc_it(bsh, CSeqdesc::e_Pub); desc_it; ++desc_it) {
109  if (s_FindLatestCitSub(desc_it->GetPub(), latestDate, latestCitSub, latestPub)) {
110  latestSeqdesc.Reset(&(*desc_it));
111  seh = desc_it.GetSeq_entry_Handle();
112  }
113  }
114 
115  if (!latestCitSub) {
116  message.append(sm_NoEarlierCitSub);
117  return CRef<CSeqdesc>();
118  }
119 
120  CRef<CDate> today(new CDate);
122 
123  _ASSERT(latestDate && latestCitSub && latestSeqdesc);
124  if (today && today->Compare(*latestDate) == CDate::eCompare_same) {
125  if (!latestCitSub->IsSetDescr()) {
126 
127  CRef<CSeqdesc> newDesc(new CSeqdesc);
128  newDesc->Assign(*latestSeqdesc);
129  CPubdesc& pubdesc = newDesc->SetPub();
130  EDIT_EACH_PUB_ON_PUBDESC(pub_iter, pubdesc) {
131  CPub& pub = **pub_iter;
132  if (pub.IsSub() && pub.SameCitation(*latestPub)) {
133  pub.SetSub().SetDescr(text);
134  changedSeqdesc.Reset(latestSeqdesc);
135  message.append(sm_ChangeExistingCitSub);
136  return newDesc;
137  }
138  }
139 
140  }
141  else if (NStr::EqualCase(latestCitSub->GetDescr(), text)) {
142  message.append(sm_ExistingCitSub);
143  return CRef<CSeqdesc>();
144  }
145  else {
146  message.append(sm_DifferentCitSub);
147  return CRef<CSeqdesc>();
148  }
149  }
150 
151  // otherwise, make a new cit-sub from template
152  CRef<CSeqdesc> new_desc(new CSeqdesc);
153  CRef<CPub> new_pub(new CPub);
154  new_pub->SetSub().Assign(*latestCitSub);
155  new_pub->SetSub().SetDescr(text);
156  new_pub->SetSub().SetDate(*today);
157  new_desc->SetPub().SetPub().Set().push_back(new_pub);
158  message.append(sm_AddedCitSub);
159  return new_desc;
160 }
161 
163 
USING_SCOPE(objects)
static bool s_FindLatestCitSub(const CPubdesc &pubdesc, CConstRef< CDate > &latestDate, CConstRef< CCit_sub > &latestCitSub, CConstRef< CPub > &latestPub)
static const CDate * s_GetLaterDate(const CDate *d1, const CDate *d2)
CBioseq_Handle –.
static CRef< objects::CSeqdesc > s_GetCitSubForUpdatedSequence(const objects::CBioseq_Handle &bsh, string &message, CConstRef< objects::CSeqdesc > &changedSeqdesc, objects::CSeq_entry_Handle &seh)
Generates/Creates a Cit-sub publication that will be added to the sequence.
static const char * sm_SubmitterUpdateText
static const char * sm_ExistingCitSub
static const char * sm_AddedCitSub
static CRef< objects::CSeqdesc > s_GetCitSubForTrimmedSequence(const objects::CBioseq_Handle &bsh, string &message, CConstRef< objects::CSeqdesc > &changedSeqdesc, objects::CSeq_entry_Handle &seh)
static const char * sm_ChangeExistingCitSub
static CRef< objects::CSeqdesc > sx_GetCitSubForSequence(const objects::CBioseq_Handle &bsh, string &message, CConstRef< objects::CSeqdesc > &changedSeqdesc, objects::CSeq_entry_Handle &seh, const CTempString &text)
static const char * sm_NoEarlierCitSub
static const char * sm_TrimmedText
static const char * sm_DifferentCitSub
Definition: Date.hpp:53
ECompare Compare(const CDate &date) const
Definition: Date.cpp:83
void SetToTime(const CTime &time, EPrecision prec=ePrecision_second)
Definition: Date.cpp:57
@ ePrecision_day
Definition: Date.hpp:58
@ eCompare_same
They're equivalent.
Definition: Date.hpp:75
@ eCompare_after
*this comes second.
Definition: Date.hpp:76
Definition: Pub.hpp:56
bool SameCitation(const CPub &other) const
Definition: Pub.cpp:739
@Pubdesc.hpp User-defined methods of the data storage class.
Definition: Pubdesc.hpp:54
CSeq_entry_Handle –.
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
void Reset(void)
Reset handle and make it not to point to any seq-entry.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
#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 EqualCase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-sensitive equality of a substring with another string.
Definition: ncbistr.hpp:5319
CTime CurrentTime(CTime::ETimeZone tz=CTime::eLocal, CTime::ETimeZonePrecision tzp=CTime::eTZPrecisionDefault)
Definition: ncbitime.hpp:2184
const TDescr & GetDescr(void) const
Get the Descr member data.
Definition: Cit_sub_.hpp:476
const TDate & GetDate(void) const
Get the Date member data.
Definition: Cit_sub_.hpp:455
bool IsSetDescr(void) const
description of changes for public view Check if a value has been assigned to Descr data member.
Definition: Cit_sub_.hpp:464
void SetDate(TDate &value)
Assign a value to Date data member.
Definition: Cit_sub_.cpp:101
bool IsSetDate(void) const
replaces imp, will become required Check if a value has been assigned to Date data member.
Definition: Cit_sub_.hpp:443
void SetDescr(const TDescr &value)
Assign a value to Descr data member.
Definition: Cit_sub_.hpp:485
E_Choice Which(void) const
Which variant is currently selected.
Definition: Date_.hpp:271
@ e_Str
for those unparsed dates
Definition: Date_.hpp:128
const TSub & GetSub(void) const
Get the variant data.
Definition: Pub_.cpp:189
TSub & SetSub(void)
Select the variant.
Definition: Pub_.cpp:195
bool IsSub(void) const
Check if variant Sub is selected.
Definition: Pub_.hpp:590
void SetPub(TPub &value)
Assign a value to Pub data member.
Definition: Pubdesc_.cpp:72
TPub & SetPub(void)
Select the variant.
Definition: Seqdesc_.cpp:362
@ e_Pub
a reference to the publication
Definition: Seqdesc_.hpp:122
static void text(MDB_val *v)
Definition: mdb_dump.c:62
Utility macros and typedefs for exploring NCBI objects from pub.asn.
#define FOR_EACH_PUB_ON_PUBDESC(Itr, Var)
FOR_EACH_PUB_ON_PUBDESC EDIT_EACH_PUB_ON_PUBDESC.
Definition: pub_macros.hpp:127
#define EDIT_EACH_PUB_ON_PUBDESC(Itr, Var)
Definition: pub_macros.hpp:130
#define _ASSERT
Modified on Fri Sep 20 14:58:19 2024 by modify_doxy.py rev. 669887