src/hg/instinct/bioInt2/bioGeneLevel.c 1.1

1.1 2009/03/20 06:06:31 jsanborn
initial commit
Index: src/hg/instinct/bioInt2/bioGeneLevel.c
===================================================================
RCS file: src/hg/instinct/bioInt2/bioGeneLevel.c
diff -N src/hg/instinct/bioInt2/bioGeneLevel.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/hg/instinct/bioInt2/bioGeneLevel.c	20 Mar 2009 06:06:31 -0000	1.1
@@ -0,0 +1,77 @@
+/* mapProbesToGenes - Will maps probes in BED format to overlapping gene(s). */
+#include "common.h"
+#include "linefile.h"
+#include "hash.h"
+#include "options.h"
+#include "jksql.h"
+#include "hPrint.h"
+#include "hdb.h"  
+#include "dystring.h"
+#include "bioIntDb.h"
+#include "bioIntDriver.h"
+#include "cprob.h"
+#include "hgStatsLib.h"
+#include "bioController.h"
+
+
+struct analysisResult *metaGene(struct biAnalysis *ba, struct slPair *spList, 
+				char *sample, char *gene)
+{
+struct slPair *sp;
+struct slDouble *sd, *sdList = NULL;
+for (sp = spList; sp; sp = sp->next)
+    {
+    struct slDouble *vals = sp->val;
+    if (!vals)
+	continue;
+    double val = slDoubleMedian(vals);
+    sd = slDoubleNew(val);
+    slAddHead(&sdList, sd);
+    }
+
+float chi2, metaP;
+if (!fishersMetaSigned(sdList, &chi2, &metaP))
+    return NULL;
+
+slFreeList(&sdList);
+struct analysisResult *ar;
+AllocVar(ar);
+ar->sample  = cloneString(sample);
+ar->feature = cloneString(gene);
+ar->val     = metaP;
+ar->conf    = chi2;
+return ar;
+}
+
+
+struct biAnalysis *registerGeneLevelAnalyses(char *db, struct slName *datasets)
+{
+struct biAnalysis *ba, *baList = NULL;
+
+struct slName *sl;
+struct dyString *dy = newDyString(10);
+for (sl = datasets; sl; sl = sl->next)
+    {
+    dyStringPrintf(dy, "%s", sl->name);
+    if (sl->next)
+	dyStringPrintf(dy, "_");
+    }
+char *prefix = dyStringCannibalize(&dy);
+
+/* Set up Meta-Gene analysis */
+AllocVar(ba);
+ba->db = cloneString(db);
+char tableName[256];
+safef(tableName, sizeof(tableName), "%s_meta", prefix);
+
+ba->tableName = cloneString(tableName);
+ba->parameters = hashNew(0);
+ba->analyze = metaGene;
+
+slAddHead(&baList, ba);
+
+/* Setup future analysis here... */
+
+return baList;
+}  
+