context.cpp

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

CPP
601
字号
/* * =========================================================================== * PRODUCTION $Log: context.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 19:43:52  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.18 * PRODUCTION * =========================================================================== *//*  $Id: context.cpp,v 1000.1 2004/06/01 19:43:52 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*          Mati Shomrat** File Description:*   new (early 2003) flat-file generator -- context needed when (pre)formatting** ===========================================================================*/#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seq/Seq_ext.hpp>#include <objects/seq/Seg_ext.hpp>#include <objects/seq/Delta_ext.hpp>#include <objects/seq/Delta_seq.hpp>#include <objects/seqset/Bioseq_set.hpp>#include <objects/seqloc/Textseq_id.hpp>#include <objects/general/Dbtag.hpp>#include <objmgr/scope.hpp>#include <objmgr/bioseq_handle.hpp>#include <objmgr/seq_entry_handle.hpp>#include <objmgr/seq_entry_ci.hpp>#include <objmgr/seqdesc_ci.hpp>#include <objmgr/util/sequence.hpp>#include <objmgr/seq_loc_mapper.hpp>#include <objtools/format/context.hpp>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)USING_SCOPE(sequence);///////////////////////////////////////////////////////////////////////////////// CBioseqContext// constructorCBioseqContext::CBioseqContext(const CBioseq_Handle& seq, CFlatFileContext& ffctx, CMasterContext* mctx) :    m_Handle(seq),    m_Repr(CSeq_inst::eRepr_not_set),    m_Mol(CSeq_inst::eMol_not_set),    m_HasParts(false),    m_IsPart(false),    m_PartNumber(0),    m_IsDeltaLitOnly(false),    m_IsProt(false),    m_IsInGPS(false),    m_IsInNucProt(false),    m_IsGED(false),    m_IsEMBL(false),    m_IsPDB(false),    m_IsSP(false),    m_IsTPA(false),    m_IsRefSeq(false),    m_RefseqInfo(0),    m_IsGbGenomeProject(false),  // GenBank Genome project data (AE)    m_IsNcbiCONDiv(false),       // NCBI CON division (CH)    m_IsPatent(false),    m_IsGI(false),    m_IsWGS(false),    m_IsWGSMaster(false),    m_IsHup(false),    m_Gi(0),    m_ShowGBBSource(false),    m_FFCtx(ffctx),    m_Master(mctx){    x_Init(seq, m_FFCtx.GetLocation());}// destructorCBioseqContext::~CBioseqContext(void){}const CSeq_id& CBioseqContext::GetPreferredSynonym(const CSeq_id& id) const{    if ( id.IsGi()  &&  id.GetGi() == m_Gi ) {        return *m_PrimaryId;    }    CBioseq_Handle h = m_Handle.GetScope().GetBioseqHandleFromTSE(id, m_Handle);    if ( h ) {        if ( h == m_Handle ) {            return *m_PrimaryId;        } else if ( h.GetSeqId().NotEmpty() ) {            return *FindBestChoice(h.GetBioseqCore()->GetId(), CSeq_id::Score);        }    }    return id;}// initializationvoid CBioseqContext::x_Init(const CBioseq_Handle& seq, const CSeq_loc* user_loc){    _ASSERT(seq);    _ASSERT(seq.IsSetInst());    // NB: order of execution is important    x_SetId();    m_Repr = x_GetRepr();    m_Mol  = seq.GetInst_Mol();    m_Molinfo.Reset(x_GetMolInfo());    if ( IsSegmented() ) {        m_HasParts = x_HasParts();    }    m_IsPart = x_IsPart();    if ( m_IsPart ) {        _ASSERT(m_Master);        m_PartNumber = x_GetPartNumber();    }    if ( IsDelta() ) {        m_IsDeltaLitOnly = x_IsDeltaLitOnly();    }    m_IsProt = CSeq_inst::IsAa(seq.GetInst_Mol());    m_IsInGPS     = x_IsInGPS();    m_IsInNucProt = x_IsInNucProt();    x_SetLocation(user_loc);    }void CBioseqContext::x_SetLocation(const CSeq_loc* user_loc){    _ASSERT(user_loc == 0  ||  user_loc->IsInt()  ||  user_loc->IsWhole());    CRef<CSeq_loc> source;    if ( user_loc != 0 ) {        // map the location to the current bioseq        CSeq_loc_Mapper mapper(m_Handle);        mapper.SetMergeAll();  // just to be safe        source.Reset(mapper.Map(*user_loc));                // no need to map if doing the entire bioseq        if ( source->IsWhole()  ||             source->GetStart(kInvalidSeqPos) == 0  &&             source->GetEnd(kInvalidSeqPos) == m_Handle.GetInst_Length() - 1) {            source.Reset();        }        _ASSERT(!source  ||  source->IsInt());        if ( source ) {            CScope& scope = GetScope();            CSeq_loc target;            target.SetInt().SetFrom(0);            target.SetInt().SetTo(GetLength(*source, &scope) - 1);            target.SetId(*m_PrimaryId);            m_Mapper.Reset(new CSeq_loc_Mapper(*source, target, &scope));            m_Mapper->SetMergeAbutting();            m_Mapper->PreserveDestinationLocs();  // ???            m_Mapper->KeepNonmappingRanges();        }    }    // if no location is specified do the entire sequence    if ( !source ) {        source.Reset(new CSeq_loc);        source->SetWhole(*m_PrimaryId);    }    _ASSERT(source);    m_Location = source;    }void CBioseqContext::x_SetId(void){    m_PrimaryId.Reset(new CSeq_id);    m_PrimaryId->Assign(sequence::GetId(m_Handle, sequence::eGetId_Best));    m_Accession.erase();    m_PrimaryId->GetLabel(&m_Accession, CSeq_id::eContent);    ITERATE (CBioseq::TId, id_iter, m_Handle.GetBioseqCore()->GetId()) {        const CSeq_id& id = **id_iter;        const CTextseq_id* tsip = id.GetTextseq_Id();        const string& acc = (tsip != 0  &&  tsip->CanGetAccession()) ?            tsip->GetAccession() : kEmptyStr;        CSeq_id::EAccessionInfo acc_info = id.IdentifyAccession();        unsigned int acc_type = acc_info & CSeq_id::eAcc_type_mask;        unsigned int acc_div =  acc_info & CSeq_id::eAcc_division_mask;        switch ( id.Which() ) {        // Genbank, Embl or Ddbj        case CSeq_id::e_Embl:            m_IsEMBL = true;            // intentional fall through        case CSeq_id::e_Genbank:        case CSeq_id::e_Ddbj:            m_IsGED = true;            m_IsGbGenomeProject = m_IsGbGenomeProject  ||                ((acc_type & CSeq_id::eAcc_gb_genome) != 0);            m_IsNcbiCONDiv = m_IsNcbiCONDiv  ||                ((acc_type & CSeq_id::eAcc_gb_con) != 0);            break;        // Patent        case CSeq_id::e_Patent:            m_IsPatent = true;            break;        // RefSeq        case CSeq_id::e_Other:            m_IsRefSeq = true;            m_RefseqInfo = acc_info;            break;        // Gi        case CSeq_id::e_Gi:            m_IsGI = true;            m_Gi = id.GetGi();            break;        // PDB        case CSeq_id::e_Pdb:            m_IsPDB = true;            break;        // TPA        case CSeq_id::e_Tpg:        case CSeq_id::e_Tpe:        case CSeq_id::e_Tpd:            m_IsTPA = true;            break;        case CSeq_id::e_General:            if ( id.GetGeneral().CanGetDb() ) {                if ( !NStr::CompareCase(id.GetGeneral().GetDb(), "BankIt") ) {                    m_IsTPA = true;                }            }            break;        // nothing special        case CSeq_id::e_not_set:        case CSeq_id::e_Local:        case CSeq_id::e_Gibbsq:        case CSeq_id::e_Gibbmt:        case CSeq_id::e_Giim:        case CSeq_id::e_Pir:        case CSeq_id::e_Swissprot:            m_IsSP = true;            break;        case CSeq_id::e_Prf:        default:            break;        }        // WGS        m_IsWGS = m_IsWGS  ||  (acc_div == CSeq_id::eAcc_wgs);                if ( m_IsWGS  &&  !acc.empty() ) {            size_t len = acc.length();            m_IsWGSMaster =                 ((len == 12  ||  len == 15)  &&  NStr::EndsWith(acc, "000000"))  ||

⌨️ 快捷键说明

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