test_pin.cpp

来自「ncbi源码」· C++ 代码 · 共 1,309 行 · 第 1/3 页

CPP
1,309
字号
/* * =========================================================================== * PRODUCTION $Log: test_pin.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 19:47:01  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.19 * PRODUCTION * =========================================================================== */#include <ncbi_pch.hpp>#include <objtools/readers/seqdb/seqdb.hpp>#include <serial/serial.hpp>#include <serial/objostr.hpp>#include <iostream>#include <string>#include <corelib/ncbimtx.hpp>#include <objmgr/util/sequence.hpp>#include <objects/seqloc/Seq_id.hpp>#include <sys/types.h>#include <sys/wait.h>#include <assert.h>USING_NCBI_SCOPE;#include <sys/time.h>#include <unistd.h>inline double dbl_time(void){    struct timeval tv;    gettimeofday(& tv, 0);        return tv.tv_sec + double(tv.tv_usec) / 1000000.0;}struct charbox {    char xyz[10234];};//#include "thr_test.cpp"int hang10(){    if (long(& dbl_time) == 1102000L) {        cout << "inconceivable!" << endl;    }    return 0;}class CAccelThread {public:    CAccelThread(CSeqDB & db)        : _db(db)    {    }        void RunInline(void)    {//         _pid = fork();        //         if (! _pid) {            _Iterate();            exit(0);//         }    }        void Run(void)    {        _pid = fork();                if (! _pid) {            _Iterate();            exit(0);        }    }        void Wait(void)    {        if (_pid) {            waitpid(_pid, 0, 0);            _pid = 0;        }    }    private:    void _Iterate(void)    {        Uint4 oidx = 0;                try {            Uint4 oid = 0;            const char * buf = 0;                    Uint4 hashesque = 0;                    Uint4 part = _db.GetNumSeqs() / 40;            Uint4 parts = part;                    cout << "ITER:" << flush;                    while(_db.CheckOrFindOID(oid)) {                if (oid > parts) {                    parts += part;                    cout << "+" << flush;                }                                /*Uint4 oid_len =*/ _db.GetSequence(oid, & buf);                //                 for(Uint4 ii = 0; ii < oid_len; ii += 511) {//                     hashesque += buf[ii];//                 }                            _db.RetSequence(& buf);                            oid ++;                oidx = oid;                                if (oid > 2763324) {                    x_PossiblyStopMaybe();                }            }            _hash = hashesque;            cout << "!" << endl;        }        catch(...) {            cout << "***" << oidx << "-" << _db.GetNumSeqs() << endl;        }    }        void x_PossiblyStopMaybe(void)    {        //cout << " It is not widely known that I once leveled Rome. " << endl;    }        CSeqDB & _db;    Uint4    _hash;    Uint4    _pid;};int test1(int argc, char ** argv){    string dbpath = "/net/fridge/vol/export/blast/db/blast";        list<string> args;        while(argc > 1) {        args.push_front(string(argv[--argc]));    }        bool use_mm        = true;    bool deletions     = true;    Int8 num_display   = -1;    Int4 num_itera     = 1;    bool look_seq      = false;    bool show_bioseq   = false;    bool show_fasta    = false;    bool get_bioseq    = false;    bool show_progress = true;    bool approx        = true;    bool accel_thread  = false;    bool accel_inline  = false;        string dbname("nr");    char seqtype = kSeqTypeProt;        bool failed      = false;        while(! args.empty()) {        string desc;                string s = args.front();        args.pop_front();                if (s == "-accel1") {            s = "-accel2";            accel_thread = true;        } else desc += " [-accel1]";                if (s == "-accel3") {            s = "-accel2";            accel_thread = true;            accel_inline = true;        } else desc += " [-accel1]";                if (s == "-accel2") {            CSeqDB nt("nr", 'p');                        CAccelThread accel(nt);                        vector<Uint4> V;                        Uint4 numseq = nt.GetNumSeqs();                        for(Uint4 i = 0; i < numseq; i+=2) {                // Pick a random location in the array; push the                // value at that location onto the end.                                // Put i into the old location for that value.                                V.push_back(0);                                Uint4 loc = (rand() + (rand() << 16)) % V.size();                                V[i/2] = V[loc];                V[loc] = i/2;            }                        double t_s(dbl_time());                        if (accel_thread) {                if (accel_inline) {                    accel.RunInline();                } else {                    accel.Run();                }            }                        Uint4 part = V.size() / 40;            Uint4 parts = part;                        cout << "iter:" << flush;                        for(Uint4 i = 0; i < V.size(); i++) {                if (i > parts) {                    parts += part;                    cout << "-" << flush;                }                                Uint4 oid = V[i];                                const char * buf = 0;                nt.GetSequence(oid, & buf);                nt.RetSequence(& buf);            }                        double t_e(dbl_time());                        cout << "#" << endl;            cout << "time elapsed: " << (t_e - t_s) << endl;                                    double w_s(dbl_time());                        accel.Wait();                        double w_e(dbl_time());                        cout << "time elapsed: " << (w_e - w_s) << endl;                        return 0;        } else desc += " [-accel2]";                if (s == "-fromcpp") {            const char * ge = getenv("BLASTDB");            string pe("BLASTDB=/home/bealer/code/ut/internal/blast/unit_test/data:" + string(ge ? ge : ""));            putenv((char*)pe.c_str());                        CSeqDB local1("seqp", 'p');            CSeqDB local2("seqp", 'p', 0, 0, false);                        Int4 num1 = local1.GetNumSeqs();            Int4 num2 = local1.GetNumSeqs();                    assert(num1 >= 1);            assert(num1 == num2);                        cout << "Test worked." << endl;            return 0;        } else desc += " [-fromcpp]";                if (s == "-alphabeta") {                        // Note: this test is NOT EXPECTED to work, unless the            // user has databases named "alpha" and "beta" somewhere            // in their path.                        CSeqDB ab("alpha beta", 'p');                        for(Uint4 i = 0; i < ab.GetNumSeqs(); i++) {                cout << "-----seq " << i << " length " << ab.GetSeqLength(i) << " ------------" << endl;            }                        return 0;        } else desc += " [-alphabeta]";                if (s == "-here") {            CSeqDB nr("tenth", 'p');                        for(int i = 0; i<100; i++) {                CRef<CBioseq> bs = nr.GetBioseq(i);                                cout << "-----seq " << i << "------------" << endl;                                auto_ptr<CObjectOStream>                    outpstr(CObjectOStream::Open(eSerial_AsnText, cout));                                *outpstr << *bs;            }                        return 0;        } else desc += " [-here]";                if (s == "-dyn") {            CSeqDB db("nr", 'p');                        cout << "Num oids: " << db.GetNumSeqs() << endl;                        char * buf1 = 0;                        Int4 len = db.GetAmbigSeqAlloc(10,                                           & buf1,                                           kSeqDBNuclBlastNA8,                                           eNew);                        cout << "Length (10): " << len << endl;                        delete[] buf1;                        return 0;        } else desc += " [-dyn]";                if (s == "-limit") {            {                CSeqDB db("/home/bealer/seqdb/tenth", 'p', 10, 20, true);                                cout << "Num oids: " << db.GetNumSeqs() << endl;                                CSeqDBIter i = db.Begin();                                while(i) {                    CRef<CBioseq> bs = db.GetBioseq(i.GetOID());                                        cout << "-----seq "                         << i.GetOID() << " length "                         << i.GetLength() << "-------" << endl;                                        ++i;                }            }            {                CSeqDB db("swissprot", 'p', 135, 175, true);                                cout << "Num oids: " << db.GetNumSeqs() << endl;                                CSeqDBIter i = db.Begin();                                while(i) {                    CRef<CBioseq> bs = db.GetBioseq(i.GetOID());                                        cout << "-----seq "                         << i.GetOID() << " length "                         << i.GetLength() << "-------" << endl;                                        ++i;                }            }                        return 0;        } else desc += " [-local]";                if (s == "-local") {            CSeqDB nr("/home/bealer/seqdb/tenth", 'p');                        for(int i = 0; i<100; i++) {                CRef<CBioseq> bs = nr.GetBioseq(i);                                cout << "-----seq " << i << "------------" << endl;                                auto_ptr<CObjectOStream>                    outpstr(CObjectOStream::Open(eSerial_AsnText, cout));                                *outpstr << *bs;            }                        return 0;        } else desc += " [-local]";                if (s == "-seqids") {            CSeqDB nr(/*dbpath,*/ "nr", 'p');                        for(int i = 0; i<100; i++) {                list< CRef<CSeq_id> > seqids =                    nr.GetSeqIDs(i);                                cout << "-----seq " << i << "------------" << endl;                                for(list< CRef<CSeq_id> >::iterator j = seqids.begin();                    j != seqids.end();                    j++) {                                        cout << "SEQID----*:" << endl;                                        auto_ptr<CObjectOStream>                        outpstr(CObjectOStream::Open(eSerial_AsnText, cout));                                        CRef<CSeq_id> ident = *j;                                        *outpstr << *ident;                }            }                        return 0;        } else desc += " [-seqids]";                if (s == "-memtest") {            CSeqDB nt("nt", 'n', 0, 0, false);                        Uint4 oid = 0;                        for(int i = 0; i<100; i++) {                const char * buf(0);                                if (! nt.CheckOrFindOID(oid))                    break;                                cout << "-----------------" << endl;                                if (1) {                    int length = nt.GetSequence(oid, & buf);                                        cout << "NT OID = " << oid << ", length is " << length << endl;                                        int y = (length > 16) ? 16 : length;                                        for(int x = 0; x < y; x++) {                        if ((x & 3) == 0)                            cout << " ";                                                if (unsigned(buf[x]) < 0x10)                            cout << "0";                                                cout << hex << (unsigned(buf[x]) & 0xFF) << " ";

⌨️ 快捷键说明

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