00001 #include "log.h" 00002 #include "format.h" 00003 #include "gfr.h" 00004 00005 00006 00007 static int sortGfrInterReads (GfrInterRead *a, GfrInterRead *b) 00008 { 00009 int diff; 00010 00011 diff = a->pairType - b->pairType; 00012 if (diff != 0) { 00013 return diff; 00014 } 00015 diff = a->number1 - b->number1; 00016 if (diff != 0) { 00017 return diff; 00018 } 00019 return a->number2 - b->number2; 00020 } 00021 00022 00023 00024 static void obtainPairCounts (GfrEntry *currGE) 00025 { 00026 GfrPairCount *currPC; 00027 GfrInterRead *currGIR,*nextGIR; 00028 int i,j; 00029 00030 currGE->pairCounts = arrayCreate (100,GfrPairCount); 00031 arraySort (currGE->interReads,(ARRAYORDERF)sortGfrInterReads); 00032 i = 0; 00033 while (i < arrayMax (currGE->interReads)) { 00034 currGIR = arrp (currGE->interReads,i,GfrInterRead); 00035 currPC = arrayp (currGE->pairCounts,arrayMax (currGE->pairCounts),GfrPairCount); 00036 currPC->number1 = currGIR->number1; 00037 currPC->number2 = currGIR->number2; 00038 currPC->pairType = currGIR->pairType; 00039 currPC->count = 1; 00040 j = i + 1; 00041 while (j < arrayMax (currGE->interReads)) { 00042 nextGIR = arrp (currGE->interReads,j,GfrInterRead); 00043 if (currGIR->pairType == nextGIR->pairType && currGIR->number1==nextGIR->number1 && currGIR->number2==nextGIR->number2) { 00044 currPC->count++; 00045 } 00046 else { 00047 break; 00048 } 00049 j++; 00050 } 00051 i = j; 00052 } 00053 } 00054 00055 00056 00057 int main (int argc, char *argv[]) 00058 { 00059 GfrEntry *currGE; 00060 int count; 00061 00062 gfr_init ("-"); 00063 gfr_addNewColumnType (GFR_COLUMN_NAME_PAIR_COUNT); 00064 puts (gfr_writeHeader ()); 00065 count = 0; 00066 while (currGE = gfr_nextEntry ()){ 00067 obtainPairCounts (currGE); 00068 puts (gfr_writeGfrEntry (currGE)); fflush (stdout); 00069 count++; 00070 } 00071 gfr_deInit (); 00072 warn ("%s_numGfrEntries: %d",argv[0],count); 00073 return 0; 00074 } 00075 00076