obj_convert.cpp

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

CPP
1,304
字号
    }};////////////////////////////////////////////////////////////////////////////// seq-feat conversions//class CSeq_featConverter : public CObjConverter{public:    // seq-feat -> seq-id    // we return a set of unique seq-feats for each location    void ToSeqId(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CSeq_feat* feat = dynamic_cast<const CSeq_feat*> (&obj);        if (feat) {            CObjectConverter::Convert(scope, feat->GetLocation(),                                      CSeq_id::GetTypeInfo()->GetName(), objs);            // deal with IDs from product location            if (feat->IsSetProduct()) {                CObjectConverter::Convert(scope, feat->GetProduct(),                                          CSeq_id::GetTypeInfo()->GetName(),                                          objs);            }            // deal with dbxrefs            if (feat->IsSetDbxref()) {                ITERATE (CSeq_feat::TDbxref, iter, feat->GetDbxref()) {                    const CDbtag& dbtag = **iter;                    CRef<CSeq_id> id(new CSeq_id(dbtag, false));                    if (id->Which() != CSeq_id::e_not_set) {                        objs.push_back( CConstRef<CObject> (id.GetPointer()) );                    }                }            }        }    }    // seq-feat -> seq-loc    // identity conversion    void ToSeqLoc(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CSeq_feat* feat = dynamic_cast<const CSeq_feat*>(&obj);        if ( !feat ) {            return;        }        objs.push_back(CConstRef<CObject>(&feat->GetLocation()));        if (feat->IsSetProduct()) {            objs.push_back(CConstRef<CObject>(&feat->GetProduct()));        }        // deal with dbxrefs        if (feat->IsSetDbxref()) {            ITERATE (CSeq_feat::TDbxref, iter, feat->GetDbxref()) {                const CDbtag& dbtag = **iter;                CRef<CSeq_id> id(new CSeq_id(dbtag, false));                if (id->Which() != CSeq_id::e_not_set) {                    CRef<CSeq_loc> loc(new CSeq_loc());                    loc->SetWhole(*id);                    objs.push_back( CConstRef<CObject> (loc.GetPointer()) );                }            }        }    }    // seq-feat -> seq-feat    // identity conversion    void ToSeqFeat(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CSeq_feat* feat = dynamic_cast<const CSeq_feat*>(&obj);        if (feat) {            objs.push_back(CConstRef<CObject>(feat));        }    }    // seq-feat -> seq-annot    // this should ideally return the parent annot of the feature    // we compromise by returning the annots for the location    void ToSeqAnnot(CScope& scope, const CObject& obj, TObjList& objs) const    {        TObjList locs;        ToSeqLoc(scope, obj, locs);        ITERATE (TObjList, loc_iter, locs) {            CObjectConverter::Convert(scope, **loc_iter,                                      CSeq_annot::GetTypeInfo(), objs);        }    }};////////////////////////////////////////////////////////////////////////////// document conversions//class CDocumentConverter : public CObjConverter{public:    // all forms of document conversion rely on the underlying object    // exposed by the document.  So, CDocConverter::ToObject merely passes    // control back to convert with the underlying object.    void ToObject(CScope& scope, const CObject& obj,                  const string& to_type, TObjList& objs) const    {        const IDocument* doc = dynamic_cast<const IDocument*> (&obj);        if (doc) {            CObjectConverter::Convert(scope, *doc->GetObject(), to_type, objs);        }    }    //    // all remaining API calls to this class are exceptions    //    class CDocConvertException  : EXCEPTION_VIRTUAL_BASE public CException    {    public:        // Enumerated list of document management errors        enum EErrCode {            eConversionNotSupported        };        // Translate the specific error code into a string representations of        // that error code.        virtual const char* GetErrCodeString(void) const        {            switch (GetErrCode()) {            case eConversionNotSupported: return "eConversionNotSupported";            default:                      return CException::GetErrCodeString();            }        }        NCBI_EXCEPTION_DEFAULT(CDocConvertException, CException);    };    void ToSeqSubmit(CScope& scope, const CObject& obj, TObjList& objs) const    {        NCBI_THROW(CDocConvertException, eConversionNotSupported,                   "Direct conversion not supported");    }    void ToSeqEntry(CScope& scope, const CObject& obj, TObjList& objs) const    {        NCBI_THROW(CDocConvertException, eConversionNotSupported,                   "Direct conversion not supported");    }    void ToBioseqSet(CScope& scope, const CObject& obj, TObjList& objs) const    {        NCBI_THROW(CDocConvertException, eConversionNotSupported,                   "Direct conversion not supported");    }    void ToBioseq(CScope& scope, const CObject& obj, TObjList& objs) const    {        NCBI_THROW(CDocConvertException, eConversionNotSupported,                   "Direct conversion not supported");    }    void ToSeqId(CScope& scope, const CObject& obj, TObjList& objs) const    {        NCBI_THROW(CDocConvertException, eConversionNotSupported,                   "Direct conversion not supported");    }    void ToSeqLoc(CScope& scope, const CObject& obj, TObjList& objs) const    {        NCBI_THROW(CDocConvertException, eConversionNotSupported,                   "Direct conversion not supported");    }    void ToSeqFeat(CScope& scope, const CObject& obj, TObjList& objs) const    {        NCBI_THROW(CDocConvertException, eConversionNotSupported,                   "Direct conversion not supported");    }    void ToSeqAnnot(CScope& scope, const CObject& obj, TObjList& objs) const    {        NCBI_THROW(CDocConvertException, eConversionNotSupported,                   "Direct conversion not supported");    }};////////////////////////////////////////////////////////////////////////////// converter cacheDEFINE_STATIC_MUTEX(s_ObjCvtMutex);typedef map<string, CRef<IObjConverter> > TCvtMap;static TCvtMap s_CvtMap;struct SFillDefaultConverters{    SFillDefaultConverters()    {        CMutexGuard LOCK(s_ObjCvtMutex);        if ( !s_CvtMap.empty() ) {            return;        }        CObjectConverter::Register(CSeq_submit::GetTypeInfo(), *new CSeq_submitConverter());        CObjectConverter::Register(CSeq_entry::GetTypeInfo(),  *new CSeq_entryConverter());        CObjectConverter::Register(CBioseq_set::GetTypeInfo(), *new CBioseq_setConverter());        CObjectConverter::Register(CBioseq::GetTypeInfo(),     *new CBioseqConverter());        CObjectConverter::Register(CSeq_id::GetTypeInfo(),     *new CSeq_idConverter());        CObjectConverter::Register(CSeq_loc::GetTypeInfo(),    *new CSeq_locConverter());        CObjectConverter::Register(CSeq_feat::GetTypeInfo(),   *new CSeq_featConverter());        CObjectConverter::Register(CSeq_align::GetTypeInfo(),  *new CSeq_alignConverter());        CObjectConverter::Register(CSeq_align_set::GetTypeInfo(),  *new CSeq_align_setConverter());        CObjectConverter::Register(CSeq_annot::GetTypeInfo(),  *new CSeq_annotConverter());        // internal-only types!        s_CvtMap["Document"] = CRef<IObjConverter>(new CDocumentConverter());    }};static SFillDefaultConverters s_InitConverters;////////////////////////////////////////////////////////////////////////////// object conversion//void CObjectConverter::Convert(CScope& scope, const CObject& obj,                               const CTypeInfo* info, TObjList& objs){    Convert(scope, obj, info->GetName(), objs);}void CObjectConverter::Convert(CScope& scope, const CObject& obj,                               const string& to_type, TObjList& objs){    //    // check to see if our object is a serial object first    //    string from_type;    {{         const CSerialObject* so = dynamic_cast<const CSerialObject*> (&obj);         if (so) {             from_type = so->GetThisTypeInfo()->GetName();         }     }}    //    // the only other supported object is an IDocument-derived document    //    if (from_type.empty()) {        const IDocument* doc = dynamic_cast<const IDocument*> (&obj);        if (doc) {            from_type = "Document";        }    }    // short-circuit: identity transforms    if (from_type == to_type) {        objs.push_back(CConstRef<CObject>(&obj));        return;    }    TCvtMap::const_iterator iter = s_CvtMap.find(from_type);    if (iter != s_CvtMap.end()) {        iter->second->ToObject(scope, obj, to_type, objs);        return;    }}////////////////////////////////////////////////////////////////////////////// converter registration//void CObjectConverter::Register(const CTypeInfo* info, IObjConverter& cvt){    CMutexGuard LOCK(s_ObjCvtMutex);    s_CvtMap[info->GetName()] = CRef<IObjConverter>(&cvt);}//////////////////////////////////////////////////////////////////////////////  conversion cache//const CConvertCache::TObjList& CConvertCache::Convert(CScope& scope,                        const CObject& obj,                       const CTypeInfo* info){    if (info) {        return Convert(scope, obj, info->GetName());    }    return m_EmptyObjList;}const CConvertCache::TObjList& CConvertCache::Convert(CScope& scope,                       const CObject& obj,                       const string& type_name){    SCacheKey key(scope, obj, type_name);    CConvertCache::TCache::iterator pos;    if ((pos = m_ObjCache.find(key)) == m_ObjCache.end()) {        TCache::value_type val(key, m_EmptyObjList);        CObjectConverter::Convert(scope, obj, type_name, val.second);        pair<CConvertCache::TCache::iterator, bool>            r(m_ObjCache.insert(val));        if (!r.second) {            return m_EmptyObjList;        }        pos = r.first;    }    return pos->second;}bool CConvertCache::SCacheKeySort::operator() (const SCacheKey& key1,                                               const SCacheKey& key2) const{    if (key1.m_Scope.GetPointer() < key2.m_Scope.GetPointer()) {        return true;    }    if (key1.m_Scope.GetPointer() >  key2.m_Scope.GetPointer()) {        return false;    }    // key1.m_Scope == key2.m_Scope    if (key1.m_Obj.GetPointer() < key2.m_Obj.GetPointer()) {        return true;    }    if (key1.m_Obj.GetPointer() > key2.m_Obj.GetPointer()) {        return false;    }    // (key1.m_Scope == key2.m_Scope) && (key1.m_Obj == key2.m_Obj)    return (NStr::CompareCase(key1.m_Type, key2.m_Type) < 0);};END_NCBI_SCOPE/* * =========================================================================== * $Log: obj_convert.cpp,v $ * Revision 1000.4  2004/06/01 20:44:10  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.19 * * Revision 1.19  2004/05/21 22:27:40  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.18  2004/05/07 15:40:50  dicuccio * Reworked initialization to be more robust * * Revision 1.17  2004/05/03 12:48:46  dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.16  2004/04/16 14:37:46  dicuccio * Use GetCompleteBioseq() instead of GetBioseq() * * Revision 1.15  2004/04/05 14:25:38  dicuccio * Don't forget to save results of seq-align-set -> annot conversion * * Revision 1.14  2004/04/05 12:17:23  dicuccio * Added CSeq_align_set converter * * Revision 1.13  2004/03/05 17:29:12  dicuccio * Added bioseq -> bioseq-set conversion * * Revision 1.12  2004/01/21 19:21:17  dicuccio * Added handling of dbxrefs as seq-ids and seq-locs for seq-feats * * Revision 1.11  2004/01/21 12:38:18  dicuccio * redesigned CObjectCOnverter API to eliminate temporary object creation * * Revision 1.10  2004/01/15 18:00:02  dicuccio * First pass at clean-up and elimination of temporary object creation * * Revision 1.9  2003/12/09 15:44:04  dicuccio * Use CExpcetion::GetMsg() instead of what() * * Revision 1.8  2003/11/18 17:43:43  dicuccio * Added conversion for CBioseq_set * * Revision 1.7  2003/10/14 19:43:58  dicuccio * Return the product's seq-loc as well as the main feature seq-loc for features * with products * * Revision 1.6  2003/10/10 17:14:37  dicuccio * Added safety net around object manager calls to trap exceptions.  Added better * conversion of seq-align -> seq-loc.  Reformatted some code. * * Revision 1.5  2003/10/10 16:00:48  friedman * Added CConvertCache * * Revision 1.4  2003/09/30 15:17:28  dicuccio * Cleaned up object conversion for seq-align, seq-feat.  Added default pathways * for seq-entry, bioseq.  Added seq-annot conversion * * Revision 1.3  2003/09/25 12:25:08  friedman * Implemented: *         ToSeqFeat * Added: *         ToSeqAlign *         CSeq_alignConverter * * Revision 1.2  2003/09/24 18:23:17  dicuccio * Use standard annot selector retrieval function from CSeqUtils * * Revision 1.1  2003/09/16 13:58:08  dicuccio * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

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