struct vGfx *vgOpenPng(int width, int height, char *fileName, boolean useTransparency) /* Open up something that will write out a PNG file upon vgClose. * If useTransparency, then the first color in memgfx's colormap/palette is * assumed to be the image background color, and pixels of that color * are made transparent. */ { struct memPng *png; struct memGfx *mg; struct vGfx *vg; /* Set up virtual graphics with memory methods. */ vg = vgHalfInit(width, height); vgMgMethods(vg); vg->close = (vg_close)memPngClose; /* Get our mg + fileName structure. We're forcing * inheritence from mg essentially. */ AllocVar(png); png->fileName = cloneString(fileName); png->useTransparency = useTransparency; /* Fill in the mg part of this structure with normal memGfx. */ mg = mgNew(width, height); if (png->useTransparency) mgClearPixelsTrans(mg); else mgClearPixels(mg); png->mg = *mg; freez(&mg); /* We don't need this copy any more. */ vg->data = png; return vg; }
struct vGfx *vgOpenGif(int width, int height, char *fileName, boolean useTransparency) /* Open up something that will someday be a PostScript file. */ { struct memGif *gif; struct memGfx *mg; struct vGfx *vg; /* Set up virtual graphics with memory methods. */ vg = vgHalfInit(width, height); vgMgMethods(vg); vg->close = (vg_close)memGifClose; /* Get our mg + fileName structure. We're forcing * inheritence from mg essentially. */ AllocVar(gif); gif->fileName = cloneString(fileName); gif->useTransparency = useTransparency; /* Fill in the mg part of this structure with normal memGfx. */ mg = mgNew(width, height); mgClearPixels(mg); gif->mg = *mg; freez(&mg); /* We don't need this copy any more. */ vg->data = gif; return vg; }
struct memGfx *getScaledMg(int bases, int height) /* Allocate a memGfx big enough for bases. */ { int width = baseToDot(bases); struct memGfx *mg; uglyf("Allocatting memory graphic of %d x %d (for %d bases)\n", width, height, bases); mg = mgNew(width, height); mgClearPixels(mg); return mg; }
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); }
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); }