lib/ffAli.c

Go to the documentation of this file.
00001 /* Some relatively small utility functions that act on ffAlis.
00002  * (Separated from fuzzyFinder.c so people can do light ffAli 
00003  * work without including 100k of fuzzyFinder object code.) 
00004  *
00005  * This file is copyright 2002 Jim Kent, but license is hereby
00006  * granted for all use - public, private or commercial. */
00007 
00008 #include "common.h"
00009 #include "dnautil.h"
00010 #include "fuzzyFind.h"
00011 
00012 static char const rcsid[] = "$Id: ffAli.c,v 1.9 2004/02/13 09:33:32 kent Exp $";
00013 
00014 void ffFreeAli(struct ffAli **pAli)
00015 /* Dispose of memory gotten from fuzzyFind(). */
00016 {
00017 struct ffAli *ali = *pAli;
00018 if (ali != NULL)
00019     {
00020     while (ali->right)
00021         ali = ali->right;
00022     slFreeList(&ali);
00023     }
00024 *pAli = NULL;
00025 }
00026 
00027 int ffOneIntronOrientation(struct ffAli *left, struct ffAli *right)
00028 /* Return 1 for GT/AG intron between left and right, -1 for CT/AC, 0 for no
00029  * intron. */
00030 {
00031 if (left->nEnd != right->nStart)
00032     return 0;
00033 return intronOrientation(left->hEnd, right->hStart);
00034 }
00035 
00036 int ffIntronOrientation(struct ffAli *ali)
00037 /* Return + for positive orientation overall, - for negative,
00038  * 0 if can't tell. */
00039 {
00040 struct ffAli *left = ali, *right;
00041 int orient = 0;
00042 
00043 if (left != NULL)
00044     {
00045     while((right = left->right) != NULL)
00046         {
00047         orient += intronOrientation(left->hEnd, right->hStart);
00048         left = right;
00049         }
00050     }
00051 return orient;
00052 }
00053 
00054 struct ffAli *ffRightmost(struct ffAli *ff)
00055 /* Return rightmost block of alignment. */
00056 {
00057 while (ff->right != NULL)
00058     ff = ff->right;
00059 return ff;
00060 }
00061 
00062 struct ffAli *ffMakeRightLinks(struct ffAli *rightMost)
00063 /* Given a pointer to the rightmost block in an alignment
00064  * which has all of the left pointers filled in, fill in
00065  * the right pointers and return the leftmost block. */
00066 {
00067 struct ffAli *ff, *last = NULL;
00068 
00069 for (ff = rightMost; ff != NULL; ff = ff->left)
00070     {
00071     ff->right = last;
00072     last = ff;
00073     }
00074 return last;
00075 }
00076 
00077 
00078 static int countGoodStart(struct ffAli *ali)
00079 /* Return number of perfect matchers at start. */
00080 {
00081 DNA *n = ali->nStart;
00082 DNA *h = ali->hStart;
00083 int count = ali->nEnd - ali->nStart;
00084 int i;
00085 for (i=0; i<count; ++i)
00086     {
00087     if (*n++ != *h++)
00088         break;
00089     }
00090 return i;
00091 }
00092 
00093 static int countGoodEnd(struct ffAli *ali)
00094 /* Return number of perfect matchers at start. */
00095 {
00096 DNA *n = ali->nEnd;
00097 DNA *h = ali->hEnd;
00098 int count = ali->nEnd - ali->nStart;
00099 int i;
00100 for (i=0; i<count; ++i)
00101     {
00102     if (*--n != *--h)
00103         break;
00104     }
00105 return i;
00106 }
00107 
00108 void ffCountGoodEnds(struct ffAli *aliList)
00109 /* Fill in the goodEnd and badEnd scores. */
00110 {
00111 struct ffAli *ali;
00112 for (ali = aliList; ali != NULL; ali = ali->right)
00113     {
00114     ali->startGood = countGoodStart(ali);
00115     ali->endGood = countGoodEnd(ali);
00116     }
00117 }
00118 
00119 int ffAliCount(struct ffAli *d)
00120 /* How many blocks in alignment? */
00121 {
00122 int acc = 0;
00123 while (d != NULL)
00124     {
00125     ++acc;
00126     d = d->right;
00127     }
00128 return acc;
00129 }
00130 
00131 struct ffAli *ffAliFromSym(int symCount, char *nSym, char *hSym,
00132         struct lm *lm, char *nStart, char *hStart)
00133 /* Convert symbol representation of alignments (letters plus '-')
00134  * to ffAli representation.  If lm is nonNULL, ffAli result 
00135  * will be lmAlloced, else it will be needMemed. This routine
00136  * depends on nSym/hSym being zero terminated. */
00137 {
00138 struct ffAli *ffList = NULL, *ff = NULL;
00139 char n, h;
00140 int i;
00141 
00142 for (i=0; i<=symCount; ++i)
00143     {
00144     boolean isGap;
00145     n = nSym[i];
00146     h = hSym[i];
00147     isGap = (n == '-' || n == 0 || h == '-' || h == 0);
00148     if (isGap)
00149         {
00150         if (ff != NULL)
00151             {
00152             ff->nEnd = nStart;
00153             ff->hEnd = hStart;
00154             ff->left = ffList;
00155             ffList = ff;
00156             ff = NULL;
00157             }
00158         }
00159     else
00160         {
00161         if (ff == NULL)
00162             {
00163             if (lm != NULL)
00164                 {
00165                 lmAllocVar(lm, ff);
00166                 }
00167             else
00168                 {
00169                 AllocVar(ff);
00170                 }
00171             ff->nStart = nStart;
00172             ff->hStart = hStart;
00173             }
00174         }
00175     if (n != '-')
00176         {
00177         ++nStart;
00178         }
00179     if (h != '-')
00180         {
00181         ++hStart;
00182         }
00183     }
00184 ffList = ffMakeRightLinks(ffList);
00185 return ffList;
00186 }

Generated on Tue Dec 25 18:39:30 2007 for blat by  doxygen 1.5.2