|
NCBI C++ ToolKit
|
00001 /* $Id: asnval.cpp 52665 2012-01-17 16:59:45Z kans $ 00002 * =========================================================================== 00003 * 00004 * PUBLIC DOMAIN NOTICE 00005 * National Center for Biotechnology Information 00006 * 00007 * This software/database is a "United States Government Work" under the 00008 * terms of the United States Copyright Act. It was written as part of 00009 * the author's official duties as a United States Government employee and 00010 * thus cannot be copyrighted. This software/database is freely available 00011 * to the public for use. The National Library of Medicine and the U.S. 00012 * Government have not placed any restriction on its use or reproduction. 00013 * 00014 * Although all reasonable efforts have been taken to ensure the accuracy 00015 * and reliability of the software and data, the NLM and the U.S. 00016 * Government do not and cannot warrant the performance or results that 00017 * may be obtained by using this software or data. The NLM and the U.S. 00018 * Government disclaim all warranties, express or implied, including 00019 * warranties of performance, merchantability or fitness for any particular 00020 * purpose. 00021 * 00022 * Please cite the author in any work or product based on this material. 00023 * 00024 * =========================================================================== 00025 * 00026 * Author: Jonathan Kans, Clifford Clausen, Aaron Ucko 00027 * 00028 * File Description: 00029 * validator 00030 * 00031 */ 00032 00033 #include <ncbi_pch.hpp> 00034 #include <corelib/ncbistd.hpp> 00035 #include <corelib/ncbistre.hpp> 00036 #include <corelib/ncbiapp.hpp> 00037 #include <corelib/ncbienv.hpp> 00038 #include <corelib/ncbiargs.hpp> 00039 00040 #include <serial/serial.hpp> 00041 #include <serial/objistr.hpp> 00042 #include <serial/objectio.hpp> 00043 00044 #include <connect/ncbi_core_cxx.hpp> 00045 #include <connect/ncbi_util.h> 00046 00047 // Objects includes 00048 #include <objects/seq/Bioseq.hpp> 00049 #include <objects/seqloc/Seq_id.hpp> 00050 #include <objects/seqloc/Seq_loc.hpp> 00051 #include <objects/seqloc/Seq_interval.hpp> 00052 #include <objects/seq/Seq_inst.hpp> 00053 #include <objects/seq/Pubdesc.hpp> 00054 #include <objects/submit/Seq_submit.hpp> 00055 #include <objects/seqset/Seq_entry.hpp> 00056 #include <objects/seqfeat/BioSource.hpp> 00057 #include <objtools/validator/validator.hpp> 00058 #include <objtools/validator/valid_cmdargs.hpp> 00059 #include <objtools/cleanup/cleanup.hpp> 00060 00061 #include <objects/seqset/Bioseq_set.hpp> 00062 00063 // Object Manager includes 00064 #include <objmgr/object_manager.hpp> 00065 #include <objmgr/scope.hpp> 00066 #include <objmgr/seq_vector.hpp> 00067 #include <objmgr/seq_descr_ci.hpp> 00068 #include <objmgr/feat_ci.hpp> 00069 #include <objmgr/align_ci.hpp> 00070 #include <objmgr/graph_ci.hpp> 00071 #include <objmgr/seq_annot_ci.hpp> 00072 #include <objtools/data_loaders/genbank/gbloader.hpp> 00073 00074 #include <common/test_assert.h> /* This header must go last */ 00075 00076 00077 using namespace ncbi; 00078 using namespace objects; 00079 using namespace validator; 00080 00081 const char * ASNVAL_APP_VER = "10.0"; 00082 00083 ///////////////////////////////////////////////////////////////////////////// 00084 // 00085 // Demo application 00086 // 00087 00088 00089 class CAsnvalApp : public CNcbiApplication, CReadClassMemberHook 00090 { 00091 public: 00092 CAsnvalApp(void); 00093 00094 virtual void Init(void); 00095 virtual int Run (void); 00096 00097 void ReadClassMember(CObjectIStream& in, 00098 const CObjectInfo::CMemberIterator& member); 00099 00100 private: 00101 00102 void Setup(const CArgs& args); 00103 00104 CObjectIStream* OpenFile(const CArgs& args); 00105 CObjectIStream* OpenFile(string fname, const CArgs& args); 00106 00107 CConstRef<CValidError> ProcessSeqEntry(void); 00108 CConstRef<CValidError> ProcessSeqSubmit(void); 00109 CConstRef<CValidError> ProcessSeqAnnot(void); 00110 CConstRef<CValidError> ProcessSeqFeat(void); 00111 CConstRef<CValidError> ProcessBioSource(void); 00112 CConstRef<CValidError> ProcessPubdesc(void); 00113 CConstRef<CValidError> ValidateInput (void); 00114 void ValidateOneDirectory(string dir_name, bool recurse); 00115 void ValidateOneFile(string fname); 00116 void ProcessReleaseFile(const CArgs& args); 00117 CRef<CSeq_entry> ReadSeqEntry(void); 00118 CRef<CSeq_feat> ReadSeqFeat(void); 00119 CRef<CBioSource> ReadBioSource(void); 00120 CRef<CPubdesc> ReadPubdesc(void); 00121 00122 CRef<CScope> BuildScope(void); 00123 00124 void PrintValidError(CConstRef<CValidError> errors, 00125 const CArgs& args); 00126 00127 enum EVerbosity { 00128 eVerbosity_Normal = 1, 00129 eVerbosity_Spaced = 2, 00130 eVerbosity_Tabbed = 3, 00131 eVerbosity_XML = 4, 00132 eVerbosity_min = 1, eVerbosity_max = 4 00133 }; 00134 00135 void PrintValidErrItem(const CValidErrItem& item, CNcbiOstream& os, EVerbosity verbosity); 00136 00137 CRef<CObjectManager> m_ObjMgr; 00138 auto_ptr<CObjectIStream> m_In; 00139 unsigned int m_Options; 00140 bool m_Continue; 00141 bool m_OnlyAnnots; 00142 00143 size_t m_Level; 00144 size_t m_Reported; 00145 size_t m_ReportLevel; 00146 00147 bool m_StartXML; 00148 00149 bool m_DoCleanup; 00150 CCleanup m_Cleanup; 00151 00152 EDiagSev m_LowCutoff; 00153 EDiagSev m_HighCutoff; 00154 00155 CNcbiOstream* m_ValidErrorStream; 00156 CNcbiOstream* m_LogStream; 00157 }; 00158 00159 00160 CAsnvalApp::CAsnvalApp(void) : 00161 m_ObjMgr(0), m_In(0), m_Options(0), m_Continue(false), m_OnlyAnnots(false), 00162 m_Level(0), m_Reported(0), m_ValidErrorStream(0), m_LogStream(0) 00163 { 00164 } 00165 00166 00167 void CAsnvalApp::Init(void) 00168 { 00169 // Prepare command line descriptions 00170 00171 // Create 00172 auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); 00173 00174 arg_desc->AddOptionalKey 00175 ("p", "Directory", "Path to ASN.1 Files", 00176 CArgDescriptions::eInputFile); 00177 arg_desc->AddOptionalKey 00178 ("i", "InFile", "Single Input File", 00179 CArgDescriptions::eInputFile); 00180 arg_desc->AddOptionalKey( 00181 "o", "OutFile", "Single Output File", 00182 CArgDescriptions::eOutputFile); 00183 arg_desc->AddOptionalKey( 00184 "f", "Filter", "Substring Filter", 00185 CArgDescriptions::eOutputFile); 00186 arg_desc->AddDefaultKey 00187 ("x", "String", "File Selection Substring", CArgDescriptions::eString, ".ent"); 00188 arg_desc->AddFlag("u", "Recurse"); 00189 arg_desc->AddDefaultKey( 00190 "R", "SevCount", "Severity for Error in Return Code", 00191 CArgDescriptions::eInteger, "4"); 00192 arg_desc->AddDefaultKey( 00193 "Q", "SevLevel", "Lowest Severity for Error to Show", 00194 CArgDescriptions::eInteger, "3"); 00195 arg_desc->AddDefaultKey( 00196 "P", "SevLevel", "Highest Severity for Error to Show", 00197 CArgDescriptions::eInteger, "4"); 00198 CArgAllow* constraint = new CArgAllow_Integers(eDiagSevMin, eDiagSevMax); 00199 arg_desc->SetConstraint("Q", constraint); 00200 arg_desc->SetConstraint("P", constraint); 00201 arg_desc->SetConstraint("R", constraint); 00202 arg_desc->AddOptionalKey( 00203 "E", "String", "Only Error Code to Show", 00204 CArgDescriptions::eString); 00205 00206 arg_desc->AddDefaultKey("a", "a", 00207 "ASN.1 Type (a Automatic, z Any, e Seq-entry, b Bioseq, s Bioseq-set, m Seq-submit, t Batch Bioseq-set, u Batch Seq-submit", 00208 CArgDescriptions::eString, 00209 "a"); 00210 00211 arg_desc->AddFlag("b", "Input is in binary format"); 00212 arg_desc->AddFlag("c", "Batch File is Compressed"); 00213 00214 CValidatorArgUtil::SetupArgDescriptions(arg_desc.get()); 00215 arg_desc->AddFlag("annot", "Verify Seq-annots only"); 00216 00217 arg_desc->AddOptionalKey( 00218 "L", "OutFile", "Log File", 00219 CArgDescriptions::eOutputFile); 00220 00221 arg_desc->AddDefaultKey("v", "Verbosity", "Verbosity", CArgDescriptions::eInteger, "1"); 00222 CArgAllow* v_constraint = new CArgAllow_Integers(eVerbosity_min, eVerbosity_max); 00223 arg_desc->SetConstraint("v", v_constraint); 00224 00225 arg_desc->AddFlag("cleanup", "Perform BasicCleanup before validating (to match C Toolkit)"); 00226 00227 // Program description 00228 string prog_description = "ASN Validator\n"; 00229 arg_desc->SetUsageContext(GetArguments().GetProgramBasename(), 00230 prog_description, false); 00231 00232 // Pass argument descriptions to the application 00233 SetupArgDescriptions(arg_desc.release()); 00234 00235 } 00236 00237 00238 CConstRef<CValidError> CAsnvalApp::ValidateInput (void) 00239 { 00240 // Process file based on its content 00241 // Unless otherwise specifien we assume the file in hand is 00242 // a Seq-entry ASN.1 file, other option are a Seq-submit or NCBI 00243 // Release file (batch processing) where we process each Seq-entry 00244 // at a time. 00245 CConstRef<CValidError> eval; 00246 string header = m_In->ReadFileHeader(); 00247 00248 if (header == "Seq-submit" ) { // Seq-submit 00249 eval = ProcessSeqSubmit(); 00250 } else if ( header == "Seq-entry" ) { // Seq-entry 00251 eval = ProcessSeqEntry(); 00252 } else if ( header == "Seq-annot" ) { // Seq-annot 00253 eval = ProcessSeqAnnot(); 00254 } else if (header == "Seq-feat" ) { // Seq-feat 00255 eval = ProcessSeqFeat(); 00256 } else if (header == "BioSource" ) { // BioSource 00257 eval = ProcessBioSource(); 00258 } else if (header == "Pubdesc" ) { // Pubdesc 00259 eval = ProcessPubdesc(); 00260 } else { 00261 NCBI_THROW(CException, eUnknown, "Unhandled type " + header); 00262 } 00263 return eval; 00264 } 00265 00266 00267 void CAsnvalApp::ValidateOneFile(string fname) 00268 { 00269 const CArgs& args = GetArgs(); 00270 00271 bool need_to_close = false; 00272 00273 if (!m_ValidErrorStream) { 00274 string path = fname; 00275 size_t pos = NStr::Find(path, ".", 0, string::npos, NStr::eLast); 00276 if (pos != string::npos) { 00277 path = path.substr(0, pos); 00278 } 00279 path = path + ".val"; 00280 00281 m_ValidErrorStream = new CNcbiOfstream(path.c_str()); 00282 need_to_close = true; 00283 } 00284 m_In.reset(OpenFile(fname, args)); 00285 if ( NStr::Equal(args["a"].AsString(), "t")) { // Release file 00286 // Open File 00287 ProcessReleaseFile(args); 00288 } else { 00289 00290 CConstRef<CValidError> eval = ValidateInput (); 00291 00292 if ( eval ) { 00293 PrintValidError(eval, args); 00294 } 00295 00296 } 00297 if (need_to_close) { 00298 if (m_StartXML) { 00299 // close XML 00300 *m_ValidErrorStream << "</asnval>" << endl; 00301 m_StartXML = false; 00302 } 00303 m_ValidErrorStream = 0; 00304 } 00305 } 00306 00307 00308 void CAsnvalApp::ValidateOneDirectory(string dir_name, bool recurse) 00309 { 00310 const CArgs& args = GetArgs(); 00311 00312 CDir dir(dir_name); 00313 00314 string suffix = ".ent"; 00315 if (args["x"]) { 00316 suffix = args["x"].AsString(); 00317 } 00318 string mask = "*" + suffix; 00319 00320 CDir::TEntries files (dir.GetEntries(mask, CDir::eFile)); 00321 ITERATE(CDir::TEntries, ii, files) { 00322 string fname = (*ii)->GetName(); 00323 if ((*ii)->IsFile() && 00324 (!args["f"] || NStr::Find (fname, args["f"].AsString()) != string::npos)) { 00325 string fname = CDirEntry::MakePath(dir_name, (*ii)->GetName()); 00326 ValidateOneFile (fname); 00327 } 00328 } 00329 if (recurse) { 00330 CDir::TEntries subdirs (dir.GetEntries("", CDir::eDir)); 00331 ITERATE(CDir::TEntries, ii, subdirs) { 00332 string subdir = (*ii)->GetName(); 00333 if ((*ii)->IsDir() && !NStr::Equal(subdir, ".") && !NStr::Equal(subdir, "..")) { 00334 string subname = CDirEntry::MakePath(dir_name, (*ii)->GetName()); 00335 ValidateOneDirectory (subname, recurse); 00336 } 00337 } 00338 } 00339 } 00340 00341 00342 int CAsnvalApp::Run(void) 00343 { 00344 const CArgs& args = GetArgs(); 00345 Setup(args); 00346 00347 if (args["o"]) { 00348 m_ValidErrorStream = &(args["o"].AsOutputFile()); 00349 } 00350 00351 m_LogStream = args["L"] ? &(args["L"].AsOutputFile()) : &NcbiCout; 00352 00353 // note - the C Toolkit uses 0 for SEV_NONE, but the C++ Toolkit uses 0 for SEV_INFO 00354 // adjust here to make the inputs to asnvalidate match asnval expectations 00355 m_ReportLevel = args["R"].AsInteger() - 1; 00356 m_LowCutoff = static_cast<EDiagSev>(args["Q"].AsInteger() - 1); 00357 m_HighCutoff = static_cast<EDiagSev>(args["P"].AsInteger() - 1); 00358 00359 m_DoCleanup = args["cleanup"] && args["cleanup"].AsBoolean(); 00360 00361 // Process file based on its content 00362 // Unless otherwise specifien we assume the file in hand is 00363 // a Seq-entry ASN.1 file, other option are a Seq-submit or NCBI 00364 // Release file (batch processing) where we process each Seq-entry 00365 // at a time. 00366 m_Reported = 0; 00367 m_StartXML = false; 00368 00369 if ( args["p"] ) { 00370 ValidateOneDirectory (args["p"].AsString(), args["u"]); 00371 } else { 00372 if (args["i"]) { 00373 ValidateOneFile (args["i"].AsString()); 00374 } 00375 } 00376 00377 if (m_StartXML) { 00378 // close XML 00379 *m_ValidErrorStream << "</asnval>" << endl; 00380 m_StartXML = false; 00381 } 00382 00383 if (m_Reported > 0) { 00384 return 1; 00385 } else { 00386 return 0; 00387 } 00388 } 00389 00390 00391 CRef<CScope> CAsnvalApp::BuildScope (void) 00392 { 00393 CRef<CScope> scope(new CScope (*m_ObjMgr)); 00394 scope->AddDefaults(); 00395 00396 return scope; 00397 } 00398 00399 00400 void CAsnvalApp::ReadClassMember 00401 (CObjectIStream& in, 00402 const CObjectInfo::CMemberIterator& member) 00403 { 00404 m_Level++; 00405 00406 if ( m_Level == 1 ) { 00407 size_t n = 0; 00408 // Read each element separately to a local TSeqEntry, 00409 // process it somehow, and... not store it in the container. 00410 for ( CIStreamContainerIterator i(in, member); i; ++i ) { 00411 try { 00412 // Get seq-entry to validate 00413 CRef<CSeq_entry> se(new CSeq_entry); 00414 i >> *se; 00415 00416 // Validate Seq-entry 00417 CValidator validator(*m_ObjMgr); 00418 CRef<CScope> scope = BuildScope(); 00419 CSeq_entry_Handle seh = scope->AddTopLevelSeqEntry(*se); 00420 00421 if (m_DoCleanup) { 00422 m_Cleanup.SetScope (scope); 00423 m_Cleanup.BasicCleanup (*se); 00424 } 00425 00426 if ( m_OnlyAnnots ) { 00427 for (CSeq_annot_CI ni(seh); ni; ++ni) { 00428 const CSeq_annot_Handle& sah = *ni; 00429 CConstRef<CValidError> eval = validator.Validate(sah, m_Options); 00430 if ( eval ) { 00431 PrintValidError(eval, GetArgs()); 00432 } 00433 } 00434 } else { 00435 // CConstRef<CValidError> eval = validator.Validate(*se, &scope, m_Options); 00436 CStopWatch sw(CStopWatch::eStart); 00437 CConstRef<CValidError> eval = validator.Validate(seh, m_Options); 00438 if (m_ValidErrorStream) { 00439 *m_ValidErrorStream << "Elapsed = " << sw.Elapsed() << endl; 00440 } 00441 if ( eval ) { 00442 PrintValidError(eval, GetArgs()); 00443 } 00444 } 00445 n++; 00446 } catch (exception e) { 00447 if ( !m_Continue ) { 00448 throw; 00449 } 00450 // should we issue some sort of warning? 00451 } 00452 } 00453 } else { 00454 in.ReadClassMember(member); 00455 } 00456 00457 m_Level--; 00458 } 00459 00460 00461 void CAsnvalApp::ProcessReleaseFile 00462 (const CArgs& args) 00463 { 00464 CRef<CBioseq_set> seqset(new CBioseq_set); 00465 00466 // Register the Seq-entry hook 00467 CObjectTypeInfo set_type = CType<CBioseq_set>(); 00468 set_type.FindMember("seq-set").SetLocalReadHook(*m_In, this); 00469 00470 // Read the CBioseq_set, it will call the hook object each time we 00471 // encounter a Seq-entry 00472 *m_In >> *seqset; 00473 } 00474 00475 00476 CRef<CSeq_entry> CAsnvalApp::ReadSeqEntry(void) 00477 { 00478 CRef<CSeq_entry> se(new CSeq_entry); 00479 m_In->Read(ObjectInfo(*se), CObjectIStream::eNoFileHeader); 00480 00481 return se; 00482 } 00483 00484 00485 CConstRef<CValidError> CAsnvalApp::ProcessSeqEntry(void) 00486 { 00487 // Get seq-entry to validate 00488 CRef<CSeq_entry> se(ReadSeqEntry()); 00489 00490 // Validate Seq-entry 00491 CValidator validator(*m_ObjMgr); 00492 CRef<CScope> scope = BuildScope(); 00493 if (m_DoCleanup) { 00494 m_Cleanup.SetScope (scope); 00495 m_Cleanup.BasicCleanup (*se); 00496 } 00497 CSeq_entry_Handle seh = scope->AddTopLevelSeqEntry(*se); 00498 00499 if ( m_OnlyAnnots ) { 00500 for (CSeq_annot_CI ni(seh); ni; ++ni) { 00501 const CSeq_annot_Handle& sah = *ni; 00502 CConstRef<CValidError> eval = validator.Validate(sah, m_Options); 00503 if ( eval ) { 00504 PrintValidError(eval, GetArgs()); 00505 } 00506 } 00507 return CConstRef<CValidError>(); 00508 } 00509 return validator.Validate(*se, scope, m_Options); 00510 } 00511 00512 00513 CRef<CSeq_feat> CAsnvalApp::ReadSeqFeat(void) 00514 { 00515 CRef<CSeq_feat> feat(new CSeq_feat); 00516 m_In->Read(ObjectInfo(*feat), CObjectIStream::eNoFileHeader); 00517 00518 return feat; 00519 } 00520 00521 00522 CConstRef<CValidError> CAsnvalApp::ProcessSeqFeat(void) 00523 { 00524 CRef<CSeq_feat> feat(ReadSeqFeat()); 00525 00526 CRef<CScope> scope = BuildScope(); 00527 if (m_DoCleanup) { 00528 m_Cleanup.SetScope (scope); 00529 m_Cleanup.BasicCleanup (*feat); 00530 } 00531 00532 CValidator validator(*m_ObjMgr); 00533 return validator.Validate(*feat, scope, m_Options); 00534 } 00535 00536 00537 CRef<CBioSource> CAsnvalApp::ReadBioSource(void) 00538 { 00539 CRef<CBioSource> src(new CBioSource); 00540 m_In->Read(ObjectInfo(*src), CObjectIStream::eNoFileHeader); 00541 00542 return src; 00543 } 00544 00545 00546 CConstRef<CValidError> CAsnvalApp::ProcessBioSource(void) 00547 { 00548 CRef<CBioSource> src(ReadBioSource()); 00549 00550 CValidator validator(*m_ObjMgr); 00551 CRef<CScope> scope = BuildScope(); 00552 return validator.Validate(*src, scope, m_Options); 00553 } 00554 00555 00556 CRef<CPubdesc> CAsnvalApp::ReadPubdesc(void) 00557 { 00558 CRef<CPubdesc> pd(new CPubdesc()); 00559 m_In->Read(ObjectInfo(*pd), CObjectIStream::eNoFileHeader); 00560 00561 return pd; 00562 } 00563 00564 00565 CConstRef<CValidError> CAsnvalApp::ProcessPubdesc(void) 00566 { 00567 CRef<CPubdesc> pd(ReadPubdesc()); 00568 00569 CValidator validator(*m_ObjMgr); 00570 CRef<CScope> scope = BuildScope(); 00571 return validator.Validate(*pd, scope, m_Options); 00572 } 00573 00574 00575 00576 CConstRef<CValidError> CAsnvalApp::ProcessSeqSubmit(void) 00577 { 00578 CRef<CSeq_submit> ss(new CSeq_submit); 00579 00580 // Get seq-submit to validate 00581 m_In->Read(ObjectInfo(*ss), CObjectIStream::eNoFileHeader); 00582 00583 // Validae Seq-submit 00584 CValidator validator(*m_ObjMgr); 00585 CRef<CScope> scope = BuildScope(); 00586 if (ss->GetData().IsEntrys()) { 00587 ITERATE(CSeq_submit::TData::TEntrys, se, ss->GetData().GetEntrys()) { 00588 scope->AddTopLevelSeqEntry(**se); 00589 } 00590 } 00591 if (m_DoCleanup) { 00592 m_Cleanup.SetScope (scope); 00593 m_Cleanup.BasicCleanup (*ss); 00594 } 00595 00596 return validator.Validate(*ss, scope, m_Options); 00597 } 00598 00599 00600 CConstRef<CValidError> CAsnvalApp::ProcessSeqAnnot(void) 00601 { 00602 CRef<CSeq_annot> sa(new CSeq_annot); 00603 00604 // Get seq-annot to validate 00605 m_In->Read(ObjectInfo(*sa), CObjectIStream::eNoFileHeader); 00606 00607 // Validae Seq-annot 00608 CValidator validator(*m_ObjMgr); 00609 CRef<CScope> scope = BuildScope(); 00610 if (m_DoCleanup) { 00611 m_Cleanup.SetScope (scope); 00612 m_Cleanup.BasicCleanup (*sa); 00613 } 00614 CSeq_annot_Handle sah = scope->AddSeq_annot(*sa); 00615 return validator.Validate(sah, m_Options); 00616 } 00617 00618 00619 void CAsnvalApp::Setup(const CArgs& args) 00620 { 00621 // Setup application registry and logs for CONNECT library 00622 CORE_SetLOG(LOG_cxx2c()); 00623 CORE_SetREG(REG_cxx2c(&GetConfig(), false)); 00624 // Setup MT-safety for CONNECT library 00625 // CORE_SetLOCK(MT_LOCK_cxx2c()); 00626 00627 // Create object manager 00628 m_ObjMgr = CObjectManager::GetInstance(); 00629 if ( args["r"] ) { 00630 // Create GenBank data loader and register it with the OM. 00631 // The last argument "eDefault" informs the OM that the loader must 00632 // be included in scopes during the CScope::AddDefaults() call. 00633 CGBDataLoader::RegisterInObjectManager(*m_ObjMgr); 00634 } 00635 00636 m_OnlyAnnots = args["annot"]; 00637 00638 // Set validator options 00639 m_Options = CValidatorArgUtil::ArgsToValidatorOptions(args); 00640 } 00641 00642 00643 CObjectIStream* CAsnvalApp::OpenFile 00644 (const CArgs& args) 00645 { 00646 // file name 00647 string fname = args["i"].AsString(); 00648 00649 // file format 00650 ESerialDataFormat format = eSerial_AsnText; 00651 if ( args["b"] ) { 00652 format = eSerial_AsnBinary; 00653 } 00654 00655 return CObjectIStream::Open(fname, format); 00656 } 00657 00658 00659 CObjectIStream* CAsnvalApp::OpenFile 00660 (string fname, const CArgs& args) 00661 { 00662 // file format 00663 ESerialDataFormat format = eSerial_AsnText; 00664 if ( args["b"] ) { 00665 format = eSerial_AsnBinary; 00666 } 00667 00668 return CObjectIStream::Open(fname, format); 00669 } 00670 00671 void CAsnvalApp::PrintValidError 00672 (CConstRef<CValidError> errors, 00673 const CArgs& args) 00674 { 00675 EVerbosity verbosity = static_cast<EVerbosity>(args["v"].AsInteger()); 00676 00677 if ( errors->TotalSize() == 0 ) { 00678 return; 00679 } 00680 00681 for ( CValidError_CI vit(*errors); vit; ++vit) { 00682 if (vit->GetSeverity() >= m_ReportLevel) { 00683 ++m_Reported; 00684 } 00685 if ( vit->GetSeverity() < m_LowCutoff || vit->GetSeverity() > m_HighCutoff) { 00686 continue; 00687 } 00688 if (args["E"] && !(NStr::EqualNocase(args["E"].AsString(), vit->GetErrCode()))) { 00689 continue; 00690 } 00691 PrintValidErrItem(*vit, *m_ValidErrorStream, verbosity); 00692 } 00693 m_ValidErrorStream->flush(); 00694 } 00695 00696 00697 static string s_GetSeverityLabel (EDiagSev sev) 00698 { 00699 static const string str_sev[] = { 00700 "INFO", "WARNING", "ERROR", "REJECT", "FATAL", "MAX" 00701 }; 00702 if (sev < 0 || sev > eDiagSevMax) { 00703 return "NONE"; 00704 } 00705 00706 return str_sev[sev]; 00707 } 00708 00709 00710 void CAsnvalApp::PrintValidErrItem 00711 (const CValidErrItem& item, 00712 CNcbiOstream& os, 00713 EVerbosity verbosity) 00714 { 00715 switch (verbosity) { 00716 case eVerbosity_Normal: 00717 os << s_GetSeverityLabel(item.GetSeverity()) 00718 << ": valid [" << item.GetErrGroup() << "." << item.GetErrCode() <<"] " 00719 << item.GetMsg() << " " << item.GetObjDesc() << endl; 00720 break; 00721 case eVerbosity_Spaced: 00722 { 00723 string spacer = " "; 00724 string msg = item.GetAccnver() + spacer; 00725 msg = msg.substr(0, 15); 00726 msg += s_GetSeverityLabel(item.GetSeverity()); 00727 msg += spacer; 00728 msg = msg.substr(0, 30); 00729 msg += item.GetErrGroup() + "_" + item.GetErrCode(); 00730 os << msg << endl; 00731 } 00732 break; 00733 case eVerbosity_Tabbed: 00734 os << item.GetAccnver() << "\t" 00735 << s_GetSeverityLabel(item.GetSeverity()) << "\t" 00736 << item.GetErrGroup() << "_" << item.GetErrCode() << endl; 00737 break; 00738 case eVerbosity_XML: 00739 { 00740 string msg = NStr::XmlEncode(item.GetMsg()); 00741 if (!m_StartXML) { 00742 os << "<asnval version=\"" << ASNVAL_APP_VER << "\" severity cutoff=\"" 00743 << s_GetSeverityLabel(m_LowCutoff) << "\">" << endl; 00744 m_StartXML = true; 00745 } 00746 if (item.IsSetFeatureId()) { 00747 os << " <message severity=\"" << s_GetSeverityLabel(item.GetSeverity()) 00748 << "\" seq-id=\"" << item.GetAccnver() 00749 << "\" feat-id=\"" << item.GetFeatureId() 00750 << "\" code=\"" << item.GetErrGroup() << "_" << item.GetErrCode() 00751 << "\">" << msg << "</message>" << endl; 00752 } else { 00753 os << " <message severity=\"" << s_GetSeverityLabel(item.GetSeverity()) 00754 << "\" seq-id=\"" << item.GetAccnver() 00755 << "\" code=\"" << item.GetErrGroup() << "_" << item.GetErrCode() 00756 << "\">" << msg << "</message>" << endl; 00757 } 00758 } 00759 break; 00760 } 00761 } 00762 00763 00764 ///////////////////////////////////////////////////////////////////////////// 00765 // MAIN 00766 00767 00768 int main(int argc, const char* argv[]) 00769 { 00770 return CAsnvalApp().AppMain(argc, argv, 0, eDS_Default, 0); 00771 }
1.7.5.1
Modified on Wed May 23 12:52:46 2012 by modify_doxy.py rev. 337098