⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objmgr_demo.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* * =========================================================================== * PRODUCTION $Log: objmgr_demo.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 18:30:37  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.68 * PRODUCTION * =========================================================================== *//*  $Id: objmgr_demo.cpp,v 1000.2 2004/06/01 18:30:37 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:*   Examples of using the C++ object manager** ===========================================================================*/#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>// Objects includes#include <objects/seq/Bioseq.hpp>#include <objects/seq/Seq_annot.hpp>#include <objects/seq/Seq_inst.hpp>#include <objects/seq/Seq_ext.hpp>#include <objects/seqloc/Seq_id.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqloc/Seq_interval.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objects/seqset/Bioseq_set.hpp>#include <objects/seqfeat/seqfeat__.hpp>#include <objects/seqalign/Seq_align.hpp>// Object manager includes#include <objmgr/scope.hpp>#include <objmgr/seq_vector.hpp>#include <objmgr/seqdesc_ci.hpp>#include <objmgr/feat_ci.hpp>#include <objmgr/graph_ci.hpp>#include <objmgr/align_ci.hpp>#include <objmgr/bioseq_ci.hpp>#include <objmgr/seq_annot_ci.hpp>#include <objmgr/impl/synonyms.hpp>#include <objmgr/object_manager.hpp>#include <objtools/data_loaders/genbank/gbloader.hpp>#include <objtools/data_loaders/genbank/seqref.hpp>#include <objtools/data_loaders/genbank/readers/id1/reader_id1_cache.hpp>#include <bdb/bdb_blobcache.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);/////////////////////////////////////////////////////////////////////////////////  Demo application//class CDemoApp : public CNcbiApplication{public:    virtual void Init(void);    virtual int  Run (void);    CRef<CGBDataLoader> gb_loader;//    auto_ptr<CBDB_BLOB_Cache> bdb_cache;    auto_ptr<CBDB_Cache> blob_cache;    auto_ptr<CBDB_Cache> id_cache;};void CDemoApp::Init(void){    // Prepare command line descriptions    //    // Create    auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);    // GI to fetch    arg_desc->AddOptionalKey("gi", "SeqEntryID",                             "GI id of the Seq-Entry to fetch",                             CArgDescriptions::eInteger);    arg_desc->AddOptionalKey("id", "SeqEntryID",                             "Seq-id of the Seq-Entry to fetch",                             CArgDescriptions::eString);    arg_desc->AddOptionalKey("asn_id", "SeqEntryID",                             "ASN.1 of Seq-id of the Seq-Entry to fetch",                             CArgDescriptions::eString);    arg_desc->AddOptionalKey("file", "SeqEntryFile",                             "file with Seq-Entry to load (text ASN.1)",                             CArgDescriptions::eInputFile);    arg_desc->AddOptionalKey("bfile", "SeqEntryFile",                             "file with Seq-Entry to load (binary ASN.1)",                             CArgDescriptions::eInputFile);    arg_desc->AddDefaultKey("count", "RepeatCount",                            "repeat test work RepeatCount times",                            CArgDescriptions::eInteger, "1");    arg_desc->AddDefaultKey("pause", "Pause",                            "pause between tests in seconds",                            CArgDescriptions::eInteger, "0");    arg_desc->AddDefaultKey("resolve", "ResolveMethod",                            "Method of segments resolution",                            CArgDescriptions::eString, "tse");    arg_desc->SetConstraint("resolve",                            &(*new CArgAllow_Strings,                              "none", "tse", "all"));    arg_desc->AddDefaultKey("loader", "Loader",                            "Use specified loaders",                            CArgDescriptions::eString, "");    arg_desc->AddFlag("seq_map", "scan SeqMap on full depth");    arg_desc->AddFlag("print_tse", "print TSE with sequence");    arg_desc->AddFlag("print_descr", "print all found descriptors");    arg_desc->AddFlag("print_features", "print all found features");    arg_desc->AddFlag("only_features", "do only one scan of features");    arg_desc->AddFlag("get_mapped_location", "get mapped location");    arg_desc->AddFlag("get_original_feature", "get original location");    arg_desc->AddFlag("get_mapped_feature", "get mapped feature");    arg_desc->AddFlag("skip_alignments", "do not search for alignments");    arg_desc->AddFlag("print_alignments", "print all found Seq-aligns");    arg_desc->AddFlag("get_mapped_alignments", "get mapped alignments");    arg_desc->AddFlag("reverse", "reverse order of features");    arg_desc->AddFlag("no_sort", "do not sort features");    arg_desc->AddDefaultKey("max_feat", "MaxFeat",                            "Max number of features to iterate",                            CArgDescriptions::eInteger, "0");    arg_desc->AddDefaultKey("depth", "depth",                            "Max depth of segments to iterate",                            CArgDescriptions::eInteger, "100");    arg_desc->AddFlag("adaptive", "Use adaptive depth of segments");    arg_desc->AddFlag("unnamed",                      "include features from unnamed Seq-annots");    arg_desc->AddOptionalKey("named", "NamedAnnots",                             "include features from named Seq-annots "                             "(comma separated list)",                             CArgDescriptions::eString);    arg_desc->AddFlag("allnamed",                      "include features from all named Seq-annots");    arg_desc->AddFlag("nosnp",                      "exclude snp features - only unnamed Seq-annots");    arg_desc->AddOptionalKey("exclude_named", "ExcludeNamedAnnots",                             "exclude features from named Seq-annots"                             "(comma separated list)",                             CArgDescriptions::eString);    arg_desc->AddDefaultKey("feat_type", "FeatType",                            "Type of features to select",                            CArgDescriptions::eInteger, "-1");    arg_desc->AddDefaultKey("feat_subtype", "FeatSubType",                            "Subtype of features to select",                            CArgDescriptions::eInteger, "-1");    arg_desc->AddFlag("cache",                      "use BDB cache");/*	    arg_desc->AddDefaultKey("cache_mode", "CacheMode",                            "Cache classes to use",                            CArgDescriptions::eString, "new");    arg_desc->SetConstraint("cache_mode",                            &(*new CArgAllow_Strings,                              "old", "newid", "new"));*/	    arg_desc->AddDefaultKey("id_cache_days", "id_cache_days",                            "number of days to keep gi->sat/satkey cache",                            CArgDescriptions::eInteger, "1");    // Program description    string prog_description = "Example of the C++ object manager usage\n";    arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),                              prog_description, false);    // Pass argument descriptions to the application    //    SetupArgDescriptions(arg_desc.release());}extern CAtomicCounter newCObjects;int CDemoApp::Run(void){    // Process command line args: get GI to load    const CArgs& args = GetArgs();    // Create seq-id, set it to GI specified on the command line    CRef<CSeq_id> id;    if ( args["gi"] ) {        int gi = args["gi"].AsInteger();        id.Reset(new CSeq_id);        id->SetGi(gi);    }    else if ( args["id"] ) {        id.Reset(new CSeq_id(args["id"].AsString()));    }    else if ( args["asn_id"] ) {        id.Reset(new CSeq_id);        string text = args["asn_id"].AsString();        if ( text.find("::=") == NPOS ) {            text = "Seq-id ::= " + text;        }        CNcbiIstrstream ss(text.c_str());        ss >> MSerial_AsnText >> *id;    }    else {        ERR_POST(Fatal << "One of -gi, -id or -asn_id arguments is required");    }    SAnnotSelector::EResolveMethod resolve = SAnnotSelector::eResolve_TSE;    if ( args["resolve"].AsString() == "all" )        resolve = SAnnotSelector::eResolve_All;    if ( args["resolve"].AsString() == "none" )        resolve = SAnnotSelector::eResolve_None;    if ( args["resolve"].AsString() == "tse" )        resolve = SAnnotSelector::eResolve_TSE;    if ( !args["loader"].AsString().empty() ) {        string env = "GENBANK_LOADER_METHOD="+args["loader"].AsString();        ::putenv(::strdup(env.c_str()));    }    int repeat_count = args["count"].AsInteger();    int pause = args["pause"].AsInteger();    bool only_features = args["only_features"];    bool print_tse = args["print_tse"];    bool print_descr = args["print_descr"];    bool print_features = args["print_features"];    bool get_mapped_location = args["get_mapped_location"];    bool get_original_feature = args["get_original_feature"];    bool get_mapped_feature = args["get_mapped_feature"];    bool print_alignments = args["print_alignments"];    bool skip_alignments = args["skip_alignments"];    bool get_mapped_alignments = args["get_mapped_alignments"];    SAnnotSelector::ESortOrder order =        args["reverse"] ?        SAnnotSelector::eSortOrder_Reverse : SAnnotSelector::eSortOrder_Normal;    if ( args["no_sort"] )        order = SAnnotSelector::eSortOrder_None;    int max_feat = args["max_feat"].AsInteger();    int depth = args["depth"].AsInteger();    bool adaptive = args["adaptive"];    int feat_type = args["feat_type"].AsInteger();    int feat_subtype = args["feat_subtype"].AsInteger();    bool nosnp = args["nosnp"];    bool include_unnamed = args["unnamed"];    bool include_allnamed = args["allnamed"];    set<string> include_named;    if ( args["named"] ) {        string names = args["named"].AsString();        size_t comma_pos;        while ( (comma_pos = names.find(',')) != NPOS ) {            include_named.insert(names.substr(0, comma_pos));            names.erase(0, comma_pos+1);        }        include_named.insert(names);    }    set<string> exclude_named;    if ( args["exclude_named"] ) {        string names = args["exclude_named"].AsString();        size_t comma_pos;        while ( (comma_pos = names.find(',')) != NPOS ) {            exclude_named.insert(names.substr(0, comma_pos));            names.erase(0, comma_pos+1);        }        exclude_named.insert(names);    }    bool scan_seq_map = args["seq_map"];    // Create object manager. Use CRef<> to delete the OM on exit.    CRef<CObjectManager> pOm(new CObjectManager);    if ( args["cache"] ) {        // caching options        CNcbiRegistry& reg = GetConfig();        string cache_path = ".genbank_cache";        //CSystemPath::ResolvePath("<home>", "cache");        cache_path    = reg.GetString("LOCAL_CACHE", "Path", cache_path,                                      CNcbiRegistry::eErrPost);        int cache_age = reg.GetInt("LOCAL_CACHE", "Age", 5,                                   CNcbiRegistry::eErrPost);        if (cache_age == 0) {            cache_age = 5;   // keep objects for 5 days (default)        }        auto_ptr<CCachedId1Reader> id1_reader;        if (!cache_path.empty()) {            try {                {{                    // make sure our cache directory exists first                    CDir dir(cache_path);                    if ( !dir.Exists() ) {                        dir.Create();                    }                }}                // setup blob cache                CCachedId1Reader* rdr;//                string cache_mode = args["cache_mode"].AsString();				// unconditionally force "new" cache mode (TODO: clean up)				string cache_mode = "new";  				                if ( cache_mode == "new" ) {                    blob_cache.reset(new CBDB_Cache());                    ICache::TTimeStampFlags flags =                        ICache::fTimeStampOnRead |                        ICache::fExpireLeastFrequentlyUsed |                        ICache::fPurgeOnStartup;                    blob_cache->SetTimeStampPolicy(flags, cache_age*24*60*60);                    blob_cache->Open(cache_path.c_str(), "blobs");                    rdr = new CCachedId1Reader(5, blob_cache.get());                }                else {					_ASSERT(0);/*					                    bdb_cache.reset(new CBDB_BLOB_Cache());

⌨️ 快捷键说明

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