qualifiers.cpp

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

CPP
730
字号
/* * =========================================================================== * PRODUCTION $Log: qualifiers.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 19:45:20  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.15 * PRODUCTION * =========================================================================== *//*  $Id: qualifiers.cpp,v 1000.1 2004/06/01 19:45: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, NCBI** File Description:*   new (early 2003) flat-file generator -- qualifier types*   (mainly of interest to implementors)** ===========================================================================*/#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <serial/enumvalues.hpp>#include <objects/general/Dbtag.hpp>#include <objects/general/Object_id.hpp>#include <objects/pub/Pub_set.hpp>#include <objects/seqfeat/Seq_feat.hpp>#include <objects/seqfeat/Cdregion.hpp>#include <objects/seqfeat/BioSource.hpp>#include <objects/seqfeat/Code_break.hpp>#include <objects/seqfeat/Genetic_code_table.hpp>#include <objects/seqfeat/Gb_qual.hpp>#include <objects/seqfeat/OrgMod.hpp>#include <objects/seqfeat/SubSource.hpp>#include <objects/seq/Seq_inst.hpp>#include <objects/seq/MolInfo.hpp>#include <objects/seq/seqport_util.hpp>#include <objmgr/seq_vector.hpp>#include <objtools/format/items/qualifiers.hpp>#include <objtools/format/context.hpp>#include "utils.hpp"BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)const string IFlatQVal::kSemicolon = "; ";const string IFlatQVal::kComma     = ", ";const string IFlatQVal::kEOL       = "\n";static bool s_IsNote(IFlatQVal::TFlags flags){    return (flags & IFlatQVal::fIsNote);}static bool s_StringIsJustQuotes(const string& str){    ITERATE(string, it, str) {        if ( (*it != '"')  ||  (*it != '\'') ) {            return false;        }    }    return true;}static string s_GetGOText(const CUser_field& field, bool is_ftable){    string text_string, evidence, go_id;    int pmid = 0;    ITERATE (CUser_field::C_Data::TFields, it, field.GetData().GetFields()) {        if ( !(*it)->CanGetLabel()  ||  !(*it)->GetLabel().IsStr() ) {            continue;        }                const string& label = (*it)->GetLabel().GetStr();        const CUser_field::C_Data& data = (*it)->GetData();                if ( label == "text string"  &&  data.IsStr() ) {            text_string = data.GetStr();        }                if ( label == "go id" ) {            if ( data.IsStr() ) {                go_id = data.GetStr();            } else if ( data.IsInt() ) {                go_id = NStr::IntToString(data.GetInt());            }        }                if ( label == "evidence"  &&  data.IsStr() ) {            evidence = data.GetStr();        }                if ( label == "pubmed id"  &&  data.IsInt() ) {            pmid = data.GetInt();        }    }        CNcbiOstrstream text;        text << text_string;    if ( is_ftable ) {        text << "|" << go_id << "|";        if ( pmid != 0 ) {            text <<  pmid;        }        if ( !evidence.empty() ) {            text << "|" << evidence;        }    } else {         if ( !go_id.empty() ) {            text << " [goid " << go_id << "]";            if ( !evidence.empty() ) {                text << " [evidence " << evidence << "]";            }            if ( pmid != 0 ) {                text << " [pmid " << pmid << "]";            }        }    }    return NStr::TruncateSpaces(CNcbiOstrstreamToString(text));}/////////////////////////////////////////////////////////////////////////////// CFormatQual - low-level formatted qualifierCFormatQual::CFormatQual(const string& name, const string& value,  const string& prefix, const string& suffix, TStyle style) :    m_Name(name), m_Value(value), m_Prefix(prefix), m_Suffix(suffix),    m_Style(style){}CFormatQual::CFormatQual(const string& name, const string& value, TStyle style) :    m_Name(name), m_Value(value), m_Prefix(kEmptyStr), m_Suffix(kEmptyStr),    m_Style(style){}//////////////////////////////////////////////////////////////////////////////// CFlatStringQVal {CFlatStringQVal::CFlatStringQVal(const string& value, TStyle style)    :  IFlatQVal(&kEmptyStr, &kSemicolon),       m_Value(NStr::TruncateSpaces(value)), m_Style(style){}CFlatStringQVal::CFlatStringQVal(const string& value, const string& pfx, const string& sfx, TStyle style)    :   IFlatQVal(&pfx, &sfx),        m_Value(NStr::TruncateSpaces(value)),        m_Style(style){}void CFlatStringQVal::Format(TFlatQuals& q, const string& name,                           CBioseqContext& ctx, IFlatQVal::TFlags flags) const{    x_AddFQ(q, (s_IsNote(flags) ? "note" : name), m_Value, m_Style);}// }//////////////////////////////////////////////////////////////////////////////// CFlatStringListQVal {void CFlatStringListQVal::Format(TFlatQuals& q, const string& name,                           CBioseqContext& ctx, IFlatQVal::TFlags flags) const{    if ( s_IsNote(flags) ) {        m_Suffix = &kSemicolon;    }    x_AddFQ(q,             (s_IsNote(flags) ? "note" : name),            JoinNoRedund(m_Value, "; "),            m_Style);}// }void CFlatCodeBreakQVal::Format(TFlatQuals& q, const string& name,                              CBioseqContext& ctx, IFlatQVal::TFlags) const{    ITERATE (CCdregion::TCode_break, it, m_Value) {        string pos = CFlatSeqLoc((*it)->GetLoc(), ctx).GetString();        string aa  = "OTHER";        switch ((*it)->GetAa().Which()) {        case CCode_break::C_Aa::e_Ncbieaa:            aa = GetAAName((*it)->GetAa().GetNcbieaa(), true);            break;        case CCode_break::C_Aa::e_Ncbi8aa:            aa = GetAAName((*it)->GetAa().GetNcbi8aa(), false);            break;        case CCode_break::C_Aa::e_Ncbistdaa:            aa = GetAAName((*it)->GetAa().GetNcbistdaa(), false);            break;        default:            return;        }        x_AddFQ(q, name, "(pos:" + pos + ",aa:" + aa + ')',             CFormatQual::eUnquoted);    }}CFlatCodonQVal::CFlatCodonQVal(unsigned int codon, unsigned char aa, bool is_ascii)    : m_Codon(CGen_code_table::IndexToCodon(codon)),      m_AA(GetAAName(aa, is_ascii)), m_Checked(true){}void CFlatCodonQVal::Format(TFlatQuals& q, const string& name, CBioseqContext& ctx,                          IFlatQVal::TFlags) const{    if ( !m_Checked ) {        // ...    }    x_AddFQ(q, name, "(seq:\"" + m_Codon + "\",aa:" + m_AA + ')');}void CFlatExpEvQVal::Format(TFlatQuals& q, const string& name,                          CBioseqContext&, IFlatQVal::TFlags) const{    const char* s = 0;    switch (m_Value) {    case CSeq_feat::eExp_ev_experimental:      s = "experimental";      break;    case CSeq_feat::eExp_ev_not_experimental:  s = "not_experimental";  break;    default:                                   break;    }    if (s) {        x_AddFQ(q, name, s, CFormatQual::eUnquoted);    }}void CFlatIllegalQVal::Format(TFlatQuals& q, const string&, CBioseqContext &ctx,                            IFlatQVal::TFlags) const{    // XXX - return if too strict    x_AddFQ(q, m_Value->GetQual(), m_Value->GetVal());}void CFlatMolTypeQVal::Format(TFlatQuals& q, const string& name,                            CBioseqContext& ctx, IFlatQVal::TFlags flags) const{    const char* s = 0;    switch ( m_Biomol ) {    case CMolInfo::eBiomol_unknown:        switch ( m_Mol ) {        case CSeq_inst::eMol_dna:  s = "unassigned DNA"; break;        case CSeq_inst::eMol_rna:  s = "unassigned RNA"; break;        default:                   break;        }        break;    case CMolInfo::eBiomol_genomic:        switch ( m_Mol ) {        case CSeq_inst::eMol_dna:  s = "genomic DNA";  break;        case CSeq_inst::eMol_rna:  s = "genomic RNA";  break;        default:                   break;        }        break;    case CMolInfo::eBiomol_pre_RNA:  s = "pre-mRNA";  break;    case CMolInfo::eBiomol_mRNA:     s = "mRNA";      break;    case CMolInfo::eBiomol_rRNA:     s = "rRNA";      break;    case CMolInfo::eBiomol_tRNA:     s = "tRNA";      break;    case CMolInfo::eBiomol_snRNA:    s = "snRNA";     break;    case CMolInfo::eBiomol_scRNA:    s = "scRNA";     break;    case CMolInfo::eBiomol_other_genetic:    case CMolInfo::eBiomol_other:        switch ( m_Mol ) {        case CSeq_inst::eMol_dna:  s = "other DNA";  break;        case CSeq_inst::eMol_rna:  s = "other RNA";  break;        default:                   break;        }        break;    case CMolInfo::eBiomol_cRNA:    case CMolInfo::eBiomol_transcribed_RNA:  s = "other RNA";  break;    case CMolInfo::eBiomol_snoRNA:           s = "snoRNA";     break;    }    if ( s == 0 ) {        switch ( m_Mol ) {        case CSeq_inst::eMol_rna:            s = "unassigned RNA";            break;        case CSeq_inst::eMol_aa:            s = 0;            break;        case CSeq_inst::eMol_dna:        default:            s = "unassigned DNA";            break;        }    }    if ( s != 0 ) {        x_AddFQ(q, name, s);    }}void CFlatOrgModQVal::Format(TFlatQuals& q, const string& name,                           CBioseqContext& ctx, IFlatQVal::TFlags flags) const{    string subname = m_Value->GetSubname();    if ( s_StringIsJustQuotes(subname) ) {        subname = kEmptyStr;    }    if ( subname.empty() ) {        return;    }

⌨️ 快捷键说明

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