747563375ea7f3caaaeb7a6d0092706078b0bde9 markd Mon Apr 18 16:57:33 2016 -0700 simplified the code a bit diff --git src/hg/mrnaToGene/mrnaToGene.c src/hg/mrnaToGene/mrnaToGene.c index ae59d14..bd013b3 100644 --- src/hg/mrnaToGene/mrnaToGene.c +++ src/hg/mrnaToGene/mrnaToGene.c @@ -158,86 +158,89 @@ if (cdsStr == NULL) { int dotIdx = getGbVersionIdx(acc); if (dotIdx >= 0) { acc[dotIdx] = '\0'; cdsStr = cdsQuery(conn, acc, cdsBuf, cdsBufSize); acc[dotIdx] = '.'; } } if (dash != NULL) *dash = '-'; return cdsStr; } -struct genbankCds getCds(struct sqlConnection *conn, struct psl *psl) -/* Lookup the CDS, either in the database or hash, or generate for query. If - * not found and looks like a it has a genbank version, try without the - * version. If allCds is true, generate a cds that covers the query. Conn - * maybe null if gCdsTable exists or gAllCds or gNoCds are true. If CDS can't be - * obtained, start and end are both set to -1. If there is an error parsing - * it, start and end are both set to 0. */ +/* CDS return when the is no CDS */ +static struct genbankCds NO_CDS = {-1, -1, FALSE, FALSE}; + +static struct genbankCds getCdsAll(struct psl *psl) +/* return CDS structure when it is assume the transcript is CDS */ { struct genbankCds cds; -ZeroVar(&cds); -if (gNoCds) - { - cds.start = -1; - cds.end = -1; - cds.startComplete = FALSE; - cds.endComplete = FALSE; - } -else if (gAllCds) - { cds.start = psl->qStart; cds.end = psl->qEnd; if (psl->strand[0] == '-') reverseIntRange(&cds.start, &cds.end, psl->qSize); cds.startComplete = TRUE; cds.endComplete = TRUE; +return cds; } -else + +static struct genbankCds getCdsFromSpec(struct sqlConnection *conn, struct psl *psl) +/* get CDS from specification in database or file */ { +struct genbankCds cds = NO_CDS; char cdsBuf[4096]; char *cdsStr = getCdsForAcc(conn, psl->qName, cdsBuf, sizeof(cdsBuf)); if (cdsStr == NULL) { if (!gQuiet) fprintf(stderr, "Warning: no CDS for %s\n", psl->qName); - cds.start = cds.end = -1; } - else - { - if (!genbankCdsParse(cdsStr, &cds)) +else if (!genbankCdsParse(cdsStr, &cds)) { if (!gQuiet) fprintf(stderr, "Warning: invalid CDS for %s: %s\n", psl->qName, cdsStr); } else if ((cds.end-cds.start) > psl->qSize) { if (!gQuiet) fprintf(stderr, "Warning: CDS for %s (%u..%u) longer than qSize (%u)\n", psl->qName, cds.start, cds.end, psl->qSize); - cds.start = cds.end = -1; - } - } + cds = NO_CDS; } return cds; } +static struct genbankCds getCds(struct sqlConnection *conn, struct psl *psl) +/* Lookup the CDS, either in the database or hash, or generate for query. If + * not found and looks like a it has a genbank version, try without the + * version. If allCds is true, generate a cds that covers the query. Conn + * maybe null if gCdsTable exists or gAllCds or gNoCds are true. If CDS can't be + * obtained, start and end are both set to -1. If there is an error parsing + * it, start and end are both set to 0. */ +{ +if (gNoCds) + return NO_CDS; +else if (gAllCds) + return getCdsAll(psl); +else + return getCdsFromSpec(conn, psl); +} + struct genePred* pslToGenePred(struct psl *psl, struct genbankCds *cds) /* Convert a psl to genePred with specified CDS string; return NULL * if should be skipped. cdsStr maybe NULL if not available. */ { unsigned optFields = gGenePredExt ? (genePredAllFlds) : 0; if ((cds->start == cds->end) && !(gKeepInvalid || gNoCds)) return NULL; if (gRequireUtr && ((cds->start == 0) || (cds->end == psl->qSize))) { if (!gQuiet) fprintf(stderr, "Warning: no 5' or 3' UTR for %s\n", psl->qName); return NULL; } return genePredFromPsl3(psl, cds, optFields, gPslOptions,