static void readTaggedNumLine(struct lineFile *lf, char *tag, int count, int *intOut, double *floatOut) /* Read in a line that starts with tag and then has count numbers. * Complain and die if tag is unexpected or other problem occurs. * Put output as integers and/or floating point into intOut and * floatOut. */ { char *line; int i = 0; char *word; if (!lineFileNextReal(lf, &line)) lineFileUnexpectedEnd(lf); word = nextWord(&line); if (!sameWord(tag, word)) errAbort("Expecting %s got %s line %d of %s", tag, word, lf->lineIx, lf->fileName); for (i = 0; i < count; ++i) { word = nextWord(&line); if (word == NULL) errAbort("Not enough numbers line %d of %s", lf->lineIx, lf->fileName); if (!isdigit(word[0])) errAbort("Expecting number got %s line %d of %s", word, lf->lineIx, lf->fileName); if (intOut) intOut[i] = atoi(word); if (floatOut) floatOut[i] = atof(word); } word = nextWord(&line); if (word != NULL) errAbort("Too many numbers line %d of %s", lf->lineIx, lf->fileName); }
void makeMotifs(char *inFile, struct hash *tfHash, char *outFile) /* Parse input motifs and save them to outFile in dnaMotif format. */ { struct lineFile *lf = lineFileOpen(inFile, TRUE); FILE *f = mustOpen(outFile, "w"); struct hashEl *hel; for (;;) { char *line; char *words[256], *word; int wordCount; struct dnaMotif *motif; if (!lineFileSkipTo(lf, "Probability matrix for")) break; lineFileNeedNext(lf, &line, NULL); wordCount = chopLine(line, words); if (wordCount >= ArraySize(words)) errAbort("Line %d of %s is too long\n", lf->lineIx, lf->fileName); if (!sameString(words[0], "#")) badFormat(lf); AllocVar(motif); motif->columnCount = wordCount-1; readBaseProbs(lf, words, "#A", &motif->aProb, motif->columnCount); readBaseProbs(lf, words, "#C", &motif->cProb, motif->columnCount); readBaseProbs(lf, words, "#T", &motif->tProb, motif->columnCount); readBaseProbs(lf, words, "#G", &motif->gProb, motif->columnCount); if (!lineFileSkipTo(lf, "Source:")) lineFileUnexpectedEnd(lf); lineFileReuse(lf); lineFileNeedNext(lf, &line, NULL); word = nextWord(&line); word = nextWord(&line); if (word == NULL) errAbort("Short Source: line %d of %s", lf->lineIx, lf->fileName); motif->name = cloneString(word); hel = hashLookup(tfHash, motif->name); if (hel == NULL) errAbort("%s in %s but not GFFs", motif->name, lf->fileName); hel->val = motif; dnaMotifTabOut(motif, f); } carefulClose(&f); lineFileClose(&lf); }
static struct joinerSet *parseIdentifierSet(struct lineFile *lf, char *line, struct hash *symHash, struct dyString *dyBuf) /* Parse out one joiner record - keep going until blank line or * end of file. */ { struct joinerSet *js; struct joinerField *jf; char *word, *e; char *parts[3]; int partCount; /* Parse through first line - first word is name. */ word = nextWord(&line); if (word == NULL || strchr(word, '=') != NULL) errAbort("joiner without name line %d of %s\n", lf->lineIx, lf->fileName); AllocVar(js); js->name = cloneString(word); js->lineIx = lf->lineIx; while ((word = nextWord(&line)) != NULL) { char *e = strchr(word, '='); if (e != NULL) *e++ = 0; if (sameString(word, "typeOf")) { js->typeOf = cloneSpecified(lf, word, e); } else if (sameString(word, "external")) { js->external = cloneSpecified(lf, word, e); } else if (sameString(word, "fuzzy")) { js->isFuzzy = TRUE; } else if (sameString(word, "dependency")) { js->isDependency = TRUE; } else { errAbort("Unknown attribute %s line %d of %s", word, lf->lineIx, lf->fileName); } } /* Parse second line, make sure it is quoted, and save as description. */ line = nextSubbedLine(lf, symHash, dyBuf); if (line == NULL) lineFileUnexpectedEnd(lf); line = trimSpaces(line); if (line[0] != '"' || lastChar(line) != '"') errAbort("Expecting quoted line, line %d of %s\n", lf->lineIx, lf->fileName); line[strlen(line)-1] = 0; js->description = cloneString(line+1); /* Go through subsequent lines. */ while ((line = nextSubbedLine(lf, symHash, dyBuf)) != NULL) { /* Keep grabbing until we get a blank line. */ line = skipLeadingSpaces(line); if (line[0] == 0) break; /* First word in line should be database.tabe.field. */ word = nextWord(&line); partCount = chopString(word, ".", parts, ArraySize(parts)); if (partCount != 3) errAbort("Expecting database.table.field line %d of %s", lf->lineIx, lf->fileName); /* Allocate struct and save table and field. */ AllocVar(jf); jf->lineIx = lf->lineIx; jf->table = cloneString(parts[1]); jf->field = cloneString(parts[2]); if (js->fieldList == NULL && !js->isFuzzy) { jf->isPrimary = TRUE; jf->unique = TRUE; jf->full = TRUE; } jf->minCheck = 1.0; slAddHead(&js->fieldList, jf); /* Database may be a comma-separated list. Parse it here. */ jf->dbList = parseDatabaseList(lf, parts[0]); /* Look for other fields in subsequent space-separated words. */ while ((word = nextWord(&line)) != NULL) { if ((e = strchr(word, '=')) != NULL) *e++ = 0; if (sameString("comma", word)) { jf->separator = cloneString(","); } else if (sameString("separator", word)) { jf->separator = cloneSpecified(lf, word, e); } else if (sameString("chopBefore", word)) { if (e == NULL) unspecifiedVar(lf, word); slNameStore(&jf->chopBefore, e); } else if (sameString("chopAfter", word)) { if (e == NULL) unspecifiedVar(lf, word); slNameStore(&jf->chopAfter, e); } else if (sameString("indexOf", word)) { jf->indexOf = TRUE; } else if (sameString("dupeOk", word)) { if (!jf->isPrimary) warn("dupeOk outsite primary key line %d of %s", lf->lineIx, lf->fileName); jf->unique = FALSE; } else if (sameString("minCheck", word)) { if (e == NULL) unspecifiedVar(lf, word); jf->minCheck = atof(e); } else if (sameString("unique", word)) { jf->unique = TRUE; } else if (sameString("full", word)) { jf->full = TRUE; } else if (sameString("splitPrefix", word)) { jf->splitPrefix = cloneSpecified(lf, word, e); } else if (sameString("splitSuffix", word)) { jf->splitSuffix = cloneSpecified(lf, word, e); } else if (sameString("exclude", word)) { if (e == NULL) unspecifiedVar(lf, word); slNameStore(&jf->exclude, e); } else { errAbort("Unrecognized attribute %s line %d of %s", word, lf->lineIx, lf->fileName); } } if (jf->indexOf && jf->separator == NULL) errAbort("indexOf without comma or separator line %d of %s", lf->lineIx, lf->fileName); if (jf->isPrimary && jf->separator != NULL) errAbort("Error line %d of %s\n" "Primary key can't be a list (comma or separator)." , lf->lineIx, lf->fileName); } slReverse(&js->fieldList); return js; }
void lineFileNeedNext(struct lineFile *lf, char **retStart, int *retSize) /* Fetch next line from file. Squawk and die if it's not there. */ { if (!lineFileNext(lf, retStart, retSize)) lineFileUnexpectedEnd(lf); }