void doTracks(char *proteinID, char *mrnaID, char *aa, int *yOffp, char *psOutput) /* draw various protein tracks */ { int l; char aaOrigOffsetStr[20]; int hasResFreq; char uniProtDbName[50]; char *protDbDate; char *chrom; char strand; char *kgId, *kgPep, *protPep; char cond_str[255]; char *answer; //int i, ll; //char *chp1, *chp2; g_font = mgSmallFont(); safef(pbScaleStr, sizeof(pbScaleStr), "%d", pbScale); if (psOutput != NULL) { pbScale = atoi(cartOptionalString(cart, "pbt.pbScaleStr")); } if (cgiOptionalString("trackOffset") != NULL) { trackOrigOffset = atoi(cgiOptionalString("trackOffset")); } if (cgiOptionalString("pbScaleStr") != NULL) { pbScale = atoi(cgiOptionalString("pbScaleStr")); } if (cgiOptionalString("pbScale") != NULL) { scaleButtonPushed = TRUE; if (strcmp(cgiOptionalString("pbScale"), "1/6") == 0) pbScale = 1; if (strcmp(cgiOptionalString("pbScale"), "1/2") == 0) pbScale = 3; if (strcmp(cgiOptionalString("pbScale"), "FULL") == 0) pbScale = 6; if (strcmp(cgiOptionalString("pbScale"), "DNA") == 0) pbScale =22; safef(pbScaleStr, sizeof(pbScaleStr), "%d", pbScale); cgiMakeHiddenVar("pbScaleStr", pbScaleStr); } else { scaleButtonPushed = FALSE; } if (psOutput == NULL) { if (cgiVarExists("pbt.left3")) { relativeScroll(-0.95); initialWindow = FALSE; } else if (cgiVarExists("pbt.left2")) { relativeScroll(-0.475); initialWindow = FALSE; } else if (cgiVarExists("pbt.left1")) { relativeScroll(-0.02); initialWindow = FALSE; } else if (cgiVarExists("pbt.right1")) { relativeScroll(0.02); initialWindow = FALSE; } else if (cgiVarExists("pbt.right2")) { relativeScroll(0.475); initialWindow = FALSE; } else if (cgiVarExists("pbt.right3")) { relativeScroll(0.95); initialWindow = FALSE; } } dnaUtilOpen(); l=strlen(aa); /* initialize AA properties */ aaPropertyInit(&hasResFreq); sfCount = getSuperfamilies2(proteinID); if (sfCount == 0) { sfCount = getSuperfamilies(proteinID); } if (mrnaID != NULL) { if (kgVersion == KG_III) { doExonTrack = FALSE; sqlSafefFrag(cond_str, sizeof(cond_str), "spId='%s'", proteinID); kgId = sqlGetField(database, "kgXref", "kgId", cond_str); if (kgId != NULL) { sqlSafefFrag(cond_str, sizeof(cond_str), "name='%s'", kgId); kgPep = sqlGetField(database, "knownGenePep", "seq", cond_str); //printf("<pre><br>%s", kgPep);fflush(stdout); if (kgPep != NULL) { if (strstr(protDbName, "proteins") != NULL) { protDbDate = strstr(protDbName, "proteins") + strlen("proteins"); safef(uniProtDbName, sizeof(uniProtDbName),"sp%s", protDbDate); sqlSafefFrag(cond_str, sizeof(cond_str), "acc='%s'", proteinID); protPep = sqlGetField(uniProtDbName, "protein", "val", cond_str); //printf("<br>%s\n", protPep);fflush(stdout); if (protPep != NULL) { if (sameWord(kgPep, protPep)) { //printf("<br>MATCH!\n");fflush(stdout); sqlSafefFrag(cond_str, sizeof(cond_str), "qName='%s'", kgId); answer = sqlGetField(database, kgProtMapTableName, "qName", cond_str); if (answer != NULL) { /* NOTE: passing in kgId instead of proteinID because kgProtMap2's qName uses kgId instead of protein display ID */ getExonInfo(kgId, &exCount, &chrom, &strand); assert(exCount > 0); doExonTrack = TRUE; } } /* else { chp1 = kgPep; printf("<br>"); chp2 = protPep; ll = strlen(kgPep); if (strlen(protPep) < ll) ll= strlen(protPep); for (i=0; i<ll; i++) { if (*chp1 != *chp2) { printf("%c", *chp1); } else { printf("."); } chp1++; chp2++; } } //printf("</pre>");fflush(stdout); */ } } } } } else { doExonTrack = TRUE; getExonInfo(proteinID, &exCount, &chrom, &strand); assert(exCount > 0); } /* do the following only if pbTracks called doTracks() */ if (initialWindow && IAmPbTracks) { prevGBOffsetSav = calPrevGB(exCount, chrom, strand, l, yOffp, proteinID, mrnaID); trackOrigOffset = prevGBOffsetSav; if (trackOrigOffset > (protSeqLen*pbScale - 600)) trackOrigOffset = protSeqLen*pbScale - 600; /* prevent negative value */ if (trackOrigOffset < 0) trackOrigOffset = 0; } /* if this if for PDF/Postscript, the trackOrigOffset is already calculated previously, use the saved value */ if (psOutput != NULL) { trackOrigOffset = atoi(cartOptionalString(cart, "pbt.trackOffset")); } } /*printf("<br>%d %d<br>%d %d\n", prevGBStartPos, prevGBEndPos, blockGenomeStartPositive[exCount-1], blockGenomeStartPositive[0]); fflush(stdout); */ if (strand == '-') { if ((prevGBStartPos <= blockGenomeStartPositive[exCount-1]) && (prevGBEndPos >= blockGenomeStartPositive[0])) { showPrevGBPos = FALSE; } } else { if ((prevGBStartPos <= blockGenomeStartPositive[0]) && (prevGBEndPos >= blockGenomeStartPositive[exCount-1])) { showPrevGBPos = FALSE; } } if ((cgiOptionalString("aaOrigOffset") != NULL) && scaleButtonPushed) { trackOrigOffset = atoi(cgiOptionalString("aaOrigOffset"))*pbScale; } pixWidth = 160+ protSeqLen*pbScale; if (pixWidth > MAX_PB_PIXWIDTH) { pixWidth = MAX_PB_PIXWIDTH; } if ((protSeqLen*pbScale - trackOrigOffset) < MAX_PB_PIXWIDTH) { pixWidth = protSeqLen*pbScale - trackOrigOffset + 160; } if (pixWidth < 550) pixWidth = 550; insideWidth = pixWidth-gfxBorder; if (proteinInSupportedGenome) { pixHeight = 250; } else { pixHeight = 215; } if (sfCount > 0) pixHeight = pixHeight + 20; /* make room for individual residues display */ if (pbScale >=6) pixHeight = pixHeight + 20; if (pbScale >=18) pixHeight = pixHeight + 30; if (psOutput) { vg = vgOpenPostScript(pixWidth, pixHeight, psOutput); suppressHtml = TRUE; hideControls = TRUE; } else { trashDirFile(&gifTn, "pbt", "pbt", ".png"); vg = vgOpenPng(pixWidth, pixHeight, gifTn.forCgi, FALSE); } /* Put up horizontal scroll controls. */ hWrites("Move "); hButton("pbt.left3", "<<<"); hButton("pbt.left2", " <<"); hButton("pbt.left1", " < "); hButton("pbt.right1", " > "); hButton("pbt.right2", ">> "); hButton("pbt.right3", ">>>"); hPrintf("     "); /* Put up scaling controls. */ hPrintf("Current scale: "); if (pbScale == 1) hPrintf("1/6 "); if (pbScale == 3) hPrintf("1/2 "); if (pbScale == 6) hPrintf("FULL "); if (pbScale == 22) hPrintf("DNA "); hPrintf("    Rescale to "); hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"1/6\">\n"); hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"1/2\">\n"); hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"FULL\">\n"); if (kgVersion == KG_III) { /* for KG III, the protein has to exist in the kgProtMap2 table (which will turn on doExonTrack flag) to provide the genomic position data needed for DNA sequence display */ if ((proteinInSupportedGenome) && (doExonTrack)) hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"DNA\">\n"); } else { if (proteinInSupportedGenome) hPrintf("<INPUT TYPE=SUBMIT NAME=\"pbScale\" VALUE=\"DNA\">\n"); } hPrintf("<FONT SIZE=1><BR><BR></FONT>\n"); g_vg = vg; pbRed = vgFindColorIx(g_vg, 0xf9, 0x51, 0x59); pbBlue = vgFindColorIx(g_vg, 0x00, 0x00, 0xd0); bkgColor = vgFindColorIx(vg, 255, 254, 232); vgBox(vg, 0, 0, insideWidth, pixHeight, bkgColor); /* Start up client side map. */ hPrintf("<MAP Name=%s>\n", mapName); vgSetClip(vg, 0, gfxBorder, insideWidth, pixHeight - 2*gfxBorder); /* start drawing indivisual tracks */ doAAScale(l, yOffp, 1); if (pbScale >= 6) doResidues(aa, l, yOffp); if (pbScale >= 18) doDnaTrack(chrom, strand, exCount, l, yOffp); if ((mrnaID != NULL) && showPrevGBPos) { doPrevGB(exCount, chrom, strand, l, yOffp, proteinID, mrnaID); } if (mrnaID != NULL) { if (doExonTrack) doExon(exCount, chrom, l, yOffp, proteinID, mrnaID); } doCharge(aa, l, yOffp); doHydrophobicity(aa, l, yOffp); doCysteines(aa, l, yOffp); if (sfCount > 0) doSuperfamily(ensPepName, sfCount, yOffp); if (hasResFreq) doAnomalies(aa, l, yOffp); doAAScale(l, yOffp, -1); vgClose(&vg); /* Finish map and save out picture and tell html file about it. */ hPrintf("</MAP>\n"); /* put tracks image here */ hPrintf( "\n<IMG SRC=\"%s\" BORDER=1 WIDTH=%d HEIGHT=%d USEMAP=#%s><BR>", gifTn.forCgi, pixWidth, pixHeight, mapName); if (proteinInSupportedGenome) { hPrintf("<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#tracks\" TARGET=_blank>"); } else { if (hIsGsidServer()) { hPrintf("<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbGsid/pbTracksHelp.shtml#tracks\" TARGET=_blank>"); } else { hPrintf("<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#tracks\" TARGET=_blank>"); } } hPrintf("Explanation of Protein Tracks</A><br>"); safef(trackOffset, sizeof(trackOffset), "%d", trackOrigOffset); cgiMakeHiddenVar("trackOffset", trackOffset); /* remember where the AA base origin is so that it can be passed to next PB page */ aaOrigOffset = trackOrigOffset/pbScale; safef(aaOrigOffsetStr, sizeof(aaOrigOffsetStr), "%d", aaOrigOffset); cgiMakeHiddenVar("aaOrigOffset", aaOrigOffsetStr); /* save the following state variables, to be used by PDF/Postcript processing */ cartSetString(cart,"pbt.pbScaleStr", pbScaleStr); cartSetString(cart,"pbt.trackOffset", trackOffset); cartSaveSession(cart); fflush(stdout); }
void makeActiveImagePB(char *psOutput, char *psOutput2) /* Make image and image map. */ { char *mapName = "map"; int pixWidth, pixHeight; char *answer; char cond_str[255]; struct sqlConnection *conn; struct sqlConnection *connCentral; char query[256]; struct sqlResult *sr; char **row; int iypos; char *blatGbDb; char *sciName, *commonName; char *spDisplayId; char *oldDisplayId; conn = sqlConnect(UNIPROT_DB_NAME); hPrintf("<br><font size=4>Protein "); hPrintf("<A HREF=\"http://www.uniprot.org/uniprot/%s\" TARGET=_blank><B>%s</B></A>\n", proteinID, proteinID); 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(" %s\n", description); hPrintf("</font><br>"); hPrintf("Organism: "); /* get scientific and Genbank common name of this organism */ sciName = NULL; commonName = NULL; sqlSafefFrag(cond_str, sizeof(cond_str),"accession='%s'", proteinID); answer = sqlGetField(PROTEOME_DB_NAME, "spXref3", "division", cond_str); if (answer != NULL) { sqlSafefFrag(cond_str, sizeof(cond_str), "id=%s and nameType='scientific name'", answer); sciName = sqlGetField(PROTEOME_DB_NAME, "taxonNames", "name", cond_str); sqlSafefFrag(cond_str, sizeof(cond_str), "id=%s and nameType='genbank common name'", answer); commonName = sqlGetField(PROTEOME_DB_NAME, "taxonNames", "name", cond_str); } if (sciName != NULL) { hPrintf("%s", sciName); } if (commonName != NULL) { hPrintf(" (%s)", commonName); } hPrintf("<br>"); protSeq = getAA(proteinID); if (protSeq == NULL) { hUserAbort("%s is not a current valid entry in UniProtKB\n", proteinID); } protSeqLen = strlen(protSeq); fflush(stdout); iypos = 15; doTracks(proteinID, mrnaID, protSeq, &iypos, psOutput); if (!hTableExists(database, "pbStamp")) goto histDone; pbScale = 3; pixWidth = 765; insideWidth = pixWidth-gfxBorder; pixHeight = 350; if (psOutput2) { vg2 = vgOpenPostScript(pixWidth, pixHeight, psOutput2); } else { trashDirFile(&gifTn2, "pbt", "pbt", ".png"); vg2 = vgOpenPng(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<MAP Name=%s>\n", mapName); vgSetClip(vg2, 0, gfxBorder, insideWidth, pixHeight - 2*gfxBorder); iypos = 15; /* Draw stamps. */ doStamps(proteinID, mrnaID, protSeq, vg2, &iypos); /* Finish map. */ hPrintf("</MAP>\n"); /* Save out picture and tell html file about it. */ vgClose(&vg2); hPrintf("<P>"); hPrintf("\n<IMG SRC=\"%s\" BORDER=1 WIDTH=%d HEIGHT=%d USEMAP=#%s><BR>", gifTn2.forCgi, pixWidth, pixHeight, mapName); if (proteinInSupportedGenome) { hPrintf("\n<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#histograms\" TARGET=_blank>"); } else { hPrintf("\n<A HREF=\"../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml#histograms\" TARGET=_blank>"); } hPrintf("Explanation of Protein Property Histograms</A><BR>"); hPrintf("<P>"); histDone: hPrintf("<P>"); fflush(stdout); /* See if a UCSC Genome Browser exist for this organism. If so, display BLAT link. */ connCentral = hConnectCentral(); sqlSafef(query, sizeof(query), "select defaultDb.name from dbDb, defaultDb where dbDb.scientificName='%s' and dbDb.name=defaultDb.name", sciName); sr = sqlGetResult(connCentral, query); row = sqlNextRow(sr); if (row != NULL) { blatGbDb = strdup(row[0]); } else { blatGbDb = NULL; } sqlFreeResult(&sr); hDisconnectCentral(&connCentral); if (proteinInSupportedGenome || (blatGbDb != NULL)) { hPrintf("\n<B>UCSC Links:</B><BR>\n "); hPrintf("<UL>\n"); /* Show GB links only if the protein belongs to a supported genome */ if (proteinInSupportedGenome) { doGenomeBrowserLink(proteinID, mrnaID, hgsidStr); doGeneDetailsLink(proteinID, mrnaID, hgsidStr); } /* Show Gene Sorter link only if it is valid for this genome */ if (hgNearOk(database)) { doGeneSorterLink(protDisplayID, mrnaID, hgsidStr); } /* Show BLAT link if we have UCSC Genome Browser for it */ if (blatGbDb != NULL) { doBlatLink(blatGbDb, sciName, commonName, protSeq); } hPrintf("</UL><P>"); } /* This section shows various types of domains */ conn = sqlConnect(UNIPROT_DB_NAME); domainsPrint(conn, proteinID); hPrintf("<P>"); /* Do Pathway section only if the protein belongs to a supported genome */ if (proteinInSupportedGenome); { doPathwayLinks(proteinID, mrnaID); } printFASTA(proteinID, protSeq); }
struct hvGfx *hvGfxOpenPng(int width, int height, char *fileName, boolean useTransparency) /* Open up something that we'll write out as a PNG someday. */ { return hvGfxAlloc(vgOpenPng(width, height, fileName, useTransparency)); }