src/hg/instinct/hgBed15ToArrayVal/hgBed15ToArrayVal.c 1.3
1.3 2010/03/10 22:57:17 jsanborn
updated
Index: src/hg/instinct/hgBed15ToArrayVal/hgBed15ToArrayVal.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/hgBed15ToArrayVal/hgBed15ToArrayVal.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -B -U 1000000 -r1.2 -r1.3
--- src/hg/instinct/hgBed15ToArrayVal/hgBed15ToArrayVal.c 24 Sep 2008 00:02:54 -0000 1.2
+++ src/hg/instinct/hgBed15ToArrayVal/hgBed15ToArrayVal.c 10 Mar 2010 22:57:17 -0000 1.3
@@ -1,131 +1,133 @@
/* hgBed15ToArrayVal - generate 3 cols tab separated file from a bed 15 table */
#include "common.h"
#include "hCommon.h"
#include "hdb.h"
#define MAXSAMPLE 5000
void usage()
/* Explain usage and exit. */
{
errAbort(
"hgBed15ToArrayVal - generate 3 cols tab separated file from a bed 15 table.\n"
"usage:\n"
" hgBed15ToArrayVal sampleDb sampleTable arrayDb bed15Table outFile\n"
" sampleDb datbase name \n"
" sampleTable table name \n"
" arrayDb datbase name of the source array data\n"
" bed15Table table name of the bed15 array data \n"
" outFile output file name\n"
"example: hgBed15ToArrayVal vantVeer labTrack hg18 vantVeerExp vantVeerExpArrayVal.tab\n");
}
+char localDb[128] = "localDb";
+
int main(int argc, char *argv[])
{
struct sqlConnection *conn;
int sampleCount = 0;
char *sampleId[MAXSAMPLE];
char query[256];
struct sqlResult *sr;
char **row;
char expId1[255], measure[255];
char *chp, *chp1, *chp2;
/* a unique numerical value, representing NULL (to be set to NULL after loading) */
char nullString[100] = {"-9999.8888"};
char *probeName, *expCount, *expIds, *expScores;
boolean oneRecDone = FALSE;
char *sampleDb, *sampleTable, *outFn;
char *expDb, *expTable;
FILE *outf;
if (argc != 6) usage();
sampleDb = argv[1];
sampleTable = argv[2];
expDb = argv[3];
expTable = argv[4];
outFn = argv[5];
outf = mustOpen(outFn, "w");
-conn= hAllocConn(sampleDb);
+conn= hAllocConnProfile(localDb, sampleDb);
sprintf(query,"select * from %s.%s", sampleDb, sampleTable);
sr = sqlMustGetResult(conn, query);
row = sqlNextRow(sr);
sampleCount = 0;
while (row != NULL)
{
sampleId[sampleCount] = strdup(row[1]);
sampleCount++;
row = sqlNextRow(sr);
}
sqlFreeResult(&sr);
sprintf(query,"select name, expCount, expIds, expScores from %s.%s", expDb, expTable);
sr = sqlMustGetResult(conn, query);
row = sqlNextRow(sr);
while (row != NULL)
{
probeName = row[0];
expCount = row[1];
expIds = row[2];
expScores = row[3];
chp1 = expIds;
chp2 = expScores;
oneRecDone = FALSE;
while (!oneRecDone)
{
chp = chp1;
while (!((*chp == ',') || (*chp == '\0')))chp++;
if (*chp == '\0') oneRecDone = TRUE;
*chp = '\0';
safef(expId1, sizeof(expId1), "%s", chp1);
chp++;
chp1 = chp;
chp = chp2;
while (!((*chp == ',') || (*chp == '\0')))chp++;
*chp = '\0';
if (strlen(chp2) != 0)
{
if (!sameWord(chp2, "NA"))
{
safef(measure, sizeof(measure), "%s", chp2);
}
else
{
safef(measure, sizeof(measure), "%s", nullString);
}
}
else
{
safef(measure, sizeof(measure), "%s", nullString);
}
chp ++;
chp2 = chp;
if (!oneRecDone)
fprintf(outf, "%s\t%s\t%s\n", sampleId[atoi(expId1)], probeName, measure);
}
row = sqlNextRow(sr);
}
sqlFreeResult(&sr);
hFreeConn(&conn);
fclose(outf);
return(0);
}