00001 #include "log.h"
00002 #include "format.h"
00003 #include "intervalFind.h"
00004 #include <stdlib.h>
00005 #include "geneFusionsConfig.h"
00006 #include "gfr.h"
00007 #include <math.h>
00008 #include "linestream.h"
00009 #include "common.h"
00010
00011 #define MILLION 1000000.0
00012
00013 typedef struct {
00014 char* geneID;
00015 double value;
00016 } GeneExpression;
00017
00018
00019 static int sortGeneByID( GeneExpression* a, GeneExpression* b ) {
00020 return strcmp (b->geneID, a->geneID);
00021 }
00022
00023 int main (int argc, char *argv[])
00024 {
00025 int i ;
00026 char* line;
00027 Array geneExpression = arrayCreate(25000, GeneExpression);
00028 if (argc != 2) {
00029 usage ("Usage: %s <prefix>\nNote:prefix.composite.expression is supposed to exist.",argv[0]);
00030 }
00031 Stringa buffer=stringCreate( 50 );
00032 stringPrintf( buffer, "%s.composite.expression", argv[1]);
00033 LineStream ls = ls_createFromFile( string(buffer) );
00034 while( line=ls_nextLine(ls)) {
00035 WordIter w = wordIterCreate( line, "\t", 1);
00036 GeneExpression* currGE = arrayp( geneExpression, arrayMax( geneExpression ), GeneExpression);
00037 currGE->geneID = hlr_strdup( wordNext(w) );
00038 currGE->value = atof( wordNext(w) );
00039 wordIterDestroy( w );
00040 }
00041 arraySort( geneExpression, (ARRAYORDERF)sortGeneByID );
00042 gfr_init ( "-" );
00043 GfrEntry* gfrE;
00044 while( gfrE = gfr_nextEntry() ) {
00045 int idx1, idx2;
00046 GeneExpression* toSearchGE ;
00047 AllocVar( toSearchGE );
00048 toSearchGE->geneID = hlr_strdup( gfrE->nameTranscript1);
00049 arrayFind( geneExpression, toSearchGE, &idx1, (ARRAYORDERF)sortGeneByID );
00050 hlr_free( toSearchGE->geneID );
00051 toSearchGE->geneID = hlr_strdup( gfrE->nameTranscript2);
00052 arrayFind( geneExpression, toSearchGE, &idx2, (ARRAYORDERF)sortGeneByID );
00053 printf( "%s\t%f\n", gfrE->id, (double) gfrE->numInter / ( arrp( geneExpression, idx1, GeneExpression)->value + arrp( geneExpression, idx2, GeneExpression)->value) /2.0 );
00054 hlr_free( toSearchGE->geneID );
00055 freeMem( toSearchGE );
00056 }
00057 gfr_deInit();
00058 for( i=0; i<arrayMax( geneExpression ); i++ )
00059 hlr_free( arrp( geneExpression, i, GeneExpression)->geneID);
00060 arrayDestroy(geneExpression);
00061 return 0;
00062 }
00063