locus_item.cpp
来自「ncbi源码」· C++ 代码 · 共 573 行 · 第 1/2 页
CPP
573 行
/* * =========================================================================== * PRODUCTION $Log: locus_item.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 19:45:04 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * PRODUCTION * =========================================================================== *//* $Id: locus_item.cpp,v 1000.2 2004/06/01 19:45:04 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 -- locus item implementation**/#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <objects/general/Date.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seq/MolInfo.hpp>#include <objects/seqloc/Textseq_id.hpp>#include <objects/seqblock/GB_block.hpp>#include <objects/seqblock/EMBL_block.hpp>#include <objects/seqblock/SP_block.hpp>#include <objects/seqblock/PDB_block.hpp>#include <objects/seqblock/PDB_replace.hpp>#include <objects/seqfeat/BioSource.hpp>#include <objects/seqfeat/Org_ref.hpp>#include <objects/seqfeat/OrgName.hpp>#include <objects/seqfeat/SubSource.hpp>#include <objmgr/scope.hpp>#include <objmgr/seqdesc_ci.hpp>#include <objmgr/feat_ci.hpp>#include <objmgr/bioseq_handle.hpp>#include <objmgr/util/sequence.hpp>#include <objtools/format/formatter.hpp>#include <objtools/format/text_ostream.hpp>#include <objtools/format/items/locus_item.hpp>#include <objtools/format/context.hpp>#include "utils.hpp"BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)USING_SCOPE(sequence);CLocusItem::CLocusItem(CBioseqContext& ctx) : CFlatItem(&ctx), m_Length(0), m_Biomol(CMolInfo::eBiomol_unknown), m_Date("01-JAN-1900"){ x_GatherInfo(ctx);}void CLocusItem::Format(IFormatter& formatter, IFlatTextOStream& text_os) const{ formatter.FormatLocus(*this, text_os); }const string& CLocusItem::GetName(void) const{ return m_Name;}size_t CLocusItem::GetLength(void) const{ return m_Length;}CLocusItem::TStrand CLocusItem::GetStrand(void) const{ return m_Strand;}CLocusItem::TBiomol CLocusItem::GetBiomol(void) const{ return m_Biomol;}CLocusItem::TTopology CLocusItem::GetTopology (void) const{ return m_Topology;}const string& CLocusItem::GetDivision(void) const{ return m_Division;}const string& CLocusItem::GetDate(void) const{ return m_Date;}/***************************************************************************//* PRIVATE *//***************************************************************************/void CLocusItem::x_GatherInfo(CBioseqContext& ctx){ CSeqdesc_CI mi_desc(ctx.GetHandle(), CSeqdesc::e_Molinfo); if ( mi_desc ) { x_SetObject(mi_desc->GetMolinfo()); } // NB: order of execution is important, as some values depend on others x_SetName(ctx); x_SetLength(ctx); x_SetBiomol(ctx); // must come befoer x_SetStrand x_SetStrand(ctx); x_SetTopology(ctx); x_SetDivision(ctx); x_SetDate(ctx);}// Namevoid CLocusItem::x_SetName(CBioseqContext& ctx){ CBioseq_Handle::TBioseqCore seq = ctx.GetHandle().GetBioseqCore(); CConstRef<CSeq_id> id = FindBestChoice(seq->GetId(), CSeq_id::Score); const CTextseq_id* tsid = id->GetTextseq_Id(); if ( tsid && tsid->CanGetName() ) { m_Name = tsid->GetName(); } if ( m_Name.empty() || x_NameHasBadChars(m_Name) ) { m_Name = id->GetSeqIdString(); }}bool CLocusItem::x_NameHasBadChars(const string& name) const{ ITERATE(string, iter, name) { if ( !isalnum(*iter) ) { return true; } } return false;}// Lengthvoid CLocusItem::x_SetLength(CBioseqContext& ctx){ m_Length = sequence::GetLength(ctx.GetLocation(), &ctx.GetScope());}// Strandvoid CLocusItem::x_SetStrand(CBioseqContext& ctx){ const CBioseq_Handle& bsh = ctx.GetHandle(); CSeq_inst::TMol bmol = bsh.IsSetInst_Mol() ? bsh.GetInst_Mol() : CSeq_inst::eMol_not_set; m_Strand = bsh.IsSetInst_Strand() ? bsh.GetInst_Strand() : CSeq_inst::eStrand_not_set; if ( m_Strand == CSeq_inst::eStrand_other ) { m_Strand = CSeq_inst::eStrand_not_set; } // cleanup for formats other than GBSeq if ( !ctx.Config().IsFormatGBSeq() ) { // if ds-DNA don't show ds if ( bmol == CSeq_inst::eMol_dna && m_Strand == CSeq_inst::eStrand_ds ) { m_Strand = CSeq_inst::eStrand_not_set; } // ss-any RNA don't show ss if ( (bmol > CSeq_inst::eMol_rna || (m_Biomol >= CMolInfo::eBiomol_mRNA && m_Biomol <= CMolInfo::eBiomol_peptide)) && m_Strand == CSeq_inst::eStrand_ss ) { m_Strand = CSeq_inst::eStrand_not_set; } }}// Biomolvoid CLocusItem::x_SetBiomol(CBioseqContext& ctx){ if ( ctx.IsProt() ) { return; } CSeq_inst::TMol bmol = ctx.GetHandle().GetBioseqMolType(); if ( bmol > CSeq_inst::eMol_aa ) { bmol = CSeq_inst::eMol_not_set; } const CMolInfo* molinfo = dynamic_cast<const CMolInfo*>(GetObject()); if ( molinfo && molinfo->GetBiomol() <= CMolInfo::eBiomol_transcribed_RNA ) { m_Biomol = molinfo->GetBiomol(); } if ( m_Biomol <= CMolInfo::eBiomol_genomic ) { if ( bmol == CSeq_inst::eMol_aa ) { m_Biomol = CMolInfo::eBiomol_peptide; } else if ( bmol == CSeq_inst::eMol_na ) { m_Biomol = CMolInfo::eBiomol_unknown; } else if ( bmol == CSeq_inst::eMol_rna ) { m_Biomol = CMolInfo::eBiomol_pre_RNA; } else { m_Biomol = CMolInfo::eBiomol_genomic; } } else if ( m_Biomol == CMolInfo::eBiomol_other_genetic ) { if ( bmol == CSeq_inst::eMol_rna ) { m_Biomol = CMolInfo::eBiomol_pre_RNA; } }}// Topologyvoid CLocusItem::x_SetTopology(CBioseqContext& ctx){ const CBioseq_Handle& bsh = ctx.GetHandle(); m_Topology = bsh.GetInst_Topology(); // an interval is always linear if ( !ctx.GetLocation().IsWhole() ) { m_Topology = CSeq_inst::eTopology_linear; }}// Divisionvoid CLocusItem::x_SetDivision(CBioseqContext& ctx){ // contig style (old genome_view flag) forces CON division if ( ctx.DoContigStyle() ) { m_Division = "CON"; return; } // "genome view" forces CON division if ( (ctx.IsSegmented() && !ctx.HasParts()) ||
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?