00001 #include "log.h" 00002 #include "format.h" 00003 #include "bowtieParser.h" 00004 #include "bp.h" 00005 #include <stdio.h> 00006 #include <sys/types.h> 00007 #include <unistd.h> 00008 #include "geneFusionsConfig.h" 00009 00010 00011 00012 int main (int argc, char *argv[]) 00013 { 00014 Array breakPoints; 00015 BreakPoint *currBP; 00016 BreakPointRead *currBPR; 00017 int i,j; 00018 Stringa buffer,cmd; 00019 FILE *fp; 00020 BowtieQuery *currBQ; 00021 Texta invalidJunctions; 00022 int index; 00023 char *str = NULL; 00024 00025 buffer = stringCreate (100); 00026 stringPrintf (buffer,"bpJunctionReads_%d.fa",getpid ()); 00027 fp = fopen (string (buffer),"w"); 00028 if (fp == NULL) { 00029 die ("Unable to open file: %s",string (buffer)); 00030 } 00031 bp_init ("-"); 00032 breakPoints = bp_getBreakPoints (); 00033 for (i = 0; i < arrayMax (breakPoints); i++) { 00034 currBP = arrp (breakPoints,i,BreakPoint); 00035 for (j = 0; j < arrayMax (currBP->breakPointReads); j++) { 00036 currBPR = arrp (currBP->breakPointReads,j,BreakPointRead); 00037 fprintf (fp,">%s|%s\n%s\n",currBP->tileCoordinate1,currBP->tileCoordinate2,currBPR->read); 00038 } 00039 } 00040 bp_deInit (); 00041 fclose (fp); 00042 00043 invalidJunctions = textCreate (1000); 00044 cmd = stringCreate (100); 00045 stringPrintf (cmd,"bowtie --quiet -p 4 -n 0 -f %s/%s/%s %s",BOWTIE_INDEXES,BOWTIE_GENOME, BOWTIE_GENOME, string (buffer)); 00046 bowtieParser_initFromPipe (string (cmd)); 00047 while (currBQ = bowtieParser_nextQuery ()) { 00048 textAdd (invalidJunctions,currBQ->sequenceName); 00049 } 00050 bowtieParser_deInit (); 00051 stringPrintf (cmd,"rm -f %s",string (buffer)); 00052 hlr_system (string (cmd),0); 00053 00054 arraySort (invalidJunctions,(ARRAYORDERF)arrayStrcmp); 00055 arrayUniq (invalidJunctions,NULL,(ARRAYORDERF)arrayStrcmp); 00056 for (i = 0; i < arrayMax (breakPoints); i++) { 00057 currBP = arrp (breakPoints,i,BreakPoint); 00058 stringPrintf (buffer,"%s|%s",currBP->tileCoordinate1,currBP->tileCoordinate2); 00059 strReplace (&str,string (buffer)); 00060 if (!arrayFind (invalidJunctions,&str,&index,(ARRAYORDERF)arrayStrcmp)) { 00061 puts (bp_writeBreakPoint (currBP)); 00062 } 00063 } 00064 stringDestroy (buffer); 00065 stringDestroy (cmd); 00066 return 0; 00067 }