inc/pairHmm.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  phmmMommy
struct  phmmState
struct  phmmMatrix

Defines

#define phmmPackMommy(stateIx, qOff, tOff)   ((UBYTE)((stateIx) + ((-(qOff))<<5) + ((-(tOff))<<6)))
#define phmmMommyTraceBit   (1<<7)

Functions

phmmMatrixphmmMatrixNew (int stateCount, char *query, int querySize, char *target, int targetSize)
void phmmMatrixFree (struct phmmMatrix **pAm)
phmmStatephmmNameState (struct phmmMatrix *am, int stateIx, char *name, char emitLetter)
phmmAliPairphmmTraceBack (struct phmmMatrix *am, struct phmmMommy *end)
void phmmPrintTrace (struct phmmMatrix *am, struct phmmAliPair *pairList, boolean showStates, FILE *f, boolean extraAtEnds)
axtphhmTraceToAxt (struct phmmMatrix *am, struct phmmAliPair *pairList, int score, char *qName, char *tName)

Variables

UBYTE phmmNullMommy


Define Documentation

#define phmmMommyTraceBit   (1<<7)

Definition at line 29 of file pairHmm.h.

Referenced by phmmTraceBack().

#define phmmPackMommy ( stateIx,
qOff,
tOff   )     ((UBYTE)((stateIx) + ((-(qOff))<<5) + ((-(tOff))<<6)))

Definition at line 26 of file pairHmm.h.


Function Documentation

struct axt* phhmTraceToAxt ( struct phmmMatrix am,
struct phmmAliPair pairList,
int  score,
char *  qName,
char *  tName 
) [read]

Definition at line 304 of file pairHmm.c.

References AllocArray, AllocVar, cloneString(), phmmAliPair::next, axt::qEnd, axt::qName, axt::qStart, axt::qStrand, axt::qSym, phmmAliPair::queryIx, phmmAliPair::querySym, axt::score, slCount(), axt::symCount, phmmAliPair::targetIx, phmmAliPair::targetSym, axt::tEnd, axt::tName, axt::tStart, axt::tStrand, and axt::tSym.

Referenced by axtAffine().

00307 {
00308 struct axt *axt;
00309 struct phmmAliPair *pair;
00310 int qEnd, tEnd;
00311 char *qSym, *tSym;
00312 int i;
00313 
00314 /* Make sure got something real. */
00315 if ((pair = pairList) == NULL)
00316     return NULL;
00317 
00318 /* Allocate memory for axt. */
00319 AllocVar(axt);
00320 axt->symCount = slCount(pairList);
00321 axt->qSym = AllocArray(qSym, axt->symCount+1);
00322 axt->tSym = AllocArray(tSym, axt->symCount+1);
00323 
00324 /* Fill in basic fields. */
00325 axt->qName = cloneString(qName);
00326 axt->tName = cloneString(tName);
00327 axt->qStrand = axt->tStrand = '+';
00328 axt->qStart = qEnd = pair->queryIx;
00329 axt->tStart = tEnd = pair->targetIx;
00330 axt->score = score;
00331 
00332 /* Store alignment symbols and keep track of last symbol used. */
00333 for (i=0, pair = pairList; pair != NULL; pair = pair->next, ++i)
00334     {
00335     qSym[i] = pair->querySym;
00336     tSym[i] = pair->targetSym;
00337     qEnd = pair->queryIx;
00338     tEnd = pair->targetIx;
00339     }
00340 
00341 /* Store end and return. */
00342 axt->qEnd = qEnd + 1;
00343 axt->tEnd = tEnd + 1;
00344 return axt;
00345 }

Here is the call graph for this function:

Here is the caller graph for this function:

void phmmMatrixFree ( struct phmmMatrix **  pAm  ) 

Definition at line 70 of file pairHmm.c.

References phmmMatrix::allCells, phmmMatrix::allScores, freeMem(), freez(), and phmmMatrix::states.

Referenced by axtAffine().

00073 {
00074 struct phmmMatrix *am = *pAm;
00075 if (am != NULL)
00076     {
00077     freeMem(am->states);
00078     freeMem(am->allCells);
00079     freeMem(am->allScores);
00080     freez(pAm);
00081     }
00082 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct phmmMatrix* phmmMatrixNew ( int  stateCount,
char *  query,
int  querySize,
char *  target,
int  targetSize 
) [read]

Definition at line 24 of file pairHmm.c.

References phmmMatrix::allCells, AllocVar, phmmMatrix::allScores, phmmState::cells, phmmState::lastScores, needLargeMem(), needMem(), phmmMatrix::qDim, phmmMatrix::query, phmmMatrix::querySize, phmmState::scores, phmmMatrix::stateByteSize, phmmMatrix::stateCount, phmmState::stateIx, phmmMatrix::states, phmmMatrix::stateSize, phmmMatrix::target, phmmMatrix::targetSize, and phmmMatrix::tDim.

Referenced by affineAlign(), and xenAlignSmall().

00027 {
00028 int i;
00029 struct phmmMommy *allCells;
00030 int allCellSize;
00031 int rowSize;
00032 int *allScores;
00033 struct phmmMatrix *am;
00034 
00035 AllocVar(am);
00036 am->query = query;
00037 am->target = target;
00038 am->querySize = querySize;
00039 am->targetSize = targetSize;
00040 am->qDim = rowSize = am->querySize + 1;
00041 am->tDim = am->targetSize + 1;
00042 am->stateCount = stateCount;
00043 am->stateSize = rowSize * am->tDim;
00044 am->stateByteSize = am->stateSize * sizeof(struct phmmMommy);
00045 am->states = needMem(stateCount * sizeof(struct phmmState));
00046 
00047 /* Initialize matrix of cells for each state. */
00048 allCellSize = stateCount * am->stateByteSize;
00049 am->allCells = allCells = needLargeMem(allCellSize); 
00050 memset(allCells, 0, allCellSize);
00051 for (i=0; i<stateCount; ++i)
00052     {
00053     am->states[i].cells = allCells;
00054     allCells += am->stateSize;
00055     am->states[i].stateIx = i;
00056     }
00057 
00058 /* Initialize two rows of scores for each state. */
00059 allScores = am->allScores = needMem(rowSize * 2 * stateCount * sizeof(int) );
00060 for (i=0; i<stateCount; ++i)
00061     {
00062     am->states[i].scores = allScores;
00063     allScores += rowSize;
00064     am->states[i].lastScores = allScores;
00065     allScores += rowSize;
00066     }
00067 return am;
00068 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct phmmState* phmmNameState ( struct phmmMatrix am,
int  stateIx,
char *  name,
char  emitLetter 
) [read]

Definition at line 84 of file pairHmm.c.

References phmmState::emitLetter, phmmState::name, and phmmMatrix::states.

Referenced by affineAlign(), and xenAlignSmall().

00087 {
00088 struct phmmState *state;
00089 assert(stateIx < am->stateCount);
00090 state = &am->states[stateIx];
00091 state->name = name;
00092 state->emitLetter = emitLetter;
00093 return state;
00094 }

Here is the caller graph for this function:

void phmmPrintTrace ( struct phmmMatrix am,
struct phmmAliPair pairList,
boolean  showStates,
FILE *  f,
boolean  extraAtEnds 
)

Definition at line 187 of file pairHmm.c.

References FALSE, phmmAliPair::hiddenSym, lineLen, phmmAliPair::next, phmmMatrix::query, phmmAliPair::queryIx, phmmMatrix::querySize, phmmAliPair::querySym, phmmMatrix::target, phmmAliPair::targetIx, phmmMatrix::targetSize, phmmAliPair::targetSym, and TRUE.

00190 {
00191 struct phmmAliPair *pair;
00192 #define lineLen 50
00193 char asyms[lineLen+1];
00194 char qsyms[lineLen+1];
00195 char tsyms[lineLen+1];
00196 char hsyms[lineLen+1];
00197 int lineIx = 0;
00198 int qs, ts;
00199 boolean gotQs = FALSE;
00200 
00201 if ((pair = pairList) == NULL)
00202     {
00203     fprintf(f, "Empty pair list\n");
00204     return;
00205     }
00206 
00207 qs = pair->queryIx;
00208 ts = pair->targetIx;
00209 
00210 /* Print out up to 25 bp of initial non-matching parts. */
00211 if (extraAtEnds)
00212     {
00213     int qStart = qs;
00214     int tStart = ts;
00215     int i;
00216 
00217     for (i= -25; i < 0; ++i)
00218         {
00219         int qIx = qStart + i;
00220         int tIx = tStart + i;
00221         qsyms[lineIx] = (qIx >= 0 ? am->query[qIx] : ' ');
00222         tsyms[lineIx] = (tIx >= 0 ? am->target[tIx] : ' ' );
00223         asyms[lineIx] = hsyms[lineIx] = ' ';
00224         if (qIx >= 0 || tIx >= 0)
00225             {
00226             ++lineIx;
00227             if (!gotQs)
00228                 {
00229                 gotQs = TRUE;
00230                 qs = qIx;
00231                 ts = tIx;
00232                 }
00233             }
00234         }
00235     }
00236 
00237 /* Print out matching parts */
00238 for (pair = pairList; pair != NULL; pair = pair->next)
00239     {
00240     qsyms[lineIx] = pair->querySym;
00241     tsyms[lineIx] = pair->targetSym;
00242     asyms[lineIx] = (pair->querySym == pair->targetSym ? '|' : ' ');
00243     hsyms[lineIx] = pair->hiddenSym;
00244     if (++lineIx == lineLen)
00245         {
00246         qsyms[lineIx] = asyms[lineIx] = tsyms[lineIx] = hsyms[lineIx] = 0;
00247         fprintf(f, "%5d %s\n", qs, qsyms);
00248         fprintf(f, "%5s %s\n", "", asyms);
00249         fprintf(f, "%5d %s\n", ts, tsyms);
00250         if (showStates)
00251             fprintf(f, "%5s %s\n", "", hsyms);
00252         fputc('\n', f);
00253         lineIx = 0;
00254         if (pair->next)
00255             {
00256             qs = pair->next->queryIx;
00257             ts = pair->next->targetIx;
00258             }
00259         }
00260     }
00261 
00262 /* Print out last bit - first get last pair. */
00263 if (extraAtEnds)
00264     {
00265     for (pair = pairList; pair->next != NULL; pair = pair->next)
00266         ;
00267 
00268         {
00269         int qIx, tIx, i;
00270         int residue = lineLen - lineIx;
00271         for (i=1; i<=residue; i++)
00272             {
00273             if ((qIx = pair->queryIx+i) >= am->querySize)
00274                 qsyms[lineIx] = ' ';
00275             else
00276                 qsyms[lineIx] = am->query[qIx];
00277             if ((tIx = pair->targetIx+i) >= am->targetSize)
00278                 tsyms[lineIx] = ' ';
00279             else
00280                 tsyms[lineIx] = am->target[tIx];
00281             asyms[lineIx] = ' ';
00282             hsyms[lineIx] = ' ';
00283             ++lineIx;
00284             assert(lineIx <= lineLen);
00285             }
00286         }
00287     }
00288 
00289 /* Print out anything not printed out yet. */
00290 if (lineIx != 0)
00291     {
00292     qsyms[lineIx] = asyms[lineIx] = tsyms[lineIx] = hsyms[lineIx] = 0;
00293     fprintf(f, "%5d %s\n", qs, qsyms);
00294     fprintf(f, "%5s %s\n", "", asyms);
00295     fprintf(f, "%5d %s\n", ts, tsyms);
00296     if (showStates)
00297         fprintf(f, "%5s %s\n", "", hsyms);
00298     fputc('\n', f);
00299     lineIx = 0;
00300     }
00301 #undef lineLen
00302 }

struct phmmAliPair* phmmTraceBack ( struct phmmMatrix am,
struct phmmMommy end 
) [read]

Definition at line 134 of file pairHmm.c.

References AllocVar, phmmMommy::mommy, phmmFindMatrixIx(), phmmFindMommy(), phmmMommyTraceBit, slAddHead, and UBYTE.

00137 {
00138 struct phmmAliPair *pairList = NULL, *pair;
00139 struct phmmMommy *cell, *parent = end;
00140 int parentSix, parentTix, parentQix;
00141 int sIx, tIx, qIx;
00142 
00143 phmmFindMatrixIx(am, parent, &parentSix, &parentQix, &parentTix);
00144 for (;;)
00145     {
00146     cell = parent;
00147     sIx = parentSix;
00148     tIx = parentTix;
00149     qIx = parentQix;
00150 
00151     if ((parent = phmmFindMommy(am, cell)) == NULL)
00152         break;
00153     phmmFindMatrixIx(am, parent, &parentSix, &parentQix, &parentTix);
00154     
00155     cell->mommy |= phmmMommyTraceBit;
00156 
00157     AllocVar(pair);
00158     pair->hiddenIx = (UBYTE)sIx;
00159     pair->hiddenSym = am->states[sIx].emitLetter; 
00160 
00161     if (parentQix == qIx - 1 && parentTix == tIx - 1 )
00162         {
00163         pair->queryIx = qIx-1;
00164         pair->querySym = am->query[qIx-1];
00165         pair->targetIx = tIx - 1;
00166         pair->targetSym = am->target[tIx-1];
00167         }
00168     else if (parentQix == qIx) /* && parentTix == tIx-1 */
00169         {
00170         pair->queryIx = -1;
00171         pair->querySym = '-';
00172         pair->targetIx = tIx-1;
00173         pair->targetSym = am->target[tIx-1];
00174         }
00175     else  /* parentTix == tIx  && parentQix == qIx-1 */
00176         {
00177         pair->queryIx = qIx-1;
00178         pair->querySym = am->query[qIx-1];
00179         pair->targetIx = -1;
00180         pair->targetSym = '-';
00181         }
00182     slAddHead(&pairList, pair);
00183     }
00184 return pairList;
00185 }

Here is the call graph for this function:


Variable Documentation

UBYTE phmmNullMommy

Definition at line 13 of file pairHmm.c.

Referenced by phmmFindMommy().


Generated on Tue Dec 25 19:09:37 2007 for blat by  doxygen 1.5.2