Sleipnir
src/clusthierarchicali.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 CLUSHIERARCHICALI_H
00023 #define CLUSHIERARCHICALI_H
00024 
00025 #include <string>
00026 #include <vector>
00027 
00028 #include "fullmatrix.h"
00029 #include "halfmatrix.h"
00030 
00031 namespace Sleipnir {
00032 
00033 class CHierarchy;
00034 
00035 class CHierarchyImpl {
00036 protected:
00037     ~CHierarchyImpl( );
00038 
00039     std::string GetSave( const std::vector<std::string>* = NULL ) const;
00040     bool Save( std::ostream&, size_t, const std::vector<std::string>* ) const;
00041 
00042     bool IsGene( ) const {
00043 
00044         return !( m_pLeft && m_pRight ); }
00045 
00046     size_t              m_iID;
00047     size_t              m_iWeight;
00048     float               m_dScore;
00049     const CHierarchy*   m_pLeft;
00050     const CHierarchy*   m_pRight;
00051 };
00052 
00053 class CClustHierarchicalImpl {
00054 protected:
00055 
00056     static CHierarchy* Cluster( const CDistanceMatrix&, const std::vector<bool>* = NULL );
00057     static CHierarchy* ConstructHierarchy( const std::vector<size_t>&, const std::vector<size_t>&,
00058         const std::vector<float>&, size_t );
00059     static void UpdateDistances( size_t, size_t, CDistanceMatrix&, size_t, size_t, std::vector<float>&,
00060         std::vector<size_t>& );
00061 
00062     static void AssertParentage( std::vector<size_t>& veciChildren, std::vector<size_t>& veciChild1,
00063         std::vector<size_t>& veciChild2, size_t iChild, size_t iParent ) {
00064 
00065         veciChildren[ iParent ] += veciChildren[ iChild ];
00066         iParent -= veciChild1.size( );
00067         veciChild2[ iParent ] = veciChild1[ iParent ];
00068         veciChild1[ iParent ] = iChild; }
00069 };
00070 
00071 }
00072 
00073 #endif // CLUSHIERARCHICALI_H