void CBaseCountItem::x_GatherInfo(CBioseqContext& ctx) { if ( ctx.IsProt() ) { x_SetSkip(); return; } CSeqVector v(ctx.GetLocation(), ctx.GetHandle().GetScope(), CBioseq_Handle::eCoding_Iupac); const size_t COUNT = kMax_UChar+1; TSeqPos counters[COUNT] = {}; // "{}" will set all counters to zero // every how many bases do we check if the flatfile generator is canceled? // (feel free to adjust this number if it makes things faster) const static TSeqPos kCancelCheckBases = 4096; CSeqVector_CI it(v, 0, CSeqVector_CI::eCaseConversion_lower); TSeqPos count = v.size(); while ( count > 0 ) { const TSeqPos uBasesToCopyRightNow = min( kCancelCheckBases, count ); ITERATE_SIMPLE(uBasesToCopyRightNow) { ++counters[*it]; ++it; } count -= uBasesToCopyRightNow; ctx.ThrowIfCanceled(); } m_A = counters[Uchar('a')]; m_C = counters[Uchar('c')]; m_G = counters[Uchar('g')]; m_T = counters[Uchar('t')]; m_Other = v.size() - m_A - m_C - m_G - m_T; }
void CBaseCountItem::x_GatherInfo(CBioseqContext& ctx) { if ( ctx.IsProt() ) { x_SetSkip(); return; } CSeqVector v(ctx.GetLocation(), ctx.GetHandle().GetScope(), CBioseq_Handle::eCoding_Iupac); const size_t COUNT = kMax_UChar+1; TSeqPos counters[COUNT]; for ( size_t i = 0; i < COUNT; ++i) { counters[i] = 0; } CSeqVector_CI it(v, 0, CSeqVector_CI::eCaseConversion_lower); for ( TSeqPos count = v.size(); count; --count, ++it ) { ++counters[*it]; } m_A = counters[Uchar('a')]; m_C = counters[Uchar('c')]; m_G = counters[Uchar('g')]; m_T = counters[Uchar('t')]; m_Other = v.size() - m_A - m_C - m_G - m_T; }
void CGenbankGatherer::x_DoSingleSection(CBioseqContext& ctx) const { CConstRef<IFlatItem> item; const CFlatFileConfig& cfg = ctx.Config(); // these macros make the code easier to read and less repetitive #define GATHER_BLOCK(BlockType, ItemClassName) \ if( cfg.IsShownGenbankBlock(CFlatFileConfig::fGenbankBlocks_##BlockType) ) { \ item.Reset( new ItemClassName(ctx) ); \ ItemOS() << item; \ } #define GATHER_ANCHOR(BlockType, block_str) \ if( cfg.IsShownGenbankBlock(CFlatFileConfig::fGenbankBlocks_##BlockType) ) { \ item.Reset( new CHtmlAnchorItem(ctx, (block_str) ) ); \ ItemOS() << item; \ } #define GATHER_VIA_FUNC(BlockType, FuncName) \ if( cfg.IsShownGenbankBlock(CFlatFileConfig::fGenbankBlocks_##BlockType) ) { \ FuncName(); \ } // if there's a callback, let it know we've entered another bioseq if( cfg.GetGenbankBlockCallback() ) { CFlatFileConfig::CGenbankBlockCallback::EBioseqSkip eBioseqSkip = cfg.GetGenbankBlockCallback()->notify_bioseq( ctx ); if( eBioseqSkip == CFlatFileConfig::CGenbankBlockCallback::eBioseqSkip_Yes ) { return; } } // gather needed blocks GATHER_BLOCK(Head, CStartSectionItem); GATHER_ANCHOR(Locus, "locus"); GATHER_BLOCK(Locus, CLocusItem); GATHER_BLOCK(Defline, CDeflineItem); GATHER_BLOCK(Accession, CAccessionItem); GATHER_BLOCK(Version, CVersionItem); GATHER_BLOCK(Project, CGenomeProjectItem); if ( ctx.IsProt() ) { bool show_dbsource = true; CBioseq_Handle& bsh = ctx.GetHandle(); FOR_EACH_SEQID_ON_BIOSEQ_HANDLE (sid_itr, bsh) { CSeq_id_Handle sid = *sid_itr; switch (sid.Which()) { case NCBI_SEQID(Other): { CConstRef<CSeq_id> id = sid.GetSeqId(); const CTextseq_id& tsid = *id->GetTextseq_Id (); if (tsid.IsSetAccession()) { const string& acc = tsid.GetAccession (); if (NStr::StartsWith (acc, "WP_")) { show_dbsource = false; } } break; } default: break; } }