📄 objmgr_demo.cpp
字号:
bdb_cache->Open(cache_path.c_str()); // Cache cleaning // Objects age should be assigned in days, negative value // means cleaning is disabled if (cache_age) { CTime time_stamp(CTime::eCurrent); time_t age = time_stamp.GetTimeT(); age -= 60 * 60 * 24 * cache_age; bdb_cache->Purge(age); } rdr = new CCachedId1Reader(5, bdb_cache.get());*/ } id1_reader.reset(rdr); int id_days = args["id_cache_days"].AsInteger(); if ( cache_mode != "old" ) { id_cache.reset(new CBDB_Cache()); ICache::TTimeStampFlags flags = ICache::fTimeStampOnCreate| ICache::fCheckExpirationAlways; id_cache->SetTimeStampPolicy(flags, id_days*24*60*60); id_cache->Open((cache_path+"/id").c_str(), "ids"); rdr->SetIdCache(id_cache.get()); } else { _ASSERT(0);/* bdb_cache->GetIntCache()-> SetExpirationTime(id_days*24*60*60); rdr->SetIdCache(bdb_cache->GetIntCache());*/ } LOG_POST(Info << "ID1 cache enabled in " << cache_path); } catch(CException& e) { LOG_POST(Error << "ID1 cache initialization failed in " << cache_path << ": " << e.what()); }#ifndef _DEBUG catch(...) { LOG_POST(Error << "ID1 cache initialization failed in " << cache_path); }#endif } else { LOG_POST(Info << "ID1 cache disabled."); } gb_loader = new CGBDataLoader("GenBank", id1_reader.release(), 2); } else { // Create genbank data loader and register it with the OM. // The last argument "eDefault" informs the OM that the loader // must be included in scopes during the CScope::AddDefaults() call gb_loader = new CGBDataLoader("ID", 0, 2); } pOm->RegisterDataLoader(*gb_loader, CObjectManager::eDefault); // Create a new scope. CScope scope(*pOm); // Add default loaders (GB loader in this demo) to the scope. scope.AddDefaults(); if ( args["file"] ) { CRef<CSeq_entry> entry(new CSeq_entry); args["file"].AsInputFile() >> MSerial_AsnText >> *entry; scope.AddTopLevelSeqEntry(*entry); } if ( args["bfile"] ) { CRef<CSeq_entry> entry(new CSeq_entry); args["bfile"].AsInputFile() >> MSerial_AsnBinary >> *entry; scope.AddTopLevelSeqEntry(*entry); } {{ CConstRef<CSeqref> sr = gb_loader->GetSatSatkey(*id); if ( !sr ) { ERR_POST("Cannot resolve Seq-id "<<id->AsFastaString()); } else { NcbiCout << "Resolved: "<<id->AsFastaString()<< " gi="<<sr->GetGi()<< " sat="<<sr->GetSat()<<" satkey="<<sr->GetSatKey()<<NcbiEndl; } }} // Get bioseq handle for the seq-id. Most of requests will use this handle. CBioseq_Handle handle = scope.GetBioseqHandle(*id); // Check if the handle is valid if ( !handle ) { ERR_POST(Fatal << "Bioseq not found"); } {{ NcbiCout << "Synonyms:" << NcbiEndl; CConstRef<CSynonymsSet> syns = scope.GetSynonyms(handle); ITERATE ( CSynonymsSet, it, *syns ) { CSeq_id_Handle idh = CSynonymsSet::GetSeq_id_Handle(it); NcbiCout << " " << idh.AsString() << NcbiEndl; } }} if ( print_tse ) { NcbiCout << "-------------------- TSE --------------------\n"; NcbiCout << MSerial_AsnText << *handle.GetTopLevelEntry().GetCompleteSeq_entry() << '\n'; NcbiCout << "-------------------- END --------------------\n"; } CSeq_id_Handle master_id = CSeq_id_Handle::GetHandle(*id); for ( int c = 0; c < repeat_count; ++c ) { if ( c && pause ) { SleepSec(pause); } if ( scan_seq_map ) { TSeqRange range(0, handle.GetBioseqLength()-1); for (size_t levels = 0; levels < 4; ++levels) { CConstRef<CSeqMap> seq_map(&handle.GetSeqMap()); CSeqMap::const_iterator seg = seq_map->ResolvedRangeIterator(&handle.GetScope(), range.GetFrom(), range.GetLength(), eNa_strand_plus, levels); for ( ; seg; ++seg ) { switch (seg.GetType()) { case CSeqMap::eSeqRef: break; case CSeqMap::eSeqData: case CSeqMap::eSeqGap: break; case CSeqMap::eSeqEnd: _ASSERT("Unexpected END segment" && 0); break; default: _ASSERT("Unexpected segment type" && 0); break; } } } } string sout; int count; if ( !only_features ) { // List other sequences in the same TSE NcbiCout << "TSE sequences:" << NcbiEndl; CBioseq_CI bit; bit = CBioseq_CI(scope, handle.GetTopLevelSeqEntry()); for ( ; bit; ++bit) { NcbiCout << " "<<bit->GetSeqId()->DumpAsFasta()<<NcbiEndl; } // Get the bioseq CConstRef<CBioseq> bioseq(&handle.GetBioseq()); // -- use the bioseq: print the first seq-id NcbiCout << "First ID = " << (*bioseq->GetId().begin())->DumpAsFasta() << NcbiEndl; // Get the sequence using CSeqVector. Use default encoding: // CSeq_data::e_Iupacna or CSeq_data::e_Iupacaa. CSeqVector seq_vect = handle.GetSeqVector(CBioseq_Handle::eCoding_Iupac); // -- use the vector: print length and the first 10 symbols NcbiCout << "Sequence: length=" << seq_vect.size(); if (seq_vect.CanGetRange(0, seq_vect.size() - 1)) { NcbiCout << " data="; sout = ""; for (TSeqPos i = 0; (i < seq_vect.size()) && (i < 10); i++) { // Convert sequence symbols to printable form sout += seq_vect[i]; } NcbiCout << NStr::PrintableString(sout) << NcbiEndl; } else { NcbiCout << " data unavailable" << NcbiEndl; } // CSeq_descr iterator: iterates all descriptors starting // from the bioseq and going the seq-entries tree up to the // top-level seq-entry. count = 0; for (CSeqdesc_CI desc_it(handle); desc_it; ++desc_it) { if ( print_descr ) { NcbiCout << "\n" << MSerial_AsnText << *desc_it; } count++; } cout << "\n"; NcbiCout << "Seqdesc count: " << count << NcbiEndl; count = 0; for (CSeq_annot_CI ai(scope, handle.GetTopLevelSeqEntry()); ai; ++ai) { ++count; } NcbiCout << "Seq_annot count (recursive): " << count << NcbiEndl; count = 0; for (CSeq_annot_CI ai(scope, handle.GetTopLevelSeqEntry(), CSeq_annot_CI::eSearch_entry); ai; ++ai) { ++count; } NcbiCout << "Seq_annot count (non-recursive): " << count << NcbiEndl; } // CSeq_feat iterator: iterates all features which can be found in the // current scope including features from all TSEs. // Construct seq-loc to get features for. CSeq_loc loc; // No region restrictions -- the whole bioseq is used: loc.SetWhole(*id); count = 0; // Create CFeat_CI using the current scope and location. // No feature type restrictions. SAnnotSelector base_sel; base_sel .SetResolveMethod(resolve) .SetSortOrder(order) .SetMaxSize(max_feat) .SetResolveDepth(depth) .SetAdaptiveDepth(adaptive); if ( include_allnamed ) { base_sel.SetAllNamedAnnots(); } if ( include_unnamed ) { base_sel.AddUnnamedAnnots(); } ITERATE ( set<string>, it, include_named ) { base_sel.AddNamedAnnots(*it); } if ( nosnp ) { base_sel.ExcludeNamedAnnots("SNP"); } ITERATE ( set<string>, it, exclude_named ) { base_sel.ExcludeNamedAnnots(*it); } {{ SAnnotSelector sel = base_sel; if ( feat_type >= 0 ) { sel.SetFeatType(SAnnotSelector::TFeatType(feat_type)); } if ( feat_subtype >= 0 ) { sel.SetFeatSubtype(SAnnotSelector::TFeatSubtype(feat_subtype)); } //int cnt0 = newCObjects.Get(); CFeat_CI it(scope, loc, sel); //int cnt1 = newCObjects.Get(); for ( ; it; ++it) { count++; if ( get_mapped_location ) it->GetLocation(); if ( get_original_feature ) it->GetOriginalFeature(); if ( get_mapped_feature ) it->GetMappedFeature(); // Get seq-annot containing the feature if ( print_features ) { NcbiCout << "Feature:"; if ( it->IsSetPartial() ) { NcbiCout << " partial = " << it->GetPartial(); } NcbiCout << "\n" << MSerial_AsnText << it->GetMappedFeature(); if ( 1 ) { NcbiCout << "Original location:\n" << MSerial_AsnText << it->GetOriginalFeature().GetLocation(); } else { NcbiCout << "Location:\n" << MSerial_AsnText << it->GetLocation(); } } CSeq_annot_Handle annot = it.GetAnnot(); /* const CSeq_id* mapped_id = 0; it->GetLocation().CheckId(mapped_id); _ASSERT(mapped_id); _ASSERT(CSeq_id_Handle::GetHandle(*mapped_id) == master_id); */ } //int cnt2 = newCObjects.Get(); if ( feat_type >= 0 || feat_subtype >= 0 ) { NcbiCout << "Feat count (whole, requested): "; } else { NcbiCout << "Feat count (whole, any): "; } NcbiCout << count << NcbiEndl; //NcbiCout << "Init new: " << (cnt1 - cnt0) << " iteratr new: " << (cnt2-cnt1) << NcbiEndl; _ASSERT(count == (int)it.GetSize()); }} if ( only_features ) continue; { count = 0; // The same region (whole sequence), but restricted feature type: // searching for e_Cdregion features only. If the sequence is // segmented (constructed), search for features on the referenced // sequences in the same top level seq-entry, ignore far pointers. SAnnotSelector sel = base_sel; sel.SetFeatType(CSeqFeatData::e_Cdregion); for ( CFeat_CI it(scope, loc, sel); it; ++it ) { count++; // Get seq vector filtered with the current feature location. // e_ViewMerged flag forces each residue to be shown only once. CSeqVector cds_vect = handle.GetSequenceView (it->GetLocation(), CBioseq_Handle::eViewMerged, CBioseq_Handle::eCoding_Iupac); // Print first 10 characters of each cd-region NcbiCout << "cds" << count << " len=" << cds_vect.size() << " data="; if ( cds_vect.size() == 0 ) { NcbiCout << "Zero size from: " << MSerial_AsnText << it->GetOriginalFeature().GetLocation(); NcbiCout << "Zero size to: " << MSerial_AsnText << it->GetMappedFeature().GetLocation(); NcbiCout << "Zero size to: " << MSerial_AsnText << it->GetLocation(); CSeqVector v2 = handle.GetSequenceView (it->GetLocation(), CBioseq_Handle::eViewMerged, CBioseq_Handle::eCoding_Iupac); NcbiCout << v2.size() << NcbiEndl; const CSeq_id* mapped_id = 0; it->GetMappedFeature().GetLocation().CheckId(mapped_id); _ASSERT(mapped_id); _ASSERT(CSeq_id_Handle::GetHandle(*mapped_id)==master_id); } sout = ""; for (TSeqPos i = 0; (i < cds_vect.size()) && (i < 10); i++) { // Convert sequence symbols to printable form sout += cds_vect[i]; } NcbiCout << NStr::PrintableString(sout) << NcbiEndl; } NcbiCout << "Feat count (whole, cds): " << count << NcbiEndl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -