void loadCr2g(char *fileName, struct cr2g **chromLists) { char buf[512]; struct cr2g *el; FILE *f = mustOpen(fileName, "r"); char *words[8]; int wordCount; char *parts[3]; int partCount; int chromIx; uglyf("Loading %s<BR>\n", fileName); while (fgets(buf, sizeof(buf), f) != NULL) { wordCount = chopString(buf, whiteSpaceChopper, words, ArraySize(words)); if (wordCount != 3) errAbort("Bad cr2g file\n"); partCount = chopString(words[0], ":-", parts, ArraySize(parts)); if (partCount != 3) errAbort("Bad cr2g file\n"); AllocVar(el); chromIx = findChromIx(parts[0]); el->strand = words[1][0]; el->start = atoi(parts[1]); el->end = atoi(parts[2]); strncpy(el->geneName, words[2], sizeof(el->geneName)); el->next = chromLists[chromIx]; chromLists[chromIx] = el; } uglyf("Done loading %s<BR>\n", fileName); fclose(f); }
void doCleanSeq(char *inputFileName, char *outputFileName) { FILE *outputFileHandle = NULL; struct lineFile *lf; char *line; char *row[9], *rsId[2]; struct hashEl *hel = NULL; boolean skipping = FALSE; outputFileHandle = mustOpen(outputFileName, "w"); lf = lineFileOpen(inputFileName, TRUE); while (lineFileNext(lf, &line, NULL)) { if (line[0] == '>') { skipping = FALSE; chopString(line, "|", row, ArraySize(row)); chopString(row[2], " ", rsId, ArraySize(rsId)); hel = hashLookup(snpHash, rsId[0]); if (hel) skipping = TRUE; else { hashAdd(snpHash, cloneString(rsId[0]), NULL); fprintf(outputFileHandle, ">%s\n", rsId[0]); } } else if (!skipping) fprintf(outputFileHandle, "%s\n", line); } carefulClose(&outputFileHandle); lineFileClose(&lf); }
void getBackgroundStatus(char *url) /* fetch status as the latest complete html block available */ { char *html = NULL; if (fileSize(url)==0) { htmlOpen("Background Status"); errAbort("No output found. Expecting output in [%s].", url); htmlClose(); return; } readInGulp(url, &html, NULL); int numLines = chopString(html, "\n", NULL, 1000000); char **lines = NULL; AllocArray(lines, numLines); chopString(html, "\n", lines, numLines); int end; for (end=numLines-1; end >= 0 && ! (endsWith(lines[end], "</html>") || endsWith(lines[end], "</HTML>")) ; --end) /* do nothing */ ; if (end < 0) { htmlOpen("Background Status"); errAbort("No complete html found"); htmlClose(); return; } int start; for (start=end; start >= 0 && ! (startsWith("<html>", lines[start]) || startsWith("<HTML>", lines[start])) ; --start) /* do nothing */ ; if (start < 0) { htmlOpen("Background Status"); errAbort("No html start tag found"); htmlClose(); return; } puts("Content-Type: text/html\n"); int line; boolean autoRefreshFound = FALSE; boolean successfullyUploaded = FALSE; for (line=start; line <= end; line++) { puts(lines[line]); if (startsWith("setTimeout(\"location = location;", lines[line])) autoRefreshFound = TRUE; if (startsWith("Output has been successfully uploaded", lines[line])) successfullyUploaded = TRUE; } // if it looks like the background is no longer running, // include the .err stdout output for more informative problem message char urlErr[512]; char *textErr = NULL; safef(urlErr, sizeof urlErr, "%s.err", url); if (!autoRefreshFound && !successfullyUploaded && (fileSize(urlErr) > 0)) { readInGulp(urlErr, &textErr, NULL); printf("%s", textErr); } }
static void parseSourceOrganism() /* parse source /organism fields, output as srcOrg if different from org */ { int numOrgs, i; char **orgs; if (gbSourceOrganism->val->stringSize == 0) return; if (srcOrgBuf == NULL) srcOrgBuf = dyStringNew(256); dyStringClear(srcOrgBuf); numOrgs = chopString(gbSourceOrganism->val->string, ";", NULL, 0); AllocArray(orgs, numOrgs); chopString(gbSourceOrganism->val->string, ";", orgs, numOrgs); for (i = 0; i < numOrgs; i++) { if (!sameString(orgs[i], gbOrganismField->val->string)) { if (srcOrgBuf->stringSize > 0) dyStringAppendC(srcOrgBuf, ';'); dyStringAppend(srcOrgBuf, orgs[i]); } } freeMem(orgs); if (srcOrgBuf->stringSize > 0) kvtAdd(kvt, "srcOrg", srcOrgBuf->string); }
void getOffset(char *directoryName, char *chromName, char *outputFileName) { FILE *outputFileHandle = mustOpen(outputFileName, "w"); struct lineFile *lf = NULL; char *line; off_t offset; char *row[9], *rsId[2]; char inputFileName[64]; safef(inputFileName, sizeof(inputFileName), "%s/%s.fa", directoryName, chromName); lf = lineFileOpen(inputFileName, TRUE); while (lineFileNext(lf, &line, NULL)) { if (line[0] == '>') { chopString(line, "|", row, ArraySize(row)); chopString(row[2], " ", rsId, ArraySize(rsId)); offset = lineFileTell(lf); fprintf(outputFileHandle, "%s\t%s\t%ld\n", rsId[0], chromName, offset); } } carefulClose(&outputFileHandle); lineFileClose(&lf); }
static void parseRestOfCdnaInfo(char *textInfo, struct wormCdnaInfo *retInfo) /* Parse text info string into a binary structure retInfo. */ { int wordCount; char *words[32]; char *s; wordCount = chopString(textInfo, "|", words, ArraySize(words)); if (wordCount < 8) errAbort("Expecting at least 8 fields in cDNA database, got %d", wordCount); if ((s = realInfoString(words[0])) != NULL) retInfo->orientation = s[0]; retInfo->gene = realInfoString(words[1]); retInfo->product = realInfoString(words[2]); if ((s = realInfoString(words[3])) != NULL) { char *parts[2]; int partCount; partCount = chopString(s, ".", parts, ArraySize(parts)); if (partCount == 2) { retInfo->knowStart = retInfo->knowEnd = TRUE; if (parts[0][0] == '<') { retInfo->knowStart = FALSE; parts[0] += 1; } if (parts[1][0] == '>') { retInfo->knowEnd = FALSE; parts[1] += 1; } retInfo->cdsStart = atoi(parts[0]); retInfo->cdsEnd = atoi(parts[1]); } } if ((s = realInfoString(words[4])) != NULL) { if (sameString("embryo", s)) retInfo->isEmbryonic = TRUE; else if (sameString("adult", s)) retInfo->isAdult = TRUE; } if ((s = realInfoString(words[5])) != NULL) { if (sameString("herm", s)) retInfo->isHermaphrodite = TRUE; else if (sameString("male", s)) retInfo->isMale = TRUE; } if ((s = realInfoString(words[6])) != NULL) { /* Reserved. Unused currently */ } retInfo->description = realInfoString(words[7]); }
void viewWaba(char *wabName) /* Show human readable waba alignment. */ { struct lineFile *lf = lineFileOpen(wabName, TRUE); int lineSize; char *line; char *qSym; char *tSym; char *hSym; int symCount; int wordCount, partCount; char *words[16], *parts[4]; int qStart, qEnd, tStart, tEnd; char strand; while (lineFileNext(lf, &line, &lineSize)) { printf("%s\n", line); wordCount = chopLine(line, words); if (wordCount != 10) errAbort("Funny info line %d of %s\n", lf->lineIx, lf->fileName); partCount = chopString(words[6], ":-", parts, ArraySize(parts)); if (partCount != 3) errAbort("Bad query range line %d of %s\n", lf->lineIx, lf->fileName); qStart = atoi(parts[1]); qEnd = atoi(parts[2]); strand = words[7][0]; partCount = chopString(words[8], ":-", parts, ArraySize(parts)); if (partCount != 3) errAbort("Bad target range line %d of %s\n", lf->lineIx, lf->fileName); tStart = atoi(parts[1]); tEnd = atoi(parts[2]); if (!lineFileNext(lf, &line, &lineSize)) errAbort("Unexpected EOF."); symCount = strlen(line); qSym = cloneString(line); if (!lineFileNext(lf, &line, &lineSize)) errAbort("Unexpected EOF."); tSym = cloneString(line); if (!lineFileNext(lf, &line, &lineSize)) errAbort("Unexpected EOF."); hSym = cloneString(line); if (strand == '+') xenShowAli(qSym, tSym, hSym, symCount, stdout, qStart, tStart, '+', '+', 60); else xenShowAli(qSym, tSym, hSym, symCount, stdout, qEnd, tStart, '-', '+', 60); freeMem(hSym); freeMem(tSym); freeMem(qSym); } lineFileClose(&lf); }
static struct slName *parseAttrVals(struct gff3Ann *g3a, char *attr, char *valsStr) /* parse an attribute into its values */ { int i, numVals = chopString(valsStr, ",", NULL, 0); char **vals = needMem((numVals+1)*sizeof(char**)); // +1 allows for no values chopString(valsStr, ",", vals, numVals); struct slName *escVals = NULL; for (i = 0; i < numVals; i++) slSafeAddHead(&escVals, unescapeSlName(g3a, vals[i])); freeMem(vals); slReverse(&escVals); return escVals; }
static void parseAttrs(struct gff3Ann *g3a, char *attrsCol) /* parse the attribute column in an annotation record */ { int i, numAttrs = chopString(attrsCol, ";", NULL, 0); char **attrVals = needMem(numAttrs*sizeof(char**)); chopString(attrsCol, ";", attrVals, numAttrs); for (i = 0; i < numAttrs; i++) { char *av = trimSpaces(attrVals[i]); if (strlen(av) > 0) parseAttrVal(g3a, av); } freeMem(attrVals); slReverse(&g3a->attrs); }
void splitSeqFile(char *inputFileName, char *logFileName, char *outputDirBasename, int filesPerDir) { FILE *outputFileHandle = NULL; FILE *logFileHandle = mustOpen(logFileName, "w"); char outputFileName[64]; char dirName[64]; int fileCount = 0; int dirCount = 0; struct lineFile *lf = lineFileOpen(inputFileName, TRUE); char *line; int lineSize; boolean firstLine = TRUE; char *row[9], *rsId[2]; safef(dirName, sizeof(dirName), "%s-%d", outputDirBasename, dirCount); makeDir(dirName); while (lineFileNext(lf, &line, &lineSize)) { if (line[0] == '>') { if (!firstLine) carefulClose(&outputFileHandle); else firstLine = FALSE; fileCount++; if (fileCount == filesPerDir) { fileCount = 0; dirCount++; safef(dirName, sizeof(dirName), "%s-%d", outputDirBasename, dirCount); makeDir(dirName); } /* use rsId for filename */ chopString(line, "|", row, ArraySize(row)); chopString(row[2], " ", rsId, ArraySize(rsId)); safef(outputFileName, sizeof(outputFileName), "%s/%s", dirName, rsId[0]); outputFileHandle = mustOpen(outputFileName, "w"); fprintf(logFileHandle, "%s\t%s/%s\n", rsId[0], dirName, rsId[0]); } else fprintf(outputFileHandle, "%s\n", line); } carefulClose(&outputFileHandle); carefulClose(&logFileHandle); lineFileClose(&lf); }
/** * static func. * * Example: /foo/bar[10]/zod[3] would return: * ret: {"foo", "bar", "zod" } * index: { 0, 10, 3 } */ bool Shell::chopPath( const string& path, vector< string >& ret, vector< unsigned int >& index ) { bool isAbsolute = chopString( path, ret, '/' ); if ( isAbsolute ) { index.clear(); } else { index.clear(); } for ( unsigned int i = 0; i < ret.size(); ++i ) { index.push_back( 0 ); if ( ret[i] == "." ) continue; if ( ret[i] == ".." ) { continue; } if ( !extractIndex( ret[i], index[i] ) ) { cout << "Error: Shell::chopPath: Failed to parse indices in path '" << path << "'\n"; ret.resize( 0 ); index.resize( 0 ); return isAbsolute; } unsigned int pos = ret[i].find_first_of( '[' ); if ( pos != string::npos ) ret[i] = ret[i].substr( 0, pos ); } return isAbsolute; }
Color gbGeneColor(struct track *tg, void *item, struct hvGfx *hvg) /* Return color to draw gene in. */ { struct sqlConnection *conn = hAllocConn(database); struct sqlResult *sr; char query[512]; struct bed *bed = item; struct COG *COG=NULL; char *temparray[160]; char **row; if(hTableExists(database, "COG")) { sprintf(query, "select * from COG where name = '%s'", bed->name); sr = sqlGetResult(conn, query); if ((row = sqlNextRow(sr)) != NULL) COG = COGLoad(row); sqlFreeResult(&sr); hFreeConn(&conn); initializeColors(hvg); if(COG!=NULL) { chopString(COG->code, "," , temparray, 9999); return LLshadesOfCOGS[(temparray[0][0]-'A')]; } else return blackIndex(); } else { hFreeConn(&conn); return blackIndex(); } slFreeList(&bed); }
struct finf *finfReadNext(struct lineFile *lf) /* Read in next finf from file, or NULL at EOF. */ { char ucscName[32]; char *parts[4], *words[16]; int partCount, wordCount; struct finf *finf; wordCount = lineFileChop(lf, words); if (wordCount <= 0) return NULL; lineFileExpectWords(lf, 7, wordCount); AllocVar(finf); gsToUcsc(words[0], ucscName); finf->name = cloneString(ucscName); finf->start = atoi(words[2])-1; finf->end = atoi(words[3]); if (words[5][0] != '?') { partCount = chopString(words[5], ",/", parts, ArraySize(parts)); if (partCount != 3) errAbort("Misformed field 6 line %d of %s\n", lf->lineIx, lf->fileName); finf->chainId = atoi(parts[0]); finf->linkIx = atoi(parts[1]); finf->linkCount = atoi(parts[2]); } strncpy(finf->endInfo, words[6], sizeof(finf->endInfo)); return finf; }
void Menu::showQuestLogEntries() { Ogre::OverlayManager* om = Ogre::OverlayManager::getSingletonPtr(); if (om==NULL) return; Ogre::OverlayContainer* panel = static_cast<Ogre::OverlayContainer*>( om->getOverlayElement(cQuestLogOverlay+"/Panel")); if (panel==NULL) { std::cout << "Menu::showQuestLogEntries: ERROR: Panel not found!\n"; return; }//if std::vector<QLogEntry> entries = QuestLog::getSingleton().listQuestEntries(m_QuestLogOffset, cQuestLogEntriesPerPage); if (m_QuestLogOffset>0 and entries.empty()) { //reset offset, because we've gone too far, and fetch entries again m_QuestLogOffset = 0; entries = QuestLog::getSingleton().listQuestEntries(m_QuestLogOffset, cQuestLogEntriesPerPage); } Ogre::TextAreaOverlayElement* text_elem = NULL; const Ogre::FontPtr glyphs = Ogre::FontManager::getSingleton().getByName("Console"); unsigned int i; //create text areas for entries for (i=0; i<entries.size(); ++i) { text_elem = static_cast<Ogre::TextAreaOverlayElement*>( om->createOverlayElement("TextArea", cQuestLogOverlay+"/"+IntToString(i))); text_elem->setMetricsMode(Ogre::GMM_RELATIVE); text_elem->setPosition(0.025, cQuestLogEntryHeight*i+0.5*cQuestLogEntryHeight); text_elem->setDimensions(0.725, cQuestLogEntryHeight); text_elem->setAlignment(Ogre::TextAreaOverlayElement::Left); text_elem->setCaption(chopString(Journal::getSingleton().getText(entries[i].questID, entries[i].index), cQuestLogCharHeight, glyphs)); text_elem->setFontName("Console"); text_elem->setColour(Ogre::ColourValue(1.0, 0.5, 0.0)); text_elem->setCharHeight(cQuestLogCharHeight); panel->addChild(text_elem); }//for //delete unneccessary textareas, if present for (i=entries.size(); i<m_QuestLogEntryCount; ++i) { om->destroyOverlayElement(cQuestLogOverlay+"/"+IntToString(i)); }//for m_QuestLogEntryCount = entries.size(); //show notification, if no elements are present yet if (entries.empty()) { text_elem = static_cast<Ogre::TextAreaOverlayElement*>( om->createOverlayElement("TextArea", cQuestLogOverlay+"/0")); text_elem->setMetricsMode(Ogre::GMM_RELATIVE); text_elem->setPosition(0.025, 0.0+0.5*cQuestLogEntryHeight); text_elem->setDimensions(0.725, cQuestLogEntryHeight); text_elem->setAlignment(Ogre::TextAreaOverlayElement::Center); text_elem->setCaption("You don't have any journal entries yet!"); text_elem->setFontName("Console"); text_elem->setColour(Ogre::ColourValue(1.0, 0.5, 0.0)); text_elem->setCharHeight(cQuestLogCharHeight); panel->addChild(text_elem); m_QuestLogEntryCount = 1; }//if }//func
void filter(FILE *in, FILE *out) /* Convert from tabular format to simple cDNA/associated genes on same line */ { char lineBuf[256]; char *words[64]; int wordCount; int tabs; boolean firstLine = TRUE; boolean inGeneList = FALSE; while (fgets(lineBuf, sizeof(lineBuf), in) != NULL) { tabs = leadingTabs(lineBuf); wordCount = chopString(lineBuf, whiteSpaceChopper, words, ArraySize(words)); if (tabs == 0 && wordCount >= 4 && strcmp(words[1], "Visible") == 0) { if (!firstLine) fprintf(out, "\n"); firstLine = FALSE; fprintf(out, "%s %s", words[0], words[3]); inGeneList = TRUE; } else if (inGeneList && tabs == 2) { fprintf(out, " %s", words[0]); } else { inGeneList = FALSE; } } fprintf(out, "\n"); }
struct hash *getOrtho(char *inputFileName) /* put all orthoSnp objects in ret hash */ { struct lineFile *lf = NULL; char *line; char *row[7]; int elementCount; struct orthoSnp *orthoSnpInstance = NULL; struct hash *ret = newHash(16); int count = 0; verbose(1, "opening file %s\n", inputFileName); lf = lineFileOpen(inputFileName, TRUE); while (lineFileNext(lf, &line, NULL)) { elementCount = chopString(line, "\t", row, ArraySize(row)); if (elementCount != 7) continue; count++; AllocVar(orthoSnpInstance); orthoSnpInstance->chrom = cloneString(row[0]); orthoSnpInstance->start = sqlUnsigned(row[1]); orthoSnpInstance->end = sqlUnsigned(row[2]); orthoSnpInstance->score = sqlUnsigned(row[4]); orthoSnpInstance->strand = cloneString(row[5]); orthoSnpInstance->allele = cloneString(row[6]); hashAdd(ret, cloneString(row[3]), orthoSnpInstance); } lineFileClose(&lf); verbose(1, "%d rows in hash\n", count); return ret; }
char *findEnsTrans(struct lineFile *lf, char *line) /* Find transcript name out of ensemble line. Squawk and die * if a problem. */ { char *words[32]; int wordCount, i; char *pat = "Translation:"; int patSize = strlen(pat); wordCount = chopLine(line+1, words); for (i=0; i<wordCount; ++i) { if (startsWith(pat, words[i])) return words[i] + patSize; } // Ensembl appears to have changed their format recently; handle both formats. wordCount = chopString(line+1, "|", words, ArraySize(words)); if (wordCount >= 3) { char *ptr = strchr(words[2], '.'); if (ptr != NULL) *ptr = 0; return(words[2]); } errAbort("Couldn't find '%s' key for transcript name line %d of %s", pat, lf->lineIx, lf->fileName); return NULL; }
static void pubsParseClassColors() /* parse class colors from hgFixed.pubsClassColors into the hash pubsClassColors */ { if (pubsClassColors!=NULL) return; pubsClassColors = hashNew(0); struct sqlConnection *conn = hAllocConn("hgFixed"); if (!sqlTableExists(conn, "pubsClassColors")) { return; } char *query = "NOSQLINJ SELECT class, rgbColor FROM pubsClassColors"; struct sqlResult *sr = sqlGetResult(conn, query); char **row = NULL; while ((row = sqlNextRow(sr)) != NULL) { char *class = row[0]; char *colStr = row[1]; // copied from genePredItemClassColor - is there no function for this? // convert comma sep rgb string to array char *rgbVals[5]; chopString(colStr, ",", rgbVals, sizeof(rgbVals)); struct rgbColor *rgb; AllocVar(rgb); rgb->r = (sqlUnsigned(rgbVals[0])); rgb->g = (sqlUnsigned(rgbVals[1])); rgb->b = (sqlUnsigned(rgbVals[2])); //printf("Adding hash: %s -> %d,%d,%d", class, rgb->r, rgb->g, rgb->b); hashAdd(pubsClassColors, cloneString(class), rgb); } sqlFreeResult(&sr); }
static void readTrans(char *transFile, char *faDir, struct hash *cloneHash, struct hash *fragHash) /* Read in transFile into hashes. */ { struct lineFile *lf = lineFileOpen(transFile, TRUE); char *row[3]; char *parts[3], *subParts[2]; int partCount, subCount; char faName[512]; struct clone *clone; struct frag *frag; printf("Reading %s\n", transFile); while (lineFileRow(lf, row)) { char *cloneName = row[1]; char *e = strchr(cloneName, '~'); if (e == NULL) errAbort("Missing ~ line %d of %s", lf->lineIx, lf->fileName); *e++ = 0; if ((clone = hashFindVal(cloneHash, cloneName)) == NULL) { AllocVar(clone); hashAddSaveName(cloneHash, cloneName, clone, &clone->name); chopSuffix(cloneName); sprintf(faName, "%s/%s.fa", faDir, cloneName); cloneName = NULL; clone->faFile = cloneString(faName); } AllocVar(frag); hashAddSaveName(fragHash, row[0], frag, &frag->name); partCount = chopString(row[2], "(:)", parts, ArraySize(parts)); if (partCount != 2) errAbort("Expecting (ACCESSION.VER:START..STOP) line %d of %s", lf->lineIx, lf->fileName); subCount = chopString(parts[1], ".", subParts, ArraySize(subParts)); if (subCount != 2) errAbort("Expecting START..STOP line %d of %s", lf->lineIx, lf->fileName); frag->start = atoi(subParts[0])-1; frag->end = atoi(subParts[1]); frag->clone = clone; if (clone->size < frag->end) clone->size = frag->end; slAddTail(&clone->fragList, frag); } lineFileClose(&lf); }
void doMiddle() { char *commandLine = cgiString("commandLine"); char *words[50]; int wordCount; wordCount = chopString(commandLine, whiteSpaceChopper, words, ArraySize(words)); printf("<PRE>"); test(wordCount, words); printf("</PRE>"); }
boolean wormIsGeneName(char *name) /* See if it looks like a worm gene name - that is * abc-12 * letters followed by a dash followed by a number. */ { char buf[128]; int partCount; strncpy(buf, name, sizeof(buf)); partCount = chopString(buf, "-", NULL, 0); if (partCount == 2) { char *parts[2]; chopString(buf, "-", parts, 2); return isAllAlpha(parts[0]) && isAllDigit(parts[1]); } else { return FALSE; } }
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; }
// similar but not identical to customFactory.c's parseRgb: static boolean parseRgb(char *s, unsigned char *retR, unsigned char *retG, unsigned char *retB) /* Turn comma separated list to RGB vals; return FALSE if input is not as expected. */ { char *row[4]; int wordCount = chopString(s, ",", row, ArraySize(row)); if ((wordCount != 3) || (!isdigit(row[0][0]) || !isdigit(row[1][0]) || !isdigit(row[2][0]))) return FALSE; *retR = atoi(row[0]); *retG = atoi(row[1]); *retB = atoi(row[2]); return TRUE; }
void hgCeOrfToGene(char *database, char *geneNames, char *geneTable, char *table) /* hgCeOrfToGene - Make orfToGene table for C.elegans from * GENE_DUMPS/gene_names.txt. */ { struct lineFile *lf = lineFileOpen(geneNames, TRUE); struct sqlConnection *conn; struct sqlResult *sr; char query[256]; char **row; char *tempDir = "."; FILE *f = hgCreateTabFile(tempDir, table); char *words[4]; struct hash *orfHash = newHash(17); /* Make hash to look up gene names. */ while (lineFileNextRowTab(lf, words, ArraySize(words))) { char *gene = words[0]; char *orfs = words[3]; char *type = words[2]; char *orf[128]; int i, orfCount; if (sameString(type, "Gene")) { orfCount = chopString(orfs, ",", orf, ArraySize(orf)); if (orfCount >= ArraySize(orf)) errAbort("Too many ORFs line %d of %s", lf->lineIx, lf->fileName); for (i=0; i<orfCount; ++i) hashAdd(orfHash, orf[i], cloneString(gene)); } } lineFileClose(&lf); /* For each orf in gene table write out gene name if possible, * otherwise orf name. */ conn = sqlConnect(database); safef(query, sizeof(query), "select name from %s", geneTable); sr = sqlGetResult(conn,query); while ((row = sqlNextRow(sr)) != NULL) { char *orf = row[0]; char *gene = hashFindVal(orfHash, orf); if (gene == NULL) gene = orf; fprintf(f, "%s\t%s\n", orf, gene); } sqlFreeResult(&sr); createTable(conn, table, unique); hgLoadTabFile(conn, tempDir, table, &f); }
void doFetch(char *inputFileName, char *sequenceFileName, char *outputFileName) /* lookup sequence for each line */ { struct lineFile *lf = NULL; char *line; char *row[6]; int elementCount; struct twoBitFile *tbf; char *fileChrom = NULL; int start = 0; int end = 0; char *name = NULL; int score = 0; char *strand = NULL; struct dnaSeq *chunk = NULL; FILE *outputFileHandle = mustOpen(outputFileName, "w"); tbf = twoBitOpen(sequenceFileName); lf = lineFileOpen(inputFileName, TRUE); while (lineFileNext(lf, &line, NULL)) { elementCount = chopString(line, "\t", row, ArraySize(row)); if (elementCount != 6) continue; fileChrom = cloneString(row[0]); start = sqlUnsigned(row[1]); end = sqlUnsigned(row[2]); name = cloneString(row[3]); score = sqlUnsigned(row[4]); strand = cloneString(row[5]); if (start == end) continue; assert (end > start); chunk = twoBitReadSeqFrag(tbf, fileChrom, start, end); touppers(chunk->dna); if (sameString(strand, "-")) reverseComplement(chunk->dna, chunk->size); fprintf(outputFileHandle, "%s\t%d\t%d\t%s\t%d\t%s\t%s\n", fileChrom, start, end, name, score, strand, chunk->dna); dnaSeqFree(&chunk); } lineFileClose(&lf); carefulClose(&outputFileHandle); }
int countWcDiff(char *fileName) /** Count how many lines counted are reported by 'wc'. */ { struct lineFile *lf = lineFileOpen(fileName, TRUE); char *line; int lineSize; int numLineDiff=0; char *row[3]; lineFileNeedNext(lf, &line, &lineSize); line = trimSpaces(line); chopString(line, " ", row, 3); numLineDiff=atoi(row[0]); lineFileClose(&lf); return numLineDiff; }
struct ernaHit *parseHit(char *line) /* Convert hit from text format to binary. */ { char *words[32]; int wordCount; char *parts[3]; int partCount; char *nucs[2]; int nucCount; struct ernaHit *hit; AllocVar(hit); wordCount = chopLine(line, words); hit->score = atof(words[0]); partCount = chopString(words[1], ":", parts, ArraySize(parts)); hit->chrom = wormOfficialChromName(parts[0]); hit->pos = atoi(parts[1])-1; nucCount = chopString(words[2], "->", nucs, ArraySize(nucs)); hit->from = nucs[0][0]; hit->to = nucs[1][0]; hit->totalCdna = atoi(words[10]); hit->commonErr = atoi(words[7]); return hit; }
static boolean isNcbiDate(char *date) /* Check if date string is plausibly something like 28-OCT-1999 */ { char buf[24]; char *words[4]; int wordCount; int len = strlen(date); if (len >= sizeof(buf)) return FALSE; strcpy(buf, date); wordCount = chopString(date, "-", words, ArraySize(words)); if (wordCount != 3) return FALSE; return isdigit(words[0][0]) && isalpha(words[1][0]) && isdigit(words[0][0]); }
void twoBitInfo(char *inName, char *outName) /* twoBitInfo - get information about sequences in a .2bit file. */ { struct twoBitFile *tbf; FILE *outFile; char *seqName = NULL; twoBitParseRange(inName, &inName, &seqName, NULL, NULL); tbf = twoBitOpen(inName); outFile = mustOpen(outName, "w"); if (seqName != NULL) { char *seqArray[1023]; int i; int seqCount = chopString(seqName, ",", seqArray, ArraySize(seqArray)); for (i = 0 ; i < seqCount ; i++) { if (optionExists("maskBed")) twoBitOutMaskBeds(tbf, seqArray[i], outFile); else if (optionExists("nBed")) twoBitOutNBeds(tbf, seqArray[i], outFile); else if(optionExists("noNs")) fprintf(outFile, "%s\t%d\n", seqArray[i], twoBitSeqSizeNoNs(tbf, seqArray[i])); else fprintf(outFile, "%s\t%d\n", seqArray[i], twoBitSeqSize(tbf, seqArray[i])); } } else { struct twoBitIndex *index; for (index = tbf->indexList; index != NULL; index = index->next) { if (optionExists("maskBed")) twoBitOutMaskBeds(tbf, index->name, outFile); else if (optionExists("nBed")) twoBitOutNBeds(tbf, index->name, outFile); else if(optionExists("noNs")) fprintf(outFile, "%s\t%d\n", index->name, twoBitSeqSizeNoNs(tbf, index->name)); else fprintf(outFile, "%s\t%d\n", index->name, twoBitSeqSize(tbf, index->name)); } } twoBitClose(&tbf); carefulClose(&outFile); }
static void parseAnn(struct gff3File *g3f, char *line) /* parse an annotation line */ { // extra column to check for too many char *words[gffNumCols+1]; int numWords = chopString(line, "\t", words, gffNumCols+1); if (numWords != gffNumCols) gff3FileErr(g3f, "expected %d tab-separated columns: %s", gffNumCols, line); struct gff3Ann *g3a = gff3FileAlloc(g3f, sizeof(struct gff3Ann)); g3a->file = g3f; g3a->lineNum = g3f->lf->lineIx; parseFields(g3a, words); parseAttrs(g3a, words[8]); parseStdAttrs(g3a); slAddHead(&g3f->anns, g3a); }