test_seqvector_ci.cpp

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

CPP
549
字号
/* * =========================================================================== * PRODUCTION $Log: test_seqvector_ci.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 19:47:23  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5 * PRODUCTION * =========================================================================== *//*  $Id: test_seqvector_ci.cpp,v 1000.2 2004/06/01 19:47:23 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:  Aleksey Grichenko** File Description:*   Test for CSeqVector_CI** ===========================================================================*/#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <corelib/ncbiapp.hpp>#include <corelib/ncbienv.hpp>#include <corelib/ncbiargs.hpp>#include <corelib/ncbi_system.hpp>#include <corelib/ncbi_limits.hpp>#include <util/random_gen.hpp>// Objects includes#include <objects/seqloc/Seq_id.hpp>// Object manager includes#include <objmgr/object_manager.hpp>#include <objmgr/scope.hpp>#include <objmgr/seq_vector.hpp>#include <objmgr/seq_vector_ci.hpp>#include <objtools/data_loaders/genbank/gbloader.hpp>#include <objmgr/bioseq_handle.hpp>BEGIN_NCBI_SCOPEusing namespace objects;class CTestApp : public CNcbiApplication{public:    virtual void Init(void);    virtual int  Run (void);private:    void x_TestIterate(CSeqVector_CI& vit,                       TSeqPos start,                       TSeqPos stop);    void x_TestGetData(CSeqVector_CI& vit,                       TSeqPos start,                       TSeqPos stop);    void x_TestVector(TSeqPos start,                      TSeqPos stop);    bool x_CheckBuf(const string& buf, size_t pos, size_t len) const;    CRef<CObjectManager> m_OM;    CSeqVector m_Vect;    string m_RefBuf;};void CTestApp::Init(void){    // Prepare command line descriptions    //    // Create    auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);    // GI to fetch    arg_desc->AddDefaultKey("gi", "SeqEntryID",                            "GI id of the Seq-Entry to fetch",                            CArgDescriptions::eInteger,                            "29791621");    arg_desc->AddDefaultKey("cycles", "RandomCycles",                            "repeat random test 'cycles' times",                            CArgDescriptions::eInteger, "100");    arg_desc->AddDefaultKey("seed", "RandomSeed",                            "Force random seed",                            CArgDescriptions::eInteger, "0");    arg_desc->AddFlag("no_scope", "Use seq vector with null scope");    // Program description    string prog_description = "Test for CSeqVector_CI\n";    arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),                              prog_description, false);    // Pass argument descriptions to the application    //    SetupArgDescriptions(arg_desc.release());}bool CTestApp::x_CheckBuf(const string& buf, size_t pos, size_t len) const{    if ( pos > m_RefBuf.size() || pos + len > m_RefBuf.size() ||         buf.size() != len ) {        return false;    }    return memcmp(buf.data(), m_RefBuf.data()+pos, len) == 0;}void CTestApp::x_TestIterate(CSeqVector_CI& vit,                             TSeqPos start,                             TSeqPos stop){    if (stop > m_Vect.size()) {        stop = m_Vect.size();    }    if (start != kInvalidSeqPos) {        if (start > m_Vect.size())            start = m_Vect.size();        vit.SetPos(start);    }    else {        start = vit.GetPos();    }    // cout << "Testing iterator, " << start << " - " << stop << "... ";    if (start > stop) {        // Moving down        const char* data = m_RefBuf.data();        for ( TSeqPos pos = start; pos > stop;  ) {            --vit; --pos;            if ( vit.GetPos() != pos ) {                cout << endl << "ERROR: GetPos failed at position " << pos << endl;                throw runtime_error("Test failed");            }            if (*vit != data[pos]) {                cout << endl << "ERROR: Test failed at position " << pos << endl;                throw runtime_error("Test failed");            }        }    }    else {        // Moving up        const char* data = m_RefBuf.data();        for ( TSeqPos pos = start; pos < stop; ++vit, ++pos ) {            if ( vit.GetPos() != pos ) {                cout << endl << "ERROR: GetPos failed at position " << pos << endl;                throw runtime_error("Test failed");            }            if (*vit != data[pos]) {                cout << endl << "ERROR: Test failed at position " << pos << endl;                throw runtime_error("Test failed");            }        }    }    // cout << "OK" << endl;}void CTestApp::x_TestGetData(CSeqVector_CI& vit,                             TSeqPos start,                             TSeqPos stop){    if (start == kInvalidSeqPos) {        start = vit.GetPos();    }    if (start > stop)        swap(start, stop);    // cout << "Testing GetSeqData(" << start << ", " << stop << ")... " << endl;    string buf;    vit.GetSeqData(start, stop, buf);    if (start >= stop  &&  buf.size() > 0) {        cout << endl << "ERROR: Test failed -- invalid data length" << endl;        throw runtime_error("Test failed");    }    if (stop > m_Vect.size())        stop = m_Vect.size();    if ( !x_CheckBuf(buf, start, stop - start) ) {        cout << endl << "ERROR: Test failed -- invalid data" << endl;        throw runtime_error("Test failed");    }    // cout << "OK" << endl;}void CTestApp::x_TestVector(TSeqPos start,                            TSeqPos stop){    if (start > m_Vect.size()) {        start = m_Vect.size();    }    if (stop > m_Vect.size()) {        stop = m_Vect.size();    }    // cout << "Testing vector[], " << start << " - " << stop << "... ";    if (start > stop) {        // Moving down        const char* data = m_RefBuf.data();        for (TSeqPos i = start; i > stop; ) {            --i;            if (m_Vect[i] != data[i]) {                cout << endl << "ERROR: Test failed at position " << i << endl;                throw runtime_error("Test failed");            }        }    }    else {        // Moving up        const char* data = m_RefBuf.data();        for (TSeqPos i = start; i < stop; ++i) {            if (m_Vect[i] != data[i]) {                cout << endl << "ERROR: Test failed at position " << i << endl;                throw runtime_error("Test failed");            }        }    }    // cout << "OK" << endl;}int CTestApp::Run(void){    // Process command line args: get GI to load    const CArgs& args = GetArgs();    // GI with many segments of different sizes.    int gi = args["gi"].AsInteger(); // 29791621;    m_OM.Reset(new CObjectManager);    m_OM->RegisterDataLoader(*new CGBDataLoader("ID", 0, 2),                             CObjectManager::eDefault);    CScope scope(*m_OM);    scope.AddDefaults();    CSeq_id id;    id.SetGi(gi);    CBioseq_Handle handle = scope.GetBioseqHandle(id);    // Check if the handle is valid    if ( !handle ) {        cout << "Can not find gi " << gi << endl;

⌨️ 快捷键说明

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