boolean passFilters(struct psl *psl) /* Does this psl pass our filters? */ { int milliMin = 1000 *minAli; boolean pass = FALSE; /* Check min coverage. */ pass = (psl->match + psl->repMatch >= minCover * (psl->qSize - psl->nCount)); /* Check min alignment percentage. */ pass = ((1000-pslCalcMilliBad(psl, TRUE)) > milliMin) && pass; return pass; }
struct bed *pslToBed(struct psl *psl) /* Convert a psl format row of strings to a bed, very similar to customTrack.c::customTrackPsl*/ { struct bed *bed; int i, blockCount, *chromStarts, chromStart; /* 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)); bed->blockCount = blockCount = psl->blockCount; bed->blockSizes = (int *)cloneMem(psl->blockSizes,(sizeof(int)*psl->blockCount)); 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]; } /* Convert coordinates to relative. */ for (i=0; i<blockCount; ++i) chromStarts[i] -= chromStart; return bed; }
void showAliPlaces(char *pslName, char *faName, char *database, enum gfType qType, enum gfType tType, char *organism, boolean feelingLucky) /* Show all the places that align. */ { struct lineFile *lf = pslFileOpen(pslName); struct psl *pslList = NULL, *psl; char *browserUrl = hgTracksName(); char *hgcUrl = hgcName(); char uiState[64]; char *vis; char unhideTrack[64]; char *sort = cartUsualString(cart, "sort", sortList[0]); char *output = cartUsualString(cart, "output", outputList[0]); boolean pslOut = startsWith("psl", output); boolean isStraightNuc = (qType == gftRna || qType == gftDna); int minThreshold = (isStraightNuc ? minMatchShown : 0); sprintf(uiState, "%s=%s", cartSessionVarName(), cartSessionId(cart)); /* If user has hidden BLAT track, add a setting that will unhide the track if user clicks on a browser link. */ vis = cartOptionalString(cart, "hgUserPsl"); if (vis != NULL && sameString(vis, "hide")) snprintf(unhideTrack, sizeof(unhideTrack), "&hgUserPsl=dense"); else unhideTrack[0] = 0; while ((psl = pslNext(lf)) != NULL) { if (psl->match >= minThreshold) slAddHead(&pslList, psl); } lineFileClose(&lf); if (pslList == NULL) { puts("<table><tr><td><hr>Sorry, no matches found<hr><td></tr></table>"); return; } if (sameString(sort, "query,start")) { slSort(&pslList, pslCmpQuery); } else if (sameString(sort, "query,score")) { slSort(&pslList, pslCmpQueryScore); } else if (sameString(sort, "score")) { slSort(&pslList, pslCmpScore); } else if (sameString(sort, "chrom,start")) { slSort(&pslList, pslCmpTargetStart); } else if (sameString(sort, "chrom,score")) { slSort(&pslList, pslCmpTargetScore); } else { slSort(&pslList, pslCmpQueryScore); } if(feelingLucky) { /* If we found something jump browser to there. */ if(slCount(pslList) > 0) printLuckyRedirect(browserUrl, pslList, database, pslName, faName, uiState, unhideTrack); /* Otherwise call ourselves again not feeling lucky to print empty results. */ else { cartWebStart(cart, database, "%s BLAT Results", trackHubSkipHubName(organism)); showAliPlaces(pslName, faName, database, qType, tType, organism, FALSE); cartWebEnd(); } } else if (pslOut) { printf("<TT><PRE>"); if (!sameString(output, "psl no header")) pslxWriteHead(stdout, qType, tType); for (psl = pslList; psl != NULL; psl = psl->next) pslTabOut(psl, stdout); printf("</PRE></TT>"); } else { printf("<H2>BLAT Search Results</H2>"); printf("<TT><PRE>"); printf(" ACTIONS QUERY SCORE START END QSIZE IDENTITY CHRO STRAND START END SPAN\n"); printf("---------------------------------------------------------------------------------------------------\n"); for (psl = pslList; psl != NULL; psl = psl->next) { printf("<A HREF=\"%s?position=%s:%d-%d&db=%s&ss=%s+%s&%s%s\">", browserUrl, psl->tName, psl->tStart + 1, psl->tEnd, database, pslName, faName, uiState, unhideTrack); printf("browser</A> "); printf("<A HREF=\"%s?o=%d&g=htcUserAli&i=%s+%s+%s&c=%s&l=%d&r=%d&db=%s&%s\">", hgcUrl, psl->tStart, pslName, cgiEncode(faName), psl->qName, psl->tName, psl->tStart, psl->tEnd, database, uiState); printf("details</A> "); printf("%-14s %5d %5d %5d %5d %5.1f%% %4s %2s %9d %9d %6d\n", psl->qName, pslScore(psl), psl->qStart+1, psl->qEnd, psl->qSize, 100.0 - pslCalcMilliBad(psl, TRUE) * 0.1, skipChr(psl->tName), psl->strand, psl->tStart+1, psl->tEnd, psl->tEnd - psl->tStart); } printf("</PRE></TT>"); } pslFreeList(&pslList); }
void reviewOne(char *dir) /* Review sanity files in one contig dir. */ { char fileName[512]; struct block *blockList = NULL, *block; struct hash *blockHash = newHash(16); struct psl *psl; struct lineFile *lf; int i, aliSize; sprintf(fileName, "%s/break.lst", dir); if (!fileExists(fileName)) return; readBlockInfo(fileName, blockHash, &blockList); if (blockList == NULL) return; sprintf(fileName, "%s/sanity.psl", dir); lf = lineFileOpen(fileName, TRUE); while ((psl = pslNext(lf)) != NULL) { if (pslCalcMilliBad(psl, FALSE) < 20) { aliSize = psl->match + psl->repMatch; block = hashMustFindVal(blockHash, psl->qName); for (i=0; i<10; ++i) { if (aliSize <= thresholds[i+1]) { ++block->hitCount[i]; break; } } if (aliSize >= blockSize-2) ++block->perfectCount; } else ++weakAliCount; pslFree(&psl); } lineFileClose(&lf); /* Loop through list gathering statistics on how blocks * hit genome. */ for (block = blockList; block != NULL; block = block->next) { int numBest = 0; int numGood = 0; if (block->maskedOut) ++repMaskedCount; else { ++blockCount; if (block->perfectCount) ++perfectCount; for (i=9; i >= 0; --i) { if ((numBest = block->hitCount[i]) > 0) break; } if (numBest == 0) { ++missCount; fprintf(missLog, "%s\n", block->name); } else ++hitCount[i]; for (i=7; i<10; ++i) numGood += block->hitCount[i]; if (numGood > 1) ++dupeCount; } } freeHash(&blockHash); slFreeList(&blockList); }
int calcMilliScore(struct psl *psl) /* Figure out percentage score. */ { return 1000-pslCalcMilliBad(psl, TRUE); }