Sleipnir
src/pclset.cpp
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 #include "stdafx.h"
00023 #include "pclset.h"
00024 
00025 namespace Sleipnir {
00026 
00027 CPCLSetImpl::CPCLSetImpl( ) : m_aPCLs(NULL), m_iPCLs(0) { }
00028 
00029 CPCLSetImpl::~CPCLSetImpl( ) {
00030 
00031     Reset( ); }
00032 
00033 void CPCLSetImpl::Reset( ) {
00034 
00035     if( m_aPCLs ) {
00036         delete[] m_aPCLs;
00037         m_aPCLs = NULL; }
00038     m_iPCLs = 0;
00039     m_vecstrGenes.clear( );
00040     m_Genes.Reset( ); }
00041 
00061 bool CPCLSet::Open( const std::vector<std::string>& vecstrFiles, size_t iSkip, CPCL::ENormalize eNormalize ) {
00062     size_t                      i, j;
00063     ifstream                    ifsm;
00064     set<string>                 setstrGenes;
00065     set<string>::const_iterator iterGene;
00066 
00067     Reset( );
00068     m_aPCLs = new CPCL[ m_iPCLs = vecstrFiles.size( ) ];
00069     for( i = 0; i < m_iPCLs; ++i ) {
00070         ifsm.clear( );
00071         ifsm.open( vecstrFiles[ i ].c_str( ) );
00072         if( !m_aPCLs[ i ].Open( ifsm, iSkip ) )
00073             return false;
00074         ifsm.close( );
00075         m_aPCLs[ i ].Normalize( eNormalize );
00076         for( j = 0; j < m_aPCLs[ i ].GetGenes( ); ++j )
00077             setstrGenes.insert( m_aPCLs[ i ].GetGene( j ) ); }
00078     m_vecstrGenes.resize( setstrGenes.size( ) );
00079     for( iterGene = setstrGenes.begin( ),i = 0; iterGene != setstrGenes.end( );
00080         ++iterGene,++i ) {
00081         m_vecstrGenes[ i ] = *iterGene;
00082         m_mapGenes[ *iterGene ] = i; }
00083 
00084     m_Genes.Initialize( m_iPCLs, m_vecstrGenes.size( ) );
00085     for( i = 0; i < m_iPCLs; ++i )
00086         for( j = 0; j < m_vecstrGenes.size( ); ++j )
00087             m_Genes.Set( i, j, m_aPCLs[ i ].GetGene( m_vecstrGenes[ j ] ) );
00088 
00089     return true; }
00090 
00091 }