flat_text_formatter.cpp

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

CPP
489
字号
/* * =========================================================================== * PRODUCTION $Log: flat_text_formatter.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 19:43:34  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * PRODUCTION * =========================================================================== *//*  $Id: flat_text_formatter.cpp,v 1000.1 2004/06/01 19:43:34 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, NCBI** File Description:*   new (early 2003) flat-file generator -- base class for traditional*   line-oriented formats (GenBank, EMBL, DDBJ but not GBSeq)** ===========================================================================*/#include <ncbi_pch.hpp>#include <objtools/flat/flat_ddbj_formatter.hpp>#include <objtools/flat/flat_embl_formatter.hpp>#include <objtools/flat/flat_ncbi_formatter.hpp>#include <objtools/flat/flat_items.hpp>#include <objects/seq/Seq_ext.hpp>#include <objects/seq/Seq_hist.hpp>#include <objects/seqloc/Textseq_id.hpp>#include <objmgr/seq_vector.hpp>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)// Some of the code here may need to be split out to account for// GenBank/DDBJ differences.CFlatTextOStream::CFlatTextOStream(CNcbiOstream& stream, bool trace_topics)    : m_Stream(stream){    if (trace_topics) {        m_TraceStream.reset(CObjectOStream::Open(eSerial_AsnText, stream));    }}void CFlatTextOStream::AddParagraph(const list<string>&  lines,                                    const IFlatItem*     item,                                    const CSerialObject* topic){    if (topic  &&  m_TraceStream.get()) {        m_TraceStream->Write(topic, topic->GetThisTypeInfo());        m_TraceStream->FlushBuffer();    }    ITERATE (list<string>, it, lines) {        m_Stream << *it << '\n';    }    m_Stream << flush;}CFlatTextFormatter* CFlatTextFormatter::New(IFlatTextOStream& stream,                                            CScope& scope,                                            IFlatFormatter::EMode mode,                                            IFlatFormatter::EDatabase db,                                            IFlatFormatter::EStyle style,                                            IFlatFormatter::TFlags flags){    switch (db) {    case eDB_DDBJ:        return new CFlatDDBJFormatter(stream, scope, mode, style, flags);    case eDB_EMBL:        return new CFlatEMBLFormatter(stream, scope, mode, style, flags);    case eDB_NCBI:        return new CFlatNCBIFormatter(stream, scope, mode, style, flags);    default:        return 0; // shouldn't happen    }}void CFlatTextFormatter::BeginSequence(CFlatContext& context){    IFlatFormatter::BeginSequence(context);    m_Stream->NewSequence();}void CFlatTextFormatter::FormatHead(const CFlatHead& head){    list<string> l;    {{        CNcbiOstrstream locus_line;        string tmp;        locus_line << Pad(head.GetLocus(), tmp, 16) << ' ' << setw(11)                   << m_Context->GetLength() << ' ' << m_Context->GetUnits();        if (m_Context->IsProt()) {            locus_line << string(12, ' ');        } else {            locus_line << ' ';            switch (head.GetStrandedness()) {            case CSeq_inst::eStrand_ss:    locus_line << "ss-"; break;            case CSeq_inst::eStrand_ds:    locus_line << "ds-"; break;            case CSeq_inst::eStrand_mixed: locus_line << "ms-"; break;            default:                       locus_line << "   "; break;            }            locus_line << Pad(head.GetMolString(), tmp, 6) << "  ";        }        locus_line << (head.GetTopology() == CSeq_inst::eTopology_circular                       ? "circular " : "linear   ")                   << Upcase(head.GetDivision()) << ' ';        tmp.erase();        FormatDate(head.GetUpdateDate(), tmp);        locus_line << tmp;        Wrap(l, "LOCUS", CNcbiOstrstreamToString(locus_line));        m_Stream->AddParagraph(l, &head);        l.clear();    }}    // XXX - quote HTML if needed    Wrap(l, "DEFINITION", head.GetDefinition());    // hunt down appropriate descriptor, if any?    m_Stream->AddParagraph(l, &head);    l.clear();    {{        string acc = m_Context->GetPrimaryID().GetSeqIdString(false);        ITERATE (list<string>, it, head.GetSecondaryIDs()) {            acc += ' ' + *it;        }        Wrap(l, "ACCESSION", acc);        Wrap(l, "VERSION",             m_Context->GetAccession()             + "  GI:" + NStr::IntToString(m_Context->GetGI()));        m_Stream->AddParagraph(l, &head, &m_Context->GetPrimaryID());    }}    if ( !head.GetDBSource().empty() ) {        l.clear();        string tag = "DBSOURCE";        ITERATE (list<string>, it, head.GetDBSource()) {            Wrap(l, tag, *it);            tag.erase();        }        if ( !l.empty() ) {            m_Stream->AddParagraph(l, &head, head.GetProteinBlock());        }    }}void CFlatTextFormatter::FormatKeywords(const CFlatKeywords& keys){    list<string> l, kw;    ITERATE (list<string>, it, keys.GetKeywords()) {        kw.push_back(*it + (&*it == &keys.GetKeywords().back() ? '.' : ';'));    }    if (kw.empty()) {        kw.push_back(".");    }    string tag;    NStr::WrapList(kw, m_Stream->GetWidth(), " ", l, 0, m_Indent,                   Pad("KEYWORDS", tag, ePara));    m_Stream->AddParagraph(l, &keys);}void CFlatTextFormatter::FormatSegment(const CFlatSegment& seg){    list<string> l;    Wrap(l, "SEGMENT",         NStr::IntToString(seg.GetNum()) + " of "         + NStr::IntToString(seg.GetCount()));    m_Stream->AddParagraph(l, &seg);}void CFlatTextFormatter::FormatSource(const CFlatSource& source){    list<string> l;    {{        string name = source.GetFormalName();        if ( !source.GetCommonName().empty() ) {            name += " (" + source.GetCommonName() + ')';        }        Wrap(l, "SOURCE", name);    }}    if (DoHTML()  &&  source.GetTaxID()) {        Wrap(l, "ORGANISM",             "<a href=\"" + source.GetTaxonomyURL() + "\">"             + source.GetFormalName() + "</a>",             eSubp);    } else {        Wrap(l, "ORGANISM", source.GetFormalName(), eSubp);    }    Wrap(l, kEmptyStr, source.GetLineage() + '.');    m_Stream->AddParagraph(l, &source, &source.GetDescriptor());}void CFlatTextFormatter::FormatReference(const CFlatReference& ref){    list<string> l;    Wrap(l, "REFERENCE",         NStr::IntToString(ref.GetSerial()) + ref.GetRange(*m_Context));        {{        string authors;        ITERATE (list<string>, it, ref.GetAuthors()) {            if (it != ref.GetAuthors().begin()) {                authors += (&*it == &ref.GetAuthors().back()) ? " and " : ", ";            }            authors += *it;        }        Wrap(l, "AUTHORS", authors, eSubp);    }}    Wrap(l, "CONSRTM", ref.GetConsortium(), eSubp);    {{        string title, journal;

⌨️ 快捷键说明

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