void rConvert(FILE *f, struct hash *hash, int maxSize, char *s) /* Print out all possible word representations of s. This does * the job recursively, finding a word in the dictionary that * matches the first part of s, and then calling itself on the * remainder of s. It keeps a local stack of words it's seen. * When there is nothing left in s, it prints out the stack.*/ { static char *wordStack[128]; static int wordStackIx = 0; int len = strlen(s); int i; if (len > 0) { char numBuf[MAXWORDSIZE]; boolean gotAny = FALSE; numBuf[0] = s[0]; if (maxSize > len) maxSize = len; for (i=1; i<=maxSize; ++i) { struct hashEl *hel; numBuf[i] = 0; hel = hashLookup(hash, numBuf); while (hel != NULL) { char *mnemonic = hel->val; wordStack[wordStackIx++] = mnemonic; rConvert(f, hash, maxSize, s+i); --wordStackIx; gotAny = TRUE; hel = hashLookupNext(hel); } numBuf[i] = s[i]; } if (!gotAny) { /* We can't match any words in the dictionary. * Just output one literal number then. */ wordStack[wordStackIx++] = literal[s[0]]; rConvert(f, hash, maxSize, s+1); --wordStackIx; } } else { /* We've come to the end of the string, print out words we've composed. */ if (wordStackIx > 0) { for (i=0; i < wordStackIx; ++i) fprintf(f, "%s ", wordStack[i]); fprintf(f, "\n"); } } }
void netToAxt(char *netName, char *chainName, char *tNibDir, char *qNibDir, char *axtName) /* netToAxt - Convert net (and chain) to axt.. */ { Bits *usedBits = findUsedIds(netName); struct hash *chainHash; struct chainNet *net; struct lineFile *lf = lineFileOpen(netName, TRUE); FILE *f = mustOpen(axtName, "w"); struct dnaSeq *tChrom = NULL; struct nibTwoCache *qNtc = nibTwoCacheNew(qNibDir); char *gapFileName = optionVal("gapOut", NULL); FILE *gapFile = NULL; if (gapFileName) gapFile = mustOpen(gapFileName, "w"); lineFileSetMetaDataOutput(lf, f); chainHash = chainReadUsedSwap(chainName, qChain, usedBits); bitFree(&usedBits); while ((net = chainNetRead(lf)) != NULL) { verbose(1, "Processing %s\n", net->name); tChrom = nibTwoLoadOne(tNibDir, net->name); if (tChrom->size != net->size) errAbort("Size mismatch on %s. Net/nib out of sync or possibly nib dirs swapped?", tChrom->name); rConvert(net->fillList, tChrom, qNtc, qNibDir, chainHash, f, gapFile); freeDnaSeq(&tChrom); chainNetFree(&net); } nibTwoCacheFree(&qNtc); }
void processPhoneBook(struct hash *hash, int maxSize, char *phoneNumbers, char *output) /* Read in phone book and construct numbers for it. */ { struct lineFile *lf = lineFileOpen(phoneNumbers, TRUE); FILE *f = mustOpen(output, "w"); char *line; while (lineFileNext(lf, &line, NULL)) { fprintf(f, "Number: %s\n", line); stripNonNum(line); rConvert(f, hash, maxSize, line); fprintf(f, "\n"); } }
void rConvert(struct cnFill *fillList, struct dnaSeq *tChrom, struct nibTwoCache *qNtc, char *qNibDir, struct hash *chainHash, FILE *f, FILE *gapFile) /* Recursively output chains in net as axt. */ { struct cnFill *fill; for (fill = fillList; fill != NULL; fill = fill->next) { if (fill->chainId) convertFill(fill, tChrom, qNtc, qNibDir, chainLookup(chainHash, fill->chainId), f, gapFile); if (fill->children) rConvert(fill->children, tChrom, qNtc, qNibDir, chainHash, f, gapFile); } }
void rConvert(struct cnFill *fillList, struct hash *chainHash, FILE *f, FILE *gapFile) /* Recursively output chains in net as axt. */ { struct cnFill *fill; for (fill = fillList; fill != NULL; fill = fill->next) { if (fill->chainId) { struct chain *chain = skipMissing ? chainFind(chainHash, fill->chainId) : chainLookup(chainHash, fill->chainId); if (chain != NULL) convertFill(fill, chain, f, gapFile); } if (fill->children) rConvert(fill->children, chainHash, f, gapFile); } }
void netChainSubset(char *netIn, char *chainIn, char *chainOut) /* netChainSubset - Create chain file with subset of * * chains that appear in the net. */ { struct hash *chainHash; struct chainNet *net; struct lineFile *lf = lineFileOpen(netIn, TRUE); FILE *f = mustOpen(chainOut, "w"); char *gapFileName = optionVal("gapOut", NULL); FILE *gapFile = NULL; if (gapFileName) gapFile = mustOpen(gapFileName, "w"); chainHash = chainReadAllWithMeta(chainIn, f); while ((net = chainNetRead(lf)) != NULL) { verbose(1, "Processing %s\n", net->name); rConvert(net->fillList, chainHash, f, gapFile); chainNetFree(&net); } }