/* $Id: id_handler.cpp 452861 2014-11-25 16:39:11Z whlavina $ * =========================================================================== * * 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. * * =========================================================================== * * Authors: Vyacheslav Chetvernin * File Description: * */ #include #include #include #include #include #include #include #include #include #include BEGIN_NCBI_SCOPE BEGIN_SCOPE(gnomon) USING_SCOPE(objects); CIdHandler::CIdHandler(CScope& scope) : m_Scope(scope) { } CConstRef CIdHandler::ToCanonical(const CSeq_id& id) const { CConstRef canonical_id; try { CSeq_id_Handle idh = sequence::GetId(id, m_Scope, sequence::eGetId_Canonical | sequence::eGetId_ThrowOnError); canonical_id = idh.GetSeqId(); } catch (sequence::CSeqIdFromHandleException& e) { if (e.GetErrCode() != sequence::CSeqIdFromHandleException::eRequestedIdNotFound) throw; canonical_id.Reset(&id); } return canonical_id; } string CIdHandler::ToString(const CSeq_id& id) { return id.AsFastaString(); } CRef CIdHandler::ToSeq_id(const string& str) { return CRef(new CSeq_id(str)); } CRef CIdHandler::GnomonMRNA(Int8 id) { CRef result(new CSeq_id); CSeq_id::TGeneral& gnl = result->SetGeneral(); gnl.SetDb("GNOMON"); gnl.SetTag().SetStr(NStr::NumericToString(id) + ".m"); return result; } CRef CIdHandler::GnomonProtein(Int8 id) { CRef result(new CSeq_id); CSeq_id::TGeneral& gnl = result->SetGeneral(); gnl.SetDb("GNOMON"); gnl.SetTag().SetStr(NStr::NumericToString(id) + ".p"); return result; } bool CIdHandler::IsId(const CObject_id& obj) { Int8 id; switch (obj.GetIdType(id)) { case CObject_id::e_not_set: return false; default: return true; } } Int8 CIdHandler::GetId(const CObject_id& obj) { Int8 id; switch (obj.GetIdType(id)) { case CObject_id::e_not_set: NCBI_THROW(CException, eUnknown, "No integral ID for object ID"); default: ; } return id; } void CIdHandler::SetId(CObject_id& obj, Int8 value) { if (value >= numeric_limits::min() && value <= numeric_limits::max()) { obj.SetId(static_cast(value)); } else { obj.SetStr(NStr::NumericToString(value)); } } string GetDNASequence(CConstRef id, CScope& scope) { CBioseq_Handle bh (scope.GetBioseqHandle(*id)); if (!bh) { NCBI_THROW(CException, eUnknown, "Sequence '"+CIdHandler::ToString(*id)+"' retrieval failed"); } CSeqVector sv (bh.GetSeqVector(CBioseq_Handle::eCoding_Iupac)); string seq; sv.GetSeqData(0, sv.size(), seq); return seq; } END_SCOPE(gnomon) END_NCBI_SCOPE