src/hg/instinct/bioInt2/bioController.c 1.7

1.7 2009/03/24 05:21:54 jsanborn
updated
Index: src/hg/instinct/bioInt2/bioController.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/bioInt2/bioController.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -b -B -U 4 -r1.6 -r1.7
--- src/hg/instinct/bioInt2/bioController.c	24 Mar 2009 03:07:55 -0000	1.6
+++ src/hg/instinct/bioInt2/bioController.c	24 Mar 2009 05:21:54 -0000	1.7
@@ -18,10 +18,10 @@
 {
 errAbort(
 	 "bioController - controller for bioIntegrator pipeline\n"
 	 "usage:\n"
-	 "   bioIntegrator datasets\n"
-	 "   -datasets = comma-separated list of datasets\n"
+	 "   bioController cohort_id\n"
+	 "   -cohort_id = number of cohort in cohorts table"
 	 );
 }
 
 #define BIOINT_DB "bioInt"
@@ -88,24 +88,25 @@
 boolean analysesExists(struct sqlConnection *biConn, struct analyses *an)
 {
 char query[256];
 safef(query, sizeof(query),
-      "select * from analyses where id = %d "
+      "select * from %s where id = %d "
       "and cohort_id = %d "
       "and module_id = %d "
       "and result_table = \"%s\" "
       "and input_tables = \"%s\" ",
-      an->id, an->cohort_id, an->module_id, an->result_table, an->input_tables);
+      AN_TABLE, an->id, an->cohort_id, an->module_id, 
+      an->result_table, an->input_tables);
 
 return sqlExists(biConn, query);
 }      
 
 boolean analysesWithResultTableExists(struct sqlConnection *biConn, char *result_table)
 {
 char query[256];
 safef(query, sizeof(query),
-      "select * from analyses where result_table = \"%s\" ",
-      result_table);
+      "select * from %s where result_table = \"%s\" ",
+      AN_TABLE, result_table);
 
 return sqlExists(biConn, query);
 }      
 
@@ -113,10 +114,10 @@
 {
 struct hash *hash = hashNew(0);
 char query[256];
 safef(query, sizeof(query), 
-      "select * from analysisParams where analysis_id = %d",
-      an->id);
+      "select * from %s where analysis_id = %d",
+      AP_TABLE, an->id);
 struct analysisParams *ap, *apList = analysisParamsLoadByQuery(biConn, query);
 
 for (ap = apList; ap; ap = ap->next)
     hashAdd(hash, ap->name, ap->val);
@@ -139,9 +140,9 @@
     ap->analysis_id = an->id;
     ap->name = cloneString(name);
     ap->val = cloneString(val);
 
-    analysisParamsSaveToDbEscaped(biConn, ap, "analysisParams", 50);
+    analysisParamsSaveToDbEscaped(biConn, ap, AP_TABLE, 50);
 
     analysisParamsFree(&ap);
     }
 }
@@ -150,10 +151,10 @@
 boolean matchingParams(struct sqlConnection *biConn, int analysis_id, struct hash *params)
 {
 char query[256];
 safef(query, sizeof(query), 
-      "select * from analysisParams where analysis_id = %d",
-      analysis_id);
+      "select * from %s where analysis_id = %d",
+      AP_TABLE, analysis_id);
 
 struct analysisParams *ap, *apList = analysisParamsLoadByQuery(biConn, query);
 
 if (!apList) // no analysis params for this id 
@@ -232,9 +233,9 @@
 	foundName = TRUE;
 	break;
 	}
     
-    int id = findIdInTable(biConn, "analyses", "id", "result_table", name);
+    int id = findIdInTable(biConn, AN_TABLE, "id", "result_table", name);
     if (matchingParams(biConn, id, params))
 	{ 
 	foundName = TRUE;
 	break;
@@ -260,9 +261,9 @@
     return NULL;
 
 /* Get unique name or name already in database for exact matching analysis */
 char *result_table = createAnalysesResultTableName(biConn, cohort_id, am, input_tables, params);
-int id = findIdInTable(biConn, "analyses", "id", "result_table", result_table);
+int id = findIdInTable(biConn, AN_TABLE, "id", "result_table", result_table);
 
 struct analyses *an;
 AllocVar(an);
 an->id = id;  
@@ -272,9 +273,9 @@
 an->input_tables = cloneString(input_tables);
 
 if (!analysesExists(biConn, an))
     {
-    analysesSaveToDbEscaped(biConn, an, "analyses", 20);
+    analysesSaveToDbEscaped(biConn, an, AN_TABLE, 20);
     storeAnalysisParams(biConn, an, params);
     }
 
 return an;
@@ -283,11 +284,11 @@
 struct datasets *datasetsInCohort(struct sqlConnection *biConn, int cohort_id)
 {
 char query[256];
 safef(query, sizeof(query), 
-      "select * from datasets join datasetCohort on datasets.id = datasetCohort.dataset_id "
-      "where datasetCohort.cohort_id = %d;",
-      cohort_id);
+      "select * from %s join %s on %s.id = %s.dataset_id "
+      "where %s.cohort_id = %d;",
+      DA_TABLE, DC_TABLE, DA_TABLE, DC_TABLE, DC_TABLE, cohort_id);
 
 return datasetsLoadByQuery(biConn, query);
 }
 
@@ -295,10 +296,10 @@
 						char *field, char *val)
 {
 char query[128];
 safef(query, sizeof(query),
-      "select * from analysisModules where %s = \"%s\" ",
-      field, val);
+      "select * from %s where %s = \"%s\" ",
+      AM_TABLE, field, val);
 
 return analysisModulesLoadByQuery(biConn, query);
 }
 
@@ -309,10 +310,10 @@
     return;
 
 char query[128];
 safef(query, sizeof(query), 
-      "select * from analysisModules where id = %d", 
-      module_id);
+      "select * from %s where id = %d", 
+      AM_TABLE, module_id);
 
 struct analysisModules *am = analysisModulesLoadByQuery(biConn, query);
 if (!am)
     errAbort("No module with id = %d", module_id);
@@ -340,10 +341,10 @@
 struct biAnalysis *ba, *baList = NULL;
 
 char query[128];
 safef(query, sizeof(query), 
-      "select * from analyses where cohort_id = %d",
-      cohort_id);
+      "select * from %s where cohort_id = %d",
+      AN_TABLE, cohort_id);
 
 struct analyses *an, *anList = analysesLoadByQuery(biConn, query);
 
 if (!anList)
@@ -370,21 +371,23 @@
 
 boolean cohortExists(struct sqlConnection *biConn, int cohort_id)
 {
 char query[128];
-safef(query, sizeof(query), "select * from cohorts where id = %d", cohort_id);
+safef(query, sizeof(query), 
+      "select * from %s where id = %d", 
+      CO_TABLE, cohort_id);
 
 return sqlExists(biConn, query);
 }
 
 boolean analysisModuleExists(struct sqlConnection *biConn, struct analysisModules *am)
 {
 char query[128];
 safef(query, sizeof(query), 
-      "select * from analysisModules where id = %d "
+      "select * from %s where id = %d "
       "and name = \"%s\" "
       "and type = \"%s\" ", 
-      am->id, am->name, am->type);
+      AM_TABLE, am->id, am->name, am->type);
 
 return sqlExists(biConn, query);
 }
 
@@ -393,12 +396,12 @@
 struct analysisModules *am;
 AllocVar(am);
 am->name = cloneString(name);
 am->type = cloneString(type);
-am->id = findIdInTable(biConn, "analysisModules", "id", "name", am->name);
+am->id = findIdInTable(biConn, AM_TABLE, "id", "name", am->name);
 
 if (!analysisModuleExists(biConn, am))
-    analysisModulesSaveToDb(biConn, am, "analysisModules", 10);
+    analysisModulesSaveToDb(biConn, am, AM_TABLE, 10);
 
 analysisModulesFree(&am);
 }
 
@@ -454,16 +457,16 @@
 
 
 void prepareDatabase(struct sqlConnection *biConn)
 {
-if (!sqlTableExists(biConn, "analyses"))
-    createAnalysesTable(biConn, "analyses");
+if (!sqlTableExists(biConn, AN_TABLE))
+    createAnalysesTable(biConn, AN_TABLE);
 
-if (!sqlTableExists(biConn, "analysisParams"))
-    createAnalysisParamsTable(biConn, "analysisParams");
+if (!sqlTableExists(biConn, AP_TABLE))
+    createAnalysisParamsTable(biConn, AP_TABLE);
 
-if (!sqlTableExists(biConn, "analysisModules"))
-    createAnalysisModulesTable(biConn, "analysisModules");
+if (!sqlTableExists(biConn, AM_TABLE))
+    createAnalysisModulesTable(biConn, AM_TABLE);
 
 setupAnalysisModules(biConn);
 }