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

Go to the SVN repository for this file.

1 /* $Id: descr_apply.cpp 86789 2019-06-19 20:04:41Z foleyjp $
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: Justin Foley
27 *
28 * File Description:
29 *
30 */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbistd.hpp>
39 #include "descr_apply.hpp"
40 
42 using namespace objects;
43 
44 
45 static void sReportError(
46  ILineErrorListener* pEC,
47  EDiagSev severity,
48  const string& message,
50 {
51  if (!pEC) {
52  // throw an exception
53  return;
54  }
55 
56 
59  problemType,
60  severity,
61  "",
62  0,
63  "",
64  "",
65  "",
66  message));
67 
68  pEC->PutError(*pErr);
69 }
70 
71 
72 static bool s_IsDBLink(const CSeqdesc& descriptor)
73 {
74  return descriptor.IsUser() && descriptor.GetUser().IsDBLink();
75 }
76 
77 
78 
79 // Need an error listener
81  const CBioseq_set::EClass setClass,
82  const CSeqdesc& descriptor,
83  ILineErrorListener* pEC)
84 {
85  if (descriptor.IsMolinfo()) {
86  string msg = "Molinfo is not a valid set descriptor. Skipping.";
87  sReportError(pEC, eDiag_Warning, msg);
88  return true;
89  }
90 
91 
92  if (setClass != CBioseq_set::eClass_nuc_prot &&
93  (s_IsDBLink(descriptor) ||
94  descriptor.IsSource())) {
95 
96  string descName = descriptor.IsSource() ?
97  "Biosource " :
98  "DBLink";
99  string msg = descName +
100  "descriptors can only reside on a bioseq or a nuc-prot set. Skipping.";
101  sReportError(pEC, eDiag_Warning, msg);
102  return true;
103  }
104 
105  return false;
106 }
107 
108 
109 
110 
111 static void sApplyDescriptors(const list<CRef<CSeqdesc>>& descriptors,
112  CBioseq_set& bioseqSet,
113  ILineErrorListener* pEC)
114 {
115  if (descriptors.empty()) {
116  return;
117  }
118 
119  if (!bioseqSet.IsSetClass() ||
120  bioseqSet.GetClass() == CBioseq_set::eClass_not_set) {
121  string msg = "Cannot apply descriptors to set of unknown class";
122  sReportError(pEC, eDiag_Warning, msg);
123  return;
124  }
125 
126  const auto setClass = bioseqSet.GetClass();
127  auto src_it = descriptors.begin();
128  auto& dest = bioseqSet.SetDescr().Set();
129 
130  while (src_it != descriptors.end()) {
131  auto pDescriptor = *src_it;
132  if (sReportInvalidDescriptor(setClass, *pDescriptor, pEC)) {
133  ++src_it;
134  }
135  else {
136  dest.push_back(*src_it);
137  }
138  }
139 }
140 
141 
142 void g_ApplyDescriptors(const list<CRef<CSeqdesc>>& descriptors,
143  CSeq_entry& seqEntry,
144  ILineErrorListener* pEC) {
145 
146  if (seqEntry.IsSet()) {
147  sApplyDescriptors(descriptors, seqEntry.SetSet(), pEC);
148  }
149  else
150  if (seqEntry.IsSeq()) {
151  for (auto pDescriptor : descriptors) {
152  seqEntry.SetDescr().Set().emplace_back(pDescriptor);
153  }
154  }
155 }
156 
158 
159 
AutoPtr –.
Definition: ncbimisc.hpp:401
static CLineError * Create(EProblem eProblem, EDiagSev eSeverity, const std::string &strSeqId, unsigned int uLine, const std::string &strFeatureName=string(""), const std::string &strQualifierName=string(""), const std::string &strQualifierValue=string(""), const std::string &strErrorMessage=string(""), const TVecOfLines &vecOfOtherLines=TVecOfLines())
Use this because the constructor is protected.
Definition: line_error.cpp:42
Definition: Seq_entry.hpp:56
void SetDescr(CSeq_descr &value)
Definition: Seq_entry.cpp:134
bool IsDBLink() const
virtual bool PutError(const ILineError &)=0
Store error in the container, and return true if error was stored fine, and return false if the calle...
@ eProblem_GeneralParsingError
Definition: line_error.hpp:106
Include a standard set of the NCBI C++ Toolkit most basic headers.
static void sReportError(ILineErrorListener *pEC, EDiagSev severity, const string &message, ILineError::EProblem problemType=ILineError::eProblem_GeneralParsingError)
Definition: descr_apply.cpp:45
static bool s_IsDBLink(const CSeqdesc &descriptor)
Definition: descr_apply.cpp:72
void g_ApplyDescriptors(const list< CRef< CSeqdesc >> &descriptors, CSeq_entry &seqEntry, ILineErrorListener *pEC)
static void sApplyDescriptors(const list< CRef< CSeqdesc >> &descriptors, CBioseq_set &bioseqSet, ILineErrorListener *pEC)
static bool sReportInvalidDescriptor(const CBioseq_set::EClass setClass, const CSeqdesc &descriptor, ILineErrorListener *pEC)
Definition: descr_apply.cpp:80
EDiagSev
Severity level for the posted diagnostics.
Definition: ncbidiag.hpp:650
@ eDiag_Warning
Warning message.
Definition: ncbidiag.hpp:652
#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 IsSetClass(void) const
Check if a value has been assigned to Class data member.
TSet & SetSet(void)
Select the variant.
Definition: Seq_entry_.cpp:130
TClass GetClass(void) const
Get the Class member data.
bool IsSeq(void) const
Check if variant Seq is selected.
Definition: Seq_entry_.hpp:257
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
void SetDescr(TDescr &value)
Assign a value to Descr data member.
@ eClass_nuc_prot
nuc acid and coded proteins
Definition: Bioseq_set_.hpp:99
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 IsSource(void) const
Check if variant Source is selected.
Definition: Seqdesc_.hpp:1190
bool IsUser(void) const
Check if variant User is selected.
Definition: Seqdesc_.hpp:1122
Modified on Sun Mar 03 03:13:46 2024 by modify_doxy.py rev. 669887