Пример #1
0
static struct memGfx *altColorLabels(char **labels, int labelCount, int width)
/* Return a memory image with alternating colors. */
{
struct memGfx *mg = NULL;
Color c1,c2;
MgFont *font = mgMediumFont();
int lineHeight = mgFontLineHeight(font)-1;
int height = lineHeight * labelCount, i;
int y = 0;

/* Allocate picture and set up colors. */
mg = mgNew(width, height);
c1 = mgFindColor(mg, 0xE0, 0xE0, 0xFF);
c2 = mgFindColor(mg, 0xFF, 0xC8, 0xC8);

/* Draw text. */
for (i=labelCount-1; i >= 0; --i)
    {
    Color c = ((i&1) ? c2 : c1);
    mgDrawBox(mg, 0, y, width, lineHeight, c);
    mgTextRight(mg, 0+1, y+1, width-1, lineHeight, MG_BLACK, font, labels[i]);
    y += lineHeight;
    }

return mg;
}
Пример #2
0
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;
}
Пример #3
0
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;
}
Пример #4
0
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;
}
Пример #5
0
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);
}
Пример #6
0
struct memGfx *mgLoadGif(char *name)
/* Create memory image based on gif file. 
 * Note this is based on a very old gif reader
 * that only handles the GIF87a version. 
 * This is the same that mgSaveGif creates at
 * least.  This version of gif was always
 * color mapped. */
{
int c;
char type[7];
int gif_colors = 0;

gif_line = 0;
iphase = 0;
iy = 0;
gif_mg = NULL;
gif_file = mustOpen(name, "rb");
if (fread(&gif, 1, sizeof(gif), gif_file) < sizeof(gif))
    {
    goto TRUNCOUT;
    }
memcpy(type, gif.giftype, 6);
type[6] = 0;
if (!startsWith("GIF", type))
    {
    errAbort("Not a good GIF file");
    goto BADOUT;
    }
if (!sameString("GIF87a", type))
    {
    errAbort("Gif is version %s, sadly load_gif only speaks version GIF87a", type);
    goto BADOUT;
    }
gif_colors = (1<<((gif.colpix&PIXMASK)+1));
if (gif.colpix&COLTAB)
    {
    int size = gif_colors*3;
    if (fread(gif_cmap, 1, size, gif_file) < size)
        goto TRUNCOUT;
    }
for (;;)    /* skip over extension blocks and other junk til get ',' */
    {
    if ((c = fgetc(gif_file)) == READ_ERROR)
        goto TRUNCOUT;
    if (c == ',')
        break;
    if (c == ';')    /* semi-colon is end of piccie */
        goto TRUNCOUT;
    if (c == '!')    /* extension block */
        {
        if ((c = fgetc(gif_file)) == READ_ERROR)    /* skip extension type */
            goto TRUNCOUT;
        for (;;)
            {
            if ((c = fgetc(gif_file)) == READ_ERROR)
                goto TRUNCOUT;
            if (c == 0)    /* zero 'count' means end of extension */
                break;
            while (--c >= 0)
                {
                if (fgetc(gif_file) == READ_ERROR)
                    goto TRUNCOUT;
                }
            }
        }
    }
if (fread(&gim, 1, sizeof(gim), gif_file) < sizeof(gim))
    goto TRUNCOUT;
gif_width = (gim.whi<<8) + gim.wlo;
gif_height = (gim.hhi<<8) + gim.hlo;

gif_mg = mgNew(gif_width, gif_height);

/* Gif files can have color maps in two places.  Let
 * the gim color map overwrite the one in the gif header
 * here. */
if (gim.flags&COLTAB)
    {
    int size;
    gif_colors = (1<<((gim.flags&PIXMASK)+1));
    size = gif_colors*3;
    if (fread(gif_cmap, 1, size, gif_file) < size)
        goto TRUNCOUT;
    }
if (gif_colors > 0)
    {
    if (gif_colors > 256)
       errAbort("Too many colors in %s", name);
    memcpy(gif_mg->colorMap, gif_cmap, 3*gif_colors);
    }

switch (gif_decoder(gif_width))
    {
    case READ_ERROR:
    case BAD_CODE_SIZE:
        goto TRUNCOUT;
    case OUT_OF_MEMORY:
	errAbort("out of memory");
        goto BADOUT;
    default:
        break;
    }
carefulClose(&gif_file);
return(gif_mg);

TRUNCOUT:
errAbort("%s is truncated", name);
BADOUT:
carefulClose(&gif_file);
mgFree(&gif_mg);
return(NULL);
}
Пример #7
0
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);
}