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

📄 asn2flat.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * =========================================================================== * PRODUCTION $Log: asn2flat.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 18:27:20  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * PRODUCTION * =========================================================================== *//*  $Id: asn2flat.cpp,v 1000.1 2004/06/01 18:27:20 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:  Aaron Ucko, Mati Shomrat, NCBI** File Description:*   flat-file generator application** ===========================================================================*/#include <ncbi_pch.hpp>#include <corelib/ncbiapp.hpp>#include <serial/objistr.hpp>#include <serial/serial.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqloc/Seq_interval.hpp>#include <objmgr/object_manager.hpp>#include <objmgr/scope.hpp>#include <objmgr/seq_entry_ci.hpp>#include <objtools/data_loaders/genbank/gbloader.hpp>#include <objtools/format/flat_file_config.hpp>#include <objtools/format/flat_file_generator.hpp>#include <objtools/format/flat_expt.hpp>#include <objects/seqset/gb_release_file.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);class CAsn2FlatApp : public CNcbiApplication, public CGBReleaseFile::ISeqEntryHandler{public:    void Init(void);    int  Run (void);    bool HandleSeqEntry(CRef<CSeq_entry>& se);private:    // types    typedef CFlatFileConfig::TFormat    TFormat;    typedef CFlatFileConfig::TMode      TMode;    typedef CFlatFileConfig::TStyle     TStyle;    typedef CFlatFileConfig::TFlags     TFlags;    typedef CFlatFileConfig::TView      TView;    CObjectIStream* x_OpenIStream(const CArgs& args);    CFlatFileGenerator* x_CreateFlatFileGenerator(const CArgs& args);    TFormat         x_GetFormat(const CArgs& args);    TMode           x_GetMode(const CArgs& args);    TStyle          x_GetStyle(const CArgs& args);    TFlags          x_GetFlags(const CArgs& args);    TView           x_GetView(const CArgs& args);    TSeqPos x_GetFrom(const CArgs& args);    TSeqPos x_GetTo  (const CArgs& args);    void x_GetLocation(const CSeq_entry_Handle& entry,        const CArgs& args, CSeq_loc& loc);    CBioseq_Handle x_DeduceTarget(const CSeq_entry_Handle& entry);    // data    CRef<CObjectManager>        m_Objmgr;       // Object Manager    CNcbiOstream*               m_Os;           // Output stream    CRef<CFlatFileGenerator>    m_FFGenerator;  // Flat-file generator};void CAsn2FlatApp::Init(void){    auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);    arg_desc->SetUsageContext(        GetArguments().GetProgramBasename(),        "Convert an ASN.1 Seq-entry into a flat report",        false);        // input    {{        // name        arg_desc->AddOptionalKey("i", "InputFile",             "Input file name", CArgDescriptions::eInputFile);                // input file serial format (AsnText\AsnBinary\XML, default: AsnText)        arg_desc->AddDefaultKey("serial", "SerialFormat", "Input file format",            CArgDescriptions::eString, "text");        arg_desc->SetConstraint("serial", &(*new CArgAllow_Strings,            "text", "binary", "XML"));    }}    // batch processing    {{        arg_desc->AddOptionalKey("batch", "BatchMode",            "Process NCBI release file", CArgDescriptions::eString);        // compression        arg_desc->AddFlag("c", "Compressed file");        // propogate top descriptors        arg_desc->AddFlag("p", "Propogate top descriptors");    }}        // output    {{         // name        arg_desc->AddOptionalKey("o", "OutputFile",             "Output file name", CArgDescriptions::eOutputFile);    }}        // loaders    {{        arg_desc->AddOptionalKey("load", "Loader", "Add data loader",            CArgDescriptions::eString);        // currently we support only the Genbank loader.        arg_desc->SetConstraint("load", &(*new CArgAllow_Strings, "gb"));    }}    // report    {{        // format (default: genbank)        arg_desc->AddDefaultKey("format", "Format", "Output format",            CArgDescriptions::eString, "genbank");        arg_desc->SetConstraint("format", &(*new CArgAllow_Strings,            "genbank", "embl", "ddbj", "gbseq", "ftable", "gff"));        // mode (default: dump)        arg_desc->AddDefaultKey("mode", "Mode", "Restriction level",            CArgDescriptions::eString, "gbench");        arg_desc->SetConstraint("mode",             &(*new CArgAllow_Strings, "release", "entrez", "gbench", "dump"));        // style (default: normal)        arg_desc->AddDefaultKey("style", "Style", "Formatting style",            CArgDescriptions::eString, "normal");        arg_desc->SetConstraint("style",             &(*new CArgAllow_Strings, "normal", "segment", "master", "contig"));        // flags (default: 0)        arg_desc->AddDefaultKey("flags", "Flags", "Custom flags",            CArgDescriptions::eInteger, "0");        // view (default: nucleotide)        arg_desc->AddDefaultKey("view", "View", "View",            CArgDescriptions::eString, "nuc");        arg_desc->SetConstraint("view",             &(*new CArgAllow_Strings, "all", "prot", "nuc"));                // id        arg_desc->AddOptionalKey("id", "ID",             "Specific ID to display", CArgDescriptions::eString);        // from        arg_desc->AddOptionalKey("from", "From",            "Begining of shown range", CArgDescriptions::eInteger);                // to        arg_desc->AddOptionalKey("to", "To",            "End of shown range", CArgDescriptions::eInteger);                // strand                // accession to extract    }}        SetupArgDescriptions(arg_desc.release());}int CAsn2FlatApp::Run(void){    const CArgs&   args = GetArgs();    // create object manager    m_Objmgr.Reset(new CObjectManager);    if ( !m_Objmgr ) {        NCBI_THROW(CFlatException, eInternal, "Could not create object manager");    }    if ( args["load"]  &&  args["load"].AsString() == "gb" ) {        m_Objmgr->RegisterDataLoader(*new CGBDataLoader("ID"),                                 CObjectManager::eDefault);    }    // open the output stream    m_Os = args["o"] ? &(args["o"].AsOutputFile()) : &cout;    if ( m_Os == 0 ) {        NCBI_THROW(CFlatException, eInternal, "Could not open output stream");    }    // create the flat-file generator    m_FFGenerator.Reset(x_CreateFlatFileGenerator(args));    if ( args["batch"] ) {        CGBReleaseFile in(args["i"].AsString());        in.RegisterHandler(this);        in.Read();  // HandleSeqEntry will be called from this function    } else {        // open the input file (default: stdin)        auto_ptr<CObjectIStream> in(x_OpenIStream(args));        // read in the seq-entry        CRef<CSeq_entry> se(new CSeq_entry);        if ( !se ) {            NCBI_THROW(CFlatException, eInternal,                 "Could not allocate Seq-entry object");        }        in->Read(ObjectInfo(*se));        if ( se->Which() == CSeq_entry::e_not_set ) {            NCBI_THROW(CFlatException, eInternal, "Invalid Seq-entry");        }        HandleSeqEntry(se);    }    m_Os->flush();    return 0;}bool CAsn2FlatApp::HandleSeqEntry(CRef<CSeq_entry>& se){    const CArgs&   args = GetArgs();    // create new scope    CRef<CScope> scope(new CScope(*m_Objmgr));    if ( !scope ) {        NCBI_THROW(CFlatException, eInternal, "Could not create scope");    }    scope->AddDefaults();    // add entry to scope        CSeq_entry_Handle entry = scope->AddTopLevelSeqEntry(*se);    if ( !entry ) {        NCBI_THROW(CFlatException, eInternal, "Failed to insert entry to scope.");    }    // generate flat file    if ( args["from"]  ||  args["to"] ) {        CSeq_loc loc;        x_GetLocation(entry, args, loc);        m_FFGenerator->Generate(loc, *scope, *m_Os);    } else {        m_FFGenerator->Generate(entry, *m_Os);

⌨️ 快捷键说明

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