00001 #include "log.h"
00002 #include "format.h"
00003 #include "geneFusionsConfig.h"
00004 #include "gfr.h"
00005 #include "gd.h"
00006 #include "gdfontmb.h"
00007 #include "gdfonts.h"
00008 #include "gdfontt.h"
00009
00010
00011 #define IMAGE_HEIGHT 200
00012 #define MIN_IMAGE_WIDTH 600
00013 #define SIDE_MARGIN 10
00014 #define Y_COORDINATE_TRANSCRIPT_1 50
00015 #define Y_COORDINATE_TRANSCRIPT_2 150
00016 #define SPACER 12 // number of pixels between exons
00017 #define EXON_SIZE 6 // number of pixels along the side of a square
00018
00019
00020
00021 static void drawTranscript (int numberExons, int yCoordinateTranscript, gdImagePtr im, int color)
00022 {
00023 int i;
00024 int xEndCoordinateTranscript;
00025
00026 xEndCoordinateTranscript = SIDE_MARGIN + numberExons * EXON_SIZE + (numberExons + 1) * SPACER;
00027 gdImageLine(im,SIDE_MARGIN,yCoordinateTranscript,xEndCoordinateTranscript,yCoordinateTranscript,color);
00028 for (i = 1; i <= numberExons; i++) {
00029 gdImageFilledRectangle(im,
00030 SIDE_MARGIN + i * SPACER + (i - 1) * EXON_SIZE,
00031 yCoordinateTranscript - EXON_SIZE / 2,
00032 SIDE_MARGIN + i * SPACER + (i - 1) * EXON_SIZE + EXON_SIZE,
00033 yCoordinateTranscript + EXON_SIZE / 2,
00034 color);
00035 }
00036 }
00037
00038 void drawNumbers(gdImagePtr im, int numExons, int color) {
00039 int i;
00040 Stringa buffer = stringCreate(3);
00041 for( i=1; i<=numExons; i++) {
00042 stringPrintf( buffer, "%d", i);
00043 gdImageString( im, gdFontGetTiny(),
00044 SIDE_MARGIN + i * SPACER + EXON_SIZE * i - EXON_SIZE / 2 - strlen(string(buffer)) * gdFontGetTiny()->w / 2,
00045 im->sy / 2,
00046 (unsigned char*) string(buffer), color);
00047 }
00048 stringDestroy(buffer);
00049 }
00050
00051 static void makeImage (GfrEntry *currGE)
00052 {
00053 gdImagePtr im;
00054 FILE *jpegout;
00055 int black,white, gray, blue, orange, green, color;
00056 int maxNumberExons;
00057 int imageWidth;
00058 int i;
00059 int xCoord1, xCoord2;
00060
00061 static Stringa buffer = NULL;
00062
00063 maxNumberExons = MAX (currGE->numExonsTranscript1,currGE->numExonsTranscript2);
00064 imageWidth = MAX (maxNumberExons * EXON_SIZE + (maxNumberExons + 1) * SPACER + 2 * SIDE_MARGIN,MIN_IMAGE_WIDTH);
00065 im = gdImageCreate(imageWidth,IMAGE_HEIGHT);
00066 white = gdImageColorAllocate(im,255,255,255);
00067 gray = gdImageColorAllocate(im,192,192,192);
00068 blue = gdImageColorAllocate(im,0,0,255);
00069 black = gdImageColorAllocate(im,0,0,0);
00070 orange = gdImageColorAllocate(im,255,69,0);
00071 green = gdImageColorAllocate(im, 46,139,87);
00072
00073 gdImageString (im,gdFontGetMediumBold (),SIDE_MARGIN,Y_COORDINATE_TRANSCRIPT_1 - 30,(unsigned char*)currGE->geneSymbolTranscript1,black);
00074 gdImageString (im,gdFontGetMediumBold (),SIDE_MARGIN,Y_COORDINATE_TRANSCRIPT_2 + 18,(unsigned char*)currGE->geneSymbolTranscript2,black);
00075 drawTranscript (currGE->numExonsTranscript1,Y_COORDINATE_TRANSCRIPT_1,im,black);
00076 drawTranscript (currGE->numExonsTranscript2,Y_COORDINATE_TRANSCRIPT_2,im,black);
00077 drawNumbers ( im, MAX( currGE->numExonsTranscript1, currGE->numExonsTranscript2), black);
00078 for( i = 0; i< arrayMax( currGE->pairCounts); i++ ) {
00079 GfrPairCount* currGEPC = arrp( currGE->pairCounts, i, GfrPairCount);
00080 switch( currGEPC->pairType ) {
00081 case GFR_PAIR_TYPE_EXONIC_EXONIC:
00082 xCoord1 = SIDE_MARGIN + currGEPC->number1 * SPACER + currGEPC->number1 * EXON_SIZE - EXON_SIZE / 2;
00083 xCoord2 = SIDE_MARGIN + currGEPC->number2 * SPACER + currGEPC->number2 * EXON_SIZE - EXON_SIZE / 2;
00084 color = orange;
00085 break;
00086 case GFR_PAIR_TYPE_EXONIC_INTRONIC:
00087 xCoord1 = SIDE_MARGIN + currGEPC->number1 * SPACER + currGEPC->number1 * EXON_SIZE - EXON_SIZE / 2;
00088 xCoord2 = SIDE_MARGIN + currGEPC->number2 * SPACER + currGEPC->number2 * EXON_SIZE + SPACER / 2;
00089 color = orange;
00090 break;
00091 case GFR_PAIR_TYPE_EXONIC_JUNCTION:
00092 xCoord1 = SIDE_MARGIN + currGEPC->number1 * SPACER + currGEPC->number1 * EXON_SIZE - EXON_SIZE / 2;
00093 xCoord2 = SIDE_MARGIN + (currGEPC->number2/2) * SPACER + (currGEPC->number2)/2 * EXON_SIZE + (currGEPC->number2 % 2) * SPACER;
00094 color = orange;
00095 break;
00096 case GFR_PAIR_TYPE_INTRONIC_EXONIC:
00097 xCoord1 = SIDE_MARGIN + currGEPC->number1 * SPACER + currGEPC->number1 * EXON_SIZE + SPACER / 2;
00098 xCoord2 = SIDE_MARGIN + currGEPC->number2 * SPACER + currGEPC->number2 * EXON_SIZE - EXON_SIZE / 2;
00099 color = green;
00100 break;
00101 case GFR_PAIR_TYPE_INTRONIC_INTRONIC:
00102 xCoord1 = SIDE_MARGIN + currGEPC->number1 * SPACER + currGEPC->number1 * EXON_SIZE + SPACER / 2;
00103 xCoord2 = SIDE_MARGIN + currGEPC->number2 * SPACER + currGEPC->number2 * EXON_SIZE + SPACER / 2;
00104 color = green;
00105 break;
00106 case GFR_PAIR_TYPE_INTRONIC_JUNCTION:
00107 xCoord1 = SIDE_MARGIN + currGEPC->number1 * SPACER + currGEPC->number1 * EXON_SIZE + SPACER / 2;
00108 xCoord2 = SIDE_MARGIN + (currGEPC->number2/2) * SPACER + (currGEPC->number2)/2 * EXON_SIZE + (currGEPC->number2 % 2) * SPACER;
00109 color = green;
00110 break;
00111 case GFR_PAIR_TYPE_JUNCTION_JUNCTION:
00112 xCoord1 = SIDE_MARGIN + (currGEPC->number1/2) * SPACER + (currGEPC->number1) / 2 * EXON_SIZE + (currGEPC->number1 % 2) * SPACER;
00113 xCoord2 = SIDE_MARGIN + (currGEPC->number2/2) * SPACER + (currGEPC->number2) / 2 * EXON_SIZE + (currGEPC->number2 % 2) * SPACER;
00114 color = gray;
00115 break;
00116 case GFR_PAIR_TYPE_JUNCTION_EXONIC:
00117 xCoord1 = SIDE_MARGIN + (currGEPC->number1/2) * SPACER + (currGEPC->number1) / 2 * EXON_SIZE + (currGEPC->number1 % 2) * SPACER;
00118 xCoord2 = SIDE_MARGIN + currGEPC->number2 * SPACER + currGEPC->number2 * EXON_SIZE - EXON_SIZE / 2;
00119 color = gray;
00120 break;
00121 case GFR_PAIR_TYPE_JUNCTION_INTRONIC:
00122 xCoord1 = SIDE_MARGIN + (currGEPC->number1/2) * SPACER + (currGEPC->number1) / 2 * EXON_SIZE + (currGEPC->number1 % 2) * SPACER;
00123 xCoord2 = SIDE_MARGIN + currGEPC->number2 * SPACER + currGEPC->number2 * EXON_SIZE + SPACER / 2;
00124 color = gray;
00125 break;
00126 default:
00127 xCoord1 = SIDE_MARGIN;
00128 xCoord2 = SIDE_MARGIN;
00129 color = white;
00130 break;
00131 }
00132 gdImageLine(im,
00133 xCoord1,
00134 Y_COORDINATE_TRANSCRIPT_1,
00135 xCoord2,
00136 Y_COORDINATE_TRANSCRIPT_2,
00137 color);
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 stringCreateClear (buffer,100);
00156 stringPrintf (buffer,"%s.jpg",currGE->id);
00157 jpegout = fopen(string (buffer), "wb");
00158 gdImageJpeg(im, jpegout, -1);
00159 fclose(jpegout);
00160 gdImageDestroy(im);
00161 }
00162
00163
00164
00165 int main (int argc, char *argv[])
00166 {
00167 GfrEntry *currGE;
00168 int count;
00169
00170 count = 0;
00171 gfr_init ("-");
00172 puts (gfr_writeHeader ());
00173 while (currGE = gfr_nextEntry ()){
00174 makeImage (currGE);
00175 puts (gfr_writeGfrEntry (currGE));
00176 count++;
00177 }
00178 gfr_deInit ();
00179 warn ("%s_numGfrEntries: %d",argv[0],count);
00180 return 0;
00181 }
00182