0bd4eed635aa15c13a16b0d95f6293f07e75ae68
galt
  Mon Nov 15 15:37:32 2010 -0800
fixed bug in handling translated psls
diff --git src/lib/basicBed.c src/lib/basicBed.c
index d5af77b..4a792f4 100644
--- src/lib/basicBed.c
+++ src/lib/basicBed.c
@@ -653,44 +653,55 @@
 
 /* A tiny bit of error checking on the psl. */
 if (psl->qStart >= psl->qEnd || psl->qEnd > psl->qSize 
     || psl->tStart >= psl->tEnd || psl->tEnd > psl->tSize)
     {
     errAbort("mangled psl format for %s", psl->qName);
     }
 
 /* Allocate bed and fill in from psl. */
 AllocVar(bed);
 bed->chrom = cloneString(psl->tName);
 bed->chromStart = bed->thickStart = chromStart = psl->tStart;
 bed->chromEnd = bed->thickEnd = psl->tEnd;
 bed->score = 1000 - 2*pslCalcMilliBad(psl, TRUE);
 if (bed->score < 0) bed->score = 0;
-strncpy(bed->strand,  psl->strand, sizeof(bed->strand));
+//strncpy(bed->strand,  psl->strand, sizeof(bed->strand));
+bed->strand[0] = psl->strand[0];
 bed->blockCount = blockCount = psl->blockCount;
 bed->blockSizes = (int *)cloneMem(psl->blockSizes,(sizeof(int)*psl->blockCount));
+if (pslIsProtein(psl))
+    {
+    /* Convert blockSizes from protein to dna. */
+    for (i=0; i<blockCount; ++i)
+	bed->blockSizes[i] *= 3;
+    }
 bed->chromStarts = chromStarts = (int *)cloneMem(psl->tStarts, (sizeof(int)*psl->blockCount));
 bed->name = cloneString(psl->qName);
 
 /* Switch minus target strand to plus strand. */
 if (psl->strand[1] == '-')
     {
     int chromSize = psl->tSize;
     reverseInts(bed->blockSizes, blockCount);
     reverseInts(chromStarts, blockCount);
     for (i=0; i<blockCount; ++i)
-	chromStarts[i] = chromSize - chromStarts[i];
+	chromStarts[i] = chromSize - chromStarts[i] - bed->blockSizes[i];
+    if (bed->strand[0] == '-')
+	bed->strand[0] = '+';
+    else
+	bed->strand[0] = '-';
     }
 
 /* Convert coordinates to relative. */
 for (i=0; i<blockCount; ++i)
     chromStarts[i] -= chromStart;
 return bed;
 }
 
 void makeItBed12(struct bed *bedList, int numFields)
 /* If it's less than bed 12, make it bed 12. The numFields */
 /* param is for how many fields the bed *currently* has. */
 {
 int i = 1;
 struct bed *cur;
 for (cur = bedList; cur != NULL; cur = cur->next)