shi_reader.cpp

来自「ncbi源码」· C++ 代码 · 共 286 行

CPP
286
字号
/* * =========================================================================== * PRODUCTION $Log: shi_reader.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:01:49  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * PRODUCTION * =========================================================================== *//*  $Id: shi_reader.cpp,v 1000.1 2004/06/01 21:01:49 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:  Vladimir Tereshkov * * File Description: *    CShiReader - taxplot file format loader */#include <ncbi_pch.hpp>#include "shi_reader.hpp"#include <gui/core/doc_exception.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/idocument.hpp>#include <gui/core/plugin_utils.hpp>#include <gui/core/version.hpp>#include <gui/plugin/PluginCommandSet.hpp>#include <gui/plugin/PluginInfo.hpp>#include <gui/plugin/PluginValue.hpp>#include <gui/utils/message_box.hpp>#include <gui/objutils/utils.hpp>#include <gui/dialogs/file_browser.hpp>#include <objects/general/Object_id.hpp>#include <objects/seq/Seqdesc.hpp>#include <objects/seq/Seq_descr.hpp>#define BIT32			0x80000000#define BIT31			0x40000000#define THREE			0x7#define THIRTEEN		0x1FFF#define EIGHTEEN		0x3FFFF#define TWENTYSEVEN		0x7FFFFFF#define THIRTYONE		0x7FFFFFFFBEGIN_NCBI_SCOPEUSING_SCOPE(objects);//// factory implementations//void CShiReader::GetInfo(CPluginInfo& info){    info.Reset();    // version info macro    info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,                 string(__DATE__) + " " + string(__TIME__),                 "CShiReader",                 "Taxplot File", "Read a Taxplot file format",                 "http://graceland.ncbi.nlm.nih.gov:6224"                 "/staff/tereshko/plugin_help/shi.html");    // command info    CPluginCommandSet& cmds     = info.SetCommands();    CPluginCommand& load_args   = cmds.AddDataCommand(eDataCommand_load);        load_args.AddArgument("file", "File name", CPluginArg::eFile);}//// Default ctor//CShiReader::CShiReader(){}//// One and only dtor//CShiReader::~CShiReader(){}//// Load()// This is a pure virtual requirement and is the main plugin hook.//void CShiReader::Load(CPluginMessage& msg){    const CPluginCommand& args = msg.GetRequest().GetCommand();    CPluginReply& reply = msg.SetReply();    string fname = args["file"].AsString();    if ( fname.empty() ) {        reply.SetStatus(eMessageStatus_ignored);        return;    }    try {                    CNcbiIfstream istr(fname.c_str(), ios::binary);        CRef<CShiReaderCache> dataCache(new CShiReaderCache(fname));        dataCache->CreateCache(istr);        CRef<CScope> scope(new CScope(CDocManager::GetObjectManager()));                    scope->AddDefaults();        IDocument* doc = CDocManager::CreateDocument(*scope, *dataCache);                    reply.AddObject(*doc);    }    catch (exception& e) {        _TRACE("failed to read shi: " << e.what());    }    catch (...) {        _TRACE("failed to read shi: unknown error");    }}inline Int4 CShiReaderCache::x_GetNextInt(Uchar * buff, CT_OFF_TYPE & pos){    Uchar * ptr =  buff + pos * 4;        Int4 ret = (Int4(ptr[3]) << 24) |         (Int4(ptr[2]) << 16) |         (Int4(ptr[1]) << 8)  |         (Int4(ptr[0]));    pos += 1;    return ret;}void CShiReaderCache::CreateCache(CNcbiIfstream & fileStream){    SOneShiRecord   shiRecord;    vector<Uchar>   buff;    Int4            value,no_more,last_gi,nshi;    const Int4      cutoff = 1000;    map<Int4, Int4> taxMap;    fileStream.seekg(0, ios::end);    CT_POS_TYPE fileSize = fileStream.tellg();    CT_OFF_TYPE sz = fileSize - CT_POS_TYPE(0);    fileStream.seekg(0, ios::beg);      buff.resize(sz);    fileStream.read(((char*)&buff[0]), sz);    no_more = 0; last_gi = 1;     shiRecord.m_Gi = 0;    CT_OFF_TYPE fileCursor = 0;    m_Cache.clear();    nshi =  x_GetNextInt(&buff[0], fileCursor);    value = x_GetNextInt(&buff[0], fileCursor);    while ((fileCursor * 4) < sz){        // building rec. structure        if (last_gi) {	            shiRecord.m_Nqugi = THIRTYONE & value;		            fileCursor +=1;            shiRecord.m_Chromosome = x_GetNextInt(&buff[0], fileCursor);            shiRecord.m_Pdb        = x_GetNextInt(&buff[0], fileCursor);            value                  = x_GetNextInt(&buff[0], fileCursor);                        shiRecord.m_Gi         = 0;        }        else {            // first gi after last_gi            if (shiRecord.m_Gi == 0) shiRecord.m_Gi = TWENTYSEVEN & value;        }        shiRecord.m_Symmet   = BIT31 & value;        shiRecord.m_Orgclass = THREE & (value>>27);        shiRecord.m_Dagi     = TWENTYSEVEN & value;         value =  x_GetNextInt(&buff[0], fileCursor);        shiRecord.m_Taxid = (BIT32&value)?((THIRTYONE & value)>>13):value;        shiRecord.m_Score = (BIT32&value)?(THIRTEEN & value):x_GetNextInt(&buff[0], fileCursor);         if ((fileCursor * 4) < sz) {	            value   = x_GetNextInt(&buff[0], fileCursor);            last_gi = (BIT32&value);		        }        else last_gi = 1;        // checking and adding                if ((shiRecord.m_Score > cutoff) && (taxMap.insert(pair<Int4, Int4>(shiRecord.m_Taxid, shiRecord.m_Score)).second==false)){                   if (taxMap[shiRecord.m_Taxid] < shiRecord.m_Score) taxMap[shiRecord.m_Taxid] = shiRecord.m_Score;      // already present, updating             }                 // taxMap contains only valuable data right here        if (last_gi) {             taxMap.insert(pair<Int4, Int4>(0, shiRecord.m_Gi)); // adding current gi as 0 position            m_Cache.push_back(taxMap);                          taxMap.clear();           }        } }END_NCBI_SCOPE/* * =========================================================================== * $Log: shi_reader.cpp,v $ * Revision 1000.1  2004/06/01 21:01:49  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.9 * * Revision 1.9  2004/06/01 18:10:55  dicuccio * Use plugin args instead of internal file browser dialog * * Revision 1.8  2004/05/21 22:27:49  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.7  2004/05/20 20:34:39  tereshko * Changed initial Gi value to zero * * Revision 1.6  2004/05/03 13:31:33  dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.5  2004/03/11 17:47:51  dicuccio * Code formatting changes.  Use new file open dialog * * Revision 1.4  2004/02/20 20:03:27  ucko * Fix to compile with stricter implementations of CT_POS_TYPE * * Revision 1.3  2004/01/28 16:00:56  tereshko * Added current gi extraction, loosen filter criteria * * Revision 1.2  2004/01/21 16:33:34  tereshko * +Changes for CodeWarrior in this folder * * Revision 1.4  2004/01/21 16:09:43  rsmith * change stream position types for picky compiler (Codewarrior). * * Revision 1.3  2004/01/21 14:16:28  dicuccio * Adjusted API to be more coding standard compliant. * * Revision 1.2  2004/01/15 18:08:05  tereshko * Fixed for GCC_295 * * Revision 1.1  2004/01/14 16:35:59  tereshko * CShiReader data plugin * * Revision 1.3  2003/12/10 15:09:32  dicuccio * Changed menu item - capitalize AGP * * Revision 1.2  2003/12/09 21:33:54  jcherry * Added url for help * * Revision 1.1  2003/12/09 00:20:09  jcherry * Initial version * * =========================================================================== */

⌨️ 快捷键说明

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