Protein: ");
hPrintf("%s", proteinID);
/* Please note the hiv database name is hard wired here.*/
safef(query, sizeof(query),
"select subjId from hivVax003Vax004.gsIdXref where aaSeqId = '%s'", proteinID);
sr = sqlMustGetResult(conn, query);
row = sqlNextRow(sr);
if (row != NULL)
{
printf("
");
hPrintf("Subject: ");
hPrintf("", row[0]);
hPrintf("%s
", row[0]);
}
sqlFreeResult(&sr);
spDisplayId = spAccToId(conn, spFindAcc(conn, proteinID));
if (strstr(spDisplayId, spFindAcc(conn, proteinID)) == NULL)
{
hPrintf(" (aka %s", spDisplayId);
/* show once if the new and old displayId are the same */
oldDisplayId = oldSpDisplayId(spDisplayId);
if (oldDisplayId != NULL)
{
if (!sameWord(spDisplayId, oldDisplayId))
{
hPrintf(" or %s", oldSpDisplayId(spDisplayId));
}
}
hPrintf(")\n");
}
hPrintf("
");
protSeq = getAA(proteinID);
if (protSeq == NULL)
{
errAbort("%s is not a current valid entry in UniProt(SWISS-PROT/TrEMBL)\n", proteinID);
}
protSeqLen = strlen(protSeq);
fflush(stdout);
iypos = 15;
doTracks(proteinID, mrnaID, protSeq, &iypos, psOutput);
if (!hTableExists(database, "pbStamp")) goto histDone;
pbScale = 3;
pixWidth = 520;
insideWidth = pixWidth-gfxBorder;
pixHeight = 350;
if (psOutput2)
{
vg2 = vgOpenPostScript(pixWidth, pixHeight, psOutput2);
}
else
{
trashDirFile(&gifTn2, "pbt", "pbt", ".gif");
vg2 = vgOpenGif(pixWidth, pixHeight, gifTn2.forCgi, FALSE);
}
g_vg = vg2;
pbRed = vgFindColorIx(vg2, 0xf9, 0x51, 0x59);
pbBlue = vgFindColorIx(g_vg, 0x00, 0x00, 0xd0);
normalColor = pbBlue;
abnormalColor = pbRed;
bkgColor = vgFindColorIx(vg2, 255, 254, 232);
vgBox(vg2, 0, 0, insideWidth, pixHeight, bkgColor);
/* Start up client side map. */
mapName=cloneString("pbStamps");
hPrintf("\n\n");
/* Save out picture and tell html file about it. */
vgClose(&vg2);
hPrintf("");
hPrintf("\n![](\"%s\")
",
gifTn2.forCgi, pixWidth, pixHeight, mapName);
if (proteinInSupportedGenome)
{
hPrintf("\n");
}
else
{
hPrintf("\n");
}
hPrintf("Explanation of Protein Property Histograms
");
hPrintf("
");
histDone:
hPrintf("
");
fflush(stdout);
printFASTA(proteinID, protSeq);
}
void doTrackForm(char *psOutput, char *psOutput2)
/* Make the tracks display form */
{
if (psOutput != NULL)
{
suppressHtml = TRUE;
hideControls = TRUE;
}
/* Tell browser where to go when they click on image. */
hPrintf("
");
}
void handlePostscript()
/* Deal with Postscript output. */
{
struct tempName psTn;
struct tempName psTn2;
char *pdfFile = NULL;
trashDirFile(&psTn, "pbt", "pbt", ".eps");
trashDirFile(&psTn2, "pbt", "pbt2", ".eps");
printf("PostScript/PDF Output
\n");
printf("PostScript images can be printed at high resolution "
"and edited by many drawing programs such as Adobe Illustrator.");
printf(" PDF can be viewed with Adobe Acrobat Reader.
\n");
doTrackForm(psTn.forCgi, psTn2.forCgi);
printf("Click here to download "
"the current protein tracks graphic in PostScript. ", psTn.forCgi);
pdfFile = convertEpsToPdf(psTn.forCgi);
if(pdfFile != NULL)
{
printf("
Click here to download "
"the current protein tracks graphic in PDF", pdfFile);
}
else
printf("
PDF format not available");
printf("
Click here to download "
"the current protein histograms graphic in PostScript. ", psTn2.forCgi);
pdfFile = convertEpsToPdf(psTn2.forCgi);
if(pdfFile != NULL)
{
printf("
Click here to download "
"the current protein histograms graphic in PDF", pdfFile);
}
else
printf("
PDF format not available");
freez(&pdfFile);
}
void doMiddle(struct cart *theCart)
/* Print the body of an html file. */
{
char cond_str[255];
struct sqlConnection *conn;
char *proteinAC;
char *chp, *chp1, *chp9;
char *debugTmp = NULL;
char *chromStr, *cdsStartStr, *cdsEndStr, posStr[255];
char *supportedGenomeDatabase;
char *answer;
char *queryID;
/* Initialize layout and database. */
cart = theCart;
/* Uncomment this to see parameters for debugging. */
/* Be careful though, it breaks if custom track
* is more than 4k */
/*
{ struct dyString *state = cgiUrlString();
hPrintf("State: %s\n", state->string);
}
*/
queryID = cartOptionalString(cart, "proteinID");
if (sameString(queryID, ""))
{
errAbort("Please go back and enter a gene symbol or a Swiss-Prot/TrEMBL protein ID.\n");
}
if (cgiVarExists("db"))
{
/* if db is known, get key variables set */
proteinInSupportedGenome = TRUE;
database = cgiOptionalString("db");
organism = hDbOrganism(database);
protDbName = hPdbFromGdb(database);
proteinID = strdup(queryID);
}
else
{
protCntInSwissByGene = searchProteinsInSwissProtByGene(queryID);
/* no CGI 'db' variable means it did not come in from GB but from pbGateway */
/* search existing GB databases to see if this protein can be found */
protCntInSupportedGenomeDb =
searchProteinsInSupportedGenomes(queryID, &supportedGenomeDatabase);
if ((protCntInSupportedGenomeDb > 1) || protCntInSwissByGene >= 1)
{
/* more than 1 proteins match the query ID, present selection web page */
proteinInSupportedGenome = 1;
presentProteinSelections(queryID, protCntInSwissByGene, protCntInSupportedGenomeDb);
return;
}
else
{
if (protCntInSupportedGenomeDb == 1)
{
/* one and only one protein found in a genome DB that support KG and PB */
proteinInSupportedGenome = TRUE;
database = strdup(supportedGenomeDatabase);
organism = hDbOrganism(database);
protDbName = hPdbFromGdb(database);
proteinID=strdup(queryID);
}
else
{
/* not found in genome DBs that support KG/PB */
/* now search PROTEOME_DB_NAMES to see if this protein is there. */
answer = uniProtFindPrimAcc(queryID);
if (answer == NULL)
{
if (hIsGsidServer())
{
errAbort(
"'%s' does not seem to be a valid protein ID.
Click here to start another query."
, queryID);
}
else
{
errAbort(
"'%s' does not seem to be a valid UniProt(Swiss-Prot/TrEMBL) protein ID or a gene symbol.
Click here to start another query."
, queryID);
}
}
proteinInSupportedGenome = FALSE;
database = strdup(GLOBAL_PB_DB);
organism = strdup("");
protDbName = strdup(PROTEOME_DB_NAME);
proteinID = strdup(answer);
}
}
if (proteinInSupportedGenome)
{
spConn = sqlConnect(database);
safef(cond_str, sizeof(cond_str), "alias='%s'", queryID);
proteinID = sqlGetField(database, "kgSpAlias", "spID", cond_str);
safef(cond_str, sizeof(cond_str), "spID='%s'", proteinID);
answer = sqlGetField(database, "kgXref", "spDisplayID", cond_str);
safef(cond_str, sizeof(cond_str), "proteinID='%s'", answer);
chromStr = sqlGetField(database, "knownGene", "chrom", cond_str);
if (chromStr)
{
cdsStartStr = sqlGetField(database, "knownGene", "cdsStart", cond_str);
cdsEndStr = sqlGetField(database, "knownGene", "cdsEnd", cond_str);
safef(posStr, sizeof(posStr), "%s:%s-%s", chromStr, cdsStartStr, cdsEndStr);
positionStr = strdup(posStr);
cartSetString(cart, "position", positionStr);
cartSetString(cart, "organism", organism);
}
}
}
/* print out key variables for debugging */
/* printf("
before enter main section:
proteinInSupportedGenome=%d
proteinID=%s
database=%s
organism=%s
protDbName=%s\n",
proteinInSupportedGenome, proteinID, database, organism, protDbName);fflush(stdout);
*/
if (hTableExists(database, "kgProtMap2"))
{
kgVersion = KG_III;
strcpy(kgProtMapTableName, "kgProtMap2");
}
debugTmp = cartUsualString(cart, "hgDebug", "off");
if(sameString(debugTmp, "on"))
hgDebug = TRUE;
else
hgDebug = FALSE;
conn = hAllocConn(database);
hgsid = cartOptionalString(cart, "hgsid");
if (hgsid != NULL)
{
safef(hgsidStr, sizeof(hgsidStr), "&hgsid=%s", hgsid);
}
else
{
strcpy(hgsidStr, "");
}
/* check proteinID to see if it is a valid SWISS-PROT/TrEMBL accession or display ID */
/* then assign the accession number to global variable proteinID */
safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
proteinAC = sqlGetField(protDbName, "spXref3", "accession", cond_str);
if (proteinAC == NULL)
{
safef(cond_str, sizeof(cond_str), "displayID='%s'", proteinID);
proteinAC = sqlGetField(protDbName, "spXref3", "accession", cond_str);
if (proteinAC == NULL)
{
if (hIsGsidServer())
{
safef(cond_str, sizeof(cond_str), "acc='%s'", proteinID);
proteinAC = sqlGetField(protDbName, "uniProtAlias", "acc", cond_str);
if (proteinAC != NULL)
{
protDisplayID = proteinID;
proteinID = proteinAC;
}
else
{
errAbort("'%s' does not seem to be a valid protein ID.
Click here to start another query."
, proteinID);
}
}
else
{
errAbort("'%s' does not seem to be a valid Swiss-Prot/TrEMBL protein ID or gene symbol.
Click here to start another query."
, proteinID);
}
}
else
{
protDisplayID = proteinID;
proteinID = proteinAC;
}
}
else
{
safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
protDisplayID = sqlGetField(protDbName, "spXref3", "displayID", cond_str);
}
if (proteinInSupportedGenome)
{
if (kgVersion == KG_III)
{
safef(cond_str, sizeof(cond_str), "spId='%s'", proteinID);
mrnaID = sqlGetField(database, "kgXref", "kgId", cond_str);
}
else
{
safef(cond_str, sizeof(cond_str), "proteinID='%s'", protDisplayID);
mrnaID = sqlGetField(database, "knownGene", "name", cond_str);
}
}
else
{
mrnaID = NULL;
positionStr = NULL;
}
safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
description = sqlGetField(protDbName, "spXref3", "description", cond_str);
if (positionStr != NULL)
{
chp = strstr(positionStr, ":");
*chp = '\0';
prevGBChrom = cloneString(positionStr);
chp1 = chp + 1;
chp9 = strstr(chp1, "-");
*chp9 = '\0';
prevGBStartPos = atoi(chp1);
chp1 = chp9 + 1;
prevGBEndPos = atoi(chp1);
}
else
{
prevGBChrom = NULL;
prevGBStartPos = -1;
prevGBEndPos = -1;
}
/* Do main display. */
if (cgiVarExists("pbt.psOutput"))
handlePostscript();
else
{
doTrackForm(NULL, NULL);
}
}
void doDown(struct cart *cart)
{
hPrintf("The Browser is Being Updated
\n");
hPrintf("The browser is currently unavailable. We are in the process of\n");
hPrintf("updating the database and the display software.\n");
hPrintf("Please try again later.\n");
}
/* Other than submit and Submit all these vars should start with pbt.
* to avoid weeding things out of other program's namespaces.
* Because the browser is a central program, most of it's cart
* variables are not pbt. qualified. It's a good idea if other
* program's unique variables be qualified with a prefix though. */
char *excludeVars[] = { "submit", "Submit", "pbt.reset",
"pbt.in1", "pbt.in2", "pbt.in3", "pbt.inBase",
"pbt.out1", "pbt.out2", "pbt.out3",
"pbt.left1", "pbt.left2", "pbt.left3",
"pbt.right1", "pbt.right2", "pbt.right3",
"pbt.dinkLL", "pbt.dinkLR", "pbt.dinkRL", "pbt.dinkRR",
"pbt.tui", "pbt.hideAll", "pbt.psOutput", "hideControls",
NULL };
void resetVars()
/* Reset vars except for position and database. */
{
static char *except[] = {"db", "position", NULL};
char *cookieName = hUserCookie();
int sessionId = cgiUsualInt(cartSessionVarName(), 0);
char *hguidString = findCookieData(cookieName);
int userId = (hguidString == NULL ? 0 : atoi(hguidString));
struct cart *oldCart = cartNew(userId, sessionId, NULL, NULL);
cartRemoveExcept(oldCart, except);
cartCheckout(&oldCart);
cgiVarExcludeExcept(except);
}
int main(int argc, char *argv[])
{
cgiSpoof(&argc, argv);
htmlSetBackground(hBackgroundImage());
if (cgiVarExists("pbt.reset"))
resetVars();
/* call cartHtmlShellPbGlobal to accomodate situations that PB not entered from GB */
cartHtmlShellPbGlobal("GSID Proteome Browser", doMiddle, hUserCookie(), excludeVars, NULL);
return 0;
}