src/hg/instinct/raToDb/raToDb.c 1.8

1.8 2010/04/12 02:29:30 jsanborn
fixed sorting by priority
Index: src/hg/instinct/raToDb/raToDb.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/raToDb/raToDb.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -b -B -U 4 -r1.7 -r1.8
--- src/hg/instinct/raToDb/raToDb.c	11 Apr 2010 03:46:15 -0000	1.7
+++ src/hg/instinct/raToDb/raToDb.c	12 Apr 2010 02:29:30 -0000	1.8
@@ -531,9 +531,9 @@
 
 if (hashFindVal(raHash, "priority"))
     *(ra->priority) = atof(((char *) hashFindVal(raHash, "priority")));
 else
-    *(ra->priority) = 0.0;
+    *(ra->priority) = 10000.0;  // default, put at bottom. 
 
 if (hashFindVal(raHash, "height"))
     *(ra->height) = atoi(((char *) hashFindVal(raHash, "height")));
 else
@@ -570,8 +570,23 @@
     i++;
     }
 }
 
+int raDbCmpPriority(const void *va, const void *vb)
+/* Compare to sort columns based on priority. */
+{
+const struct raDb *a = *((struct raDb **)va);
+const struct raDb *b = *((struct raDb **)vb);
+float dif = *(a->priority) - *(b->priority);
+if (dif < 0)
+    return -1;
+else if (dif > 0)
+    return 1;
+else
+    return 0;
+}
+
+
 void raToDb(char *db, char *raName)
 /* raToDb - RA to database table converter RA to database converter. */
 {
 struct hash *raHash, *raHashList = readRaFile(raName);
@@ -591,8 +606,9 @@
 	}
     slAddHead(&raList, ra); 
     numPass += 1;
     }
+slSort(raList, raDbCmpPriority);
 
 struct sqlConnection *conn = hAllocConnProfile(localDbProfile, db);
 
 char *raDbName;