bf57cd55cdc4e37fd0b320c7cb090d9807f32a20 kate Sun Mar 25 22:55:56 2012 -0700 encodeExperiment table 'production copy' lives on preview server. API call looks there if table not found on localhost. diff --git src/hg/hgApi/hgApi.c src/hg/hgApi/hgApi.c index 206f4fe..a6cdda5 100644 --- src/hg/hgApi/hgApi.c +++ src/hg/hgApi/hgApi.c @@ -301,32 +301,38 @@ if (found) dyStringPrintf(output, "{\"pos\": \"%s:%d-%d\"}", gp->chrom, start + 1, end); else dyStringPrintf(output, "{\"error\": \"%d is an invalid %s for this gene\"}", num, sameString(cmd, "codonToPos") ? "codon" : "exon"); } else dyStringPrintf(output, "{\"error\": \"Couldn't find item: %s\"}", name); sqlFreeResult(&sr); hFreeConn(&conn); } else if (!strcmp(cmd, "encodeExperiments")) { // Return list of ENCODE experiments. Note: database is ignored. // TODO: add selector for org=human|mouse, retire db= // e.g. http://genome.ucsc.edu/cgi-bin/hgApi?db=hg18&cmd=encodeExperiments + // NOTE: This table lives only on development and preview servers -- use preview + // if not found on localhost struct sqlConnection *connExp = sqlConnect(ENCODE_EXP_DATABASE); - /* TODO: any need to use connection pool ? */ + if (!sqlTableExists(connExp, ENCODE_EXP_TABLE)) + { + sqlDisconnect(&connExp); + connExp = sqlConnectProfile("preview", ENCODE_EXP_DATABASE); + } struct encodeExp *exp = NULL, *exps = encodeExpLoadAllFromTable(connExp, ENCODE_EXP_TABLE); dyStringPrintf(output, "[\n"); while ((exp = slPopHead(&exps)) != NULL) { encodeExpJson(output, exp); dyStringAppend(output,",\n"); } output->string[dyStringLen(output)-2] = '\n'; output->string[dyStringLen(output)-1] = ']'; dyStringPrintf(output, "\n"); sqlDisconnect(&connExp); } else if (!strcmp(cmd, "encodeExpId")) { // Return list of ENCODE expID's found in a database