#include "common.h"#include "linefile.h"#include "gapCalc.h"Include dependency graph for gapCalc.c:

Go to the source code of this file.
Data Structures | |
| struct | gapCalc |
Functions | |
| char * | gapCalcSampleFileContents () |
| static int | interpolate (int x, int *s, double *v, int sCount) |
| static double | calcSlope (double y2, double y1, double x2, double x1) |
| static void | readTaggedNumLine (struct lineFile *lf, char *tag, int count, int *intOut, double *floatOut) |
| gapCalc * | gapCalcRead (struct lineFile *lf) |
| gapCalc * | gapCalcFromString (char *s) |
| gapCalc * | gapCalcFromFile (char *fileName) |
| gapCalc * | gapCalcDefault () |
| gapCalc * | gapCalcRnaDna () |
| gapCalc * | gapCalcCheap () |
| gapCalc * | gapCalcOriginal () |
| void | gapCalcFree (struct gapCalc **pGapCalc) |
| int | gapCalcCost (struct gapCalc *gapCalc, int dq, int dt) |
| void | gapCalcTest (struct gapCalc *gapCalc) |
Variables | |
| static char const | rcsid [] = "$Id: gapCalc.c,v 1.4 2006/06/18 23:09:36 kate Exp $" |
| static char * | originalGapCosts |
| static char * | defaultGapCosts |
| static char * | rnaDnaGapCosts |
| static char * | cheapGapCosts |
| static double calcSlope | ( | double | y2, | |
| double | y1, | |||
| double | x2, | |||
| double | x1 | |||
| ) | [static] |
| struct gapCalc* gapCalcCheap | ( | ) | [read] |
Definition at line 267 of file gapCalc.c.
References cheapGapCosts, and gapCalcFromString().
00269 { 00270 return gapCalcFromString(cheapGapCosts); 00271 }
Here is the call graph for this function:

| int gapCalcCost | ( | struct gapCalc * | gapCalc, | |
| int | dq, | |||
| int | dt | |||
| ) |
Definition at line 296 of file gapCalc.c.
References gapCalc::bLastPos, gapCalc::bLastPosVal, gapCalc::bLastSlope, gapCalc::bLong, gapCalc::bPosCount, gapCalc::bSmall, interpolate(), gapCalc::longPos, gapCalc::qLastPos, gapCalc::qLastPosVal, gapCalc::qLastSlope, gapCalc::qLong, gapCalc::qPosCount, gapCalc::qSmall, gapCalc::smallSize, gapCalc::tLastPos, gapCalc::tLastPosVal, gapCalc::tLastSlope, gapCalc::tLong, gapCalc::tPosCount, and gapCalc::tSmall.
Referenced by chainCalcScore(), chainCalcScoreSubChain(), chainConnectCost(), chainConnectGapCost(), and gapCalcTest().
00298 { 00299 if (dt < 0) dt = 0; 00300 if (dq < 0) dq = 0; 00301 if (dt == 0) 00302 { 00303 if (dq < gapCalc->smallSize) 00304 return gapCalc->qSmall[dq]; 00305 else if (dq >= gapCalc->qLastPos) 00306 return gapCalc->qLastPosVal + gapCalc->qLastSlope * (dq-gapCalc->qLastPos); 00307 else 00308 return interpolate(dq, gapCalc->longPos, gapCalc->qLong, gapCalc->qPosCount); 00309 } 00310 else if (dq == 0) 00311 { 00312 if (dt < gapCalc->smallSize) 00313 return gapCalc->tSmall[dt]; 00314 else if (dt >= gapCalc->tLastPos) 00315 return gapCalc->tLastPosVal + gapCalc->tLastSlope * (dt-gapCalc->tLastPos); 00316 else 00317 return interpolate(dt, gapCalc->longPos, gapCalc->tLong, gapCalc->tPosCount); 00318 } 00319 else 00320 { 00321 int both = dq + dt; 00322 if (both < gapCalc->smallSize) 00323 return gapCalc->bSmall[both]; 00324 else if (both >= gapCalc->bLastPos) 00325 return gapCalc->bLastPosVal + gapCalc->bLastSlope * (both-gapCalc->bLastPos); 00326 else 00327 return interpolate(both, gapCalc->longPos, gapCalc->bLong, gapCalc->bPosCount); 00328 } 00329 }
Here is the call graph for this function:

Here is the caller graph for this function:

| struct gapCalc* gapCalcDefault | ( | ) | [read] |
Definition at line 255 of file gapCalc.c.
References defaultGapCosts, and gapCalcFromString().
00257 { 00258 return gapCalcFromString(defaultGapCosts); 00259 }
Here is the call graph for this function:

| void gapCalcFree | ( | struct gapCalc ** | pGapCalc | ) |
Definition at line 279 of file gapCalc.c.
References gapCalc::bLong, gapCalc::bSmall, freeMem(), freez(), gapCalc::longPos, gapCalc::qLong, gapCalc::qSmall, gapCalc::tLong, and gapCalc::tSmall.
00281 { 00282 struct gapCalc *gapCalc = *pGapCalc; 00283 if (gapCalc != NULL) 00284 { 00285 freeMem(gapCalc->qSmall); 00286 freeMem(gapCalc->tSmall); 00287 freeMem(gapCalc->bSmall); 00288 freeMem(gapCalc->longPos); 00289 freeMem(gapCalc->qLong); 00290 freeMem(gapCalc->tLong); 00291 freeMem(gapCalc->bLong); 00292 freez(pGapCalc); 00293 } 00294 }
Here is the call graph for this function:

| struct gapCalc* gapCalcFromFile | ( | char * | fileName | ) | [read] |
Definition at line 231 of file gapCalc.c.
References defaultGapCosts, gapCalcFromString(), gapCalcRead(), lineFileClose(), lineFileOpen(), originalGapCosts, sameString, TRUE, and verbose().
00233 { 00234 struct gapCalc *gapCalc = NULL; 00235 00236 if (sameString(fileName, "loose")) 00237 { 00238 verbose(2, "using loose linear gap costs (chicken/human)\n"); 00239 gapCalc = gapCalcFromString(defaultGapCosts); 00240 } 00241 else if (sameString(fileName, "medium")) 00242 { 00243 verbose(2, "using medium (original) linear gap costs (mouse/human)\n"); 00244 gapCalc = gapCalcFromString(originalGapCosts); 00245 } 00246 else 00247 { 00248 struct lineFile *lf = lineFileOpen(fileName, TRUE); 00249 gapCalc = gapCalcRead(lf); 00250 lineFileClose(&lf); 00251 } 00252 return gapCalc; 00253 }
Here is the call graph for this function:

| struct gapCalc* gapCalcFromString | ( | char * | s | ) | [read] |
Definition at line 222 of file gapCalc.c.
References cloneString(), gapCalcRead(), lineFileClose(), lineFileOnString(), and TRUE.
Referenced by gapCalcCheap(), gapCalcDefault(), gapCalcFromFile(), gapCalcOriginal(), and gapCalcRnaDna().
00224 { 00225 struct lineFile *lf = lineFileOnString("string", TRUE, cloneString(s)); 00226 struct gapCalc *gapCalc = gapCalcRead(lf); 00227 lineFileClose(&lf); 00228 return gapCalc; 00229 }
Here is the call graph for this function:

Here is the caller graph for this function:

| struct gapCalc* gapCalcOriginal | ( | ) | [read] |
Definition at line 273 of file gapCalc.c.
References gapCalcFromString(), and originalGapCosts.
00275 { 00276 return gapCalcFromString(originalGapCosts); 00277 }
Here is the call graph for this function:

Definition at line 144 of file gapCalc.c.
References AllocArray, AllocVar, gapCalc::bSmall, interpolate(), gapCalc::qSmall, readTaggedNumLine(), gapCalc::smallSize, and gapCalc::tSmall.
Referenced by gapCalcFromFile(), and gapCalcFromString().
00146 { 00147 int i, tableSize, startLong = -1; 00148 struct gapCalc *gapCalc; 00149 int *gapInitPos; 00150 double *gapInitQGap; 00151 double *gapInitTGap; 00152 double *gapInitBothGap; 00153 00154 AllocVar(gapCalc); 00155 00156 /* Parse file. */ 00157 readTaggedNumLine(lf, "tableSize", 1, &tableSize, NULL); 00158 readTaggedNumLine(lf, "smallSize", 1, &gapCalc->smallSize, NULL); 00159 AllocArray(gapInitPos,tableSize); 00160 AllocArray(gapInitQGap,tableSize); 00161 AllocArray(gapInitTGap,tableSize); 00162 AllocArray(gapInitBothGap,tableSize); 00163 readTaggedNumLine(lf, "position", tableSize, gapInitPos, NULL); 00164 readTaggedNumLine(lf, "qGap", tableSize, NULL, gapInitQGap); 00165 readTaggedNumLine(lf, "tGap", tableSize, NULL, gapInitTGap); 00166 readTaggedNumLine(lf, "bothGap", tableSize, NULL, gapInitBothGap); 00167 00168 /* Set up precomputed interpolations for small gaps. */ 00169 AllocArray(gapCalc->qSmall, gapCalc->smallSize); 00170 AllocArray(gapCalc->tSmall, gapCalc->smallSize); 00171 AllocArray(gapCalc->bSmall, gapCalc->smallSize); 00172 for (i=1; i<gapCalc->smallSize; ++i) 00173 { 00174 gapCalc->qSmall[i] = 00175 interpolate(i, gapInitPos, gapInitQGap, tableSize); 00176 gapCalc->tSmall[i] = 00177 interpolate(i, gapInitPos, gapInitTGap, tableSize); 00178 gapCalc->bSmall[i] = interpolate(i, gapInitPos, 00179 gapInitBothGap, tableSize); 00180 } 00181 00182 /* Set up to handle intermediate values. */ 00183 for (i=0; i<tableSize; ++i) 00184 { 00185 if (gapCalc->smallSize == gapInitPos[i]) 00186 { 00187 startLong = i; 00188 break; 00189 } 00190 } 00191 if (startLong < 0) 00192 errAbort("No position %d in gapCalcRead()\n", gapCalc->smallSize); 00193 gapCalc->longCount = tableSize - startLong; 00194 gapCalc->qPosCount = tableSize - startLong; 00195 gapCalc->tPosCount = tableSize - startLong; 00196 gapCalc->bPosCount = tableSize - startLong; 00197 gapCalc->longPos = cloneMem(gapInitPos + startLong, gapCalc->longCount * sizeof(int)); 00198 gapCalc->qLong = cloneMem(gapInitQGap + startLong, gapCalc->qPosCount * sizeof(double)); 00199 gapCalc->tLong = cloneMem(gapInitTGap + startLong, gapCalc->tPosCount * sizeof(double)); 00200 gapCalc->bLong = cloneMem(gapInitBothGap + startLong, gapCalc->bPosCount * sizeof(double)); 00201 00202 /* Set up to handle huge values. */ 00203 gapCalc->qLastPos = gapCalc->longPos[gapCalc->qPosCount-1]; 00204 gapCalc->tLastPos = gapCalc->longPos[gapCalc->tPosCount-1]; 00205 gapCalc->bLastPos = gapCalc->longPos[gapCalc->bPosCount-1]; 00206 gapCalc->qLastPosVal = gapCalc->qLong[gapCalc->qPosCount-1]; 00207 gapCalc->tLastPosVal = gapCalc->tLong[gapCalc->tPosCount-1]; 00208 gapCalc->bLastPosVal = gapCalc->bLong[gapCalc->bPosCount-1]; 00209 gapCalc->qLastSlope = calcSlope(gapCalc->qLastPosVal, gapCalc->qLong[gapCalc->qPosCount-2], 00210 gapCalc->qLastPos, gapCalc->longPos[gapCalc->qPosCount-2]); 00211 gapCalc->tLastSlope = calcSlope(gapCalc->tLastPosVal, gapCalc->tLong[gapCalc->tPosCount-2], 00212 gapCalc->tLastPos, gapCalc->longPos[gapCalc->tPosCount-2]); 00213 gapCalc->bLastSlope = calcSlope(gapCalc->bLastPosVal, gapCalc->bLong[gapCalc->bPosCount-2], 00214 gapCalc->bLastPos, gapCalc->longPos[gapCalc->bPosCount-2]); 00215 freez(&gapInitPos); 00216 freez(&gapInitQGap); 00217 freez(&gapInitTGap); 00218 freez(&gapInitBothGap); 00219 return gapCalc; 00220 }
Here is the call graph for this function:

Here is the caller graph for this function:

| struct gapCalc* gapCalcRnaDna | ( | ) | [read] |
Definition at line 261 of file gapCalc.c.
References gapCalcFromString(), and rnaDnaGapCosts.
00263 { 00264 return gapCalcFromString(rnaDnaGapCosts); 00265 }
Here is the call graph for this function:

| char* gapCalcSampleFileContents | ( | ) |
Definition at line 74 of file gapCalc.c.
References defaultGapCosts.
00076 { 00077 return defaultGapCosts; 00078 }
| void gapCalcTest | ( | struct gapCalc * | gapCalc | ) |
Definition at line 331 of file gapCalc.c.
References gapCalcCost(), and verbose().
00333 { 00334 int i; 00335 for (i=1; i<=10; i++) 00336 { 00337 verbose(1, "%d: %d %d %d\n", i, gapCalcCost(gapCalc, i, 0), 00338 gapCalcCost(gapCalc, 0, i), gapCalcCost(gapCalc, i/2, i-i/2)); 00339 } 00340 for (i=1; ; i *= 10) 00341 { 00342 verbose(1, "%d: %d %d %d\n", i, gapCalcCost(gapCalc, i, 0), gapCalcCost(gapCalc, 0, i), 00343 gapCalcCost(gapCalc, i/2, i-i/2)); 00344 if (i == 1000000000) 00345 break; 00346 } 00347 verbose(1, "%d %d cost %d\n", 6489540, 84240, gapCalcCost(gapCalc, 84240, 6489540)); 00348 verbose(1, "%d %d cost %d\n", 2746361, 1075188, gapCalcCost(gapCalc, 1075188, 2746361)); 00349 verbose(1, "%d %d cost %d\n", 6489540 + 2746361 + 72, 84240 + 1075188 + 72, gapCalcCost(gapCalc, 84240 + 1075188 + 72, 6489540 + 2746361 + 72)); 00350 }
Here is the call graph for this function:

| static int interpolate | ( | int | x, | |
| int * | s, | |||
| double * | v, | |||
| int | sCount | |||
| ) | [static] |
Definition at line 80 of file gapCalc.c.
Referenced by gapCalcCost(), and gapCalcRead().
00083 { 00084 int i, ds, ss; 00085 double dv; 00086 for (i=0; i<sCount; ++i) 00087 { 00088 ss = s[i]; 00089 if (x == ss) 00090 return v[i]; 00091 else if (x < ss) 00092 { 00093 ds = ss - s[i-1]; 00094 dv = v[i] - v[i-1]; 00095 return v[i-1] + dv * (x - s[i-1]) / ds; 00096 } 00097 } 00098 /* If get to here extrapolate from last two values */ 00099 ds = s[sCount-1] - s[sCount-2]; 00100 dv = v[sCount-1] - v[sCount-2]; 00101 return v[sCount-2] + dv * (x - s[sCount-2]) / ds; 00102 }
Here is the caller graph for this function:

| static void readTaggedNumLine | ( | struct lineFile * | lf, | |
| char * | tag, | |||
| int | count, | |||
| int * | intOut, | |||
| double * | floatOut | |||
| ) | [static] |
Definition at line 110 of file gapCalc.c.
References errAbort(), lineFileNextReal(), lineFileUnexpectedEnd(), nextWord(), and sameWord.
Referenced by gapCalcRead().
00116 { 00117 char *line; 00118 int i = 0; 00119 char *word; 00120 if (!lineFileNextReal(lf, &line)) 00121 lineFileUnexpectedEnd(lf); 00122 word = nextWord(&line); 00123 if (!sameWord(tag, word)) 00124 errAbort("Expecting %s got %s line %d of %s", 00125 tag, word, lf->lineIx, lf->fileName); 00126 for (i = 0; i < count; ++i) 00127 { 00128 word = nextWord(&line); 00129 if (word == NULL) 00130 errAbort("Not enough numbers line %d of %s", lf->lineIx, lf->fileName); 00131 if (!isdigit(word[0])) 00132 errAbort("Expecting number got %s line %d of %s", 00133 word, lf->lineIx, lf->fileName); 00134 if (intOut) 00135 intOut[i] = atoi(word); 00136 if (floatOut) 00137 floatOut[i] = atof(word); 00138 } 00139 word = nextWord(&line); 00140 if (word != NULL) 00141 errAbort("Too many numbers line %d of %s", lf->lineIx, lf->fileName); 00142 }
Here is the call graph for this function:

Here is the caller graph for this function:

char* cheapGapCosts [static] |
Initial value:
"tableSize 3\n"
"smallSize 100\n"
"position 1 100 1000\n"
"qGap 0 30 300\n"
"tGap 0 30 300\n"
"bothGap 0 30 300\n"
Definition at line 65 of file gapCalc.c.
Referenced by gapCalcCheap().
char* defaultGapCosts [static] |
Initial value:
"tablesize 11\n" "smallSize 111\n" "position 1 2 3 11 111 2111 12111 32111 72111 152111 252111\n" "qGap 325 360 400 450 600 1100 3600 7600 15600 31600 56600\n" "tGap 325 360 400 450 600 1100 3600 7600 15600 31600 56600\n" "bothGap 625 660 700 750 900 1400 4000 8000 16000 32000 57000\n"
Definition at line 48 of file gapCalc.c.
Referenced by gapCalcDefault(), gapCalcFromFile(), and gapCalcSampleFileContents().
char* originalGapCosts [static] |
Initial value:
"tableSize 11\n"
"smallSize 111\n"
"position 1 2 3 11 111 2111 12111 32111 72111 152111 252111\n"
"qGap 350 425 450 600 900 2900 22900 57900 117900 217900 317900\n"
"tGap 350 425 450 600 900 2900 22900 57900 117900 217900 317900\n"
"bothGap 750 825 850 1000 1300 3300 23300 58300 118300 218300 318300\n"
Definition at line 38 of file gapCalc.c.
Referenced by gapCalcFromFile(), and gapCalcOriginal().
char const rcsid[] = "$Id: gapCalc.c,v 1.4 2006/06/18 23:09:36 kate Exp $" [static] |
char* rnaDnaGapCosts [static] |
Initial value:
"tablesize 12\n" "smallSize 111\n" "position 1 2 3 11 31 111 2111 12111 32111 72111 152111 252111\n" "qGap 325 360 400 450 600 800 1100 3600 7600 15600 31600 56600\n" "tGap 200 210 220 250 300 400 500 600 800 1200 2000 4000\n" " bothGap 625 660 700 750 900 1100 1400 4000 8000 16000 32000 57000\n"
Definition at line 57 of file gapCalc.c.
Referenced by gapCalcRnaDna().
1.5.2