static boolean ctdExists(struct section *section, struct sqlConnection *conn, char *geneId) /* Return TRUE if CTD database exists and it has an entry with the gene symbol */ { char query[1024]; char *geneSymbol; if (isRgdGene(conn)) { if (sqlTableExists(conn, "rgdGene2Xref") == FALSE) return FALSE; } else { if (sqlTableExists(conn, "kgXref") == FALSE) return FALSE; } if (sqlTableExists(conn, "hgFixed.ctdSorted") == TRUE) { if (isRgdGene(conn)) { sqlSafef(query, sizeof(query), "select ChemicalId from rgdGene2Xref x, hgFixed.ctdSorted c" " where x.info=c.GeneSymbol and infoType = 'Name' and rgdGeneId='%s' limit 1", geneId); geneSymbol = sqlQuickString(conn, query); } else { sqlSafef(query, sizeof(query), "select ChemicalId from kgXref x, hgFixed.ctdSorted c" " where x.geneSymbol=c.GeneSymbol and kgId='%s' limit 1", geneId); geneSymbol = sqlQuickString(conn, query); } if (geneSymbol != NULL) return(TRUE); } return(FALSE); }
static int reactomeCount(struct pathwayLink *pl, struct sqlConnection *conn, char *geneId) /* Count up number of hits. */ { int ret = 0; char query[256]; char *spID, *chp; char condStr[256]; char *origSpID; /* check the existence of kgXref table first */ if (!isRgdGene(conn)) { if (!sqlTableExists(conn, "kgXref")) return(0); } else { if (!sqlTableExists(conn, "rgdGene2Xref")) return(0); } if (isRgdGene(conn)) { sqlSafefFrag(condStr, sizeof(condStr), "name='%s'", geneId); spID = sqlGetField(database, "rgdGene2ToUniProt", "value", condStr); } else { sqlSafefFrag(condStr, sizeof(condStr), "kgID='%s'", geneId); spID = sqlGetField(database, "kgXref", "spID", condStr); } if (spID != NULL) { origSpID = cloneString(spID); /* convert splice variant UniProt ID to its main root ID */ chp = strstr(spID, "-"); if (chp != NULL) *chp = '\0'; if (!isRgdGene(conn)) { sqlSafef(query, sizeof(query), "select count(*) from %s.spReactomeEvent, %s.spVariant, %s.kgXref where kgID='%s' and kgXref.spID=variant and variant = '%s' and spReactomeEvent.spID=parent", PROTEOME_DB_NAME, PROTEOME_DB_NAME, database, geneId, origSpID); } else { sqlSafef(query, sizeof(query), "select count(*) from %s.spReactomeEvent, %s.spVariant, %s.rgdGene2ToUniProt where name='%s' and value=variant and variant = '%s' and spReactomeEvent.spID=parent", PROTEOME_DB_NAME, PROTEOME_DB_NAME, database, geneId, origSpID); } ret = sqlQuickNum(conn, query); } return ret; }
static int keggCount(struct pathwayLink *pl, struct sqlConnection *conn, char *geneId) /* Count up number of hits. */ { char query[256]; if (!isRgdGene(conn)) { sqlSafef(query, sizeof(query), "select count(*) from keggPathway k, kgXref x where k.kgID=x.kgId and x.kgId='%s'", geneId); } else { sqlSafef(query, sizeof(query), "select count(*) from rgdGene2KeggPathway k, rgdGene2 x where k.rgdId=x.name and x.name='%s'", geneId); } return sqlQuickNum(conn, query); }
char *getSwissProtAcc(struct sqlConnection *conn, struct sqlConnection *spConn, char *geneId) /* Look up SwissProt id. Return NULL if not found. FreeMem this when done. * spConn is existing SwissProt database conn. May be NULL. */ { char *proteinSql = genomeSetting("proteinSql"); char query[256]; char *someAcc, *primaryAcc = NULL; if (isRgdGene(conn)) { return(getRgdGeneUniProtAcc(curGeneId, conn)); } sqlSafef(query, sizeof(query), proteinSql, geneId); someAcc = sqlQuickString(conn, query); if (someAcc == NULL || someAcc[0] == 0) return NULL; primaryAcc = spFindAcc(spConn, someAcc); freeMem(someAcc); return primaryAcc; }
static void keggLink(struct pathwayLink *pl, struct sqlConnection *conn, char *geneId) /* Print out kegg database link. */ { char query[512], **row; struct sqlResult *sr; if (isRgdGene(conn)) { sqlSafef(query, sizeof(query), "select distinct k.locusID, k.mapID, keggMapDesc.description" " from rgdGene2KeggPathway k, keggMapDesc, rgdGene2 x" " where k.rgdId=x.name " " and x.name='%s'" " and k.mapID = keggMapDesc.mapID" , geneId); } else { sqlSafef(query, sizeof(query), "select k.locusID, k.mapID, keggMapDesc.description" " from keggPathway k, keggMapDesc, kgXref x" " where k.kgID=x.kgId " " and x.kgID='%s'" " and k.mapID = keggMapDesc.mapID" , geneId); } sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { hPrintf("<A HREF=\"http://www.genome.ad.jp/kegg-bin/show_pathway?%s+%s\" TARGET=_blank>", row[1], row[0]); hPrintf("%s</A> - %s<BR>", row[1], row[2]); } sqlFreeResult(&sr); }
void cartMain(struct cart *theCart) /* We got the persistent/CGI variable cart. Now * set up the globals and make a web page. */ { hgBotDelay(); cart = theCart; getDbAndGenome(cart, &database, &genome, oldVars); initGenbankTableNames(database); getGenomeSettings(); if (cartVarExists(cart, hggDoKgMethod)) doKgMethod(); else if (cartVarExists(cart, hggDoTxInfoDescription)) doTxInfoDescription(); else { struct sqlConnection *conn = NULL; char *geneName = cartUsualString(cart, hggGene, NULL); if (isEmpty(geneName)) { // Silly googlebots. hUserAbort("Error: the hgg_gene parameter is missing from the cart and the CGI params."); } /* if kgProtMap2 table exists, this means we are doing KG III */ if (hTableExists(database, "kgProtMap2")) kgVersion = KG_III; conn = hAllocConn(database); curGeneId = findGeneId(conn, geneName); getGenePosition(conn); curGenePred = getCurGenePred(conn); curGeneName = getGeneName(curGeneId, conn); spConn = hAllocConn(UNIPROT_DB_NAME); swissProtAcc = getSwissProtAcc(conn, spConn, curGeneId); if (isRgdGene(conn)) swissProtAcc=getRgdGeneUniProtAcc(curGeneId, conn); /* Check command variables, and do the ones that * don't want to put up the hot link bar etc. */ if (cartVarExists(cart, hggDoGetMrnaSeq)) doGetMrnaSeq(conn, curGeneId, curGeneName); else if (cartVarExists(cart, hggDoWikiTrack)) doWikiTrack(conn); else if (cartVarExists(cart, hggDoGetProteinSeq)) doGetProteinSeq(conn, curGeneId, curGeneName); else if (cartVarExists(cart, hggDoRnaFoldDisplay)) doRnaFoldDisplay(conn, curGeneId, curGeneName); else if (cartVarExists(cart, hggDoOtherProteinSeq)) doOtherProteinSeq(conn, curGeneName); else if (cartVarExists(cart, hggDoOtherProteinAli)) doOtherProteinAli(conn, curGeneId, curGeneName); else { /* Default case - start fancy web page. */ measureTiming = isNotEmpty(cartOptionalString(cart, "measureTiming")); struct trackDb *tdb = hTrackDbForTrack(database, genomeSetting("knownGene")); isGencode = trackDbSettingOn(tdb, "isGencode"); isGencode2 = trackDbSettingOn(tdb, "isGencode2"); cartWebStart(cart, database, "%s Gene %s (%s) Description and Page Index", genome, curGeneName, isGencode2 ? curGeneId : curAlignId); webMain(conn, tdb); cartWebEnd(); } hFreeConn(&spConn); hFreeConn(&conn); } cartRemovePrefix(cart, hggDoPrefix); }
char *linkGetUrl(struct link *link, struct sqlConnection *conn, char *geneId) /* Return URL string if possible or NULL if not. FreeMem this when done. */ { char query[512]; struct sqlResult *sr; char **row; char *url = NULL; /* Some special case code here for things that need to * do more than check a table. */ if (sameString(link->name, "family")) { if (!hgNearOk(database)) return NULL; } if (sameString(link->name, "protBrowser")) { if (!hgPbOk(database)) return NULL; /* special processing for PB, since we need the protein ID, instead everything key off from gene ID */ /* use UniProt accession instead of displayID, because display ID sometimes changes */ if (swissProtAcc == NULL || swissProtAcc[0] == 0) return NULL; if (isRgdGene(conn)) { safef(query, sizeof(query), "../cgi-bin/pbGlobal?proteinID=%s", swissProtAcc); } else { safef(query, sizeof(query), "../cgi-bin/pbTracks?db=%s&proteinID=%s", database, swissProtAcc); } return(cloneString(query)); } if (sameString(link->name, "tbSchema")) { char *geneTable = genomeSetting("knownGene"); struct trackDb *tdb = hTrackDbForTrack(sqlGetDatabase(conn), geneTable); struct dyString *dy = NULL; if (tdb == NULL) return NULL; dy = newDyString(256); dyStringPrintf(dy, link->url, tdb->grp, geneTable, geneTable); trackDbFree(&tdb); addLinkExtras(link, dy); return dyStringCannibalize(&dy); } geneId = cloneAndCut(geneId, link->preCutAt); safef(query, sizeof(query), link->idSql, geneId); sr = sqlGetResult(conn, query); row = sqlNextRow(sr); if (row != NULL && row[0][0] != 0) /* If not null or empty */ { struct dyString *dy = newDyString(0); char *name = cloneAndCut(row[0], link->postCutAt); dyStringPrintf(dy, link->url, name, row[1], row[2], row[3]); addLinkExtras(link, dy); url = dyStringCannibalize(&dy); freez(&name); } sqlFreeResult(&sr); freeMem(geneId); return url; }
static void synonymPrint(struct section *section, struct sqlConnection *conn, char *id) /* Print out SwissProt comments - looking up typeId/commentVal. */ { char *protAcc = getSwissProtAcc(conn, spConn, id); char *spDisplayId; char *refSeqAcc = ""; char *mrnaAcc = ""; char *oldDisplayId; char condStr[255]; char *kgProteinID; char *parAcc; /* parent accession of a variant splice protein */ char *chp; if (isRgdGene(conn)) { rgdGene2SynonymPrint(section,conn, id); return; } if (sqlTablesExist(conn, "kgAlias")) printAlias(id, conn); if (sameWord(genome, "Zebrafish")) { char *xrefTable = "ensXRefZfish"; char *geneIdCol = "ensGeneId"; /* get Gene Symbol and RefSeq accession from Zebrafish-specific */ /* cross-reference table */ printGeneSymbol(id, xrefTable, geneIdCol, conn); refSeqAcc = getRefSeqAcc(id, xrefTable, geneIdCol, conn); hPrintf("<B>ENSEMBL ID:</B> %s", id); } else { char query[256]; char *toRefTable = genomeOptionalSetting("knownToRef"); if (toRefTable != NULL && sqlTableExists(conn, toRefTable)) { safef(query, sizeof(query), "select value from %s where name='%s'", toRefTable, id); refSeqAcc = emptyForNull(sqlQuickString(conn, query)); } if (sqlTableExists(conn, "kgXref")) { safef(query, sizeof(query), "select mRNA from kgXref where kgID='%s'", id); mrnaAcc = emptyForNull(sqlQuickString(conn, query)); } if (sameWord(genome, "C. elegans")) hPrintf("<B>WormBase ID:</B> %s<BR>", id); else hPrintf("<B>UCSC ID:</B> %s<BR>", id); } if (refSeqAcc[0] != 0) { hPrintf("<B>RefSeq Accession: </B> <A HREF=\""); printOurRefseqUrl(stdout, refSeqAcc); hPrintf("\">%s</A><BR>\n", refSeqAcc); } else if (mrnaAcc[0] != 0) { safef(condStr, sizeof(condStr), "acc = '%s'", mrnaAcc); if (sqlGetField(database, "gbCdnaInfo", "acc", condStr) != NULL) { hPrintf("<B>Representative RNA: </B> <A HREF=\""); printOurMrnaUrl(stdout, mrnaAcc); hPrintf("\">%s</A><BR>\n", mrnaAcc); } else /* do not show URL link if it is not found in gbCdnaInfo */ { hPrintf("<B>Representative RNA: %s </B>", mrnaAcc); } } if (protAcc != NULL) { kgProteinID = cloneString(""); if (hTableExists(sqlGetDatabase(conn), "knownGene") && (isNotEmpty(cartOptionalString(cart, hggChrom)) && differentWord(cartOptionalString(cart, hggChrom),"none"))) { safef(condStr, sizeof(condStr), "name = '%s' and chrom = '%s' and txStart=%s and txEnd=%s", id, cartOptionalString(cart, hggChrom), cartOptionalString(cart, hggStart), cartOptionalString(cart, hggEnd)); kgProteinID = sqlGetField(database, "knownGene", "proteinID", condStr); } hPrintf("<B>Protein: "); if (strstr(kgProteinID, "-") != NULL) { parAcc = cloneString(kgProteinID); chp = strstr(parAcc, "-"); *chp = '\0'; /* show variant splice protein and the UniProt link here */ hPrintf("<A HREF=\"http://www.uniprot.org/uniprot%s\" " "TARGET=_blank>%s</A></B>, splice isoform of ", kgProteinID, kgProteinID); hPrintf("<A HREF=\"http://www.uniprot.org/uniprot/%s\" " "TARGET=_blank>%s</A></B>\n", parAcc, parAcc); } else { hPrintf("<A HREF=\"http://www.uniprot.org/uniprot/%s\" " "TARGET=_blank>%s</A></B>\n", protAcc, protAcc); } /* show SWISS-PROT display ID if it is different than the accession ID */ /* but, if display name is like: Q03399 | Q03399_HUMAN, then don't show display name */ spDisplayId = spAnyAccToId(spConn, protAcc); if (spDisplayId == NULL) { errAbort("<br>%s seems to no longer be a valid protein ID in our latest UniProtKB DB.", protAcc); } if (strstr(spDisplayId, protAcc) == 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) && !sameWord(protAcc, oldDisplayId)) { hPrintf(" or %s", oldDisplayId); } } hPrintf(")<BR>\n"); } } printCcds(id, conn); }
static void ctdPrint(struct section *section, struct sqlConnection *conn, char *geneId) /* Print out CTD section. */ { char query[256]; struct sqlResult *sr; char **row; char *chemId, *chemName; int chemCnt; int first = 1; boolean showCompleteCtdList; struct dyString *currentCgiUrl; showCompleteCtdList = FALSE; if (cgiOptionalString("showAllCtdRef") != NULL) { if (sameWord(cgiOptionalString("showAllCtdRef"), "Y") || sameWord(cgiOptionalString("showAllCtdRef"), "y") ) { showCompleteCtdList = TRUE; } cartRemove(cart, "showAllCtdRef"); } currentCgiUrl = cgiUrlString(); /* List chemicals related to this gene */ if (isRgdGene(conn)) { sqlSafef(query, sizeof(query), "select ChemicalId, ChemicalName from rgdGene2Xref x, hgFixed.ctdSorted c where x.info=c.GeneSymbol and rgdGeneId='%s' and infoType='Name'", geneId); } else { sqlSafef(query, sizeof(query), "select ChemicalId, ChemicalName from kgXref x, hgFixed.ctdSorted c where x.geneSymbol=c.GeneSymbol and kgId='%s'", geneId); } sr = sqlMustGetResult(conn, query); row = sqlNextRow(sr); chemCnt = 0; while (row != NULL) { chemId = cloneString(row[0]); chemName = cloneString(row[1]); if (first) { printf("<B>The following chemicals interact with this gene</B>\n"); printf("<UL>"); first = 0; } printf("<LI><A HREF=\"http://ctd.mdibl.org/detail.go?type=chem&acc=%s\" target=_blank>", chemId); printf("%s</A>\n", chemId); printf("%s\n", chemName); printf("</LI>"); chemCnt++; row = sqlNextRow(sr); /* Initially, just show no more than 10 items */ if ((!showCompleteCtdList) && (chemCnt >= 10) && (row != NULL)) { chemCnt++; break; } } sqlFreeResult(&sr); if (!first) printf("</UL>"); /* Offer user the option to see the complete list */ if ((!showCompleteCtdList) && chemCnt > 10) { printf("<B> more ... </B>"); printf("<A HREF=\"%s?showAllCtdRef=Y&%s#ctd\">click here to view the complete list</A> " ,"hgGene", currentCgiUrl->string); } return; }
static void reactomeLink(struct pathwayLink *pl, struct sqlConnection *conn, char *geneId) { char condStr[255]; char *spID, *chp; struct sqlConnection *conn2; char query2[256]; struct sqlResult *sr2; char **row2; char *eventDesc; char *eventID; /* check the existence of kgXref table first */ if (isRgdGene(conn)) { if (!sqlTableExists(conn, "rgdGene2Xref")) return; } else { if (!sqlTableExists(conn, "kgXref")) return; } if (isRgdGene(conn)) { sqlSafefFrag(condStr, sizeof(condStr), "name='%s'", geneId); spID = sqlGetField(database, "rgdGene2ToUniProt", "value", condStr); } else { sqlSafefFrag(condStr, sizeof(condStr), "kgID='%s'", geneId); spID = sqlGetField(database, "kgXref", "spID", condStr); } if (spID != NULL) { /* convert splice variant UniProt ID to its main root ID */ chp = strstr(spID, "-"); if (chp != NULL) *chp = '\0'; hPrintf( "<BR>Protein %s (<A href=\"http://www.reactome.org/cgi-bin/link?SOURCE=UniProt&ID=%s\" TARGET=_blank>Reactome details)</A> participates in the following event(s):<BR><BR>" , spID, spID); conn2= hAllocConn(database); sqlSafef(query2,sizeof(query2), "select eventID, eventDesc from proteome.spReactomeEvent where spID='%s'", spID); sr2 = sqlMustGetResult(conn2, query2); row2 = sqlNextRow(sr2); while (row2 != NULL) { eventID = row2[0]; eventDesc = row2[1]; hPrintf( "<A href=\"http://www.reactome.org/cgi-bin/eventbrowser?DB=gk_current&ID=%s\" TARGET=_blank>%s</A> %s<BR>\n", eventID, eventID, eventDesc); row2 = sqlNextRow(sr2); } sqlFreeResult(&sr2); hFreeConn(&conn2); } }