Sleipnir
src/pst.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 "pst.h"
00024 #include "coalescemotifs.h"
00025 
00026 namespace Sleipnir {
00027 
00028 struct SSortRCs {
00029     bool operator()( const string& strOne, const string& strTwo ) const {
00030 
00031         return ( strOne.length( ) > strTwo.length( ) ); }
00032 };
00033 
00055 void CPST::RemoveRCs( float dPenaltyGap, float dPenaltyMismatch, CPST& PSTOut ) const {
00056     size_t          i;
00057     string          str;
00058     vector<string>  vecstrAdd;
00059     float           dOne, dTwo;
00060     int             iOne, iTwo;
00061 
00062     CPSTImpl::RemoveRCs( m_sRoot, 1.0f / m_iArity, str, vecstrAdd );
00063     if( vecstrAdd.empty( ) )
00064         return;
00065 
00066     sort( vecstrAdd.begin( ), vecstrAdd.end( ), SSortRCs( ) );
00067     PSTOut.Add( vecstrAdd[ 0 ], 0 );
00068     for( i = 1; i < vecstrAdd.size( ); ++i ) {
00069         dOne = PSTOut.Align( vecstrAdd[ i ], dPenaltyGap, dPenaltyMismatch, FLT_MAX, iOne );
00070         dTwo = PSTOut.Align( str = CCoalesceMotifLibrary::GetReverseComplement( vecstrAdd[ i ] ),
00071             dPenaltyGap, dPenaltyMismatch, FLT_MAX, iTwo );
00072         if( dTwo < dOne )
00073             PSTOut.Add( str, iTwo );
00074         else
00075             PSTOut.Add( vecstrAdd[ i ], iOne ); } }
00076 
00077 }