test_validator.cpp

来自「ncbi源码」· C++ 代码 · 共 611 行 · 第 1/2 页

CPP
611
字号
/* * =========================================================================== * PRODUCTION $Log: test_validator.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 19:48:09  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.27 * PRODUCTION * =========================================================================== *//*  $Id: test_validator.cpp,v 1000.2 2004/06/01 19:48:09 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Author:  Jonathan Kans, Clifford Clausen, Aaron Ucko * * File Description: *   Test Program for validator * */#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <corelib/ncbistre.hpp>#include <corelib/ncbiapp.hpp>#include <corelib/ncbienv.hpp>#include <corelib/ncbiargs.hpp>#include <serial/serial.hpp>#include <serial/objistr.hpp>#include <serial/objectio.hpp>#include <connect/ncbi_core_cxx.hpp>#include <connect/ncbi_util.h>// Objects includes#include <objects/seq/Bioseq.hpp>#include <objects/seqloc/Seq_id.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqloc/Seq_interval.hpp>#include <objects/seq/Seq_inst.hpp>#include <objects/submit/Seq_submit.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objtools/validator/validator.hpp>#include <objects/seqset/Bioseq_set.hpp>// Object Manager includes#include <objmgr/object_manager.hpp>#include <objmgr/scope.hpp>#include <objmgr/seq_vector.hpp>#include <objmgr/seq_descr_ci.hpp>#include <objmgr/feat_ci.hpp>#include <objmgr/align_ci.hpp>#include <objmgr/graph_ci.hpp>#include <objtools/data_loaders/genbank/gbloader.hpp>using namespace ncbi;using namespace objects;using namespace validator;/////////////////////////////////////////////////////////////////////////////////  Demo application//class CTest_validatorApplication : public CNcbiApplication, CReadClassMemberHook{public:    CTest_validatorApplication(void);    virtual void Init(void);    virtual int  Run (void);    void ReadClassMember(CObjectIStream& in,        const CObjectInfo::CMemberIterator& member);private:    void Setup(const CArgs& args);    void SetupValidatorOptions(const CArgs& args);    CObjectIStream* OpenFile(const CArgs& args);    CConstRef<CValidError> ProcessSeqEntry(void);    CConstRef<CValidError> ProcessSeqSubmit(void);    CConstRef<CValidError> ProcessSeqAnnot(void);    void ProcessReleaseFile(const CArgs& args);    CRef<CSeq_entry> ReadSeqEntry(void);    SIZE_TYPE PrintValidError(CConstRef<CValidError> errors,         const CArgs& args);    SIZE_TYPE PrintBatchErrors(CConstRef<CValidError> errors,        const CArgs& args);    void PrintValidErrItem(const CValidErrItem& item, CNcbiOstream& os);    void PrintBatchItem(const CValidErrItem& item, CNcbiOstream& os);    CRef<CObjectManager> m_ObjMgr;    auto_ptr<CObjectIStream> m_In;    unsigned int m_Options;    bool m_Continue;    size_t m_Level;    size_t m_Reported;};CTest_validatorApplication::CTest_validatorApplication(void) :    m_ObjMgr(0), m_In(0), m_Options(0), m_Continue(false), m_Level(0),    m_Reported(0){}void CTest_validatorApplication::Init(void){    // Prepare command line descriptions    // Create    auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);    arg_desc->AddDefaultKey        ("i", "ASNFile", "Seq-entry/Seq_submit ASN.1 text file",        CArgDescriptions::eInputFile, "current.prt");    arg_desc->AddFlag("s", "Input is Seq-submit");    arg_desc->AddFlag("t", "Input is Seq-set (NCBI Release file)");    arg_desc->AddFlag("b", "Input is in binary format");    arg_desc->AddFlag("c", "Continue on ASN.1 error");    arg_desc->AddFlag("g", "Registers ID loader");    arg_desc->AddFlag("nonascii", "Report Non Ascii Error");    arg_desc->AddFlag("context", "Suppress context in error msgs");    arg_desc->AddFlag("align", "Validate Alignments");    arg_desc->AddFlag("exon", "Validate exons");    arg_desc->AddFlag("splice", "Report splice error as error");    arg_desc->AddFlag("ovlpep", "Report overlapping peptide as error");    arg_desc->AddFlag("taxid", "Requires taxid");    arg_desc->AddFlag("isojta", "Requires ISO-JTA");    arg_desc->AddOptionalKey(        "x", "OutFile", "Output file for error messages",        CArgDescriptions::eOutputFile);    arg_desc->AddDefaultKey(        "q", "SevLevel", "Lowest severity error to show",        CArgDescriptions::eInteger, "1");    arg_desc->AddDefaultKey(        "r", "SevCount", "Severity error to count in return code",        CArgDescriptions::eInteger, "2");    CArgAllow* constraint = new CArgAllow_Integers(eDiagSevMin, eDiagSevMax);    arg_desc->SetConstraint("q", constraint);    arg_desc->SetConstraint("r", constraint);    // !!!    // { DEBUG    // This flag should be removed once testing is done. It is intended for    // performance testing.    arg_desc->AddFlag("debug", "Disable suspected performance bottlenecks");    // }    // Program description    string prog_description = "Test driver for Validate()\n";    arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),        prog_description, false);    // Pass argument descriptions to the application    SetupArgDescriptions(arg_desc.release());}int CTest_validatorApplication::Run(void){    const CArgs& args = GetArgs();    Setup(args);    // Open File     m_In.reset(OpenFile(args));    // Process file based on its content    // Unless otherwise specifien we assume the file in hand is    // a Seq-entry ASN.1 file, other option are a Seq-submit or NCBI    // Release file (batch processing) where we process each Seq-entry    // at a time.    CConstRef<CValidError> eval;    if ( args["t"] ) {          // Release file        ProcessReleaseFile(args);        return 0;    } else {        string header = m_In->ReadFileHeader();        if ( args["s"]  &&  header != "Seq-submit" ) {            NCBI_THROW(CException, eUnknown,                "Conflict: '-s' flag is specified but file is not Seq-submit");        }         if ( args["s"]  ||  header == "Seq-submit" ) {  // Seq-submit            eval = ProcessSeqSubmit();        } else if ( header == "Seq-entry" ) {           // Seq-entry            eval = ProcessSeqEntry();        } else if ( header == "Seq-annot" ) {           // Seq-annot            eval = ProcessSeqAnnot();        } else {            NCBI_THROW(CException, eUnknown, "Unhandaled type " + header);        }    }    unsigned int result = 0;    if ( eval ) {        result = PrintValidError(eval, args);    }    return result;}void CTest_validatorApplication::ReadClassMember(CObjectIStream& in, const CObjectInfo::CMemberIterator& member){    m_Level++;    if ( m_Level == 1 ) {        // Read each element separately to a local TSeqEntry,        // process it somehow, and... not store it in the container.        for ( CIStreamContainerIterator i(in, member); i; ++i ) {            try {                // Get seq-entry to validate                CRef<CSeq_entry> se(new CSeq_entry);                i >> *se;                // Validate Seq-entry                CValidator validator(*m_ObjMgr);                CConstRef<CValidError> eval = validator.Validate(*se, 0, m_Options);                if ( eval ) {                    m_Reported += PrintBatchErrors(eval, GetArgs());                }            } catch (exception e) {                if ( !m_Continue ) {                    throw;                }                // should we issue some sort of warning?            }        }    } else {        in.ReadClassMember(member);    }    m_Level--;}void CTest_validatorApplication::ProcessReleaseFile(const CArgs& args){    CRef<CBioseq_set> seqset(new CBioseq_set);    // Register the Seq-entry hook    CObjectTypeInfo set_type = CType<CBioseq_set>();    set_type.FindMember("seq-set").SetLocalReadHook(*m_In, this);    m_Continue = args["c"];    // Read the CBioseq_set, it will call the hook object each time we     // encounter a Seq-entry    *m_In >> *seqset;    NcbiCerr << m_Reported << " messages reported" << endl;}SIZE_TYPE CTest_validatorApplication::PrintBatchErrors(CConstRef<CValidError> errors, const CArgs& args){    if ( !errors  ||  errors->TotalSize() == 0 ) {        return 0;    }    EDiagSev show  = static_cast<EDiagSev>(args["q"].AsInteger());    CNcbiOstream* os = args["x"] ? &(args["x"].AsOutputFile()) : &NcbiCout;    SIZE_TYPE reported = 0;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?