void fillInPsls(char *pslName, struct hash *pairHash) /* Read in psl file and save overlaps between indicated pairs * in hash. */ { struct lineFile *lf = pslFileOpen(pslName); struct psl *psl; char *pairName; struct seqPair *pair; struct seqOver *so; boolean firstA; char queryClone[128], targetClone[128]; struct hashEl *hel; while ((psl = pslNext(lf)) != NULL) { fragToCloneName(psl->qName, queryClone); fragToCloneName(psl->tName, targetClone); pairName = makePairName(queryClone, targetClone, &firstA); if ((pair = hashFindVal(pairHash, pairName)) != NULL) { so = (firstA ? &pair->a : &pair->b); slAddHead(&so->pslList, psl); } else { pslFree(&psl); } } }
void pslCut(char *cutList, char *inPsl, char *outPsl) /* pslCut - Remove a list of clones from psl file.. */ { struct hash *cutHash = newHash(0); struct lineFile *lf = pslFileOpen(inPsl); FILE *f = mustOpen(outPsl, "w"); struct psl *psl; char cloneName[128]; int total = 0, cut = 0; buildCutHash(cutList, cutHash); pslWriteHead(f); while ((psl = pslNext(lf)) != NULL) { fragToCloneName(psl->tName, cloneName); if (!hashLookup(cutHash, cloneName)) { pslTabOut(psl, f); } else ++cut; ++total; pslFree(&psl); } printf("Cut %d of %d\n", cut, total); }
void addCloneInfo(char *glFileName, struct hash *cloneHash, struct clonePos **pCloneList) /* Add in clone info from one .gl file. */ { char dir[256], chrom[128], ext[64]; struct gl gl; struct lineFile *lf = lineFileOpen(glFileName, TRUE); struct clonePos *clone; char *line, *words[8]; int lineSize, wordCount; char cloneVerName[128]; char cloneName[128]; printf("Processing %s\n", glFileName); splitPath(glFileName, dir, chrom, ext); while (lineFileNext(lf, &line, &lineSize)) { wordCount = chopLine(line, words); if (wordCount == 0) continue; if (wordCount != 4) errAbort("Expecting %d words line %d of %s", 4, lf->lineIx, lf->fileName); glStaticLoad(words, &gl); fragToCloneVerName(gl.frag, cloneVerName); fragToCloneName(gl.frag, cloneName); if ((clone = hashFindVal(cloneHash, cloneName)) == NULL) { AllocVar(clone); clone->name = cloneString(cloneVerName); clone->chrom = cloneString(chrom); clone->chromStart = gl.start; clone->chromEnd = gl.end; clone->faFile = cloneString(""); slAddHead(pCloneList, clone); hashAdd(cloneHash, cloneName, clone); } else { if (!sameString(clone->chrom, chrom)) { warn("Clone %s is on chromosomes %s and %s. Ignoring %s", cloneName, clone->chrom, chrom, chrom); continue; } if (clone->chromStart > gl.start) clone->chromStart = gl.start; if (clone->chromEnd < gl.end) clone->chromEnd = gl.end; } } lineFileClose(&lf); }
struct clone *readTrans(char *fileName) /* Read info in trans file. */ { char cloneName[128], lastCloneName[128]; struct clone *cloneList = NULL, *clone = NULL; struct frag *frag; struct lineFile *lf = lineFileOpen(fileName, TRUE); char *words[8], *parts[4], *subParts[3]; int wordCount, partCount, subCount; strcpy(lastCloneName, ""); while ((wordCount = lineFileChop(lf, words)) != 0) { lineFileExpectWords(lf, 3, wordCount); partCount = chopString(words[2], "(:)", parts, ArraySize(parts)); if (partCount != 2) errAbort("Badly formatted third field line %d of %s", lf->lineIx, lf->fileName); subCount = chopString(parts[1], ".", subParts, ArraySize(subParts)); if (subCount != 2) errAbort("Badly formatted third field line %d of %s (expecting start..end)", lf->lineIx, lf->fileName); fragToCloneName(words[0], cloneName); if (!sameString(cloneName, lastCloneName)) { AllocVar(clone); clone->name = cloneString(cloneName); slAddHead(&cloneList, clone); } AllocVar(frag); frag->name = cloneString(words[0]); frag->ffaName = cloneString(words[1]); frag->start = lineFileNeedNum(lf, subParts, 0) - 1; frag->end = lineFileNeedNum(lf, subParts, 1); slAddTail(&clone->fragList, frag); strcpy(lastCloneName, cloneName); } lineFileClose(&lf); slReverse(&cloneList); return cloneList; }
void agpVsMap(char *agpName, char *infoName, char *gifName) /* agpVsMap - Plot clones in agp vs. map coordinates. */ { struct mapPos *mapList, *mp; struct agpFrag *agpList, *bp; struct hash *cloneHash = newHash(14); struct hashEl *hel; struct cloneInfo *cloneList = NULL, *clone; struct memGfx *mg = NULL; int pixWidth = 600; int pixHeight = 600; int rulerHeight = 20; int maxMapPos = 0, maxAgpPos = 0; double scaleMap, scaleAgp; Color orange, green; mapList = readInfoFile(infoName); agpList = readAgpFile(agpName); for (mp = mapList; mp != NULL; mp = mp->next) { if (mp->phase > 0) { AllocVar(clone); hel = hashAddUnique(cloneHash, mp->cloneName, clone); clone->name = hel->name; clone->mp = mp; slAddHead(&cloneList, clone); if (mp->pos > maxMapPos) maxMapPos = mp->pos; } } slReverse(&cloneList); for (bp = agpList; bp != NULL; bp = bp->next) { if (bp->chromStart > maxAgpPos) maxAgpPos = bp->chromStart; } /* Draw scatterplot on bitmap. */ mg = mgNew(pixWidth, pixHeight); mgClearPixels(mg); orange = mgFindColor(mg, 210, 150, 0); green = mgFindColor(mg, 0, 200, 0); mgDrawRuler(mg, 0, pixHeight-rulerHeight, rulerHeight, pixWidth, MG_BLACK, mgSmallFont(), 0, maxMapPos+1); scaleMap = (double)pixWidth/(double)(maxMapPos+1.0); scaleAgp = (double)(pixHeight)/(double)(maxAgpPos+1.0); for (bp = agpList; bp != NULL; bp = bp->next) { char cloneName[128]; fragToCloneName(bp->frag, cloneName); clone = hashFindVal(cloneHash, cloneName); if (clone == NULL) warn("%s is in %s but not %s", cloneName, agpName, infoName); else { int x = round(scaleMap*clone->mp->pos); int y = pixHeight - round(scaleAgp*bp->chromStart); int phase = clone->mp->phase; int back; if (phase <= 1) back = green; else if (phase == 2) back = orange; else back = MG_RED; drawPlus(mg, x, y, back); } } mgSaveGif(mg, gifName); }