comment_item.cpp

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

CPP
893
字号
/* * =========================================================================== * PRODUCTION $Log: comment_item.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 19:43:50  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8 * PRODUCTION * =========================================================================== *//*  $Id: comment_item.cpp,v 1000.2 2004/06/01 19:43:50 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:  Mati Shomrat, NCBI** File Description:*   flat-file generator -- comment item implementation**/#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <objects/seqfeat/Seq_feat.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seq/Seq_inst.hpp>#include <objects/seq/Seq_ext.hpp>#include <objects/seq/Delta_ext.hpp>#include <objects/seq/Delta_seq.hpp>#include <objects/seq/Seq_literal.hpp>#include <objects/seq/Seq_hist.hpp>#include <objects/seq/Seq_hist_rec.hpp>#include <objects/seq/Seqdesc.hpp>#include <objects/seq/MolInfo.hpp>#include <objects/seqfeat/BioSource.hpp>#include <objects/seqfeat/Org_ref.hpp>#include <objects/general/User_object.hpp>#include <objects/general/User_field.hpp>#include <objects/general/Object_id.hpp>#include <objects/general/Date.hpp>#include <objects/general/Dbtag.hpp>#include <objmgr/seqdesc_ci.hpp>#include <objtools/format/formatter.hpp>#include <objtools/format/text_ostream.hpp>#include <objtools/format/items/comment_item.hpp>#include <objtools/format/context.hpp>#include "utils.hpp"BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)// static variables initializationbool CCommentItem::sm_FirstComment = true;const string CCommentItem::kNsAreGaps = "The strings of n's in this record " \"represent gaps between contigs, and the length of each string corresponds " \"to the length of the gap.";/////////////////////////////////////////////////////////////////////////////////  CCommentItemCCommentItem::CCommentItem(CBioseqContext& ctx) :    CFlatItem(&ctx), m_First(false){    swap(m_First, sm_FirstComment);}CCommentItem::CCommentItem(const string& comment, CBioseqContext& ctx, const CSerialObject* obj) :    CFlatItem(&ctx), m_Comment(comment){    swap(m_First, sm_FirstComment);    if ( obj != 0 ) {        x_SetObject(*obj);    }}    CCommentItem::CCommentItem(const CSeqdesc&  desc, CBioseqContext& ctx) :    CFlatItem(&ctx){    swap(m_First, sm_FirstComment);    x_SetObject(desc);    x_GatherInfo(ctx);    if ( m_Comment.empty() ) {        x_SetSkip();    }}void CCommentItem::Format(IFormatter& formatter, IFlatTextOStream& text_os) const{    formatter.FormatComment(*this, text_os);}string CCommentItem::GetStringForTPA(const CUser_object& uo, CBioseqContext& ctx){    static const string tpa_string =         "THIRD PARTY ANNOTATION DATABASE: This TPA record uses data from DDBJ/EMBL/GenBank ";    if ( !ctx.IsTPA()  ||  ctx.IsRefSeq() ) {        return kEmptyStr;    }    if ( !uo.CanGetType()  ||  !uo.GetType().IsStr()  ||           uo.GetType().GetStr() != "TpaAssembly" ) {        return kEmptyStr;    }    const CSeq_inst& inst = ctx.GetHandle().GetInst();    if ( inst.CanGetHist()  &&  inst.GetHist().CanGetAssembly() ) {        return kEmptyStr;    }    string id;    vector<string> accessions;    ITERATE (CUser_object::TData, curr, uo.GetData()) {        const CUser_field& uf = **curr;        if ( !uf.CanGetData()  ||  !uf.GetData().IsFields() ) {            continue;        }        ITERATE (CUser_field::C_Data::TFields, ufi, uf.GetData().GetFields()) {            if( !(*ufi)->CanGetData()  ||  !(*ufi)->GetData().IsStr()  ||                !(*ufi)->CanGetLabel() ) {                continue;            }            const CObject_id& oid = (*ufi)->GetLabel();            if ( oid.IsStr()  &&                   (NStr::CompareNocase(oid.GetStr(), "accession") == 0) ) {                string acc = (*ufi)->GetData().GetStr();                if ( !acc.empty() ) {                    accessions.push_back(NStr::ToUpper(acc));                }            }        }    }    if ( accessions.empty() ) {        return kEmptyStr;    }    CNcbiOstrstream text;    text << tpa_string << ((accessions.size() > 1) ? "entries " : "entry ");    size_t size = accessions.size();    size_t last = size - 1;    for ( size_t i = 0; i < size; ) {        text << accessions[i];        ++i;        if ( i < size ) {            text << ((i == last) ? " and " : ", ");        }    }    return CNcbiOstrstreamToString(text);}string CCommentItem::GetStringForBankIt(const CUser_object& uo){    if ( !uo.CanGetType()  ||  !uo.GetType().IsStr()  ||         uo.GetType().GetStr() != "Submission" ) {        return kEmptyStr;    }    const string* uvc = 0, *bic = 0;    if ( uo.HasField("UniVecComment") ) {        const CUser_field& uf = uo.GetField("UniVecComment");        if ( uf.CanGetData()  &&  uf.GetData().IsStr() ) {            uvc = &(uf.GetData().GetStr());        }     }    if ( uo.HasField("AdditionalComment") ) {        const CUser_field& uf = uo.GetField("AdditionalComment");        if ( uf.CanGetData()  &&  uf.GetData().IsStr() ) {            bic = &(uf.GetData().GetStr());        }     }    CNcbiOstrstream text;    if ( uvc != 0  &&  bic != 0 ) {        text << "Vector Explanation: " << *uvc << "~Bankit Comment: " << *bic;    } else if ( uvc != 0 ) {        text << "Vector Explanation: " << *uvc;    } else if ( bic != 0 ) {         text << "Bankit Comment: " << *bic;    }    return CNcbiOstrstreamToString(text);}CCommentItem::TRefTrackStatus CCommentItem::GetRefTrackStatus(const CUser_object& uo, string* st){    TRefTrackStatus retval = eRefTrackStatus_Unknown;    if ( st != 0 ) {        st->erase();    }    if ( !uo.HasField("Status") ) {        return retval;    }    const CUser_field& field = uo.GetField("Status");    if ( field.GetData().IsStr() ) {        string status = field.GetData().GetStr();        if ( status == "Inferred" ) {             retval = eRefTrackStatus_Inferred;        } else if ( status == "Provisional" ) {            retval = eRefTrackStatus_Provisional;        } else if ( status == "Predicted" ) {            retval = eRefTrackStatus_Predicted;        } else if ( status == "Validated" ) {            retval = eRefTrackStatus_Validated;        } else if ( status == "Reviewed" ) {            retval = eRefTrackStatus_Reviewd;        } else if ( status == "Model" ) {            retval = eRefTrackStatus_Model;        } else if ( status == "WGS" ) {            retval = eRefTrackStatus_WGS;        }        if ( st != 0  &&  retval != eRefTrackStatus_Unknown ) {            *st = NStr::ToUpper(status);        }    }    return retval;}string CCommentItem::GetStringForRefTrack(const CUser_object& uo){    if ( !uo.CanGetType()  ||  !uo.GetType().IsStr()  ||         uo.GetType().GetStr() != "RefGeneTracking" ) {        return kEmptyStr;    }    string status_str;    TRefTrackStatus status = GetRefTrackStatus(uo, &status_str);    if ( status == eRefTrackStatus_Unknown ) {        return kEmptyStr;    }    string collaborator;    if ( uo.HasField("Collaborator") ) {        const CUser_field& colab_field = uo.GetField("Collaborator");        if ( colab_field.GetData().IsStr() ) {            collaborator = colab_field.GetData().GetStr();        }    }    string source;    if ( uo.HasField("GenomicSource") ) {        const CUser_field& source_field = uo.GetField("GenomicSource");        if ( source_field.GetData().IsStr() ) {            source = source_field.GetData().GetStr();        }    }    CNcbiOstrstream oss;    oss << status_str << " REFSEQ: ";    switch ( status ) {    case eRefTrackStatus_Inferred:        oss << "This record is predicted by genome sequence analysis and is "            << "not yet supported by experimental evidence.";        break;    case eRefTrackStatus_Provisional:        oss << "This record has not yet been subject to final NCBI review.";        break;    case eRefTrackStatus_Predicted:        oss << "The mRNA record is supported by experimental evidence;"            << "however, the coding sequence is predicted.";        break;    case eRefTrackStatus_Validated:        oss << "This record has undergone preliminary review of the sequence,"            << "but has not yet been subject to final review.";        break;    case eRefTrackStatus_Reviewd:        oss << "This record has been curated by "             << (collaborator.empty() ? "NCBI staff" : collaborator) << '.';        break;    case eRefTrackStatus_Model:        oss << "This record is predicted by automated computational analysis.";        break;    case eRefTrackStatus_WGS:        oss << "This record is provided to represent a collection of "            << "whole genome shotgun sequences.";        break;    default:        break;    }    if ( status != eRefTrackStatus_Reviewd  &&  !collaborator.empty() ) {        oss << "This record has been curated by " << collaborator << '.';    }    if ( !source.empty() ) {        oss << "This record is derived from an annotated genomic sequence ("            << source << ").";    }    vector < pair<const string*, bool> > assembly;    if ( uo.HasField("Assembly") ) {        const CUser_field& field = uo.GetField("Assembly");        if ( field.GetData().IsFields() ) {            ITERATE (CUser_field::C_Data::TFields, fit, field.GetData().GetFields()) {                if ( !(*fit)->GetData().IsFields() ) {                    continue;                }                ITERATE (CUser_field::C_Data::TFields, it, (*fit)->GetData().GetFields()) {                    const CUser_field& uf = **it;                    if ( !uf.CanGetLabel()  ||  !uf.GetLabel().IsStr() ) {                        continue;                    }                    const string& label = uf.GetLabel().GetStr();                    if ( label == "accession"  ||  label == "name" ) {                        bool is_accn = (label == "accession");                        if ( uf.GetData().IsStr()  &&  !uf.GetData().GetStr().empty() ) {                            assembly.push_back(make_pair(&uf.GetData().GetStr(), is_accn));                        }                    }                }            }        }    }    if ( assembly.size() > 0 ) {        oss << " The reference sequence was derived from ";        size_t assembly_size = assembly.size();        for ( size_t i = 0; i < assembly_size; ++i ) {            if ( i > 0  ) {                oss << ((i < assembly_size - 1) ? ", " : " and ");            }            oss << *(assembly[i].first);        }        oss << '.';    }    return CNcbiOstrstreamToString(oss);}bool CCommentItem::NsAreGaps(const CBioseq_Handle& seq, CBioseqContext& ctx){    if ( !seq.IsSetInst()  ||  !seq.IsSetInst_Ext() ) {        return false;    }    if ( ctx.GetRepr() == CSeq_inst::eRepr_delta  &&  ctx.IsWGS()  &&         seq.GetInst_Ext().IsDelta() ) {        ITERATE (CDelta_ext::Tdata, iter, seq.GetInst_Ext().GetDelta().Get()) {            const CDelta_seq& dseg = **iter;            if ( dseg.IsLiteral() ) {                const CSeq_literal& lit = dseg.GetLiteral();                if ( !lit.CanGetSeq_data()  &&  lit.CanGetLength()  &&                      lit.GetLength() > 0 ) {                    return true;                }            }        }    }    return false;}string CCommentItem::GetStringForWGS(CBioseqContext& ctx){    static const string default_str = "?";    if ( !ctx.IsWGSMaster()  ||  ctx.GetWGSMasterAccn().empty() ) {        return kEmptyStr;    }    const string& wgsaccn = ctx.GetWGSMasterAccn();    const string* taxname = 0;    for (CSeqdesc_CI it(ctx.GetHandle(), CSeqdesc::e_Source); it; ++it) {        const CBioSource& src = it->GetSource();        if ( src.CanGetOrg()  &&  src.GetOrg().CanGetTaxname() ) {            taxname = &(src.GetOrg().GetTaxname());        }    }    const string* first = 0, *last = 0;    for (CSeqdesc_CI it(ctx.GetHandle(), CSeqdesc::e_User); it; ++it) {        const CUser_object& uo = it->GetUser();        if ( uo.CanGetType()  &&  uo.GetType().IsStr()  &&             NStr::CompareNocase(uo.GetType().GetStr(), "WGSProjects") == 0 ) {            if ( uo.HasField("WGS_accession_first") ) {                const CUser_field& uf = uo.GetField("WGS_accession_first");                if ( uf.CanGetData()  &&  uf.GetData().IsStr() ) {                    first = &(uf.GetData().GetStr());                }            }            if ( uo.HasField("WGS_accession_last") ) {                const CUser_field& uf = uo.GetField("WGS_accession_last");                if ( uf.CanGetData()  &&  uf.GetData().IsStr() ) {                    last = &(uf.GetData().GetStr());                }            }        }    }    if ( taxname == 0  ||  taxname->empty() ) {        taxname = &default_str;    }    if ( first == 0  ||  first->empty() ) {        first = &default_str;    }    if ( last == 0  ||  last->empty() ) {        last = &default_str;    }    string version = (wgsaccn.length() == 15) ? wgsaccn.substr(4) :

⌨️ 快捷键说明

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