void chkGlue(char *bacAcc, char *finBac, char *unfinBac, char *gluedBac, int trim, char *repeatMask) /* Display glued and unglued form of BAC. */ { int trackCount = 1; int pixWidth, pixHeight; int x, y; struct memGfx *mg; struct tempName gifTn, mapTn; FILE *mapFile; printf("See picture at bottom for overview of where contigs align.\n\n"); /* Figure out basic dimensions and allocate picture. */ font = mgSmallFont(); trackWidth = 700; trackHeight = mgFontPixelHeight(font) + 4; pixWidth = trackWidth + 2*border; pixHeight = trackCount * (trackHeight+border) + border; x = y = border; mg = mgNew(pixWidth, pixHeight); mgClearPixels(mg); makeBlockColors(mg); /* Create map file. */ makeTempName(&mapTn, "glu", ".map"); mapFile = mustOpen(mapTn.forCgi, "wb"); mapWriteHead(mapFile, pixWidth, pixHeight, bacAcc, trim, repeatMask); /* Write out tracks onto picture. */ aliTrack(bacAcc, finBac, unfinBac, mg, x, y, mapFile, trim, repeatMask); /* Save pic and tell html file about it. */ makeTempName(&gifTn, "glu", ".gif"); mgSaveGif(mg, gifTn.forCgi); printf("<INPUT TYPE=HIDDEN NAME=map VALUE=\"%s\">\n", mapTn.forCgi); printf( "<P><INPUT TYPE=IMAGE SRC = \"%s\" BORDER=1 WIDTH=%d HEIGHT=%d NAME = \"clickMe\" ALIGN=BOTTOM><BR>\n", gifTn.forHtml, pixWidth, pixHeight); printf("Click on contig for detailed alignment\n"); /* Write end of map */ mapWriteBox(mapFile, mtNone, 0, 0, pixWidth, pixHeight, NULL, 0, 0, 0, 0, 0); mapWriteBox(mapFile, mtEnd, 0, 0, pixWidth, pixHeight, NULL, 0, 0, 0, 0, 0); /* Clean up. */ fclose(mapFile); mgFree(&mg); }
char *altGraphXMakeImage(struct altGraphX *ag) /* create a drawing of splicing pattern */ { MgFont *font = mgSmallFont(); int fontHeight = mgFontLineHeight(font); struct spaceSaver *ssList = NULL; struct hash *heightHash = NULL; int rowCount = 0; struct tempName gifTn; int pixWidth = atoi(cartUsualString(cart, "pix", DEFAULT_PIX_WIDTH )); int pixHeight = 0; struct hvGfx *hvg; int lineHeight = 0; double scale = 0; Color shadesOfGray[9]; int maxShade = ArraySize(shadesOfGray)-1; scale = (double)pixWidth/(ag->tEnd - ag->tStart); lineHeight = 2 * fontHeight +1; altGraphXLayout(ag, ag->tStart, ag->tEnd, scale, 100, &ssList, &heightHash, &rowCount); hashFree(&heightHash); pixHeight = rowCount * lineHeight; makeTempName(&gifTn, "hgc", ".png"); hvg = hvGfxOpenPng(pixWidth, pixHeight, gifTn.forCgi, FALSE); makeGrayShades(hvg, maxShade, shadesOfGray); hvGfxSetClip(hvg, 0, 0, pixWidth, pixHeight); altGraphXDrawPack(ag, ssList, hvg, 0, 0, pixWidth, lineHeight, lineHeight-1, ag->tStart, ag->tEnd, scale, font, MG_BLACK, shadesOfGray, "Dummy", NULL); hvGfxUnclip(hvg); hvGfxClose(&hvg); printf( "<IMG SRC = \"%s\" BORDER=1 WIDTH=%d HEIGHT=%d><BR>\n", gifTn.forHtml, pixWidth, pixHeight); return cloneString(gifTn.forHtml); }
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 agpVsMap(char *agpName, char *infoName, char *gifName) /* agpVsMap - Plot clones in agp vs. map coordinates. */ { struct mapPos *mapList, *mp; struct agpFrag *agpList, *bp; struct hash *cloneHash = newHash(14); struct hashEl *hel; struct cloneInfo *cloneList = NULL, *clone; struct memGfx *mg = NULL; int pixWidth = 600; int pixHeight = 600; int rulerHeight = 20; int maxMapPos = 0, maxAgpPos = 0; double scaleMap, scaleAgp; Color orange, green; mapList = readInfoFile(infoName); agpList = readAgpFile(agpName); for (mp = mapList; mp != NULL; mp = mp->next) { if (mp->phase > 0) { AllocVar(clone); hel = hashAddUnique(cloneHash, mp->cloneName, clone); clone->name = hel->name; clone->mp = mp; slAddHead(&cloneList, clone); if (mp->pos > maxMapPos) maxMapPos = mp->pos; } } slReverse(&cloneList); for (bp = agpList; bp != NULL; bp = bp->next) { if (bp->chromStart > maxAgpPos) maxAgpPos = bp->chromStart; } /* Draw scatterplot on bitmap. */ mg = mgNew(pixWidth, pixHeight); mgClearPixels(mg); orange = mgFindColor(mg, 210, 150, 0); green = mgFindColor(mg, 0, 200, 0); mgDrawRuler(mg, 0, pixHeight-rulerHeight, rulerHeight, pixWidth, MG_BLACK, mgSmallFont(), 0, maxMapPos+1); scaleMap = (double)pixWidth/(double)(maxMapPos+1.0); scaleAgp = (double)(pixHeight)/(double)(maxAgpPos+1.0); for (bp = agpList; bp != NULL; bp = bp->next) { char cloneName[128]; fragToCloneName(bp->frag, cloneName); clone = hashFindVal(cloneHash, cloneName); if (clone == NULL) warn("%s is in %s but not %s", cloneName, agpName, infoName); else { int x = round(scaleMap*clone->mp->pos); int y = pixHeight - round(scaleAgp*bp->chromStart); int phase = clone->mp->phase; int back; if (phase <= 1) back = green; else if (phase == 2) back = orange; else back = MG_RED; drawPlus(mg, x, y, back); } } mgSaveGif(mg, gifName); }
void makePlot(struct clonePos *xList, struct clonePos *yList, struct hash *yHash) /* Write out graphics for plot. */ { struct memGfx *mg = NULL; struct tempName gifTn; char *mapName = "map"; struct clonePos *xp, *yp; int i, j, x, y, nextX, nextY; int divisions = 10; double invZoom = 1.0/zoom; double magnify = 2.0; double newZoom = zoom*magnify; double invNewZoom = 1.0/newZoom; int xCount = slCount(xList); plotName = (xCount/zoom < 50); if (xList == NULL || yList == NULL) return; font = mgSmallFont(); posSpan(xList, &xStart, &xEnd); posSpan(yList, &yStart, &yEnd); if (pix < 50 || pix > 5000) errAbort("Pixels out of range - must be between 50 an 5000"); mg = mgNew(pix, pix); mgClearPixels(mg); /* Plot dots. */ for (xp = xList; xp != NULL; xp = xp->next) { if ((yp = hashFindVal(yHash, xp->name)) != NULL) { zoomScale(xp->pos, yp->pos, &x, &y); plot(mg, x, y, xp->name, MG_BLACK); } } /* Make zooming image map. */ printf("<MAP Name=%s>\n", mapName); for (i=0; i<divisions; ++i) { double cenX = xOff + (i + 0.5) * (invZoom / divisions); double sx = cenX - invNewZoom/2; x = i*pix/divisions; nextX = (i+1)*pix/divisions; for (j=0; j<divisions; ++j) { double cenY = yOff + (j + 0.5) * (invZoom / divisions); double sy = cenY - invNewZoom/2; y = j*pix/divisions; nextY = (j+1)*pix/divisions; mapZoomIn(x, y, nextX - x, nextY - y, sx, sy, zoom*magnify); } } printf("</MAP>\n"); /* Save image in temp dir. */ makeTempName(&gifTn, "wikPic", ".gif"); mgSaveGif(mg, gifTn.forCgi, FALSE); printf( "<P><IMG SRC = \"%s\" BORDER=1 WIDTH=%d HEIGHT=%d USEMAP=#%s><BR>\n", gifTn.forHtml, pix, pix, mapName); mgFree(&mg); /* Print some extra info. */ printf("X has %d elements ranging from %d to %d<BR>\n", slCount(xList), xStart, xEnd); printf("Y has %d elements ranging from %d to %d<BR>\n", slCount(yList), yStart, yEnd); }