src/hg/instinct/bioInt2/grabData.c 1.4
1.4 2009/04/29 18:22:08 jsanborn
fixed grabData for new db structure
Index: src/hg/instinct/bioInt2/grabData.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/bioInt2/grabData.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -b -B -U 4 -r1.3 -r1.4
--- src/hg/instinct/bioInt2/grabData.c 7 Apr 2009 03:41:09 -0000 1.3
+++ src/hg/instinct/bioInt2/grabData.c 29 Apr 2009 18:22:08 -0000 1.4
@@ -255,33 +255,8 @@
spHashListPrint(spList, slList, clinTableName);
}
-
-struct hash *probeIdToGene(struct sqlConnection *conn, struct datasets *da)
-{
-char query[512];
-
-safef(query, sizeof(query),
- "select DISTINCT %s.id,geneSymbol from %s join %s on id=probe_id "
- "join %s on gene_id=%s.id join %s on %s.kgId=%s.kgId;",
- da->probe_table, da->probe_table, da->probe_to_gene_table, GL_TABLE,
- GL_TABLE, KX_TABLE, GL_TABLE, KX_TABLE);
-
-struct sqlResult *sr = sqlGetResult(conn, query);
-char **row = NULL;
-
-struct hash *hash = hashNew(0);
-while ((row = sqlNextRow(sr)) != NULL)
- {
- char *id = row[0];
- char *gene = cloneString(row[1]);
- hashAdd(hash, id, gene);
- }
-sqlFreeResult(&sr);
-return hash;
-}
-
void medianSpHashList(struct slPair *spList, struct slName *slList)
{
struct hashEl *el;
struct slPair *sp;
@@ -304,79 +279,8 @@
}
}
}
-void grabRawData(struct sqlConnection *conn, char *tableName)
-{
-struct datasets *da = findDataset(conn, tableName);
-if (!da)
- errAbort("No dataset by name of %s in db\n", tableName);
-
-struct samples *sa, *saList = getSamples(conn, da);
-struct hash *idGeneHash = probeIdToGene(conn, da);
-
-char query[256];
-safef(query, sizeof(query), "select * from %s", tableName);
-
-struct hash *featureData = hashNew(0);
-struct slPair *sp, *spList = NULL;
-
-struct sqlResult *sr = sqlGetResult(conn, query);
-char **row = NULL;
-while ((row = sqlNextRow(sr)) != NULL)
- {
- char *probe_id = row[0];
- struct probeVals *pv = probeValsLoad(row);
-
- struct hashEl *el = hashLookup(idGeneHash, probe_id);
- if (!el)
- continue;
- char *gene = el->val;
-
- struct hash *sampleData;
- el = hashLookup(featureData, gene);
- if (!el)
- {
- sampleData = hashNew(0);
- hashAdd(featureData, gene, sampleData);
- AllocVar(sp);
- sp->name = cloneString(gene);
- sp->val = sampleData;
- slAddHead(&spList, sp);
- }
- else
- sampleData = el->val;
-
- for (sa = saList; sa; sa = sa->next)
- {
- double val = pv->sample_data[sa->exp_id];
- struct slDouble *sd = slDoubleNew(val);
-
- el = hashLookup(sampleData, sa->name);
- if (!el)
- hashAdd(sampleData, sa->name, sd);
- else
- {
- struct slDouble *sdList = el->val;
- slAddTail(&sdList, sd);
- }
- }
- }
-sqlFreeResult(&sr);
-hashFree(&featureData);
-
-struct slName *slList = NULL;
-for (sa = saList; sa; sa = sa->next)
- slNameAddHead(&slList, sa->name);
-
-slReverse(&spList);
-slReverse(&slList);
-
-medianSpHashList(spList, slList);
-
-spHashListPrint(spList, slList, tableName);
-}
-
void grabAnalysisData(struct sqlConnection *conn, char *tableName)
{
struct hash *sampleIdHash = createHash(conn, SA_TABLE, "id", "name");
struct hash *featureIdHash = createHash(conn, AF_TABLE, "id", "feature_name");
@@ -452,17 +356,12 @@
struct sqlConnection *conn = hAllocConnProfile(localDb, db);
if (!sqlTableExists(conn, tableName))
errAbort("%s doesn't exist in %s db.\n", tableName, db);
-if (isAnalysisTable(conn, tableName))
- grabAnalysisData(conn, tableName);
-else
- {
- if (getClinical)
+if (getClinical)
grabClinicalData(conn, tableName);
- else
- grabRawData(conn, tableName);
- }
+else
+ grabAnalysisData(conn, tableName);
}
int main(int argc, char *argv[])