lds_object.cpp

来自「ncbi源码」· C++ 代码 · 共 666 行 · 第 1/2 页

CPP
666
字号
/* * =========================================================================== * PRODUCTION $Log: lds_object.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 19:46:06  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.20 * PRODUCTION * =========================================================================== *//*  $Id: lds_object.cpp,v 1000.2 2004/06/01 19:46:06 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: Anatoliy Kuznetsov * * File Description:  CLDS_Object implementation. * */#include <ncbi_pch.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seqloc/Seq_id.hpp>#include <objects/seq/Seq_annot.hpp>#include <objects/seqalign/Seq_align.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objects/seqalign/Std_seg.hpp>#include <objects/seqalign/Dense_seg.hpp>#include <bdb/bdb_cursor.hpp>#include <objtools/readers/fasta.hpp>#include <objtools/lds/admin/lds_object.hpp>#include <objtools/lds/lds_set.hpp>#include <objtools/lds/lds_util.hpp>#include <objmgr/object_manager.hpp>#include <objmgr/scope.hpp>#include <objmgr/util/sequence.hpp>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)CLDS_Object::CLDS_Object(SLDS_TablesCollection& db,                          const map<string, int>& obj_map): m_db(db),  m_ObjTypeMap(obj_map),  m_MaxObjRecId(0){}CLDS_Object::~CLDS_Object(){}void CLDS_Object::DeleteCascadeFiles(const CLDS_Set& file_ids,                                      CLDS_Set* objects_deleted,                                     CLDS_Set* annotations_deleted){    if (file_ids.empty())        return;    //    //  Delete records from "object" table    //    {{    CBDB_FileCursor cur(m_db.object_db);     cur.SetCondition(CBDB_FileCursor::eFirst);     while (cur.Fetch() == eBDB_Ok) {         int fid = m_db.object_db.file_id;        if (fid && LDS_SetTest(file_ids, fid)) {/*            int object_attr_id = m_db.object_db.object_attr_id;                        if (object_attr_id) {  // delete dependent object attr                m_db.object_attr_db.object_attr_id = object_attr_id;                m_db.object_attr_db.Delete();            }*/            int object_id = m_db.object_db.object_id;            objects_deleted->insert(object_id);            m_db.object_db.Delete();        }    }    }}    //    // Delete "annot2obj"    //    {{    CBDB_FileCursor cur(m_db.annot2obj_db);     cur.SetCondition(CBDB_FileCursor::eFirst);     while (cur.Fetch() == eBDB_Ok) {         int object_id = m_db.annot2obj_db.object_id;        if (object_id && LDS_SetTest(*objects_deleted, object_id)) {            m_db.annot2obj_db.Delete();        }    }    }}    //    // Delete "annotation"    //    {{    CBDB_FileCursor cur(m_db.annot_db);     cur.SetCondition(CBDB_FileCursor::eFirst);     while (cur.Fetch() == eBDB_Ok) {         int fid = m_db.object_db.file_id;        if (fid && LDS_SetTest(file_ids, fid)) {            int annot_id = m_db.annot_db.annot_id;            annotations_deleted->insert(annot_id);            m_db.annot_db.Delete();        }    }    }}    //    // Delete "seq_id_list"    //    {{    ITERATE(CLDS_Set, it, *objects_deleted) {        int id = *it;        m_db.seq_id_list.object_id = id;        m_db.seq_id_list.Delete();    }    ITERATE(CLDS_Set, it, *annotations_deleted) {        int id = *it;        m_db.seq_id_list.object_id = id;        m_db.seq_id_list.Delete();    }    }}}void CLDS_Object::UpdateCascadeFiles(const CLDS_Set& file_ids){    if (file_ids.empty())        return;    CLDS_Set objects_deleted;    CLDS_Set annotations_deleted;    DeleteCascadeFiles(file_ids, &objects_deleted, &annotations_deleted);    ITERATE(CLDS_Set, it, file_ids) {        int fid = *it;        m_db.file_db.file_id = fid;        if (m_db.file_db.Fetch() == eBDB_Ok) {            string fname(m_db.file_db.file_name);            CFormatGuess::EFormat format =                 (CFormatGuess::EFormat)(int)m_db.file_db.format;                LOG_POST(Info << "<< Updating file >>: " << fname);            UpdateFileObjects(fid, fname, format);        }    } // ITERATE}void CLDS_Object::UpdateFileObjects(int file_id,                                     const string& file_name,                                     CFormatGuess::EFormat format){    FindMaxObjRecId();    if (format == CFormatGuess::eBinaryASN ||        format == CFormatGuess::eTextASN ||        format == CFormatGuess::eXml) {        LOG_POST(Info << "Scanning file: " << file_name);        CLDS_CoreObjectsReader sniffer;        ESerialDataFormat stream_format = FormatGuess2Serial(format);        auto_ptr<CObjectIStream>           input(CObjectIStream::Open(file_name, stream_format));        sniffer.Probe(*input);        CLDS_CoreObjectsReader::TObjectVector& obj_vector                                                 = sniffer.GetObjectsVector();        if (obj_vector.size()) {            for (unsigned int i = 0; i < obj_vector.size(); ++i) {                CLDS_CoreObjectsReader::SObjectDetails* obj_info = &obj_vector[i];                // If object is not in the database yet.                if (obj_info->ext_id == 0) {                    SaveObject(file_id, &sniffer, obj_info);                }            }            LOG_POST(Info << "LDS: "                           << obj_vector.size()                           << " object(s) found in:"                           << file_name);            sniffer.ClearObjectsVector();        } else {            LOG_POST(Info << "LDS: No objects found in:" << file_name);        }    } else if ( format == CFormatGuess::eFasta ){        CNcbiIfstream input(file_name.c_str(),                             IOS_BASE::in | IOS_BASE::binary);        SFastaFileMap fmap;            ReadFastaFileMap(&fmap, input);        int type_id;        {{        map<string, int>::const_iterator it = m_ObjTypeMap.find("FastaEntry");        _ASSERT(it != m_ObjTypeMap.end());        type_id = it->second;        }}        SFastaFileMap::TMapVector::const_iterator it;        for (it = fmap.file_map.begin(); it < fmap.file_map.end(); ++it) {            SaveObject(file_id,                        it->seq_id,                        it->description,                        it->stream_offset,                       type_id);        }            } else {        LOG_POST(Info << "Unsupported file format: " << file_name);    }}int CLDS_Object::SaveObject(int file_id,                            const string& seq_id,                            const string& description,                            size_t offset,                            int type_id){    ++m_MaxObjRecId;    EBDB_ErrCode err;/*    m_db.object_attr_db.object_attr_id = m_MaxObjRecId;    m_db.object_attr_db.object_title = description;    EBDB_ErrCode err = m_db.object_attr_db.Insert();    BDB_CHECK(err, "LDS::ObjectAttribute");*/    m_db.object_db.object_id = m_MaxObjRecId;    m_db.object_db.file_id = file_id;    m_db.object_db.seqlist_id = 0;    m_db.object_db.object_type = type_id;    m_db.object_db.file_offset = offset;//    m_db.object_db.object_attr_id = m_MaxObjRecId;    m_db.object_db.TSE_object_id = 0;    m_db.object_db.parent_object_id = 0;    m_db.object_db.object_title = description;        string ups = seq_id;     NStr::ToUpper(ups);    m_db.object_db.primary_seqid = ups;    LOG_POST(Info << "Saving Fasta object: " << seq_id);    err = m_db.object_db.Insert();    BDB_CHECK(err, "LDS::Object");    return m_MaxObjRecId;}int CLDS_Object::SaveObject(int file_id,                             CLDS_CoreObjectsReader* sniffer,                            CLDS_CoreObjectsReader::SObjectDetails* obj_info){    int top_level_id, parent_id;    _ASSERT(obj_info->ext_id == 0);  // Making sure the object is not in the DB yet    if (obj_info->is_top_level) {        top_level_id = parent_id = 0;    } else {        // Find the direct parent        {{            CLDS_CoreObjectsReader::SObjectDetails* parent_obj_info                         = sniffer->FindObjectInfo(obj_info->parent_offset);            _ASSERT(parent_obj_info);            if (parent_obj_info->ext_id == 0) { // not yet in the database                // Recursively save the parent                parent_id = SaveObject(file_id, sniffer, parent_obj_info);            } else {                parent_id = parent_obj_info->ext_id;            }        }}        // Find the top level grand parent        {{            CLDS_CoreObjectsReader::SObjectDetails* top_obj_info                         = sniffer->FindObjectInfo(obj_info->top_level_offset);            _ASSERT(top_obj_info);            if (top_obj_info->ext_id == 0) { // not yet in the database

⌨️ 快捷键说明

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