00001 #include "log.h" 00002 #include "format.h" 00003 #include "fasta.h" 00004 #include "bp.h" 00005 #include <stdio.h> 00006 #include <unistd.h> 00007 #include "geneFusionsConfig.h" 00008 #include "stringUtil.h" 00009 00010 static char* getBreakPointSequence (char *tileCoordinate1, char *tileCoordinate2) 00011 { 00012 Stringa buffer; 00013 Stringa targetsFile; 00014 FILE *fp; 00015 Array targetSeqs; 00016 int i; 00017 Seq *currSeq; 00018 static Stringa sequence = NULL; 00019 00020 buffer = stringCreate (100); 00021 targetsFile = stringCreate (100); 00022 stringPrintf (targetsFile,"targets_%d.txt",getpid ()); 00023 if (!(fp = fopen (string (targetsFile),"w")) ){ 00024 die ("Unable to open target file: %s",string (targetsFile)); 00025 } 00026 fprintf (fp,"%s\n%s",tileCoordinate1,tileCoordinate2); 00027 fclose (fp); 00028 stringPrintf (buffer,"%s %s/%s stdout -noMask -seqList=%s", 00029 BLAT_TWO_BIT_TO_FA,BLAT_DATA_DIR,BLAT_TWO_BIT_DATA_FILENAME,string (targetsFile)); 00030 fasta_initFromPipe (string (buffer)); 00031 targetSeqs = fasta_readAllSequences (0); 00032 fasta_deInit (); 00033 if (arrayMax (targetSeqs) != 2) { 00034 die ("Expected only two target sequences"); 00035 } 00036 stringCreateClear (sequence,100); 00037 for (i = 0; i < arrayMax (targetSeqs); i++) { 00038 currSeq = arrp (targetSeqs,i,Seq); 00039 stringAppendf (sequence,"%s",currSeq->sequence); 00040 hlr_free (currSeq->name); 00041 hlr_free (currSeq->sequence); 00042 } 00043 arrayDestroy (targetSeqs); 00044 stringPrintf (buffer,"rm -rf %s",string (targetsFile)); 00045 hlr_system (string (buffer),0); 00046 stringDestroy (targetsFile); 00047 stringDestroy (buffer); 00048 return string (sequence); 00049 } 00050 00051 static int sortBreakPointsByTargetAndOffset (BreakPoint *a, BreakPoint *b) 00052 { 00053 int diff; 00054 diff = strcmp (a->tileCoordinate1, b->tileCoordinate1) + strcmp(a->tileCoordinate2, b->tileCoordinate2); 00055 return diff; 00056 } 00057 00058 int main (int argc, char *argv[]) 00059 { 00060 Array breakPoints; 00061 BreakPoint *currBP; 00062 int i; 00063 char *breakPointSequence; 00064 00065 bp_init ("-"); 00066 breakPoints = bp_getBreakPoints (); 00067 arraySort (breakPoints,(ARRAYORDERF)sortBreakPointsByTargetAndOffset); 00068 00069 for (i = 0; i < arrayMax (breakPoints); i++) { 00070 currBP = arrp (breakPoints,i,BreakPoint); 00071 breakPointSequence = getBreakPointSequence (currBP->tileCoordinate1,currBP->tileCoordinate2); 00072 printf( ">%s|%s\n%s\n", currBP->tileCoordinate1, currBP->tileCoordinate2, breakPointSequence); 00073 warn(">%s|%s\n%s", currBP->tileCoordinate1, currBP->tileCoordinate2, subString( breakPointSequence, 10, strlen(breakPointSequence)-10)); 00074 } 00075 bp_deInit(); 00076 return 0; 00077 }