static struct mapAln *chainToPsl(struct chain *ch) /* convert a chain to a psl, ignoring match counts, etc */ { struct psl *psl; struct cBlock *cBlk; int iBlk; int qStart = ch->qStart, qEnd = ch->qEnd; char strand[2]; strand[0] = ch->qStrand; strand[1] = '\0'; if (ch->qStrand == '-') reverseIntRange(&qStart, &qEnd, ch->qSize); psl = pslNew(ch->qName, ch->qSize, qStart, qEnd, ch->tName, ch->tSize, ch->tStart, ch->tEnd, strand, slCount(ch->blockList), 0); for (cBlk = ch->blockList, iBlk = 0; cBlk != NULL; cBlk = cBlk->next, iBlk++) { psl->blockSizes[iBlk] = (cBlk->tEnd - cBlk->tStart); psl->qStarts[iBlk] = cBlk->qStart; psl->tStarts[iBlk] = cBlk->tStart; psl->match += psl->blockSizes[iBlk]; } psl->blockCount = iBlk; if (swapMap) pslSwap(psl, FALSE); return mapAlnNew(psl, ch->id); }
static void pslMap(char* inPslFile, char *mapFile, char *outPslFile) /* project inPsl query through mapFile query to mapFile target */ { struct chromBins *mapAlns; struct psl* inPsl; struct lineFile* inPslLf = pslFileOpen(inPslFile); FILE *outPslFh, *mapInfoFh = NULL, *mappingPslFh = NULL; if (chainMapFile) mapAlns = loadMapChains(mapFile); else mapAlns = loadMapPsls(mapFile); outPslFh = mustOpen(outPslFile, "w"); if (mapInfoFile != NULL) { mapInfoFh = mustOpen(mapInfoFile, "w"); fputs(mapInfoHdr, mapInfoFh); } if (mappingPslFile != NULL) mappingPslFh = mustOpen(mappingPslFile, "w"); while ((inPsl = pslNext(inPslLf)) != NULL) { if (swapIn) pslSwap(inPsl, FALSE); mapQueryPsl(inPsl, mapAlns, outPslFh, mapInfoFh, mappingPslFh); pslFree(&inPsl); } carefulClose(&mappingPslFh); carefulClose(&mapInfoFh); carefulClose(&outPslFh); lineFileClose(&inPslLf); }
static struct psl *mapCDnaCDnaAln(struct hapRegions *hr, struct cDnaAlign *refAln, struct psl *mappedHap) /* create cdna to cdna alignments from mappedHap and refAln, return * NULL if can't be mapped */ { struct psl *cDnaCDnaAln = NULL; if (sameString(refAln->psl->tName, mappedHap->tName) && rangeIntersection(refAln->psl->tStart, refAln->psl->tEnd, mappedHap->tStart, mappedHap->tEnd)) { pslSwap(mappedHap, FALSE); cDnaCDnaAln = pslTransMap(pslTransMapNoOpts, refAln->psl, mappedHap); pslSwap(mappedHap, FALSE); if ((hr->hapRefCDnaFh != NULL) && (cDnaCDnaAln != NULL)) cDnaAlignPslOut(cDnaCDnaAln, refAln->alnId, hr->hapRefCDnaFh); } return cDnaCDnaAln; }
static struct chromBins* loadMapPsls(char *pslFile) /* read a psl file and chromBins by query, linking multiple PSLs for the * same query.*/ { struct dyString* idBuf = NULL; struct chromBins* mapAlns = chromBinsNew((chromBinsFreeFunc*)pslFree); int id = 0; struct psl* psl; struct lineFile *pslLf = pslFileOpen(pslFile); while ((psl = pslNext(pslLf)) != NULL) { if (swapMap) pslSwap(psl, FALSE); chromBinsAdd(mapAlns, getMappingId(psl->qName, &idBuf), psl->qStart, psl->qEnd, mapAlnNew(psl, id)); id++; } lineFileClose(&pslLf); dyStringFree(&idBuf); return mapAlns; }