gather_items.cpp

来自「ncbi源码」· C++ 代码 · 共 1,327 行 · 第 1/3 页

CPP
1,327
字号
                }                if ( ctx.IsRSContig()  ||  ctx.IsRSIntermedWGS() ) {                    if ( !has_ref_track_status ) {                        x_AddComment(new CGenomeAnnotComment(ctx, genome_build_number));                    }                }                if ( ctx.IsRSPredictedProtein()  ||                     ctx.IsRSPredictedMRna()     ||                     ctx.IsRSPredictedNCRna()    ||                     ctx.IsRSWGSProt() ) {                    SModelEvidance me;                    if ( GetModelEvidance(ctx.GetHandle(), me) ) {                        string str = CCommentItem::GetStringForModelEvidance(me);                        if ( !str.empty() ) {                            x_AddComment(new CCommentItem(str, ctx));                        }                    }                }            }}            break;        case CSeq_id::e_General:            {{                const CDbtag& dbtag = id.GetGeneral();                if ( dbtag.CanGetDb()  &&  dbtag.GetDb() == "GSDB"  &&                     dbtag.CanGetTag()  &&  dbtag.GetTag().IsId() ) {                    x_AddGSDBComment(dbtag, ctx);                }            }}            break;        case CSeq_id::e_Local:            {{                local_id = &(id.GetLocal());            }}            break;        default:            break;        }    }    if ( local_id != 0 ) {        if ( ctx.IsTPA()  ||  ctx.IsGED() ) {            if ( ctx.Config().IsModeGBench()  ||  ctx.Config().IsModeDump() ) {                x_AddComment(new CLocalIdComment(*local_id, ctx));            }        }    }}void CFlatGatherer::x_RefSeqComments(CBioseqContext& ctx) const{    bool did_tpa = false, did_ref_track = false, did_genome = false;    for (CSeqdesc_CI it(ctx.GetHandle(), CSeqdesc::e_User);  it;  ++it) {        const CUser_object& uo = it->GetUser();        // TPA        {{            if ( !did_tpa ) {                string str = CCommentItem::GetStringForTPA(uo, ctx);                if ( !str.empty() ) {                    x_AddComment(new CCommentItem(str, ctx, &uo));                    did_tpa = true;                }            }        }}        // BankIt        {{            if ( !ctx.Config().HideBankItComment() ) {                string str = CCommentItem::GetStringForBankIt(uo);                if ( !str.empty() ) {                    x_AddComment(new CCommentItem(str, ctx, &uo));                }            }        }}        // RefTrack        {{            if ( !did_ref_track ) {                string str = CCommentItem::GetStringForRefTrack(uo);                if ( !str.empty() ) {                    x_AddComment(new CCommentItem(str, ctx, &uo));                    did_ref_track = true;                }            }        }}        // Genome        {{            if ( !did_genome ) {                // !!! Not implememnted in the C version. should it be?            }        }}    }}void CFlatGatherer::x_HistoryComments(CBioseqContext& ctx) const{    const CBioseq_Handle& seq = ctx.GetHandle();    if ( !seq.IsSetInst_Hist() ) {        return;    }    const CSeq_hist& hist = seq.GetInst_Hist();    if ( hist.CanGetReplaced_by() ) {        const CSeq_hist::TReplaced_by& r = hist.GetReplaced_by();        if ( r.CanGetDate()  &&  !r.GetIds().empty() ) {            x_AddComment(new CHistComment(CHistComment::eReplaced_by,                hist, ctx));        }    }    if ( hist.IsSetReplaces()  &&  !ctx.Config().IsModeGBench() ) {        const CSeq_hist::TReplaces& r = hist.GetReplaces();        if ( r.CanGetDate()  &&  !r.GetIds().empty() ) {            x_AddComment(new CHistComment(CHistComment::eReplaces,                hist, ctx));        }    }}void CFlatGatherer::x_WGSComment(CBioseqContext& ctx) const{    if ( !ctx.IsWGSMaster()  ||  ctx.GetWGSMasterName().empty() ) {        return;    }    if ( ctx.GetTech() == CMolInfo::eTech_wgs ) {        string str = CCommentItem::GetStringForWGS(ctx);        if ( !str.empty() ) {            x_AddComment(new CCommentItem(str, ctx));        }    }}void CFlatGatherer::x_GBBSourceComment(CBioseqContext& ctx) const{    _ASSERT(ctx.ShowGBBSource());    for (CSeqdesc_CI it(ctx.GetHandle(), CSeqdesc::e_Genbank); it; ++it) {        const CGB_block& gbb = it->GetGenbank();        if ( gbb.CanGetSource()  &&  !gbb.GetSource().empty() ) {            x_AddComment(new CCommentItem(                "Original source text: " + gbb.GetSource(),                ctx,                &(*it)));        }    }}void CFlatGatherer::x_DescComments(CBioseqContext& ctx) const{    for (CSeqdesc_CI it(ctx.GetHandle(), CSeqdesc::e_Comment); it; ++it) {        x_AddComment(new CCommentItem(*it, ctx));    }}void CFlatGatherer::x_MaplocComments(CBioseqContext& ctx) const{    for (CSeqdesc_CI it(ctx.GetHandle(), CSeqdesc::e_Maploc); it; ++it) {        x_AddComment(new CCommentItem(*it, ctx));    }}void CFlatGatherer::x_RegionComments(CBioseqContext& ctx) const{    for (CSeqdesc_CI it(ctx.GetHandle(), CSeqdesc::e_Region); it; ++it) {        x_AddComment(new CCommentItem(*it, ctx));    }}void CFlatGatherer::x_HTGSComments(CBioseqContext& ctx) const{    CSeqdesc_CI desc(ctx.GetHandle(), CSeqdesc::e_Molinfo);    if ( !desc ) {        return;    }    const CMolInfo& mi = *ctx.GetMolinfo();    if ( ctx.IsRefSeq()  &&           mi.GetCompleteness() != CMolInfo::eCompleteness_unknown ) {        string str = CCommentItem::GetStringForMolinfo(mi, ctx);        if ( !str.empty() ) {            x_AddComment(new CCommentItem(str, ctx, &(*desc)));        }    }    CMolInfo::TTech tech = mi.GetTech();    if ( tech == CMolInfo::eTech_htgs_0  ||         tech == CMolInfo::eTech_htgs_1  ||         tech == CMolInfo::eTech_htgs_2 ) {        x_AddComment(new CCommentItem(            CCommentItem::GetStringForHTGS(ctx), ctx, &(*desc)));    } else {        const string& tech_str = GetTechString(tech);        if ( !tech_str.empty() ) {            x_AddComment(new CCommentItem("Method: " + tech_str, ctx, &(*desc)));        }    }}void CFlatGatherer::x_FeatComments(CBioseqContext& ctx) const{    // !!!}///////////////////////////////////////////////////////////////////////////////// SEQUENCE// We use multiple items to represent the sequence.void CFlatGatherer::x_GatherSequence(void) const{    static const TSeqPos kChunkSize = 2400; // 20 lines        bool first = true;    TSeqPos size = GetLength(m_Current->GetLocation(), &m_Current->GetScope());    for ( TSeqPos start = 0; start < size; start += kChunkSize ) {        TSeqPos end = min(start + kChunkSize, size);        *m_ItemOS << new CSequenceItem(start, end, first, *m_Current);        first = false;    }}///////////////////////////////////////////////////////////////////////////////// FEATURES// sourcevoid CFlatGatherer::x_CollectSourceDescriptors(const CBioseq_Handle& bh, CBioseqContext& ctx, TSourceFeatSet& srcs) const{    CRef<CSourceFeatureItem> sf;    CScope* scope = &ctx.GetScope();    const CSeq_loc& loc = ctx.GetLocation();    TRange print_range(0, GetLength(loc, scope) - 1);    for ( CSeqdesc_CI dit(bh, CSeqdesc::e_Source); dit;  ++dit) {        sf.Reset(new CSourceFeatureItem(dit->GetSource(), print_range, ctx));        srcs.push_back(sf);    }        // if segmented collect descriptors from segments    if ( ctx.IsSegmented() ) {        CConstRef<CSeqMap> seq_map = CSeqMap::CreateSeqMapForSeq_loc(loc, scope);                      // iterate over segments        CSeqMap_CI smit(seq_map->begin_resolved(scope, 1, CSeqMap::fFindRef));        for ( ; smit; ++smit ) {            CBioseq_Handle segh = scope->GetBioseqHandle(smit.GetRefSeqid());            if ( !segh  ||  !segh.IsSetDescr() ) {                continue;            }            CRange<TSeqPos> seg_range(smit.GetPosition(), smit.GetEndPosition());            // collect descriptors only from the segment             ITERATE(CBioseq_Handle::TDescr::Tdata, it, segh.GetDescr().Get()) {                if ( (*it)->IsSource() ) {                    sf.Reset(new CSourceFeatureItem((*it)->GetSource(), seg_range, ctx));                    srcs.push_back(sf);                }            }        }    }}void CFlatGatherer::x_CollectSourceFeatures(const CBioseq_Handle& bh, const TRange& range, CBioseqContext& ctx, TSourceFeatSet& srcs) const{    SAnnotSelector as;    as.SetFeatType(CSeqFeatData::e_Biosrc);    as.SetOverlapIntervals();    as.SetCombineMethod(SAnnotSelector::eCombine_All);    as.SetResolveDepth(1);  // in case segmented    as.SetNoMapping(false);    for ( CFeat_CI fi(bh, range.GetFrom(), range.GetTo(), as); fi; ++fi ) {        TSeqPos stop = fi->GetLocation().GetTotalRange().GetTo();        if ( stop >= range.GetFrom()  &&  stop  <= range.GetTo() ) {            CRef<CSourceFeatureItem> sf(new CSourceFeatureItem(*fi, ctx));            srcs.push_back(sf);        }    }}void CFlatGatherer::x_CollectBioSourcesOnBioseq(const CBioseq_Handle& bh, const TRange& range, CBioseqContext& ctx, TSourceFeatSet& srcs) const{    const CFlatFileConfig& cfg = ctx.Config();    // collect biosources descriptors on bioseq    if ( !cfg.IsFormatFTable()  ||  cfg.IsModeDump() ) {        x_CollectSourceDescriptors(bh, ctx, srcs);    }    // collect biosources features on bioseq    if ( !ctx.DoContigStyle()  ||  cfg.ShowContigSources() ) {        x_CollectSourceFeatures(bh, range, ctx, srcs);    }}void CFlatGatherer::x_CollectBioSources(TSourceFeatSet& srcs) const{    CBioseqContext& ctx = *m_Current;    CScope* scope = &ctx.GetScope();    const CFlatFileConfig& cfg = ctx.Config();    x_CollectBioSourcesOnBioseq(ctx.GetHandle(),                                ctx.GetLocation().GetTotalRange(),                                ctx,                                srcs);        // if protein with no sources, get sources applicable to DNA location of CDS    if ( srcs.empty()  &&  ctx.IsProt() ) {        const CSeq_feat* cds = GetCDSForProduct(ctx.GetHandle());        if ( cds != 0 ) {            const CSeq_loc& cds_loc = cds->GetLocation();            x_CollectBioSourcesOnBioseq(                scope->GetBioseqHandle(cds_loc),                cds_loc.GetTotalRange(),                ctx,                srcs);        }    }    // if no source found create one (only if not FTable format or Dump mode)    if ( srcs.empty()  &&  !cfg.IsFormatFTable()  ||  cfg.IsModeDump() ) {        CRef<CBioSource> bsrc(new CBioSource);        CRef<CSourceFeatureItem> sf(new CSourceFeatureItem(*bsrc, CRange<TSeqPos>::GetWhole(), ctx));        srcs.push_back(sf);    }}void CFlatGatherer::x_MergeEqualBioSources(TSourceFeatSet& srcs) const{    if ( srcs.size() < 2 ) {        return;    }    // !!! To Do:    // !!! * sort based on biosource    // !!! * merge equal biosources (merge locations)}void CFlatGatherer::x_SubtractFromFocus(TSourceFeatSet& srcs) const{    if ( srcs.size() < 2 ) {        return;    }    // !!! To Do:    // !!! * implement SeqLocSubtract}struct SSortByLoc{    bool operator()(const CRef<CSourceFeatureItem>& sfp1,                    const CRef<CSourceFeatureItem>& sfp2)     {        // descriptor always goes first        if ( sfp1->WasDesc()  &&  !sfp2->WasDesc() ) {            return true;        }                CSeq_loc::TRange range1 = sfp1->GetLoc().GetTotalRange();        CSeq_loc::TRange range2 = sfp2->GetLoc().GetTotalRange();        // feature with smallest left extreme is first        if ( range1.GetFrom() != range2.GetFrom() ) {            return range1.GetFrom() < range2.GetFrom();        }                // shortest first (just for flatfile)        if ( range1.GetToOpen() != range2.GetToOpen() ) {            return range1.GetToOpen() < range2.GetToOpen();        }                return false;    }};void CFlatGatherer::x_GatherSourceFeatures(void) const{    TSourceFeatSet srcs;        x_CollectBioSources(srcs);    if ( srcs.empty() ) {        return;    }    x_MergeEqualBioSources(srcs);        // sort by type (descriptor / feature) and location    sort(srcs.begin(), srcs.end(), SSortByLoc());        // if the descriptor has a focus, subtract out all other source locations.    if ( srcs.front()->GetSource().IsSetIs_focus() ) {        x_SubtractFromFocus(srcs);        // if features completely subtracted descriptor intervals,        // suppress in release, entrez modes.        if ( srcs.front()->GetLoc().GetTotalRange().GetLength() == 0  &&             m_Current->Config().HideEmptySource()  &&  srcs.size() > 1 ) {            srcs.pop_front();        }    }      ITERATE( TSourceFeatSet, it, srcs ) {        *m_ItemOS << *it;    }}

⌨️ 快捷键说明

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