0e64e5ed246694a275e787f67dca8e41ea62d1b8 aamp Mon Apr 4 05:57:10 2011 -0700 Added one function to liftOver library code that accepts either bed or position data diff --git src/hg/lib/liftOver.c src/hg/lib/liftOver.c index 4176d7d..fca013e 100644 --- src/hg/lib/liftOver.c +++ src/hg/lib/liftOver.c @@ -1188,30 +1188,81 @@ fprintf(unmapped, "%s\n", line); else { wordCount = chopLine(line, words); chrom = words[0]; start = lineFileNeedNum(lf, words, 1); end = lineFileNeedNum(lf, words, 2); fprintf(unmapped, "%s:%d-%d\n", chrom, BEDSTART_TO_POSITION(start), end); } } lineFileClose(&lf); return ct; } +int liftOverBedOrPositions(char *fileName, struct hash *chainHash, + double minMatch, double minBlocks, + int minSizeT, int minSizeQ, + int minChainT, int minChainQ, + bool fudgeThick, FILE *mapped, FILE *unmapped, + bool multiple, char *chainTable, int *errCt) +/* Sniff the first line of the file, and determine whether it's a */ +/* bed, a positions file, or neither. */ +{ +struct lineFile *lf = lineFileOpen(fileName, "TRUE"); +char *line = NULL; +char *chrom, *start, *end; +boolean isPosition = FALSE; +lineFileNextReal(lf, &line); +if (!line) + return 0; +chrom = line; +start = strchr(chrom, ':'); +if (start) + { + *start++ = 0; + end = strchr(start, '-'); + if (end) + { + *end++ = 0; + isPosition = TRUE; + } + else + return 0; + } +else + { + char *words[3]; + int numWords = chopLine(line, words); + if (numWords < 3) + return 0; + start = words[1]; + end = words[2]; + } +if (!isdigit(start[0]) || !isdigit(end[0])) + return 0; +lineFileClose(&lf); +if (isPosition) + return liftOverPositions(fileName, chainHash, minMatch, minBlocks, minSizeT, + minSizeQ, minChainT, minChainQ, fudgeThick, mapped, unmapped, + multiple, chainTable, errCt); +return liftOverBed(fileName, chainHash, minMatch, minBlocks, minSizeT, + minSizeQ, minChainT, minChainQ, fudgeThick, mapped, unmapped, + multiple, chainTable, errCt); +} + static char *remapBlockedPsl(struct hash *chainHash, struct psl *psl, double minMatch, double minBlocks, bool fudgeThick) /* Remap blocks in psl, and also chromStart/chromEnd. * Return NULL on success, an error string on failure. */ { struct chain *chainList = NULL, *chain; int pslSize = sumPslBlocks(psl); struct binElement *binList; struct binElement *el; struct liftRange *rangeList, *badRanges = NULL, *range; char *error = NULL; int i, start, end = 0; //int pslStart = psl->tStart; //int pslEnd = psl->tEnd; int thick = 0;