obj_convert.cpp

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

CPP
1,304
字号
/* * =========================================================================== * PRODUCTION $Log: obj_convert.cpp,v $ * PRODUCTION Revision 1000.4  2004/06/01 20:44:10  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.19 * PRODUCTION * =========================================================================== *//*  $Id: obj_convert.cpp,v 1000.4 2004/06/01 20:44:10 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. * * =========================================================================== * * Authors:  Mike DiCuccio * * File Description: * */#include <ncbi_pch.hpp>#include <corelib/ncbimtx.hpp>#include <gui/core/obj_convert.hpp>#include <gui/core/idocument.hpp>#include <gui/objutils/utils.hpp>#include <gui/utils/message_box.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seq/Seq_annot.hpp>#include <objects/seqalign/Seq_align.hpp>#include <objects/seqalign/Seq_align_set.hpp>#include <objects/seqloc/Seq_id.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objects/seqset/Bioseq_set.hpp>#include <objects/seqfeat/Seq_feat.hpp>#include <objects/submit/Seq_submit.hpp>#include <objmgr/annot_selector.hpp>#include <objmgr/annot_ci.hpp>#include <serial/iterator.hpp> #include <objmgr/feat_ci.hpp>#include <objmgr/align_ci.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);////////////////////////////////////////////////////////////////////////////// generic conversions//void CObjConverter::ToObject(CScope& scope, const CObject& obj,                             const string& type_name,                             TObjList& objs) const{    if (type_name == "Seq-submit") {        ToSeqSubmit(scope, obj, objs);    } else if (type_name == "Seq-entry") {        ToSeqEntry(scope, obj, objs);    } else if (type_name == "Bioseq-set") {        ToBioseqSet(scope, obj, objs);    } else if (type_name == "Bioseq") {        ToBioseq(scope, obj, objs);    } else if (type_name == "Seq-id") {        ToSeqId(scope, obj, objs);    } else if (type_name == "Seq-loc") {        ToSeqLoc(scope, obj, objs);    } else if (type_name == "Seq-feat") {        ToSeqFeat(scope, obj, objs);    } else if (type_name == "Seq-align") {        ToSeqAlign(scope, obj, objs);    } else if (type_name == "Seq-annot") {        ToSeqAnnot(scope, obj, objs);    }}// object -> seq-submit// this is a simple wrapping of a seq-entryvoid CObjConverter::ToSeqSubmit(CScope& scope, const CObject& obj,                                TObjList& objs) const{    TObjList ents;    ToSeqEntry(scope, obj, ents);    if ( !ents.empty() ) {        CRef<CSeq_submit> sub(new CSeq_submit());        objs.push_back(CConstRef<CObject>(sub.GetPointer()));        ITERATE (TObjList, iter, ents) {            CRef<CSeq_entry> entry                (const_cast<CSeq_entry*>                 (dynamic_cast<const CSeq_entry*> (iter->GetPointer())));            sub->SetData().SetEntrys().push_back(entry);        }    }}// seq-loc -> seq-entry// we pass through seq-id to seq-entry conversionvoid CObjConverter::ToSeqEntry(CScope& scope, const CObject& obj,                               TObjList& objs) const{    TObjList ids;    ToSeqId(scope, obj, ids);    ITERATE (TObjList, id_iter, ids) {        CObjectConverter::Convert(scope, **id_iter,                                  CSeq_entry::GetTypeInfo()->GetName(), objs);    }}// seq-loc -> bioseq// we pass through seq-id to seq-entry conversionvoid CObjConverter::ToBioseq(CScope& scope, const CObject& obj,                             TObjList& objs) const{    TObjList ids;    ToSeqId(scope, obj, ids);    ITERATE (TObjList, id_iter, ids) {        CObjectConverter::Convert(scope, **id_iter,                                  CBioseq::GetTypeInfo()->GetName(), objs);    }}// object -> bioseq-setvoid CObjConverter::ToBioseqSet(CScope& scope, const CObject& obj,                                TObjList& objs) const{    TObjList ents;    ToSeqEntry(scope, obj, ents);    ITERATE (TObjList, ent_iter, ents) {        const CSeq_entry& entry =            dynamic_cast<const CSeq_entry&>(**ent_iter);        if (entry.IsSet()) {            objs.push_back(CConstRef<CObject>(&entry.GetSet()));        }    }}// object -> seq-loc// we feed out of CSeq_id conversion herevoid CObjConverter::ToSeqLoc(CScope& scope, const CObject& obj,                             TObjList& objs) const{    TObjList ids;    ToSeqId(scope, obj, ids);    ITERATE (TObjList, iter, ids) {        CObjectConverter::Convert(scope, **iter,                                  CSeq_loc::GetTypeInfo()->GetName(), objs);    }}// object -> seq-annot// we feed out of CSeq_loc conversion herevoid CObjConverter::ToSeqAnnot(CScope& scope, const CObject& obj,                               TObjList& objs) const{    TObjList locs;    ToSeqLoc(scope, obj, locs);    ITERATE (TObjList, iter, locs) {        CObjectConverter::Convert(scope, **iter,                                  CSeq_annot::GetTypeInfo()->GetName(), objs);    }    // FIXME: is this necessary?    objs.sort();    objs.unique();}// object -> seq-feat// we feed out of CSeq_loc conversion herevoid CObjConverter::ToSeqFeat(CScope& scope, const CObject& obj,                              TObjList& objs) const{    TObjList loc;    ToSeqLoc(scope, obj, loc);    ITERATE (TObjList, iter, loc) {        CObjectConverter::Convert(scope, **iter,                                  CSeq_feat::GetTypeInfo()->GetName(), objs);    }}// object -> seq-align// we feed out of CSeq_entry conversion herevoid CObjConverter::ToSeqAlign(CScope& scope, const CObject& obj,                               TObjList& objs) const{    TObjList loc;    ToSeqLoc(scope, obj, loc);    ITERATE (TObjList, iter, loc) {        CObjectConverter::Convert(scope, **iter,                                  CSeq_align::GetTypeInfo()->GetName(), objs);    }    // FIXME: is this necessary?    objs.sort();    objs.unique();}////////////////////////////////////////////////////////////////////////////// seq-entry conversions//class CSeq_entryConverter : public CObjConverter{public:    // seq-entry -> seq-submit    // this is a simple wrapping; we overload this to avoid allocation    void ToSeqSubmit(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CSeq_entry* entry = dynamic_cast<const CSeq_entry*> (&obj);        if (entry) {            CRef<CSeq_submit> sub(new CSeq_submit());            sub->SetData().SetEntrys().push_back                (CRef<CSeq_entry>(const_cast<CSeq_entry*>(entry)));            objs.push_back(CConstRef<CObject>(sub.GetPointer()));        }    }    // seq-entry -> seq-entry    // identity operation    void ToSeqEntry(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CSeq_entry* entry = dynamic_cast<const CSeq_entry*> (&obj);        if (entry) {            objs.push_back(CConstRef<CObject>(entry));        }    }    // seq-entry -> bioseq-set    // NULL function    void ToBioseqSet(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CSeq_entry* entry = dynamic_cast<const CSeq_entry*> (&obj);        if (entry  &&  entry->IsSet()) {            objs.push_back(CConstRef<CObject>(&entry->GetSet()));        }    }    // seq-entry -> bioseq    // identity operation    void ToBioseq(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CSeq_entry* entry = dynamic_cast<const CSeq_entry*> (&obj);        if (entry) {            CTypeConstIterator<CBioseq> iter(*entry);            for ( ;  iter;  ++iter) {                objs.push_back(CConstRef<CObject>(&*iter));            }        }    }    // seq-entry -> seq-id    // we return only one of the seq-ids for each bioseq    void ToSeqId(CScope& scope, const CObject& obj, TObjList& objs) const    {        TObjList seqs;        ToBioseq(scope, obj, seqs);        ITERATE (TObjList, iter, seqs) {            CObjectConverter::Convert(scope, **iter,                                      CSeq_id::GetTypeInfo()->GetName(), objs);        }    }};////////////////////////////////////////////////////////////////////////////// bioseq conversions//class CBioseqConverter : public CObjConverter{public:    // bioseq -> seq-entry    // here we favor the parent seq-entry, if it exists    void ToSeqEntry(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CBioseq* bs = dynamic_cast<const CBioseq*> (&obj);        if (bs) {            CConstRef<CObject> o;            if ( bs->GetParentEntry() ) {                o.Reset(bs->GetParentEntry());            } else {                CRef<CSeq_entry> se(new CSeq_entry());                se->SetSeq(const_cast<CBioseq&>(*bs));                o.Reset(se.GetPointer());            }            objs.push_back(o);        }    }    // bioseq -> bioseq-set    void ToBioseqSet(CScope& scope, const CObject& obj, TObjList& objs) const    {        TObjList temp;        ToSeqEntry(scope, obj, temp);        ITERATE (TObjList, iter, temp) {            CRef<CSeq_entry> entry                (const_cast<CSeq_entry*>(                dynamic_cast<const CSeq_entry*>(iter->GetPointer())));            CRef<CBioseq_set> bs_set(new CBioseq_set());            bs_set->SetSeq_set().push_back(entry);            objs.push_back(CConstRef<CObject>(bs_set.GetPointer()));        }    }    // bioseq -> bioseq    // identity operation    void ToBioseq(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CBioseq* bs = dynamic_cast<const CBioseq*> (&obj);        if (bs) {            objs.push_back(CConstRef<CObject>(bs));        }    }    // bioseq -> seq-id    // we return only one of the seq-ids for this bioseq    void ToSeqId(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CBioseq* bs = dynamic_cast<const CBioseq*> (&obj);        if (bs) {            CConstRef<CSeq_id> id = FindBestChoice(bs->GetId(), CSeq_id::Score);            if (id) {                objs.push_back(CConstRef<CObject>(id.GetPointer()));            }        }    }};////////////////////////////////////////////////////////////////////////////// bioseq-set conversions//class CBioseq_setConverter : public CObjConverter{public:    // bioseq-set -> seq-entry    // we create a dummy seq-entry to hold our data    void ToSeqEntry(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CBioseq_set* bs = dynamic_cast<const CBioseq_set*> (&obj);        if (bs) {            CRef<CSeq_entry> entry(new CSeq_entry());            entry->SetSet(const_cast<CBioseq_set&>(*bs));            objs.push_back(CConstRef<CObject>(entry.GetPointer()));        }    }    // bioseq-set -> bioseq    void ToBioseq(CScope& scope, const CObject& obj, TObjList& objs) const    {        const CBioseq_set* bs = dynamic_cast<const CBioseq_set*> (&obj);        if (bs) {            CTypeConstIterator<CBioseq> iter(*bs);            for ( ;  iter;  ++iter) {                const CBioseq& bioseq = *iter;                objs.push_back(CConstRef<CObject>(&bioseq));            }        }    }    // bioseq-set -> bioseq-set    // identity conversion    void ToBioseqSet(CScope& scope, const CObject& obj, TObjList& objs)    {        const CBioseq_set* bs = dynamic_cast<const CBioseq_set*> (&obj);        if (bs) {            objs.push_back(CConstRef<CObject>(bs));        }    }    // bioseq -> seq-id    // we return only one of the seq-ids for this bioseq    void ToSeqId(CScope& scope, const CObject& obj, TObjList& objs) const    {        TObjList temp;        ToBioseq(scope, obj, temp);        ITERATE (TObjList, iter, temp) {            CObjectConverter::Convert(scope, **iter,                                      CSeq_id::GetTypeInfo(), objs);        }    }

⌨️ 快捷键说明

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