00001 #include "log.h"
00002 #include "format.h"
00003 #include "bp.h"
00004 #include <stdio.h>
00005
00006
00007
00008 static int sortBreakPointsByTileCoordinate1 (BreakPoint *a, BreakPoint *b)
00009 {
00010 return strcmp (a->tileCoordinate1,b->tileCoordinate1);
00011 }
00012
00013
00014
00015 static int sortBreakPointsByTileCoordinate2 (BreakPoint *a, BreakPoint *b)
00016 {
00017 return strcmp (a->tileCoordinate2,b->tileCoordinate2);
00018 }
00019
00020
00021
00022 int main (int argc, char *argv[])
00023 {
00024 Array breakPoints;
00025 BreakPoint *currBP,*nextBP;
00026 int i,j;
00027 char *pos;
00028 Stringa buffer;
00029 FILE *fp;
00030 char *tileCopy;
00031 int count;
00032
00033 if (argc != 2) {
00034 usage ("%s <fileName.bp>",argv[0]);
00035 }
00036
00037 bp_init (argv[1]);
00038 breakPoints = bp_getBreakPoints ();
00039 bp_deInit ();
00040
00041 buffer = stringCreate (100);
00042 pos = strchr (argv[1],'.');
00043 *pos = '\0';
00044 stringPrintf (buffer,"%s_breakPointsTranscript%d.wig",argv[1],strstr(argv[1], "_AB") ? 1 : 2);
00045 fp = fopen (string (buffer),"w");
00046 if (fp == NULL) {
00047 die ("Unable to open file: %s",string (buffer));
00048 }
00049 arraySort (breakPoints,(ARRAYORDERF)sortBreakPointsByTileCoordinate1);
00050 tileCopy = NULL;
00051 i = 0;
00052 while (i < arrayMax (breakPoints)) {
00053 currBP = arrp (breakPoints,i,BreakPoint);
00054 count = arrayMax (currBP->breakPointReads);
00055 j = i + 1;
00056 while (j < arrayMax (breakPoints)) {
00057 nextBP = arrp (breakPoints,j,BreakPoint);
00058 if (strEqual (currBP->tileCoordinate1,nextBP->tileCoordinate1)) {
00059 count += arrayMax (nextBP->breakPointReads);
00060 }
00061 else {
00062 break;
00063 }
00064 j++;
00065 }
00066 i = j;
00067 if (tileCopy == NULL) {
00068 strReplace (&tileCopy,currBP->tileCoordinate1);
00069 pos = strchr (tileCopy,':');
00070 *pos = '\0';
00071 fprintf (fp,"track type=wiggle_0 name=\"Breakpoints %s_%d\"\n",argv[1], strstr(argv[1], "_AB") ? 1 : 2);
00072 fprintf (fp,"variableStep chrom=%s span=1\n",tileCopy);
00073 }
00074 pos = strchr (currBP->tileCoordinate1,'-');
00075 fprintf (fp,"%d\t%d\n",atoi (pos + 1),count);
00076 }
00077 fprintf (fp, "%d\t%d\n",atoi (pos + 1)+1,0);
00078 fclose (fp);
00079
00080 stringPrintf (buffer,"%s_breakPointsTranscript%d.wig",argv[1],strstr(argv[1], "_AB") ? 2 : 1);
00081 fp = fopen (string (buffer),"w");
00082 if (fp == NULL) {
00083 die ("Unable to open file: %s",string (buffer));
00084 }
00085 arraySort (breakPoints,(ARRAYORDERF)sortBreakPointsByTileCoordinate2);
00086 tileCopy = NULL;
00087 i = 0;
00088 while (i < arrayMax (breakPoints)) {
00089 currBP = arrp (breakPoints,i,BreakPoint);
00090 count = arrayMax (currBP->breakPointReads);
00091 j = i + 1;
00092 while (j < arrayMax (breakPoints)) {
00093 nextBP = arrp (breakPoints,j,BreakPoint);
00094 if (strEqual (currBP->tileCoordinate2,nextBP->tileCoordinate2)) {
00095 count += arrayMax (nextBP->breakPointReads);
00096 }
00097 else {
00098 break;
00099 }
00100 j++;
00101 }
00102 i = j;
00103 if (tileCopy == NULL) {
00104 strReplace (&tileCopy,currBP->tileCoordinate2);
00105 pos = strchr (tileCopy,':');
00106 *pos = '\0';
00107 fprintf (fp,"track type=wiggle_0 name=\"Breakpoints %s_%d\"\n",argv[1],strstr(argv[1], "_AB") ? 2 : 1);
00108 fprintf (fp,"variableStep chrom=%s span=1\n",tileCopy);
00109 }
00110 pos = strchr (currBP->tileCoordinate2,':');
00111 fprintf (fp,"%d\t%d\n",atoi (pos + 1),count);
00112 }
00113 fprintf (fp, "%d\t%d\n",atoi (pos + 1)+1,0);
00114 fclose (fp);
00115 return 0;
00116 }
00117
00118