void dispatchPage() /* Look at command variables in cart and figure out which * page to draw. */ { struct sqlConnection *conn = hAllocConn(database); if (checkAndClear(hggConfigure)) { configurePage(); } else if (checkAndClear(hggConfigureOne)) { configureOnePage(); } else if (checkAndClear(hggUpload)) { uploadPage(); } else if (checkAndClear(hggSubmitUpload)) { submitUpload(conn); } else if (checkAndClear(hggImport)) { importPage(conn); } else if (checkAndClear(hggSubmitImport)) { submitImport(); } else if (checkAndClear(hggCorrelate)) { correlatePage(conn); } else if (checkAndClear(hggBrowse)) { browseRegions(conn); } else if (checkAndClear(hggSort)) { sortGenes(conn); } else { /* Default case - start fancy web page. */ if (cgiVarExists(hggPsOutput)) handlePostscript(conn); else mainPage(conn); } cartRemovePrefix(cart, hggDo); }
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, "")) { hUserAbort("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) { hUserAbort("'%s' does not seem to be a valid UniProtKB protein ID or a gene " "symbol.<br><br>Click <A HREF=\"../cgi-bin/pbGateway\">here</A> " "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); sqlSafefFrag(cond_str, sizeof(cond_str), "alias='%s'", queryID); proteinID = sqlGetField(database, "kgSpAlias", "spID", cond_str); sqlSafefFrag(cond_str, sizeof(cond_str), "spID='%s'", proteinID); answer = sqlGetField(database, "kgXref", "spDisplayID", cond_str); sqlSafefFrag(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("<br>before enter main section: <br>proteinInSupportedGenome=%d<br>proteinID=%s <br>database=%s <br>organism=%s <br>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 */ sqlSafefFrag(cond_str, sizeof(cond_str), "accession='%s'", proteinID); proteinAC = sqlGetField(protDbName, "spXref3", "accession", cond_str); if (proteinAC == NULL) { sqlSafefFrag(cond_str, sizeof(cond_str), "displayID='%s'", proteinID); proteinAC = sqlGetField(protDbName, "spXref3", "accession", cond_str); if (proteinAC == NULL) { hUserAbort("'%s' does not seem to be a valid Swiss-Prot/TrEMBL protein ID or gene symbol.<br><br>Click <A HREF=\"../cgi-bin/pbGateway\">here</A> to start another query." , proteinID); } else { protDisplayID = proteinID; proteinID = proteinAC; } } else { sqlSafefFrag(cond_str, sizeof(cond_str), "accession='%s'", proteinID); protDisplayID = sqlGetField(protDbName, "spXref3", "displayID", cond_str); } if (proteinInSupportedGenome) { if (kgVersion == KG_III) { sqlSafefFrag(cond_str, sizeof(cond_str), "spId='%s'", proteinID); mrnaID = sqlGetField(database, "kgXref", "kgId", cond_str); } else { sqlSafefFrag(cond_str, sizeof(cond_str), "proteinID='%s'", protDisplayID); mrnaID = sqlGetField(database, "knownGene", "name", cond_str); } } else { mrnaID = NULL; positionStr = NULL; } sqlSafefFrag(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); } }