flat_reference.cpp
来自「ncbi源码」· C++ 代码 · 共 711 行 · 第 1/2 页
CPP
711 行
/* * =========================================================================== * PRODUCTION $Log: flat_reference.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 19:43:28 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.11 * PRODUCTION * =========================================================================== *//* $Id: flat_reference.cpp,v 1000.2 2004/06/01 19:43:28 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** File Description:* new (early 2003) flat-file generator -- bibliographic references** ===========================================================================*/#include <ncbi_pch.hpp>#include <objtools/flat/flat_formatter.hpp>#include <serial/iterator.hpp>#include <objects/biblio/biblio__.hpp>#include <objects/general/Name_std.hpp>#include <objects/general/Person_id.hpp>#include <objects/medline/Medline_entry.hpp>#include <objects/pub/pub__.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seqloc/Patent_seq_id.hpp>#include <objmgr/impl/annot_object.hpp>#include <objmgr/util/sequence.hpp>#include <algorithm>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)static void s_FormatAffil(const CAffil& affil, string& result){ if (affil.IsStr()) { result = affil.GetStr(); } else { result.erase(); const CAffil::C_Std& std = affil.GetStd(); if (std.IsSetDiv()) { result = std.GetDiv(); } if (std.IsSetAffil()) { if (!result.empty()) { result += ", "; } result += std.GetAffil(); } if (std.IsSetStreet()) { if (!result.empty()) { result += ", "; } result += std.GetStreet(); } if (std.IsSetCity()) { if (!result.empty()) { result += ", "; } result += std.GetCity(); } if (std.IsSetSub()) { if (!result.empty()) { result += ", "; } result += std.GetSub(); } if (std.IsSetPostal_code()) { if (!result.empty()) { result += " "; } result += std.GetPostal_code(); } if (std.IsSetCountry()) { if (!result.empty()) { result += ", "; } result += std.GetCountry(); }#if 0 // not in C version... if (std.IsSetFax()) { if (!result.empty()) { result += "; "; } result += "Fax: " + std.GetFax(); } if (std.IsSetPhone()) { if (!result.empty()) { result += "; "; } result += "Phone: " + std.GetPhone(); } if (std.IsSetEmail()) { if (!result.empty()) { result += "; "; } result += "E-mail: " + std.GetEmail(); }#endif }}CFlatReference::CFlatReference(const CPubdesc& pub, const CSeq_loc* loc, const CFlatContext& ctx) : m_Pubdesc(&pub), m_Loc(loc), m_Category(eUnknown), m_Serial(0){ ITERATE (CPub_equiv::Tdata, it, pub.GetPub().Get()) { x_Init(**it, ctx); } if (m_Date.NotEmpty() && m_Date->IsStd()) { m_StdDate = &m_Date->GetStd(); } else { // complain? m_StdDate = new CDate_std(CTime::eEmpty); }}void CFlatReference::Sort(vector<CRef<CFlatReference> >& v, CFlatContext& ctx){ // XXX -- implement! // assign final serial numbers for (unsigned int i = 0; i < v.size(); ++i) { v[i]->m_Serial = i + 1; }}string CFlatReference::GetRange(const CFlatContext& ctx) const{ bool is_embl = ctx.GetFormatter().GetDatabase() == IFlatFormatter::eDB_EMBL; if (is_embl && m_Loc.Empty()) { return kEmptyStr; } CNcbiOstrstream oss; if ( !is_embl ) { oss << " (" << ctx.GetUnits(false) << ' '; } string delim; const char* to = is_embl ? "-" : " to "; for (CSeq_loc_CI it(m_Loc ? *m_Loc : ctx.GetLocation()); it; ++it) { CSeq_loc_CI::TRange range = it.GetRange(); if (it.IsWhole()) { range.SetTo(sequence::GetLength(it.GetSeq_id(), &ctx.GetHandle().GetScope()) - 1); } if (it.IsPoint()) { oss << range.GetFrom() + 1; } else { oss << delim << range.GetFrom() + 1 << to << range.GetTo() + 1; } delim = ", "; } if ( !is_embl ) { oss << ')'; } return CNcbiOstrstreamToString(oss);}void CFlatReference::GetTitles(string& title, string& journal, const CFlatContext& ctx) const{ // XXX - kludged for now (should move more logic from x_Init to here) title = m_Title; if (m_Journal.empty()) { // complain? return; } if (ctx.GetFormatter().GetDatabase() == IFlatFormatter::eDB_EMBL) { if (m_Category == CFlatReference::eSubmission) { journal = "Submitted "; if (m_Date) { journal += '('; ctx.GetFormatter().FormatDate(*m_Date, journal); journal += ") "; } journal += "to the EMBL/GenBank/DDBJ databases.\n" + m_Journal; } else { journal = m_Journal; if ( !m_Volume.empty() ) { journal += " " + m_Volume; } if ( !m_Pages.empty()) { journal += ":" + m_Pages; } if (m_Date) { journal += '('; m_Date->GetDate(&journal, "%Y"); journal += ")."; } } } else { // NCBI or DDBJ if (m_Category == CFlatReference::eSubmission) { journal = "Submitted "; if (m_Date) { journal += '('; ctx.GetFormatter().FormatDate(*m_Date, journal); journal += ") "; } journal += m_Journal; } else { journal = m_Journal; if ( !m_Volume.empty() ) { journal += " " + m_Volume; } if ( !m_Issue.empty() ) { journal += " (" + m_Issue + ')'; } if ( !m_Pages.empty()) { journal += ", " + m_Pages; } if (m_Date) { journal += " ("; m_Date->GetDate(&journal, "%Y"); journal += ')'; } } }}// can't go in the header, as IFlatFormatter isn't yet knownvoid CFlatReference::Format(IFlatFormatter& f) const{ f.FormatReference(*this);}bool CFlatReference::Matches(const CPub_set& ps) const{ // compare IDs CTypesConstIterator it; CType<CCit_gen>::AddTo(it); CType<CMedlineUID>::AddTo(it); CType<CMedline_entry>::AddTo(it); CType<CPub>::AddTo(it); CType<CPubMedId>::AddTo(it); for (it = ps; it; ++it) { if (CType<CCit_gen>::Match(it)) { const CCit_gen& gen = *CType<CCit_gen>::Get(it); if ((gen.IsSetMuid() && HasMUID(gen.GetMuid())) /* || gen.GetSerial_number() == m_Serial */) { return true; } } else if (CType<CMedlineUID>::Match(it)) { if (HasMUID(CType<CMedlineUID>::Get(it)->Get())) { return true; } } else if (CType<CMedline_entry>::Match(it)) { if (HasMUID(CType<CMedline_entry>::Get(it)->GetUid())) { return true; } } else if (CType<CPub>::Match(it)) { const CPub& pub = *CType<CPub>::Get(it); if (pub.IsMuid() && HasMUID(pub.GetMuid())) { return true; } } else if (CType<CPubMedId>::Match(it)) { if (HasPMID(CType<CPubMedId>::Get(it)->Get())) { return true; } } } return false;}void CFlatReference::x_Init(const CPub& pub, const CFlatContext& ctx){ switch (pub.Which()) { case CPub::e_Gen: x_Init(pub.GetGen(), ctx); break; case CPub::e_Sub: x_Init(pub.GetSub(), ctx); break; case CPub::e_Medline: x_Init(pub.GetMedline(), ctx); break; case CPub::e_Muid: m_MUIDs.insert(pub.GetMuid()); break; case CPub::e_Article: x_Init(pub.GetArticle(), ctx); break; case CPub::e_Journal: x_Init(pub.GetJournal(), ctx); break; case CPub::e_Book: x_Init(pub.GetBook(), ctx); break; case CPub::e_Proc: x_Init(pub.GetProc().GetBook(), ctx); break; case CPub::e_Patent: x_Init(pub.GetPatent(), ctx); break; case CPub::e_Man: x_Init(pub.GetMan(), ctx); break; case CPub::e_Equiv: ITERATE (CPub_equiv::Tdata, it, pub.GetEquiv().Get()) { x_Init(**it, ctx); } break; case CPub::e_Pmid: m_PMIDs.insert(pub.GetPmid()); break; default: break; }}void CFlatReference::x_Init(const CCit_gen& gen, const CFlatContext& ctx){ if (gen.IsSetCit() && !NStr::CompareNocase(gen.GetCit(), "unpublished") ) { m_Category = eUnpublished; m_Journal = "Unpublished"; } if (gen.IsSetAuthors()) { x_AddAuthors(gen.GetAuthors()); } if (gen.IsSetMuid()) { m_MUIDs.insert(gen.GetMuid()); } if (gen.IsSetJournal()) { x_SetJournal(gen.GetJournal(), ctx); } if (gen.IsSetVolume() && m_Volume.empty()) { m_Volume = gen.GetVolume(); } if (gen.IsSetIssue() && m_Issue.empty()) { m_Issue = gen.GetIssue(); } if (gen.IsSetPages() && m_Pages.empty()) { m_Pages = gen.GetPages(); } if (gen.IsSetDate() && !m_Date) { m_Date = &gen.GetDate();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?