DynProgr_scalar.c

Go to the documentation of this file.
00001 
00005 /*
00006  * Copyright (c) 2007-2008 ETH Zürich, Institute of Computational Science
00007  *
00008  * Permission is hereby granted, free of charge, to any person
00009  * obtaining a copy of this software and associated documentation
00010  * files (the "Software"), to deal in the Software without
00011  * restriction, including without limitation the rights to use,
00012  * copy, modify, merge, publish, distribute, sublicense, and/or sell
00013  * copies of the Software, and to permit persons to whom the
00014  * Software is furnished to do so, subject to the following
00015  * conditions:
00016  *
00017  * The above copyright notice and this permission notice shall be
00018  * included in all copies or substantial portions of the Software.
00019  *
00020  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00021  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00022  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00023  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00024  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00025  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00026  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00027  * OTHER DEALINGS IN THE SOFTWARE.
00028  */
00029 
00030 #include <sys/types.h>
00031 #include "swps3.h"
00032 #include "debug.h"
00033 #include "matrix.h"
00034 
00035 #define INFINITY (1.0/0.0)
00036 EXPORT double swps3_alignScalar( const DMatrix matrix, const char *s1, int ls1, const char *s2, int ls2, Options *options)
00037 { 
00038 static double coldel[MAX_SEQ_LENGTH], S[MAX_SEQ_LENGTH];
00039 
00040 int i, j, k;
00041 const double DelFixed = options->gapOpen;
00042 const double DelIncr = options->gapExt;
00043 double *Score_s1;
00044 double Tcd, t, MaxScore = 0, Sj, Sj1, Tj, Tj1, Trd;
00045 
00046 S[0] = coldel[0] = 0;
00047 for( j=0; j < ls2; j++ ) {
00048     coldel[j] = -INFINITY;
00049     S[j] = 0;
00050 }
00051 
00052 for( i=0; i < ls1; i++ ) {
00053 
00054     Tj1 = Sj1 = 0;
00055     Trd = -INFINITY;
00056 
00057     /* setup Score_s1 */
00058     k = s1[i];
00059     Score_s1 = matrix+k*MATRIX_DIM;
00060 
00061         for( j=0; j < ls2; j++ ) {
00062             Sj = S[j];
00063             Tcd = coldel[j] + DelIncr;
00064 
00065             if( Tcd < ( t=Sj+DelFixed ) ) Tcd = t;
00066             Tj = Sj1 + Score_s1[(int)s2[j]];
00067 
00068             Trd += DelIncr;
00069             if( Trd < ( t=Tj1+DelFixed ) ) Trd = t;
00070 
00071             if( Tj < Tcd ) Tj = Tcd;
00072             if( Tj < Trd ) Tj = Trd;
00073             if( Tj < 0 ) Tj = 0;
00074             if( Tj > MaxScore ) {
00075                 MaxScore = Tj;
00076                 if( MaxScore >= options->threshold ) { return( MaxScore ); }
00077             }
00078 
00079             coldel[j] = Tcd;
00080             S[j] = Tj1 = Tj;
00081             Sj1 = Sj;
00082         }
00083 }
00084 
00085 return( MaxScore );
00086 
00087 }

Generated on Thu Jun 5 12:44:37 2008 for swps3 by  doxygen 1.5.4