lib/xAli.c

Go to the documentation of this file.
00001 /* xAli.c was originally generated by the autoSql program, which also 
00002  * generated xAli.h and xAli.sql.  This module links the database and
00003  * the RAM representation of objects. */
00004 
00005 #include "common.h"
00006 #include "linefile.h"
00007 #include "dystring.h"
00008 #include "sqlNum.h"
00009 #include "sqlList.h"
00010 #include "xAli.h"
00011 
00012 static char const rcsid[] = "$Id: xAli.c,v 1.6 2005/04/10 14:41:26 markd Exp $";
00013 
00014 struct xAli *xAliLoad(char **row)
00015 /* Load a xAli from row fetched with select * from xAli
00016  * from database.  Dispose of this with xAliFree(). */
00017 {
00018 struct xAli *ret;
00019 int sizeOne;
00020 
00021 AllocVar(ret);
00022 ret->blockCount = sqlUnsigned(row[17]);
00023 ret->match = sqlUnsigned(row[0]);
00024 ret->misMatch = sqlUnsigned(row[1]);
00025 ret->repMatch = sqlUnsigned(row[2]);
00026 ret->nCount = sqlUnsigned(row[3]);
00027 ret->qNumInsert = sqlUnsigned(row[4]);
00028 ret->qBaseInsert = sqlSigned(row[5]);
00029 ret->tNumInsert = sqlUnsigned(row[6]);
00030 ret->tBaseInsert = sqlSigned(row[7]);
00031 strcpy(ret->strand, row[8]);
00032 ret->qName = cloneString(row[9]);
00033 ret->qSize = sqlUnsigned(row[10]);
00034 ret->qStart = sqlUnsigned(row[11]);
00035 ret->qEnd = sqlUnsigned(row[12]);
00036 ret->tName = cloneString(row[13]);
00037 ret->tSize = sqlUnsigned(row[14]);
00038 ret->tStart = sqlUnsigned(row[15]);
00039 ret->tEnd = sqlUnsigned(row[16]);
00040 sqlUnsignedDynamicArray(row[18], &ret->blockSizes, &sizeOne);
00041 assert(sizeOne == ret->blockCount);
00042 sqlUnsignedDynamicArray(row[19], &ret->qStarts, &sizeOne);
00043 assert(sizeOne == ret->blockCount);
00044 sqlUnsignedDynamicArray(row[20], &ret->tStarts, &sizeOne);
00045 assert(sizeOne == ret->blockCount);
00046 sqlStringDynamicArray(row[21], &ret->qSeq, &sizeOne);
00047 assert(sizeOne == ret->blockCount);
00048 sqlStringDynamicArray(row[22], &ret->tSeq, &sizeOne);
00049 assert(sizeOne == ret->blockCount);
00050 return ret;
00051 }
00052 
00053 struct xAli *xAliLoadAll(char *fileName) 
00054 /* Load all xAli from a tab-separated file.
00055  * Dispose of this with xAliFreeList(). */
00056 {
00057 struct xAli *list = NULL, *el;
00058 struct lineFile *lf = lineFileOpen(fileName, TRUE);
00059 char *row[23];
00060 
00061 while (lineFileRow(lf, row))
00062     {
00063     el = xAliLoad(row);
00064     slAddHead(&list, el);
00065     }
00066 lineFileClose(&lf);
00067 slReverse(&list);
00068 return list;
00069 }
00070 
00071 struct xAli *xAliCommaIn(char **pS, struct xAli *ret)
00072 /* Create a xAli out of a comma separated string. 
00073  * This will fill in ret if non-null, otherwise will
00074  * return a new xAli */
00075 {
00076 char *s = *pS;
00077 int i;
00078 
00079 if (ret == NULL)
00080     AllocVar(ret);
00081 ret->match = sqlUnsignedComma(&s);
00082 ret->misMatch = sqlUnsignedComma(&s);
00083 ret->repMatch = sqlUnsignedComma(&s);
00084 ret->nCount = sqlUnsignedComma(&s);
00085 ret->qNumInsert = sqlUnsignedComma(&s);
00086 ret->qBaseInsert = sqlSignedComma(&s);
00087 ret->tNumInsert = sqlUnsignedComma(&s);
00088 ret->tBaseInsert = sqlSignedComma(&s);
00089 sqlFixedStringComma(&s, ret->strand, sizeof(ret->strand));
00090 ret->qName = sqlStringComma(&s);
00091 ret->qSize = sqlUnsignedComma(&s);
00092 ret->qStart = sqlUnsignedComma(&s);
00093 ret->qEnd = sqlUnsignedComma(&s);
00094 ret->tName = sqlStringComma(&s);
00095 ret->tSize = sqlUnsignedComma(&s);
00096 ret->tStart = sqlUnsignedComma(&s);
00097 ret->tEnd = sqlUnsignedComma(&s);
00098 ret->blockCount = sqlUnsignedComma(&s);
00099 s = sqlEatChar(s, '{');
00100 AllocArray(ret->blockSizes, ret->blockCount);
00101 for (i=0; i<ret->blockCount; ++i)
00102     {
00103     ret->blockSizes[i] = sqlUnsignedComma(&s);
00104     }
00105 s = sqlEatChar(s, '}');
00106 s = sqlEatChar(s, ',');
00107 s = sqlEatChar(s, '{');
00108 AllocArray(ret->qStarts, ret->blockCount);
00109 for (i=0; i<ret->blockCount; ++i)
00110     {
00111     ret->qStarts[i] = sqlUnsignedComma(&s);
00112     }
00113 s = sqlEatChar(s, '}');
00114 s = sqlEatChar(s, ',');
00115 s = sqlEatChar(s, '{');
00116 AllocArray(ret->tStarts, ret->blockCount);
00117 for (i=0; i<ret->blockCount; ++i)
00118     {
00119     ret->tStarts[i] = sqlUnsignedComma(&s);
00120     }
00121 s = sqlEatChar(s, '}');
00122 s = sqlEatChar(s, ',');
00123 s = sqlEatChar(s, '{');
00124 AllocArray(ret->qSeq, ret->blockCount);
00125 for (i=0; i<ret->blockCount; ++i)
00126     {
00127     ret->qSeq[i] = sqlStringComma(&s);
00128     }
00129 s = sqlEatChar(s, '}');
00130 s = sqlEatChar(s, ',');
00131 s = sqlEatChar(s, '{');
00132 AllocArray(ret->tSeq, ret->blockCount);
00133 for (i=0; i<ret->blockCount; ++i)
00134     {
00135     ret->tSeq[i] = sqlStringComma(&s);
00136     }
00137 s = sqlEatChar(s, '}');
00138 s = sqlEatChar(s, ',');
00139 *pS = s;
00140 return ret;
00141 }
00142 
00143 void xAliFree(struct xAli **pEl)
00144 /* Free a single dynamically allocated xAli such as created
00145  * with xAliLoad(). */
00146 {
00147 struct xAli *el;
00148 
00149 if ((el = *pEl) == NULL) return;
00150 freeMem(el->qName);
00151 freeMem(el->tName);
00152 freeMem(el->blockSizes);
00153 freeMem(el->qStarts);
00154 freeMem(el->tStarts);
00155 /* All strings in qSeq are allocated at once, so only need to free first. */
00156 if (el->qSeq != NULL)
00157     freeMem(el->qSeq[0]);
00158 freeMem(el->qSeq);
00159 /* All strings in tSeq are allocated at once, so only need to free first. */
00160 if (el->tSeq != NULL)
00161     freeMem(el->tSeq[0]);
00162 freeMem(el->tSeq);
00163 freez(pEl);
00164 }
00165 
00166 void xAliFreeList(struct xAli **pList)
00167 /* Free a list of dynamically allocated xAli's */
00168 {
00169 struct xAli *el, *next;
00170 
00171 for (el = *pList; el != NULL; el = next)
00172     {
00173     next = el->next;
00174     xAliFree(&el);
00175     }
00176 *pList = NULL;
00177 }
00178 
00179 void xAliOutput(struct xAli *el, FILE *f, char sep, char lastSep) 
00180 /* Print out xAli.  Separate fields with sep. Follow last field with lastSep. */
00181 {
00182 int i;
00183 fprintf(f, "%u", el->match);
00184 fputc(sep,f);
00185 fprintf(f, "%u", el->misMatch);
00186 fputc(sep,f);
00187 fprintf(f, "%u", el->repMatch);
00188 fputc(sep,f);
00189 fprintf(f, "%u", el->nCount);
00190 fputc(sep,f);
00191 fprintf(f, "%u", el->qNumInsert);
00192 fputc(sep,f);
00193 fprintf(f, "%d", el->qBaseInsert);
00194 fputc(sep,f);
00195 fprintf(f, "%u", el->tNumInsert);
00196 fputc(sep,f);
00197 fprintf(f, "%d", el->tBaseInsert);
00198 fputc(sep,f);
00199 if (sep == ',') fputc('"',f);
00200 fprintf(f, "%s", el->strand);
00201 if (sep == ',') fputc('"',f);
00202 fputc(sep,f);
00203 if (sep == ',') fputc('"',f);
00204 fprintf(f, "%s", el->qName);
00205 if (sep == ',') fputc('"',f);
00206 fputc(sep,f);
00207 fprintf(f, "%u", el->qSize);
00208 fputc(sep,f);
00209 fprintf(f, "%u", el->qStart);
00210 fputc(sep,f);
00211 fprintf(f, "%u", el->qEnd);
00212 fputc(sep,f);
00213 if (sep == ',') fputc('"',f);
00214 fprintf(f, "%s", el->tName);
00215 if (sep == ',') fputc('"',f);
00216 fputc(sep,f);
00217 fprintf(f, "%u", el->tSize);
00218 fputc(sep,f);
00219 fprintf(f, "%u", el->tStart);
00220 fputc(sep,f);
00221 fprintf(f, "%u", el->tEnd);
00222 fputc(sep,f);
00223 fprintf(f, "%u", el->blockCount);
00224 fputc(sep,f);
00225 if (sep == ',') fputc('{',f);
00226 for (i=0; i<el->blockCount; ++i)
00227     {
00228     fprintf(f, "%u", el->blockSizes[i]);
00229     fputc(',', f);
00230     }
00231 if (sep == ',') fputc('}',f);
00232 fputc(sep,f);
00233 if (sep == ',') fputc('{',f);
00234 for (i=0; i<el->blockCount; ++i)
00235     {
00236     fprintf(f, "%u", el->qStarts[i]);
00237     fputc(',', f);
00238     }
00239 if (sep == ',') fputc('}',f);
00240 fputc(sep,f);
00241 if (sep == ',') fputc('{',f);
00242 for (i=0; i<el->blockCount; ++i)
00243     {
00244     fprintf(f, "%u", el->tStarts[i]);
00245     fputc(',', f);
00246     }
00247 if (sep == ',') fputc('}',f);
00248 fputc(sep,f);
00249 if (sep == ',') fputc('{',f);
00250 for (i=0; i<el->blockCount; ++i)
00251     {
00252     if (sep == ',') fputc('"',f);
00253     fprintf(f, "%s", el->qSeq[i]);
00254     if (sep == ',') fputc('"',f);
00255     fputc(',', f);
00256     }
00257 if (sep == ',') fputc('}',f);
00258 fputc(sep,f);
00259 if (sep == ',') fputc('{',f);
00260 for (i=0; i<el->blockCount; ++i)
00261     {
00262     if (sep == ',') fputc('"',f);
00263     fprintf(f, "%s", el->tSeq[i]);
00264     if (sep == ',') fputc('"',f);
00265     fputc(',', f);
00266     }
00267 if (sep == ',') fputc('}',f);
00268 fputc(lastSep,f);
00269 }
00270 
00271 /* --------------------Start of human generated code. -------------------- */
00272 
00273 struct xAli *xAliNext(struct lineFile *lf)
00274 /* Read next line from file and convert it to xAli.  Return
00275  * NULL at eof. */
00276 {
00277 char *row[23];
00278 if (!lineFileRow(lf, row))
00279     return NULL;
00280 return xAliLoad(row);
00281 }

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