src/hg/instinct/bioInt2/bioController.c 1.2
1.2 2009/03/21 19:54:10 jsanborn
added routine to set cohorts
Index: src/hg/instinct/bioInt2/bioController.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/bioInt2/bioController.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -b -B -U 4 -r1.1 -r1.2
--- src/hg/instinct/bioInt2/bioController.c 20 Mar 2009 06:06:31 -0000 1.1
+++ src/hg/instinct/bioInt2/bioController.c 21 Mar 2009 19:54:10 -0000 1.2
@@ -204,14 +204,14 @@
void createAnalysisFeaturesTable(struct sqlConnection *biConn, char *tableName)
{
struct dyString *dy = newDyString(1024);
dyStringPrintf(dy, "CREATE TABLE %s (\n", tableName);
-dyStringPrintf(dy, "feature_id int unsigned not null,\n");
+dyStringPrintf(dy, "id int unsigned not null,\n");
dyStringPrintf(dy, "feature_name varchar(255) not null,\n");
-dyStringPrintf(dy, "KEY(feature_id),\n");
+dyStringPrintf(dy, "KEY(id),\n");
dyStringPrintf(dy, "KEY(feature_name),\n");
-dyStringPrintf(dy, "KEY(feature_id, feature_name),\n");
-dyStringPrintf(dy, "KEY(feature_name, feature_id)\n");
+dyStringPrintf(dy, "KEY(id, feature_name),\n");
+dyStringPrintf(dy, "KEY(feature_name, id)\n");
dyStringPrintf(dy, ")\n");
sqlUpdate(biConn,dy->string);
dyStringFree(&dy);
}
@@ -234,40 +234,59 @@
boolean analysisFeatureExists(struct sqlConnection *biConn, struct analysisFeatures *af)
{
char query[256];
safef(query, sizeof(query),
- "select * from analysisFeatures where feature_id = %d "
+ "select * from analysisFeatures where id = %d "
"and feature_name = \"%s\" ",
- af->feature_id, af->feature_name);
+ af->id, af->feature_name);
return sqlExists(biConn, query);
}
+struct hash *getAnalysisFeaturesHash(struct sqlConnection *biConn)
+{
+fprintf(stdout, "getting analysis features hash.\n");
+
+struct hash *hash = hashNew(0);
+char query[128];
+safef(query, sizeof(query), "select * from analysisFeatures");
+
+struct analysisFeatures *af, *afList = analysisFeaturesLoadByQuery(biConn, query);
+
+for (af = afList; af; af = af->next)
+ hashAddInt(hash, af->feature_name, af->id);
+
+analysisFeaturesFreeList(&afList);
+return hash;
+}
+
struct hash *storeAnalysisFeaturesInDb(struct sqlConnection *biConn, struct analysisResult *arList)
{
fprintf(stdout, "storing analysis features\n");
char *tableName = "analysisFeatures";
if (!sqlTableExists(biConn, tableName))
createAnalysisFeaturesTable(biConn, tableName);
+/* Get existing analysis features */
+struct hash *hash = getAnalysisFeaturesHash(biConn);
+
struct analysisFeatures *af;
struct analysisResult *ar;
-struct hash *hash = hashNew(0);
for (ar = arList; ar; ar = ar->next)
{
if (hashLookup(hash, ar->feature))
continue; // already visited, ignore
- int feature_id = findIdInTable(biConn, tableName, "feature_id", "feature_name", ar->feature);
+ int feature_id = findIdInTable(biConn, tableName, "id", "feature_name", ar->feature);
AllocVar(af);
- af->feature_id = feature_id;
+ af->id = feature_id;
af->feature_name = cloneString(ar->feature);
if (!analysisFeatureExists(biConn, af))
analysisFeaturesSaveToDb(biConn, af, tableName, 10);
- hashAddInt(hash, af->feature_name, af->feature_id);
+ hashAddInt(hash, af->feature_name, af->id);
analysisFeaturesFree(&af);
}
return hash;
@@ -285,8 +304,9 @@
for (sa = saList; sa; sa = sa->next)
hashAddInt(hash, sa->name, sa->id);
+samplesFreeList(&saList);
return hash;
}
@@ -333,8 +353,22 @@
return TRUE;
}
+boolean analysisListExists(char *db, struct biAnalysis *baList)
+{
+struct sqlConnection *biConn = hAllocConnProfile("localDb", db);
+
+boolean exists = TRUE;
+struct biAnalysis *ba;
+for (ba = baList; ba; ba = ba->next)
+ if (!analysisExists(biConn, ba))
+ exists = FALSE;
+
+hFreeConn(&biConn);
+return exists;
+}
+
void geneLevelPipeline(struct biAnalysis *baList, struct biResults *br, struct slName *genes)
{
if (!baList)
@@ -388,25 +422,26 @@
{
/* datasets is a comma-separated string, each a different dataset table */
struct slName *slDatasets = slNameListFromComma(datasets);
-/* Get raw gene/sample data for all overlapping samples in dataset list */
-uglyTime(NULL);
-struct biResults *br = retrieveData(db, slDatasets, TRUE);
-uglyTime("retrieveData");
+struct biAnalysis *baList = registerGeneLevelAnalyses(db, slDatasets);
-if (!br)
- errAbort("No gene data!\n");
+if (!analysisListExists(db, baList))
+ {
+ /* Get raw gene/sample data for all overlapping samples in dataset list */
+ uglyTime(NULL);
+ struct biResults *br = retrieveData(db, slDatasets, TRUE);
+ uglyTime("retrieveData");
-/* Run gene level analyses (meta-gene, pathlet, etc.) */
-struct slName *genes = getAvailableGenes(db, br);
-uglyTime("Num available genes = %d", slCount(genes));
+ if (!br)
+ errAbort("No gene data!\n");
-struct biAnalysis *baList = registerGeneLevelAnalyses(db, slDatasets);
+ /* Run gene level analyses (meta-gene, pathlet, etc.) */
+ struct slName *genes = getAvailableGenes(db, br);
+ uglyTime("Num available genes = %d", slCount(genes));
-uglyTime(NULL);
-geneLevelPipeline(baList, br, genes);
-uglyTime("geneLevelPipeline");
+ geneLevelPipeline(baList, br, genes);
+ }
/* Run pathway/geneset level analyses */