shi_loader.cpp
来自「ncbi源码」· C++ 代码 · 共 203 行
CPP
203 行
/* * =========================================================================== * PRODUCTION $Log: shi_loader.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 21:14:05 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4 * PRODUCTION * =========================================================================== *//* $Id: shi_loader.cpp,v 1000.1 2004/06/01 21:14:05 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: * Shi file reader. Code ported from shipr.c CGI. */#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <corelib/ncbi_bswap.hpp>#include <gui/widgets/taxplot3d/shi_loader.hpp>USING_NCBI_SCOPE;#define BIT32 0x80000000#define BIT31 0x40000000#define THREE 0x7#define THIRTEEN 0x1FFF#define EIGHTEEN 0x3FFFF#define TWENTYSEVEN 0x7FFFFFF#define THIRTYONE 0x7FFFFFFF#define TAX0 0#define TAX1 1#define TAX2 2#define CUT 3#define XX 4#define YY 5#define LOG 6#define QUERY 7#define COGCLR 8#define XMIN 9#define XMAX 10#define YMIN 11#define YMAX 12#define RADIUS_A 13#define RADIUS_B 14#define NAME0 15#define NAME1 16#define NAME2 17#define NOTTAX1 0x80000000#define NOTTAX2 0x40000000#define TAXMASK 0x3FFFFFFFvoid CShiFile::openFile(const string name){ //m_FileStream.fastopen(name.c_str(), ios::binary); m_FileStream.open(name.c_str(), ios::binary); m_FileStream.seekg(0, ios::end); m_FileSize = m_FileStream.tellg(); m_FileStream.seekg(0, ios::beg); CT_OFF_TYPE sz = m_FileSize - CT_POS_TYPE(0); m_Buff.reset(new unsigned char[sz]); m_FileStream.read((char*)m_Buff.get(), sz); no_more = 0; last_gi = 1; m_FileCursor = 0; nshi = getNextInt(); value = getNextInt();}int CShiFile::getNextRecord(SShiRecord & rec){ // no more records if (isEof()) return 0; // building rec. structure if (last_gi) { m_Record.m_Nqugi = THIRTYONE & value; m_FileCursor +=1; m_Record.m_Chromosome = getNextInt(); m_Record.m_Pdb = getNextInt(); value = getNextInt(); } m_Record.m_Symmet = BIT31 & value; m_Record.m_Orgclass = THREE & (value>>27); m_Record.m_Dagi = TWENTYSEVEN & value; value = getNextInt(); m_Record.m_Taxid = (BIT32&value)?((THIRTYONE & value)>>13):value; m_Record.m_Score = (BIT32&value)?(THIRTEEN & value):getNextInt(); if(!isEof()) { value = getNextInt(); last_gi = (BIT32&value); } else last_gi = 1; rec = m_Record; return 1;}int ShiLoader::loadFileNew(const char * file){ auto_ptr<CShiFile> shFile(new CShiFile); shFile->openFile(file); int cutoff = 2000; SShiRecord rec; map <int, int> taxMap; while (shFile->getNextRecord(rec)){ if ((rec.m_Score > cutoff) && (taxMap.insert(pair<int,int>(rec.m_Taxid, rec.m_Score)).second==false)){ if (taxMap[rec.m_Taxid] < rec.m_Score) taxMap[rec.m_Taxid] = rec.m_Score; // already present } if (shFile->isLastGi()) { m_Cache.push_back(taxMap); taxMap.clear(); if (m_Handle && !shFile->isEof()){ int value = 1 + (static_cast<Uint8>(shFile->getFileCursor())*400)/(shFile->getFileSize() - CT_POS_TYPE(0)); if (!(value%10)) m_Handle->fireEvent(IShiLoaderEvents::eProgress, &value); } } } if (m_Handle) m_Handle->fireEvent(IShiLoaderEvents::eLoaded, NULL); return 0;}CTaxplot3dDataSource * ShiLoader::getData(int tax1, int tax2, int tax3){ m_DS->clear(); for (GIVECTOR::iterator it=m_Cache.begin(); it!=m_Cache.end(); it++){ TSMAP::iterator itm; int score1 = ((itm=it->find(tax1))!=it->end()) ? itm->second : 0; int score2 = ((itm=it->find(tax2))!=it->end()) ? itm->second : 0; int score3 = ((itm=it->find(tax3))!=it->end()) ? itm->second : 0; if ((score1!=score2!=score3) && ((score1!=0 && score2!=0) || (score1!=0 && score3!=0) || (score2!=0 && score3!=0))){ auto_ptr<CTaxplot3dDataSource::TVertex> newVertex(new CGraph3DVertex<float, float>(score1, score2, score3)); m_DS->addVertex(newVertex.get()); } } return m_DS->normalizeAll();}/* * =========================================================================== * $Log: shi_loader.cpp,v $ * Revision 1000.1 2004/06/01 21:14:05 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4 * * Revision 1.4 2004/05/21 22:27:56 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.3 2004/02/20 20:03:28 ucko * Fix to compile with stricter implementations of CT_POS_TYPE * * Revision 1.2 2004/01/14 20:49:14 tereshko * Removed debugging code * * Revision 1.1 2004/01/05 16:21:24 tereshko * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?