Sleipnir
src/compactmatrix.h
00001 /*****************************************************************************
00002 * This file is provided under the Creative Commons Attribution 3.0 license.
00003 *
00004 * You are free to share, copy, distribute, transmit, or adapt this work
00005 * PROVIDED THAT you attribute the work to the authors listed below.
00006 * For more information, please see the following web page:
00007 * http://creativecommons.org/licenses/by/3.0/
00008 *
00009 * This file is a component of the Sleipnir library for functional genomics,
00010 * authored by:
00011 * Curtis Huttenhower (chuttenh@princeton.edu)
00012 * Mark Schroeder
00013 * Maria D. Chikina
00014 * Olga G. Troyanskaya (ogt@princeton.edu, primary contact)
00015 *
00016 * If you use this library, the included executable tools, or any related
00017 * code in your work, please cite the following publication:
00018 * Curtis Huttenhower, Mark Schroeder, Maria D. Chikina, and
00019 * Olga G. Troyanskaya.
00020 * "The Sleipnir library for computational functional genomics"
00021 *****************************************************************************/
00022 #ifndef COMPACTMATRIX_H
00023 #define COMPACTMATRIX_H
00024 
00025 #include "compactmatrixi.h"
00026 
00027 namespace Sleipnir {
00028 
00040 class CCompactMatrix : CCompactMatrixImpl {
00041 public:
00042     bool Open( std::istream& istm );
00043     const unsigned char* Open( const unsigned char* pbData );
00044     void Save( std::ostream& ostm ) const;
00045 
00054     void Randomize( ) {
00055 
00056         if( m_aiData )
00057             std::random_shuffle( m_aiData, m_aiData + CountWords( ) ); }
00058 
00080     void Set( size_t iY, size_t iX, unsigned char cValue ) {
00081 
00082         if( iX == iY )
00083             return;
00084 
00085         HalfIndex( iY, iX );
00086         CCompactMatrixBase::Set( iY, iX, cValue ); }
00087 
00111     void Initialize( size_t iSize, unsigned char cValues, bool fClear ) {
00112 
00113         m_iSize = (uint32_t)iSize;
00114         return CCompactMatrixBase::Initialize( cValues, fClear ); }
00115 
00127     size_t GetSize( ) const {
00128 
00129         return m_iSize; }
00130 
00151     unsigned char Get( size_t iY, size_t iX ) const {
00152 
00153         if( iX == iY )
00154             return 0;
00155 
00156         HalfIndex( iY, iX );
00157         return CCompactMatrixBase::Get( iY, iX ); }
00158 };
00159 
00170 class CCompactFullMatrix : CCompactFullMatrixImpl {
00171 public:
00197     void Initialize( size_t iRows, size_t iColumns, unsigned char cValues, bool fClear ) {
00198 
00199         m_iRows = (uint32_t)iRows;
00200         m_iColumns = (uint32_t)iColumns;
00201         CCompactMatrixBase::Initialize( cValues, fClear ); }
00202 
00213     size_t GetRows( ) const {
00214 
00215         return m_iRows; }
00216 
00227     size_t GetColumns( ) const {
00228 
00229         return m_iColumns; }
00230 
00251     unsigned char Get( size_t iY, size_t iX ) const {
00252 
00253         return CCompactMatrixBase::Get( iY, iX ); }
00254 
00275     void Set( size_t iY, size_t iX, unsigned char cValue ) {
00276 
00277         CCompactMatrixBase::Set( iY, iX, cValue ); }
00278 };
00279 
00280 }
00281 
00282 #endif // COMPACTMATRIX_H