src/hg/lib/chainDb.c 1.13

1.13 2009/09/24 23:15:44 hiram
Settle on a single function to determine chainNormScoreDb()
Index: src/hg/lib/chainDb.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/chainDb.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -b -B -U 1000000 -r1.12 -r1.13
--- src/hg/lib/chainDb.c	3 Sep 2008 19:19:19 -0000	1.12
+++ src/hg/lib/chainDb.c	24 Sep 2009 23:15:44 -0000	1.13
@@ -1,187 +1,164 @@
 /* chainDb.c was originally generated by the autoSql program, which also 
  * generated chainDb.h and chainDb.sql.  This module links the database and
  * the RAM representation of objects. 
  *
  * This module was subsequently modified to blend better with the non-database
  * representation of chains.  This module really only deals with the chain
  * header in the database.  The blocks of the chain are loaded elsewhere,
  * and indeed in another table. */
 
 #include "common.h"
 #include "linefile.h"
 #include "dystring.h"
 #include "jksql.h"
 #include "chain.h"
 #include "chainDb.h"
 #include "hdb.h"
 
 static char const rcsid[] = "$Id$";
 
 void chainHeadStaticLoad(char **row, struct chain *ret)
 /* Load a row from chain table into ret.  The contents of ret will
  * be replaced at the next call to this function. */
 {
 
 ret->score = atof(row[0]);
 ret->tName = row[1];
 ret->tSize = sqlUnsigned(row[2]);
 ret->tStart = sqlUnsigned(row[3]);
 ret->tEnd = sqlUnsigned(row[4]);
 ret->qName = row[5];
 ret->qSize = sqlUnsigned(row[6]);
 ret->qStrand = row[7][0];
 ret->qStart = sqlUnsigned(row[8]);
 ret->qEnd = sqlUnsigned(row[9]);
 ret->id = sqlUnsigned(row[10]);
 }
 
 struct chain *chainHeadLoad(char **row)
 /* Load a chain from row fetched with select * from chain
  * from database.  Dispose of this with chainFree(). */
 {
 struct chain *ret;
 
 AllocVar(ret);
 ret->score = atof(row[0]);
 ret->tName = cloneString(row[1]);
 ret->tSize = sqlUnsigned(row[2]);
 ret->tStart = sqlUnsigned(row[3]);
 ret->tEnd = sqlUnsigned(row[4]);
 ret->qName = cloneString(row[5]);
 ret->qSize = sqlUnsigned(row[6]);
 ret->qStrand = row[7][0];
 ret->qStart = sqlUnsigned(row[8]);
 ret->qEnd = sqlUnsigned(row[9]);
 ret->id = sqlUnsigned(row[10]);
 return ret;
 }
 
 struct chain *chainHeadLoadAll(char *fileName) 
 /* Load all chain from a tab-separated file.
  * Dispose of this with chainFreeList(). */
 {
 struct chain *list = NULL, *el;
 struct lineFile *lf = lineFileOpen(fileName, TRUE);
 char *row[11];
 
 while (lineFileRow(lf, row))
     {
     el = chainHeadLoad(row);
     slAddHead(&list, el);
     }
 lineFileClose(&lf);
 slReverse(&list);
 return list;
 }
 
 struct chain *chainHeadCommaIn(char **pS, struct chain *ret)
 /* Create a chain out of a comma separated string. 
  * This will fill in ret if non-null, otherwise will
  * return a new chain */
 {
 char *s = *pS;
 
 if (ret == NULL)
     AllocVar(ret);
 ret->score = sqlDoubleComma(&s);
 ret->tName = sqlStringComma(&s);
 ret->tSize = sqlUnsignedComma(&s);
 ret->tStart = sqlUnsignedComma(&s);
 ret->tEnd = sqlUnsignedComma(&s);
 ret->qName = sqlStringComma(&s);
 ret->qSize = sqlUnsignedComma(&s);
 sqlFixedStringComma(&s, &(ret->qStrand), sizeof(ret->qStrand));
 ret->qStart = sqlUnsignedComma(&s);
 ret->qEnd = sqlUnsignedComma(&s);
 ret->id = sqlUnsignedComma(&s);
 *pS = s;
 return ret;
 }
 
 void chainHeadOutput(struct chain *el, FILE *f, char sep, char lastSep) 
 /* Print out chain.  Separate fields with sep. Follow last field with lastSep. */
 {
 fprintf(f, "%f", el->score);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
 fprintf(f, "%s", el->tName);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 fprintf(f, "%u", el->tSize);
 fputc(sep,f);
 fprintf(f, "%u", el->tStart);
 fputc(sep,f);
 fprintf(f, "%u", el->tEnd);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
 fprintf(f, "%s", el->qName);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 fprintf(f, "%u", el->qSize);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
 fprintf(f, "%c", el->qStrand);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 fprintf(f, "%u", el->qStart);
 fputc(sep,f);
 fprintf(f, "%u", el->qEnd);
 fputc(sep,f);
 fprintf(f, "%u", el->id);
 fputc(lastSep,f);
 }
 
 /* -------------------------------- End autoSql Generated Code -------------------------------- */
 
 void chainDbAddBlocks(struct chain *chain, char *track, struct sqlConnection *conn)
 /* Add blocks to chain header. */
 {
 struct dyString *query = newDyString(1024);
 struct sqlResult *sr = NULL;
 char **row;
 struct cBlock *b;
 char fullName[64];
 
 safef(fullName, sizeof(fullName), "%s_%s", chain->tName, track);
 if (!sqlTableExists(conn, fullName))
     strcpy(fullName, track);
 dyStringPrintf(query, 
 	"select tStart,tEnd,qStart from %sLink where chainId = %d",fullName, chain->id);
 
 sr = sqlGetResult(conn, query->string);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     AllocVar(b);
     b->tStart = sqlUnsigned(row[0]);
     b->tEnd = sqlUnsigned(row[1]);
     b->qStart = sqlUnsigned(row[2]);
     b->qEnd = b->qStart + (b->tEnd - b->tStart);
     slAddHead(&chain->blockList, b);
     }
 slReverse(&chain->blockList);
 sqlFreeResult(&sr);
 dyStringFree(&query);
 }
-
-boolean chainDbNormScoreAvailable(char *db, char *chromName, char *mapName,
-	char **foundTable)
-/*	check if normScore column is available in this table	*/
-{
-boolean normScoreAvailable = FALSE;
-char tableName[HDB_MAX_TABLE_STRING];
-boolean hasBin;
-
-/*      find out if the optional normScore column exists */
-if (hFindSplitTable(db, chromName, mapName, tableName, &hasBin))
-    {
-    struct sqlConnection *conn = hAllocConn(db);
-    int tblIx = sqlFieldIndex(conn, tableName, "normScore");
-    normScoreAvailable = (tblIx > -1) ? TRUE : FALSE;
-    hFreeConn(&conn);
-    }   
-
-if (normScoreAvailable && foundTable)
-	*foundTable = cloneString(tableName);
-
-return normScoreAvailable;
-}