src/hg/instinct/bioInt2/bioIntUI.c 1.18
1.18 2009/04/27 16:44:08 jsanborn
fixed correlation stuff
Index: src/hg/instinct/bioInt2/bioIntUI.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/bioInt2/bioIntUI.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -b -B -U 4 -r1.17 -r1.18
--- src/hg/instinct/bioInt2/bioIntUI.c 27 Apr 2009 06:15:48 -0000 1.17
+++ src/hg/instinct/bioInt2/bioIntUI.c 27 Apr 2009 16:44:08 -0000 1.18
@@ -280,17 +280,17 @@
struct searchResults {
struct searchResults *next;
char *name;
char *type;
- int length;
+ double val;
};
int searchResultsCmp(const void *va, const void *vb)
/* Compare function to sort array of ints. */
{
const struct searchResults *a = *((struct searchResults **)va);
const struct searchResults *b = *((struct searchResults **)vb);
-int diff = a->length - b->length;
+double diff = a->val - b->val;
if (diff < 0)
return -1;
else if (diff > 0)
return 1;
@@ -319,9 +319,9 @@
char *type = row[1];
AllocVar(sp);
sp->name = cloneString(name);
sp->type = cloneString(type);
- sp->length = strlen(sp->name);
+ sp->val = strlen(sp->name);
slAddHead(&spList, sp);
if (count > maxResponse)
break;
count++;
@@ -356,9 +356,9 @@
char *name = row[0];
AllocVar(sp);
sp->name = cloneString(name);
sp->type = cloneString("clinical");
- sp->length = strlen(sp->name);
+ sp->val = strlen(sp->name);
slAddHead(&spList, sp);
if (count < maxResponse)
break;
count++;
@@ -724,16 +724,14 @@
void getMostCorrelated()
{
int takeTop = cartUsualInt(cart, bioIntTakeTop, 5);
-
int cohort_id = cartUsualInt(cart, bioIntCohortId, -1);
-if (cohort_id == -1)
- cohort_id = 2; // hard code for first analysis during testing!
-
char *feature_name = cartOptionalString(cart, bioIntFeatureName);
-if (!feature_name)
- errAbort("%s or %s must be set for mode=getMostCorrelated\n", bioIntFeature, bioIntFeatureId);
+
+if (!feature_name || cohort_id == -1)
+ errAbort("%s or %s must be set for mode=getMostCorrelated\n",
+ bioIntFeatureName, bioIntCohortId);
struct sqlConnection *conn = hAllocConnProfile(localDb, db);
struct analysisFeatures *af = getAnalysisFeaturesByName(conn, feature_name);
@@ -750,37 +748,47 @@
errAbort("No cohort correlation table with cohort_id = %d.\n", cohort_id);
}
struct dyString *dy = dyStringNew(100);
-dyStringPrintf(dy, "select a1.feature_name, a2.feature_name, %s.val from %s "
+dyStringPrintf(dy, "select a1.feature_name, a1.type, a2.feature_name, a2.type, %s.val from %s "
"join %s as a1 on %s.feature_id1 = a1.id ",
cc->result_table, cc->result_table, AF_TABLE, cc->result_table);
dyStringPrintf(dy, "join %s as a2 on %s.feature_id2 = a2.id ",
AF_TABLE, cc->result_table);
dyStringPrintf(dy, "where feature_id1 = %d or feature_id2 = %d order by %s.val DESC",
af->id, af->id, cc->result_table);
char *query = dyStringCannibalize(&dy);
-struct slPair *sp, *spList = NULL;
+struct searchResults *sp, *spList = NULL;
struct sqlResult *sr = sqlGetResult(conn, query);
char **row = NULL;
while ((row = sqlNextRow(sr)) != NULL)
{
char *name = NULL;
+ char *type = NULL;
char *name1 = row[0];
- char *name2 = row[1];
- double val = atof(row[2]);
+ char *type1 = row[1];
+ char *name2 = row[2];
+ char *type2 = row[3];
+ double val = atof(row[4]);
if (sameString(name1, af->feature_name))
+ {
name = name2;
+ type = type2;
+ }
else if (sameString(name2, af->feature_name))
+ {
name = name1;
+ type = type1;
+ }
else // doesn't match either, should *never* get here
continue;
AllocVar(sp);
sp->name = cloneString(name);
- sp->val = slDoubleNew(val);
+ sp->type = cloneString(type);
+ sp->val = val;
slAddHead(&spList, sp);
}
slReverse(&spList);
@@ -788,23 +796,24 @@
struct json *js = newJson();
struct json *corrs = jsonAddContainer(js, "Top Correlated");
for (sp = spList, count = 0; sp && (count < takeTop); sp = sp->next, count++)
{
- struct slDouble *sd = sp->val;
- if (sd->val < 0.0)
- continue;
-
- jsonAddDouble(corrs, sp->name, sd->val);
+ if (sp->val < 0.0)
+ break;
+ struct json *data = jsonAddContainer(corrs, sp->name);
+ jsonAddString(data, "type", sp->type);
+ jsonAddDouble(data, "val", sp->val);
}
slReverse(&spList);
corrs = jsonAddContainer(js, "Top Anti-Correlated");
for (sp = spList, count = 0; sp && (count < takeTop); sp = sp->next, count++)
{
- struct slDouble *sd = sp->val;
- if (sd->val > 0.0)
- continue;
- jsonAddDouble(corrs, sp->name, sd->val);
+ if (sp->val > 0.0)
+ break;
+ struct json *data = jsonAddContainer(corrs, sp->name);
+ jsonAddString(data, "type", sp->type);
+ jsonAddDouble(data, "val", sp->val);
}
if (js)
hPrintf("%s", js->print(js));