void gifLabelVerticalText(char *fileName, char **labels, int labelCount, 
	int height)
/* Make a gif file with given labels.  This will check to see if fileName
 * exists already and has not changed, and if so do nothing. */
{
struct memGfx *straight = altColorLabels(labels, labelCount, height);
struct memGfx *rotated = mgRotate90(straight);
struct memGfx *existing = NULL;
#ifdef USE_PNG
struct tempName tn;
makeTempName(&tn, "gifLabelVertTemp", ".png");
mgSavePng(rotated, tn.forCgi, FALSE); 
rename(tn.forCgi, fileName);
#else
if (fileExists(fileName))
    existing = mgLoadGif(fileName);
/* the savings here is in the user's own browser cache - not updated if no change */
if (!sameGifContents(rotated, existing))  
    {
    struct tempName tn;
    makeTempName(&tn, "gifLabelVertTemp", ".gif");
    mgSaveGif(rotated, tn.forCgi, FALSE); 
    rename(tn.forCgi, fileName);
    }
#endif
mgFree(&straight);
mgFree(&rotated);
if (existing)
    mgFree(&existing);
}
Exemple #2
0
void gifLabelVerticalText(char *fileName, char **labels, int labelCount, 
	int height)
/* Make a gif file with given labels.  This will check to see if fileName
 * exists already, and if so do nothing. */
{
struct memGfx *straight = altColorLabels(labels, labelCount, height);
struct memGfx *rotated = mgRotate90(straight);
char tempName[512];
safef(tempName, sizeof(tempName), "%s_trash", fileName);
mgSaveGif(rotated, tempName);  /* note we cannot delete this later because of permissions */
/* the savings here is in the user's own browser cache - not updated if no change */
if (!sameFileContents(tempName,fileName))  
    mgSaveGif(rotated, fileName);
mgFree(&straight);
mgFree(&rotated);
}
Exemple #3
0
void gifLabelVerticalText(char *fileName, char **labels, int labelCount, 
	int height)
/* Make a gif file with given labels.  This will check to see if fileName
 * exists already and has not changed, and if so do nothing. */
{
struct memGfx *straight = altColorLabels(labels, labelCount, height);
struct memGfx *rotated = mgRotate90(straight);
struct memGfx *existing = NULL;
struct tempName tn;
makeTempName(&tn, "gifLabelVertTemp", ".png");
mgSavePng(rotated, tn.forCgi, FALSE); 
rename(tn.forCgi, fileName);
mgFree(&straight);
mgFree(&rotated);
if (existing)
    mgFree(&existing);
}
Exemple #4
0
void memPngClose(struct memPng **pG)
/* Write out and close and free. */
{
struct memPng *g = *pG;
if (g != NULL)
    {
    struct memGfx *mg = (struct memGfx *)g;
    mgSavePng(mg, g->fileName, g->useTransparency);
    freez(&g->fileName);
    mgFree(&mg);
    *pG = NULL;
    }
}
Exemple #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);
}
Exemple #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);
}
Exemple #7
0
void gcSquiggle(char *chromName, char *destDir, char *type, bool thick, bool line)
/* Make gcSquiggle  pic for chromosome. */
{
char gifName[512];
int chromSize = hChromSize(chromName);
struct memGfx *mg = getScaledMg(chromSize, squiggleHeight);
int dotWidth = mg->width;
char nibName[512];
FILE *nibFile;
int nibChromSize;
struct dnaSeq *seq = NULL;
double lastGcPercent = (gcPercentMin+gcPercentMax)/2;
double gcPercent;
int startBase = 0, endBase = 0, baseWidth;
int lastDot = -1, dot;
int realBaseCount;
int gcBaseCount;
bool lastMissing = TRUE;
int squigHeight = squiggleHeight-thick;
int y1,y2;

sprintf(gifName, "%s/%sgc%s.gif", destDir, chromName, type);
sprintf(nibName, "%s/%s.nib", nibDir, chromName);
nibOpenVerify(nibName, &nibFile, &nibChromSize);
if (nibChromSize != chromSize)
    errAbort("Disagreement on size of %s between database and %s\n",
    	chromName, nibName);

for (dot = 0; dot <dotWidth; ++dot)
    {
    startBase = endBase;
    endBase = dotToBase(dot+1);
    if (endBase > nibChromSize)
       endBase = nibChromSize;
    baseWidth = endBase-startBase;
    seq = nibLdPart(nibName, nibFile, nibChromSize, startBase, baseWidth);
    realBaseCount = realDnaCount(seq->dna, seq->size);
    gcBaseCount = gcDnaCount(seq->dna, seq->size);
    if (realBaseCount < 20)
        {
	/* Add psuedocounts from last time if sample is small. */
	lastMissing = TRUE;
	}
    else
        {
	gcPercent = (double)gcBaseCount/(double)realBaseCount;
	y2 = gcScaleRange(gcPercent, squigHeight);
	if (line && !lastMissing)
	    {
	    y1 = gcScaleRange(lastGcPercent, squigHeight);
	    mgDrawLine(mg, dot-1, y1, dot, y2, MG_BLACK);
	    if (thick)
	        {
		mgDrawLine(mg, dot-1, y1+1, dot, y2+1, MG_BLACK);
		}
	    }
	else
	    {
	    mgPutDot(mg, dot, y2, MG_BLACK);
	    if (thick)
	        mgPutDot(mg, dot, y2+1, MG_BLACK);
	    }
	lastGcPercent = gcPercent;
	lastMissing = FALSE;
	}
    freeDnaSeq(&seq);
    }
fclose(nibFile);
mgSaveGif(mg, gifName);
mgFree(&mg);
}
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);
}