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

Go to the SVN repository for this file.

1 /* $Id: table_data_validate_job.cpp 47106 2022-08-09 13:30:47Z 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: Dmitry Rudnev
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
36 
40 #include <objects/seq/Pubdesc.hpp>
41 
43 
45 
47 #include <objmgr/util/sequence.hpp>
48 
51 
53  : m_InputObjects(objects)
54 {
56  if (params) {
58  m_Params->Assign(*params);
59  } else {
61  }
62 }
63 
65 {
67 }
68 
70 {
71  return m_ResultErrs;
72 }
73 
74 
76 {
78 }
79 
80 
82 {
83  return "Validator job";
84 }
85 
86 
88 {
89  string jobName = "Validating";
90  string err_msg, logMsg = jobName + " - exception in Run() ";
91 
92  try {
93  CLockerGuard guard = x_GetGuard();
94  if (IsCanceled()) return eCanceled;
95  x_FetchAll();
96  }
97  catch (CException& e) {
98  err_msg = e.GetMsg();
99  LOG_POST(Error << logMsg << GetDescr() << ". " << err_msg);
100  //e.ReportAll();
101  } catch (std::exception& e) {
102  err_msg = GetDescr() + ". " + e.what();
103  LOG_POST(Error << logMsg << GetDescr() << ". " << err_msg);
104  }
105 
106  if (IsCanceled())
107  return eCanceled;
108 
109  if (!err_msg.empty()) {
110  string s = err_msg;
111  m_Error.Reset(new CAppJobError(s));
112  return eFailed;
113  }
114 
115  return eCompleted;
116 }
117 
118 
120 {
123  validator::CValidator Validator(*om);
124  Uint4 validator_opts =
125  validator::CValidator::eVal_do_tax_lookup |
126  validator::CValidator::eVal_remote_fetch |
127  validator::CValidator::eVal_far_fetch_cds_products |
128  validator::CValidator::eVal_far_fetch_mrna_products |
129  validator::CValidator::eVal_val_exons |
130  validator::CValidator::eVal_need_isojta |
131  validator::CValidator::eVal_use_entrez;
132 
133  if (RunningInsideNCBI()) {
134  validator_opts |= validator::CValidator::eVal_indexer_version;
135  }
136 
138  // validate alignments by default (no parameter) or if requested in parameter
139  validator_opts |= validator::CValidator::eVal_val_align;
140  }
142  // only validate inferences by request
143  validator_opts |= validator::CValidator::eVal_inference_accns;
144  }
145 
146  TConstScopedObjects::size_type nInputObjects(m_InputObjects.size());
147  for(TConstScopedObjects::size_type iInputObjects = 0;
148  iInputObjects < nInputObjects;
149  ++iInputObjects) {
150  const type_info& ObjType(typeid(*(m_InputObjects[iInputObjects].object.GetPointer())));
151  CConstRef<CValidError> ValidError;
152  if(ObjType == typeid(CSeq_entry)) {
153  const CSeq_entry* pSeq_entry(dynamic_cast<const CSeq_entry*>(m_InputObjects[iInputObjects].object.GetPointer()));
154  ValidError = Validator.Validate(*pSeq_entry,
155  m_InputObjects[iInputObjects].scope.GetPointer(),
156  validator_opts);
157  }
158  if (ObjType == typeid(CBioseq_set)) {
159  const CBioseq_set* pBioseq_set(dynamic_cast<const CBioseq_set*>(m_InputObjects[iInputObjects].object.GetPointer()));
160  CBioseq_set_Handle bssh = m_InputObjects[iInputObjects].scope->GetBioseq_setHandle(*pBioseq_set);
161  CSeq_entry_Handle seh = bssh.GetParentEntry();
162  ValidError = Validator.Validate(seh, validator_opts);
163  }
164  if(ObjType == typeid(CSeq_submit)) {
165  ValidError = Validator.Validate(*dynamic_cast<const CSeq_submit*>(m_InputObjects[iInputObjects].object.GetPointer()),
166  m_InputObjects[iInputObjects].scope.GetPointer(),
167  validator_opts);
168  }
169  if(ObjType == typeid(CSeq_annot)) {
170  const CSeq_annot* annot = dynamic_cast<const CSeq_annot*>(m_InputObjects[iInputObjects].object.GetPointer());
171  CSeq_annot_Handle ah = m_InputObjects[iInputObjects].scope->GetSeq_annotHandle(*annot);
172  ValidError = Validator.Validate(ah, validator_opts);
173  }
174  if(ObjType == typeid(CSeq_feat)) {
175  ValidError = Validator.Validate(*dynamic_cast<const CSeq_feat*>(m_InputObjects[iInputObjects].object.GetPointer()),
176  m_InputObjects[iInputObjects].scope.GetPointer(),
177  validator_opts);
178  }
179  if(ObjType == typeid(CBioSource)) {
180  ValidError = Validator.Validate(*dynamic_cast<const CBioSource*>(m_InputObjects[iInputObjects].object.GetPointer()),
181  m_InputObjects[iInputObjects].scope.GetPointer(),
182  validator_opts);
183  }
184  if(ObjType == typeid(CPubdesc)) {
185  ValidError = Validator.Validate(*dynamic_cast<const CPubdesc*>(m_InputObjects[iInputObjects].object.GetPointer()),
186  m_InputObjects[iInputObjects].scope.GetPointer(),
187  validator_opts);
188  }
189  if (ObjType == typeid(CSeq_id)) {
190  const CSeq_id* seq_id(dynamic_cast<const CSeq_id*>(m_InputObjects[iInputObjects].object.GetPointer()));
191  CBioseq_Handle bsh = m_InputObjects[iInputObjects].scope->GetBioseqHandle(*seq_id);
192  if (bsh) {
194  ValidError = Validator.Validate(*seh.GetCompleteSeq_entry(),
195  m_InputObjects[iInputObjects].scope.GetPointer(),
196  validator_opts);
197  }
198  }
199  if(ValidError && ValidError->TotalSize()) {
200  const CValidError::TErrs& errs(ValidError->GetErrs());
201  ValidErrs.insert(ValidErrs.end(), errs.begin(), errs.end());
202  //!! remove me!
203  /*
204 #ifdef _DEBUG
205  CNcbiOstrstream ostr;
206  {
207  unique_ptr<CObjectOStream>
208  out(CObjectOStream::Open(eSerial_AsnText, ostr));
209  ITERATE(CValidError::TErrs, iValidErrs, ValidErrs) {
210  try {
211  *out << *(*iValidErrs);
212  *out << (*iValidErrs)->GetObject();
213  } catch (const CException&) {
214  ostr << "Unable to write error" << endl;
215  }
216  }
217  }
218  _TRACE(string(CNcbiOstrstreamToString(ostr)));
219  //LOG_POST(Info << string(CNcbiOstrstreamToString(ostr)));
220 #endif */
221  }
222  }
223 }
224 
226 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CAppJobError Default implementation for IAppJobError - encapsulates a text error message.
CBioseq_Handle –.
CBioseq_set_Handle –.
CObjectFor –.
Definition: ncbiobj.hpp:2335
@Pubdesc.hpp User-defined methods of the data storage class.
Definition: Pubdesc.hpp:54
CSeq_annot_Handle –.
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
TConstScopedObjects m_InputObjects
virtual CConstIRef< IAppJobError > GetError()
Returns IAppJobError object describing internal error that caused the Job to fail.
virtual EJobState Run()
Function that does all the useful work, called by the Engine.
virtual string GetDescr() const
Returns a human readable description of the Job (optional)
virtual CRef< CObject > GetResult()
Returns the Job Result.
CRef< objects::CUser_object > m_Params
CRef< CAppJobError > m_Error
CTableDataValidateJob(const TConstScopedObjects &objects, const objects::CUser_object *params)
virtual CConstIRef< IAppJobProgress > GetProgress()
return progress object, the function shall be synchronized internally.
static bool GetDoInference(const objects::CUser_object &params)
static bool GetDoAlignment(const objects::CUser_object &params)
SIZE_TYPE TotalSize() const
Definition: ValidError.hpp:234
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
virtual bool IsCanceled() const override
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
CLockerGuard x_GetGuard()
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
@ eCanceled
Definition: app_job.hpp:91
@ eCompleted
Definition: app_job.hpp:89
@ eFailed
Definition: app_job.hpp:90
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CSeq_entry_Handle GetParentEntry(void) const
Return a handle for the parent seq-entry of the bioseq.
CConstRef< CSeq_entry > GetCompleteSeq_entry(void) const
Complete and get const reference to the seq-entry.
CSeq_entry_Handle GetTopLevelEntry(void) const
Get top level Seq-entry handle.
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
T & GetData(void)
Get data as a reference.
Definition: ncbiobj.hpp:2346
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
#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 TErrs & GetErrs(void) const
Get the Errs member data.
vector< CRef< CValidErrItem > > TErrs
Definition: ValidError_.hpp:90
The Object manager core.
CRef< objects::CObjectManager > om
USING_SCOPE(objects)
bool RunningInsideNCBI()
Definition: wx_utils.cpp:1335
Modified on Wed May 15 15:04:09 2024 by modify_doxy.py rev. 669887