100ad514ee0c866afdb787202cae49270b6c8b1e braney Thu Jul 26 12:45:30 2012 -0700 oops... wasn't dealing with CDS start and stop correctly on '-' strand diff --git src/hg/pslToBed/pslToBed.c src/hg/pslToBed/pslToBed.c index 0e25ea1..4be663e 100644 --- src/hg/pslToBed/pslToBed.c +++ src/hg/pslToBed/pslToBed.c @@ -54,35 +54,45 @@ assert(offsetInBlock < psl->blockSizes[blockNum]); return psl->tStarts[blockNum] + offsetInBlock; } } // we don't have any blocks with this query in it, just point // to the end return psl->tEnd; } static void setThick(struct psl *psl, struct bed *bed, struct cds *cds) // set thickStart and thickEnd based on CDS record { -int thickStart, thickEnd; +unsigned thickStart, thickEnd; +unsigned cdsStart = cds->start - 1; +unsigned cdsEnd = cds->end; + +if (psl->strand[0] == '-') + { + // if on negative strand, cds is from end + unsigned temp = cdsStart; + cdsStart = psl->qSize - cdsEnd; + cdsEnd = psl->qSize - temp; + } // we subtract one from start to convert to PSL coordinate system -thickStart = getTargetForQuery(psl, cds->start - 1); -thickEnd = getTargetForQuery(psl, cds->end); +thickStart = getTargetForQuery(psl, cdsStart); +thickEnd = getTargetForQuery(psl, cdsEnd); // if thickStart equals thickEnd, then there is no CDS if (thickStart == thickEnd) thickStart = thickEnd = 0; bed->thickStart = thickStart; bed->thickEnd = thickEnd; } void pslToBed(char *pslFile, char *bedFile, struct hash *cdsHash) /* pslToBed -- tranform a psl format file to a bed format file */ { struct lineFile *pslLf = pslFileOpen(pslFile); FILE *bedFh = mustOpen(bedFile, "w"); struct psl *psl; @@ -105,34 +115,37 @@ carefulClose(&bedFh); lineFileClose(&pslLf); } struct hash *getCdsHash(char *cdsFile) /* read CDS start and end for list of id's */ { struct lineFile *lf = lineFileOpen(cdsFile, TRUE); char *row[2]; struct hash *hash = newHash(0); while (lineFileRow(lf, row)) { // lines are of the form of <start>..<end> struct cds *cds; AllocVar(cds); - cds->start = atoi(row[1]); + cds->start = atoi(row[1]); // atoi will stop at '.' char *ptr = strchr(row[1], '.'); // point to first '.' ptr+=2; // step past two '.'s cds->end = atoi(ptr); + if (cds->start > cds->end) + errAbort("CDS start(%d) is before end(%d) on line %d", + cds->start, cds->end, lf->lineIx); hashAdd(hash, row[0], cds); } lineFileClose(&lf); return hash; } int main(int argc, char* argv[]) { optionInit(&argc, argv, options); if (argc != 3) usage(); char *cdsFile = optionVal("cds", NULL); struct hash *cdsHash = NULL; if (cdsFile != NULL)