int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); if (argc != 4) usage(); database=argv[1]; hSetDb(argv[1]); protDbName = hPdbFromGdb(database); fbName(argv[1], protDbName, argv[2], argv[3]); return 0; }
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); } }
static void domainsPrint(struct section *section, struct sqlConnection *conn, char *geneId) /* Print out protein domains. */ { char *db = sqlGetDatabase(conn); struct slName *el, *list; list = spExtDbAcc1List(spConn, swissProtAcc, "Interpro"); if (list != NULL) { char query[256], **row, **row2; struct sqlResult *sr, *sr2; hPrintf("<B>InterPro Domains: </B> "); hPrintf("<A HREF=\"http://www.ebi.ac.uk/interpro/protein/%s\" TARGET=_blank>", swissProtAcc); hPrintf("Graphical view of domain structure</A><BR>"); sqlSafef(query, sizeof(query), "select extAcc1,extAcc2 from extDbRef,extDb" " where extDbRef.acc = '%s'" " and extDb.val = 'Interpro' and extDb.id = extDbRef.extDb" , swissProtAcc); sr = sqlGetResult(spConn, query); while ((row = sqlNextRow(sr)) != NULL) { //hPrintf("<A HREF=\"http://www.ebi.ac.uk/interpro/entry/%s\" TARGET=_blank>", row[0]); //hPrintf("%s</A> - %s<BR>\n", row[0], row[1]); char interPro[256]; char *pdb = hPdbFromGdb(db); safef(interPro, 128, "%s.interProXref", pdb); if (hTableExists(db, interPro)) { sqlSafef(query, sizeof(query), "select description from %s where accession = '%s' and interProId = '%s'", interPro, swissProtAcc, row[0]); sr2 = sqlGetResult(conn, query); if ((row2 = sqlNextRow(sr2)) != NULL) { hPrintf("<A HREF=\"http://www.ebi.ac.uk/interpro/entry/%s\" TARGET=_blank>", row[0]); hPrintf("%s</A> - %s <BR>\n", row[0], row2[0]); } sqlFreeResult(&sr2); } else { hPrintf("<A HREF=\"http://www.ebi.ac.uk/interpro/entry/%s\" TARGET=_blank>", row[0]); hPrintf("%s</A> - %s<BR>\n", row[0], row[1]); } } hPrintf("<BR>\n"); slFreeList(&list); } if (kgVersion == KG_III) { /* Do Pfam domains here. */ list = getPfamDomainList(conn, geneId); if (list != NULL) { hPrintf("<B>Pfam Domains:</B><BR>"); for (el = list; el != NULL; el = el->next) { char query[256]; char *description; sqlSafef(query, sizeof(query), "select description from pfamDesc where pfamAC='%s'", el->name); description = sqlQuickString(conn, query); if (description == NULL) description = cloneString("n/a"); hPrintf("<A HREF=\"http://pfam.xfam.org/family?acc=%s\" TARGET=_blank>", el->name); hPrintf("%s</A> - %s<BR>\n", el->name, description); freez(&description); } slFreeList(&list); hPrintf("<BR>\n"); } /* Do SCOP domains here */ list = getDomainList(conn, geneId, "Scop"); if (list != NULL) { hPrintf("<B>SCOP Domains:</B><BR>"); for (el = list; el != NULL; el = el->next) { char query[256]; char *description; sqlSafef(query, sizeof(query), "select description from scopDesc where acc='%s'", el->name); description = sqlQuickString(conn, query); if (description == NULL) description = cloneString("n/a"); hPrintf("<A HREF=\"http://scop.berkeley.edu/sunid=%s\" TARGET=_blank>", el->name); hPrintf("%s</A> - %s<BR>\n", el->name, description); freez(&description); } slFreeList(&list); hPrintf("<BR>\n"); } } else { list = spExtDbAcc1List(spConn, swissProtAcc, "Pfam"); if (list != NULL) { char *pfamDescSql = genomeSetting("pfamDescSql"); hPrintf("<B>Pfam Domains:</B><BR>"); for (el = list; el != NULL; el = el->next) { char query[256]; char *description; sqlSafef(query, sizeof(query), pfamDescSql, el->name); description = sqlQuickString(conn, query); if (description == NULL) description = cloneString("n/a"); hPrintf("<A HREF=\"http://pfam.xfam.org/family?acc=%s\" TARGET=_blank>", el->name); hPrintf("%s</A> - %s<BR>\n", el->name, description); freez(&description); } slFreeList(&list); hPrintf("<BR>\n"); } } list = spExtDbAcc1List(spConn, swissProtAcc, "PDB"); if (list != NULL) { struct sqlConnection *conn2 = sqlConnect(db); char query[256], **row; struct sqlResult *sr; int column = 0, maxColumn=3, rowCount=0; hPrintf("<B>Protein Data Bank (PDB) 3-D Structure</B><BR>"); sqlSafef(query, sizeof(query), "select extAcc1,extAcc2 from extDbRef,extDb" " where extDbRef.acc = '%s'" " and extDb.val = 'PDB' and extDb.id = extDbRef.extDb" , swissProtAcc); sr = sqlGetResult(spConn, query); hPrintf("<TABLE><TR>\n"); while ((row = sqlNextRow(sr)) != NULL) { if (++column > maxColumn) { hPrintf("</TR><TR>"); column = 1; if (rowCount == 0) { hPrintf("<TD ALIGN=CENTER COLSPAN=4><I>To conserve bandwidth, only the images from the first %d structures are shown.</I>", maxColumn); hPrintf("</TR><TR>"); } ++rowCount; } hPrintf("<TD>"); hPrintf("<A HREF=\"http://www.rcsb.org/pdb/cgi/explore.cgi?pdbId=%s\" TARGET=_blank>", row[0]); if (rowCount < 1) hPrintf("<IMG SRC=\"http://www.rcsb.org/pdb/images/%s_asym_r_250.jpg\"><BR>", row[0]); hPrintf("%s</A> - %s ", row[0], row[1]); // include links LS-SNP and to launch viewer in PDB chimera struct tempName chimerax; lsSnpPdbChimeraSnpAnn(conn, row[0], NULL, &chimerax); hPrintf(" <A HREF=\"%s\">Chimera</A>", chimerax.forHtml); if (lsSnpPdbHasPdb(conn2, row[0])) hPrintf(" <A HREF=\"%s\" TARGET=_blank>LS-SNP</A>", lsSnpPdbGetUrlPdbSnp(row[0], NULL)); hPrintf("</TD>\n"); } hPrintf("</TR></TABLE>\n"); hPrintf("<A href=\"../goldenPath/help/chimera.html\" TARGET=_blank>Chimera help</A>\n"); hPrintf("<BR><BR>\n"); slFreeList(&list); sqlDisconnect(&conn2); } /* Do modBase link. */ { hPrintf("<B>ModBase Predicted Comparative 3D Structure on "); modBaseAnchor(swissProtAcc); hPrintf("%s", swissProtAcc); hPrintf("</A></B><BR>\n"); hPrintf("<TABLE><TR>"); hPrintf("<TD>"); modBaseAnchor(swissProtAcc); hPrintf("\n<IMG SRC=\"https://modbase.compbio.ucsf.edu/modbase-cgi/image/modbase.jpg?database_id=%s\"></A></TD>", swissProtAcc); hPrintf("<TD>"); modBaseAnchor(swissProtAcc); hPrintf("\n<IMG SRC=\"https://modbase.compbio.ucsf.edu/modbase-cgi/image/modbase.jpg?database_id=%s&axis=x°ree=90\"></A></TD>", swissProtAcc); hPrintf("<TD>"); modBaseAnchor(swissProtAcc); hPrintf("\n<IMG SRC=\"https://modbase.compbio.ucsf.edu/modbase-cgi/image/modbase.jpg?database_id=%s&axis=y°ree=90\"></A></TD>", swissProtAcc); hPrintf("</TR><TR>\n"); hPrintf("<TD ALIGN=CENTER>Front</TD>"); hPrintf("<TD ALIGN=CENTER>Top</TD>"); hPrintf("<TD ALIGN=CENTER>Side</TD>"); hPrintf("</TR></TABLE>\n"); hPrintf("<I>The pictures above may be empty if there is no " "ModBase structure for the protein. The ModBase structure " "frequently covers just a fragment of the protein. You may " "be asked to log onto ModBase the first time you click on the " "pictures. It is simplest after logging in to just click on " "the picture again to get to the specific info on that model.</I>"); } }
void presentProteinSelections(char *queryID, int protCntInSwissByGene, int protCntInSupportedGenomeDb) /* Fuction to present a web page with proteins of different organisms */ { char *gDatabase; char *org = NULL; char *spID, *displayID, *desc; char cond_str[255]; struct sqlConnection *conn, *conn3; char query[256], query3[512]; struct sqlResult *sr, *sr3; char **row, **row3; struct sqlConnection *connCentral, *proteinsConn; char queryCentral[256]; struct sqlResult *srCentral; char *answer; char *taxonId, *protAcc, *protDisp, *protOrg, *protDesc; char *oldOrg, *orgSciName; char *pbOrgSciName[MAX_PB_ORG]; boolean pbOrgPresented[MAX_PB_ORG]; boolean skipIt; int i, maxPbOrg; int otherCnt; connCentral = hConnectCentral(); hPrintf("<TABLE WIDTH=\"100%%\" BGCOLOR=\"#"HG_COL_HOTLINKS"\" BORDER=\"0\" CELLSPACING=\"0\""); hPrintf("CELLPADDING=\"2\"><TR>\n"); hPrintf("<TD ALIGN=LEFT><A HREF=\"../index.html\">%s</A></TD>", wrapWhiteFont("Home")); hPrintf("<TD style='text-align:center; color:#FFFFFF; font-size:medium;'>%s</TD>", "UCSC Proteome Browser"); if (proteinInSupportedGenome) { hPrintf("<TD ALIGN=Right><A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml\""); } else { hPrintf("<TD ALIGN=Right><A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml\""); } hPrintf("TARGET=_blank>%s</A></TD>", wrapWhiteFont("Help")); hPrintf("</TR></TABLE>"); hPrintf("<FONT SIZE=4><BR><B>Please select one of the following proteins:<BR><BR></B></FONT>\n"); /* remmember a list of scientific names for the genomes that supports PB */ sqlSafef(queryCentral, sizeof(queryCentral), "select distinct dbDb.scientificName from dbDb where hgPbOk=1"); srCentral = sqlMustGetResult(connCentral, queryCentral); row3 = sqlNextRow(srCentral); i=0; while (row3 != NULL) { pbOrgSciName[i] = strdup(row3[0]); pbOrgPresented[i] = FALSE; i++; row3 = sqlNextRow(srCentral); } maxPbOrg = i; /* go through each genome DB that supports PB */ sqlSafef(queryCentral, sizeof(queryCentral), "select defaultDb.name, dbDb.organism, dbDb.scientificName from dbDb,defaultDb where hgPbOk=1 and defaultDb.name=dbDb.name"); srCentral = sqlMustGetResult(connCentral, queryCentral); row3 = sqlNextRow(srCentral); while (row3 != NULL) { gDatabase = row3[0]; org = row3[1]; orgSciName= row3[2]; protDbName = hPdbFromGdb(gDatabase); proteinsConn = sqlConnect(protDbName); conn = sqlConnect(gDatabase); sqlSafefFrag(cond_str, sizeof(cond_str), "alias='%s' and spID != ''", queryID); answer = sqlGetField(gDatabase, "kgSpAlias", "count(distinct spID)", cond_str); if ((answer != NULL) && (!sameWord(answer, "0"))) { /* display organism name */ hPrintf("<FONT SIZE=4><B>"); hPrintf("<A href=\"http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Undef&name=%s&lvl=0&srchmode=1\" TARGET=_blank>%s</A>", cgiEncode(orgSciName), orgSciName); hPrintf(" (%s):</B></FONT>\n", org); hPrintf("<UL>"); sqlSafef(query, sizeof(query), "select distinct spID from %s.kgSpAlias where alias='%s' " "and spID != ''", gDatabase, queryID); sr = sqlMustGetResult(conn, query); row = sqlNextRow(sr); while (row != NULL) { spID = row[0]; sqlSafefFrag(cond_str, sizeof(cond_str), "accession='%s'", spID); displayID = sqlGetField(protDbName, "spXref3", "displayID", cond_str); sqlSafefFrag(cond_str, sizeof(cond_str), "accession='%s'", spID); desc = sqlGetField(protDbName, "spXref3", "description", cond_str); /* display a protein */ hPrintf( "<LI><A HREF=\"../cgi-bin/pbGlobal?proteinID=%s&db=%s\">", displayID, gDatabase); if (sameWord(spID, displayID) || (strstr(displayID, spID) != NULL)) { hPrintf("%s</A> %s\n", spID, desc); } else { hPrintf("%s</A> (aka %s) %s\n", spID, displayID, desc); } /* remember the fact that a protein is shown under this PB supported genome */ for (i=0; i<maxPbOrg; i++) { if (sameWord(orgSciName, pbOrgSciName[i])) { pbOrgPresented[i] = TRUE; } } row = sqlNextRow(sr); } hPrintf("</UL>");fflush(stdout); sqlFreeResult(&sr); } sqlDisconnect(&proteinsConn); row3 = sqlNextRow(srCentral); } sqlFreeResult(&srCentral); hDisconnectCentral(&connCentral); sqlDisconnect(&conn); if (protCntInSwissByGene > protCntInSupportedGenomeDb) { otherCnt = -1; if (protCntInSupportedGenomeDb >0) { otherCnt = 0; hPrintf("<FONT SIZE=4><B>Other Organisms:</B></FONT>\n"); hPrintf("<UL>"); } else { hPrintf("<UL>"); } oldOrg = strdup(""); conn3 = sqlConnect(UNIPROT_DB_NAME); sqlSafef(query3, sizeof(query3), "select taxon.id, gene.acc, displayId.val, binomial, description.val " "from gene, displayId, accToTaxon,taxon, description " "where gene.val='%s' and gene.acc=displayId.acc and accToTaxon.taxon=taxon.id " "and accToTaxon.acc=gene.acc and description.acc=gene.acc order by binomial", queryID); sr3 = sqlMustGetResult(conn3, query3); row3 = sqlNextRow(sr3); /* go through each protein */ while (row3 != NULL) { taxonId = row3[0]; protAcc = row3[1]; protDisp = row3[2]; protOrg = row3[3]; protDesc = row3[4]; /* decide if this entry should be skipped */ skipIt = FALSE; for (i=0; i<maxPbOrg; i++) { if (sameWord(pbOrgSciName[i], protOrg) && pbOrgPresented[i]) { skipIt = TRUE; } } /* print organism name if organism changed */ if (!sameWord(protOrg, oldOrg)) { if (!sameWord(oldOrg, "")) { hPrintf("</UL>\n"); } if (!skipIt) { sqlSafefFrag(cond_str, sizeof(cond_str), "id=%s and nameType='genbank common name'", taxonId); answer = sqlGetField(PROTEOME_DB_NAME, "taxonNames", "name", cond_str); hPrintf("<FONT SIZE=3><B>"); hPrintf("<A href=\"http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Undef&name=%s&lvl=0&srchmode=1\" TARGET=_blank>%s</A>", cgiEncode(protOrg), protOrg); if (answer != NULL) { hPrintf(" (%s)", answer); } hPrintf(":</B></FONT>\n"); } hPrintf("<UL>\n"); } /* print protein entry, if it is not already displayed in the PB supported genome list */ if (!skipIt) { otherCnt++; if (sameWord(protAcc, protDisp)) { hPrintf("<LI><A HREF=\"../cgi-bin/pbGlobal?proteinID=%s\">", protAcc); hPrintf("%s</A> %s\n", protAcc, protDesc); } else { hPrintf("<LI><A HREF=\"../cgi-bin/pbGlobal?proteinID=%s\">", protAcc); if (strstr(protDisp, protAcc) != NULL) { hPrintf("%s</A> %s\n", protAcc, protDesc); } else { hPrintf("%s</A> (aka %s) %s\n", protAcc, protDisp, protDesc); } } } oldOrg = strdup(protOrg); row3 = sqlNextRow(sr3); } if (otherCnt == 0) hPrintf("</UL>None");fflush(stdout); sqlFreeResult(&sr3); sqlDisconnect(&conn3); } }