void drawWrappedText(RenderingContext* rc, SkCanvas* cv, TextDrawInfo* text, float textSize, SkPaint& paintText) { if(text->textWrap == 0) { // set maximum for all text text->textWrap = 40; } if(text->text.length() > text->textWrap) { const char* c_str = text->text.c_str(); int end = text->text.length(); int line = 0; int pos = 0; int start = 0; while(start < end) { const char* p_str = c_str; int lastSpace = -1; int prevPos = -1; int charRead = 0; do { int lastSpace = nextWord((uint8_t*)p_str, &charRead); if (lastSpace == -1) { pos = end; } else { p_str += lastSpace; if(pos != start && charRead >= text->textWrap){ break; } pos += lastSpace; } } while(pos < end && charRead < text->textWrap); PROFILE_NATIVE_OPERATION(rc, drawTextOnCanvas(cv, c_str, pos - start , text->centerX, text->centerY + line * (textSize + 2), paintText, text->textShadow)); c_str += (pos - start); start = pos; line++; } } else { PROFILE_NATIVE_OPERATION(rc, drawTextOnCanvas(cv, text->text.data(), text->text.length(), text->centerX, text->centerY, paintText, text->textShadow)); } }
boolean lineToGffFields(struct lineFile *lf, char *line, char *fields[9]) /* Convert first eight space-separated fields to first 8 * gff items, and stick rest of line in last item. */ { char *s, *word; int i; /* Pretty much ignore comments and blank lines. */ s = skipLeadingSpaces(line); if (s[0] == '#' || s[0] == '0') return FALSE; for (i=0; i<8; ++i) { word = nextWord(&s); if (word == NULL) errAbort("Expecting at least 8 words line %d of %s", lf->lineIx, lf->fileName); fields[i] = word; } fields[8] = skipLeadingSpaces(s); return TRUE; }
XP_S16 dict_findStartsWith( DictIter* iter, const XP_UCHAR* prefix ) { ASSERT_INITED( iter ); array_edge* edge = dict_getTopEdge( iter->dict ); XP_S16 offset = findStartsWithChars( iter, prefix, 0, edge, 0 ); if ( 0 > offset ) { /* not found; do nothing */ } else if ( 0 == offset ) { if ( !firstWord( iter ) ) { offset = -1; } } else { if ( ACCEPT_ITER( iter, iter->nEdges ) || nextWord( iter ) ) { DictPosition result = figurePosition( iter ); iter->position = result; } else { offset = -1; } } return offset; }
static int countWordsUsedInPhrase(char *phrase, struct slName *wordList) /* Count the number of words in wordList that are used in phrase. * The words are in order and space-separated in phrase. */ { int count = 0; struct slName *word; char *dupe = cloneString(phrase); char *s = dupe, *w; for (word = wordList; word != NULL; word = word->next) { w = nextWord(&s); if (w == NULL) break; if (sameWord(w, word->name)) count += 1; else break; } freeMem(dupe); return count; }
char *nextQuotedWord(char **pLine) /* Generalization of nextWord. Returns next quoted * string or if no quotes next word. Updates *pLine * to point past word that is returned. Does not return * quotes. */ { char *line, c; line = skipLeadingSpaces(*pLine); if (line == NULL || line[0] == 0) return NULL; c = *line; if (c == '"' || c == '\'') { if (!parseQuotedString(line, line, pLine)) return NULL; return line; } else { return nextWord(pLine); } }
struct htmlCookie *htmlCookieFileRead(char *fileName) /* Read cookies from a line oriented file. First word in line * is the cookie name, the rest of the line the cookie value. */ { struct lineFile *lf = lineFileOpen(fileName, TRUE); struct htmlCookie *list = NULL, *cookie; char *line, *word; while (lineFileNextReal(lf, &line)) { word = nextWord(&line); line = skipLeadingSpaces(line); if (line == NULL) errAbort("Missing cookie value line %d of %s", lf->lineIx, lf->fileName); AllocVar(cookie); cookie->name = cloneString(word); cookie->value = cloneString(line); slAddHead(&list, cookie); } lineFileClose(&lf); slReverse(&list); return list; }
struct segFile *segMayOpen(char *fileName) /* Open up a segment file for reading. Read header and verify. Prepare * for subsequent calls to segNext(). Return NULL if file does not exist. */ { struct segFile *sf; struct lineFile *lf; char *line, *name, *val, *word; char *sig = "##seg"; /* Open fileName. */ if ((lf = lineFileMayOpen(fileName, TRUE)) == NULL) return NULL; AllocVar(sf); sf->lf = lf; /* Check for a valid signature. */ lineFileNeedNext(lf, &line, NULL); if (!startsWith(sig, line)) errAbort("%s does not start with %s", fileName, sig); line += strlen(sig); /* parse name=val. */ while ((word = nextWord(&line)) != NULL) { name = word; val = strchr(word, '='); if (val == NULL) errAbort("Missing = after %s line 1 of %s", name, fileName); *val++ = 0; if (sameString(name, "version")) sf->version = atoi(val); } if (sf->version == 0) errAbort("No version line 1 of %s", fileName); return sf; }
static boolean isDescriptionMatch(struct track *track, char **words, int wordCount) // We parse str and look for every word at the start of any word in track description (i.e. google style). { if(words) { // We do NOT lookup up parent hierarchy for html descriptions. char *html = track->tdb->html; if(!isEmpty(html)) { /* This probably could be made more efficient by parsing the html into some kind of b-tree, but I am assuming that the inner html loop while only happen for 1-2 words for vast majority of the tracks. */ int i, numMatches = 0; html = stripRegEx(html, "<[^>]*>", REG_ICASE); for(i = 0; i < wordCount; i++) { char *needle = words[i]; char *haystack, *tmp = cloneString(html); boolean found = FALSE; while((haystack = nextWord(&tmp))) { char *ptr = strstrNoCase(haystack, needle); if(ptr != NULL && ptr == haystack) { found = TRUE; break; } } if(found) numMatches++; else break; } if(numMatches == wordCount) return TRUE; } } return FALSE; }
XP_U32 dict_countWords( const DictIter* iter, LengthsArray* lens ) { DictIter counter; dict_initIterFrom( &counter, iter ); if ( NULL != lens ) { XP_MEMSET( lens, 0, sizeof(*lens) ); } XP_U32 count; XP_Bool ok; for ( count = 0, ok = firstWord( &counter ); ok; ok = nextWord( &counter) ) { ++count; if ( NULL != lens ) { ++lens->lens[counter.nEdges]; } } return count; }
struct mafFile *mafMayOpen(char *fileName) /* Open up a maf file and verify header. */ { struct mafFile *mf; struct lineFile *lf; char *line, *word; char *sig = "##maf"; if ((lf = lineFileMayOpen(fileName, TRUE)) == NULL) return NULL; AllocVar(mf); mf->lf = lf; lineFileNeedNext(lf, &line, NULL); if (!startsWith(sig, line)) { errAbort("%s does not start with %s", fileName, sig); } line += strlen(sig); while ((word = nextWord(&line)) != NULL) { /* Parse name=val. */ char *name = word; char *val = strchr(word, '='); if (val == NULL) errAbort("Missing = after %s line 1 of %s\n", name, fileName); *val++ = 0; if (sameString(name, "version")) mf->version = atoi(val); else if (sameString(name, "scoring")) mf->scoring = cloneString(val); } if (mf->version == 0) errAbort("No version line 1 of %s\n", fileName); return mf; }
static void indexOne( XP_U16 depth, Tile* tiles, IndexData* data, DictIter* prevIter, DictPosition* prevIndex ) { DictIter curIter; dict_initIterFrom( &curIter, prevIter ); if ( findWordStartsWith( &curIter, tiles, depth ) ) { while ( !wordsEqual( &curIter, prevIter ) ) { ++*prevIndex; if ( !nextWord( prevIter ) ) { XP_ASSERT( 0 ); } } XP_ASSERT( data->count == 0 || data->indices[data->count-1] < *prevIndex ); data->indices[data->count] = *prevIndex; if ( NULL != data->prefixes ) { XP_MEMCPY( data->prefixes + (data->count * depth), tiles, depth ); } ++data->count; } }
void addFa(char *file, struct hash *fileHash, struct hash *seqHash) /* Add a fa file to hashes. */ { struct lineFile *lf = lineFileOpen(file, TRUE); char *line, *name; char *rFile = hashStoreName(fileHash, file); while (lineFileNext(lf, &line, NULL)) { if (line[0] == '>') { struct seqFilePos *sfp; line += 1; name = nextWord(&line); if (name == NULL) errAbort("bad line %d of %s", lf->lineIx, lf->fileName); AllocVar(sfp); hashAddSaveName(seqHash, name, sfp, &sfp->name); sfp->file = rFile; sfp->pos = lineFileTell(lf); } } lineFileClose(&lf); }
void doCheck(char *line, struct sockaddr_in *hubIp) /* Send back check result - either a check in message or * jobDone. */ { char *jobIdString = nextWord(&line); if (jobIdString != NULL) { int jobId = atoi(jobIdString); struct job *job = findRunningJob(jobId); struct paraMessage pm; pmInit(&pm, ntohl(hubIp->sin_addr.s_addr), paraHubPort); if (job != NULL) pmPrintf(&pm, "checkIn %s %s running", hostName, jobIdString); else { struct job *job = findFinishedJob(jobId); if (job == NULL) pmPrintf(&pm, "checkIn %s %s free", hostName, jobIdString); else pmPrintf(&pm, "jobDone %s %s", jobIdString, job->doneMessage); } pmSend(&pm, mainRudp); } }
void wigToBedGraph(char *wigIn, char *bedOut) /* wigToBedGraph - Convert wig files to bedGraph, merging adjacent items with identical values * when possible.. */ { struct lineFile *lf = lineFileOpen(wigIn, TRUE); FILE *f = mustOpen(bedOut, "w"); struct bgOut *out = bgOutNew(f); char *line; while (lineFileNextReal(lf, &line)) { char *firstWord = nextWord(&line); struct hash *vars = hashVarLine(line, lf->lineIx); if (sameString("fixedStep", firstWord)) convertFixedStepSection(lf, vars, out); else if (sameString("variableStep", firstWord)) convertVariableStepSection(lf, vars, out); else errAbort("Expecting fixedStep or variableStep line %d of %s, got:\n\t%s", lf->lineIx, lf->fileName, line); freeHashAndVals(&vars); } bgOutFree(&out); carefulClose(&f); }
static struct hash *readDictionary(char *fileName, int *retMaxSize) /* Read in dictionary table and put it in hash that is * keyed by numeric version of string. */ { struct lineFile *lf = lineFileOpen(fileName, TRUE); char *line, *word; struct hash *hash = hashNew(18); int maxSize = 0, size; while (lineFileNext(lf, &line, NULL)) { while ((word = nextWord(&line)) != NULL) { char numBuf[MAXWORDSIZE]; toNum(word, numBuf, sizeof(numBuf)); hashAdd(hash, numBuf, cloneString(word)); size = strlen(numBuf); if (size > maxSize) maxSize = size; } } lineFileClose(&lf); *retMaxSize = maxSize; return hash; }
struct hgFindSpec *hgFindSpecFromRa(char *db, char *raFile, char *releaseTag) /* Load track info from ra file into list. */ { static boolean reEntered = FALSE; struct lineFile *lf = lineFileOpen(raFile, TRUE); char *line, *word; struct hgFindSpec *hfsList = NULL, *hfs; boolean done = FALSE; char *incFile; for (;;) { /* Seek to next line that starts with 'searchName' or 'searchTable' */ for (;;) { char *subRelease; if (!lineFileNext(lf, &line, NULL)) { done = TRUE; break; } if (startsWith("searchName", line) || startsWith("searchTable", line)) { lineFileReuse(lf); break; } else if ((incFile = trackDbInclude(raFile, line, &subRelease)) != NULL) { if (subRelease) trackDbCheckValidRelease(subRelease); if (releaseTag && subRelease && !sameString(subRelease, releaseTag)) errAbort("Include with release %s inside include with release %s line %d of %s", subRelease, releaseTag, lf->lineIx, lf->fileName); /* Set reEntered=TRUE whenever we recurse, so we don't polish * multiple times and get too many backslash-escapes. */ boolean reBak = reEntered; reEntered = TRUE; struct hgFindSpec *incHfs = hgFindSpecFromRa(db, incFile, subRelease); reEntered = reBak; hfsList = slCat(hfsList, incHfs); } } if (done) break; /* Allocate track structure and fill it in until next blank line. */ AllocVar(hfs); slAddHead(&hfsList, hfs); for (;;) { /* Break at blank line or EOF. */ if (!lineFileNext(lf, &line, NULL)) break; line = skipLeadingSpaces(line); if (line == NULL || line[0] == 0) break; /* Skip comments. */ if (line[0] == '#') continue; /* Parse out first word and decide what to do. */ word = nextWord(&line); if (line == NULL) errAbort("No value for %s line %d of %s", word, lf->lineIx, lf->fileName); line = trimSpaces(line); hgFindSpecAddInfo(hfs, word, line); } if (releaseTag) hgFindSpecAddRelease(hfs, releaseTag); } lineFileClose(&lf); if (! reEntered) { for (hfs = hfsList; hfs != NULL; hfs = hfs->next) { hgFindSpecPolish(db, hfs); } } slReverse(&hfsList); return hfsList; }
void hgGnfMicroarray(char *expTable, char *dataTable, char *atlasFile) /** Main function that does all the work for new-style*/ { struct lineFile *lf = lineFileOpen(atlasFile, TRUE); char *line; int i, wordCount, expCount; char **row; float *data; char *affyId; struct hash *hash = newHash(17); FILE *f = NULL; int dataCount = 0; /* Open Atlas file and use first line to create experiment table. */ if (!lineFileNextReal(lf, &line)) errAbort("%s is empty", lf->fileName); if (startsWith("Affy", line)) line += 4; if (startsWith("Gene Name", line)) line += 9; if (line[0] != '\t') errAbort("%s doesn't seem to be a new format atlas file", lf->fileName); expCount = lineToExpTable(line+1, expTable); if (expCount <= 0) errAbort("No experiments in %s it seems", lf->fileName); warn("%d experiments\n", expCount); f = hgCreateTabFile(tabDir, dataTable); AllocArray(row, expCount); AllocArray(data, expCount); while (lineFileNextReal(lf, &line)) { affyId = nextWord(&line); wordCount = chopByWhite(line, row, expCount); if (wordCount != expCount) errAbort("Expecting %d data points, got %d line %d of %s", expCount, wordCount, lf->lineIx, lf->fileName); if (chopName != NULL) { char *e = stringIn(chopName, affyId); if (e != NULL) *e = 0; } if (hashLookup(hash, affyId)) { warn("Duplicate %s, skipping all but first.", affyId); continue; } for (i=0; i<expCount; ++i) { data[i] = sqlFloat(row[i]); } shortDataOut(f, affyId, expCount, data); ++dataCount; if (limit != 0 && dataCount >= limit) break; } lineFileClose(&lf); if (doLoad) { struct sqlConnection *conn = sqlConnect(database); expDataCreateTable(conn, dataTable); hgLoadTabFile(conn, tabDir, dataTable, &f); hgRemoveTabFile(tabDir, dataTable); sqlDisconnect(&conn); } }
void doSearchTracks(struct group *groupList) { if (!advancedJavascriptFeaturesEnabled(cart)) { warn("Requires advanced javascript features."); return; } struct group *group; char *groups[128]; char *labels[128]; int numGroups = 1; groups[0] = ANYLABEL; labels[0] = ANYLABEL; char *currentTab = cartUsualString(cart, TRACK_SEARCH_CURRENT_TAB, "simpleTab"); char *nameSearch = cartOptionalString(cart, TRACK_SEARCH_ON_NAME); #ifdef TRACK_SEARCH_ON_TYPE char *typeSearch = cartOptionalString(cart, TRACK_SEARCH_ON_TYPE); #else///ifndef TRACK_SEARCH_ON_TYPE char *typeSearch = NULL; #endif///def TRACK_SEARCH_ON_TYPE char *descSearch; char *groupSearch = cartOptionalString(cart, TRACK_SEARCH_ON_GROUP); boolean doSearch = sameString(cartOptionalString(cart, TRACK_SEARCH), "Search") || cartUsualInt(cart, TRACK_SEARCH_PAGER, -1) >= 0; struct sqlConnection *conn = hAllocConn(database); boolean metaDbExists = sqlTableExists(conn, "metaDb"); int numMetadataSelects, tracksFound = 0; int numMetadataNonEmpty = 0; char **mdbVar = NULL; char **mdbVal = NULL; #ifdef ONE_FUNC struct hash *parents = newHash(4); #endif///def ONE_FUNC boolean simpleSearch; struct trix *trix; char trixFile[HDB_MAX_PATH_STRING]; char **descWords = NULL; int descWordCount = 0; boolean searchTermsExist = FALSE; int cols; char buf[512]; if(sameString(currentTab, "simpleTab")) { descSearch = cartOptionalString(cart, TRACK_SEARCH_SIMPLE); simpleSearch = TRUE; freez(&nameSearch); #ifdef TRACK_SEARCH_ON_TYPE freez(&typeSearch); #endif///def TRACK_SEARCH_ON_TYPE freez(&groupSearch); } else { descSearch = cartOptionalString(cart, TRACK_SEARCH_ON_DESCR); simpleSearch = FALSE; } if(descSearch) stripChar(descSearch, '"'); trackList = getTrackList(&groupList, -2); // global makeGlobalTrackHash(trackList); // NOTE: This is necessary when container cfg by '*' results in vis changes // This will handle composite/view override when subtrack specific vis exists, AND superTrack reshaping. parentChildCartCleanup(trackList,cart,oldVars); // Subtrack settings must be removed when composite/view settings are updated getSearchTrixFile(database, trixFile, sizeof(trixFile)); trix = trixOpen(trixFile); slSort(&groupList, gCmpGroup); for (group = groupList; group != NULL; group = group->next) { groupTrackListAddSuper(cart, group); if (group->trackList != NULL) { groups[numGroups] = cloneString(group->name); labels[numGroups] = cloneString(group->label); numGroups++; if (numGroups >= ArraySize(groups)) internalErr(); } } safef(buf, sizeof(buf),"Search for Tracks in the %s %s Assembly", organism, hFreezeFromDb(database)); webStartWrapperDetailedNoArgs(cart, database, "", buf, FALSE, FALSE, FALSE, FALSE); hPrintf("<div style='max-width:1080px;'>"); hPrintf("<form action='%s' name='%s' id='%s' method='get'>\n\n", hgTracksName(),TRACK_SEARCH_FORM,TRACK_SEARCH_FORM); cartSaveSession(cart); // Creates hidden var of hgsid to avoid bad voodoo safef(buf, sizeof(buf), "%lu", clock1()); cgiMakeHiddenVar("hgt_", buf); // timestamps page to avoid browser cache hPrintf("<input type='hidden' name='db' value='%s'>\n", database); hPrintf("<input type='hidden' name='%s' id='currentTab' value='%s'>\n", TRACK_SEARCH_CURRENT_TAB, currentTab); hPrintf("<input type='hidden' name='%s' value=''>\n",TRACK_SEARCH_DEL_ROW); hPrintf("<input type='hidden' name='%s' value=''>\n",TRACK_SEARCH_ADD_ROW); hPrintf("<input type='hidden' name='%s' value=''>\n",TRACK_SEARCH_PAGER); hPrintf("<div id='tabs' style='display:none; %s'>\n" "<ul>\n" "<li><a href='#simpleTab'><B style='font-size:.9em;font-family: arial, Geneva, Helvetica, san-serif;'>Search</B></a></li>\n" "<li><a href='#advancedTab'><B style='font-size:.9em;font-family: arial, Geneva, Helvetica, san-serif;'>Advanced</B></a></li>\n" "</ul>\n" "<div id='simpleTab' style='max-width:inherit;'>\n",cgiBrowser()==btIE?"width:1060px;":"max-width:inherit;"); hPrintf("<table style='width:100%%; font-size:.9em;'><tr><td colspan='2'>"); hPrintf("<input type='text' name='%s' id='simpleSearch' class='submitOnEnter' value='%s' style='max-width:1000px; width:100%%;' onkeyup='findTracksSearchButtonsEnable(true);'>\n", TRACK_SEARCH_SIMPLE,descSearch == NULL ? "" : descSearch); if (simpleSearch && descSearch) searchTermsExist = TRUE; hPrintf("</td></tr><td style='max-height:4px;'></td></tr></table>"); //hPrintf("</td></tr></table>"); hPrintf("<input type='submit' name='%s' id='searchSubmit' value='search' style='font-size:.8em;'>\n", TRACK_SEARCH); hPrintf("<input type='button' name='clear' value='clear' class='clear' style='font-size:.8em;' onclick='findTracksClear();'>\n"); hPrintf("<input type='submit' name='submit' value='cancel' class='cancel' style='font-size:.8em;'>\n"); hPrintf("</div>\n"); // Advanced tab hPrintf("<div id='advancedTab' style='width:inherit;'>\n" "<table cellSpacing=0 style='width:inherit; font-size:.9em;'>\n"); cols = 8; // Track Name contains hPrintf("<tr><td colspan=3></td>"); hPrintf("<td nowrap><b style='max-width:100px;'>Track Name:</b></td>"); hPrintf("<td align='right'>contains</td>\n"); hPrintf("<td colspan='%d'>", cols - 4); hPrintf("<input type='text' name='%s' id='nameSearch' class='submitOnEnter' value='%s' onkeyup='findTracksSearchButtonsEnable(true);' style='min-width:326px; font-size:.9em;'>", TRACK_SEARCH_ON_NAME, nameSearch == NULL ? "" : nameSearch); hPrintf("</td></tr>\n"); // Description contains hPrintf("<tr><td colspan=2></td><td align='right'>and </td>"); hPrintf("<td><b style='max-width:100px;'>Description:</b></td>"); hPrintf("<td align='right'>contains</td>\n"); hPrintf("<td colspan='%d'>", cols - 4); hPrintf("<input type='text' name='%s' id='descSearch' value='%s' class='submitOnEnter' onkeyup='findTracksSearchButtonsEnable(true);' style='max-width:536px; width:536px; font-size:.9em;'>", TRACK_SEARCH_ON_DESCR, descSearch == NULL ? "" : descSearch); hPrintf("</td></tr>\n"); if (!simpleSearch && descSearch) searchTermsExist = TRUE; hPrintf("<tr><td colspan=2></td><td align='right'>and </td>\n"); hPrintf("<td><b style='max-width:100px;'>Group:</b></td>"); hPrintf("<td align='right'>is</td>\n"); hPrintf("<td colspan='%d'>", cols - 4); cgiMakeDropListFull(TRACK_SEARCH_ON_GROUP, labels, groups, numGroups, groupSearch, "class='groupSearch' style='min-width:40%; font-size:.9em;'"); hPrintf("</td></tr>\n"); if (!simpleSearch && groupSearch) searchTermsExist = TRUE; #ifdef TRACK_SEARCH_ON_TYPE // Track Type is (drop down) hPrintf("<tr><td colspan=2></td><td align='right'>and </td>\n"); hPrintf("<td nowrap><b style='max-width:100px;'>Data Format:</b></td>"); hPrintf("<td align='right'>is</td>\n"); hPrintf("<td colspan='%d'>", cols - 4); char **formatTypes = NULL; char **formatLabels = NULL; int formatCount = getFormatTypes(&formatLabels, &formatTypes); cgiMakeDropListFull(TRACK_SEARCH_ON_TYPE, formatLabels, formatTypes, formatCount, typeSearch, "class='typeSearch' style='min-width:40%; font-size:.9em;'"); hPrintf("</td></tr>\n"); if (!simpleSearch && typeSearch) searchTermsExist = TRUE; #endif///def TRACK_SEARCH_ON_TYPE // Metadata selects require careful accounting if(metaDbExists) numMetadataSelects = printMdbSelects(conn, cart, simpleSearch, &mdbVar, &mdbVal, &numMetadataNonEmpty, cols); else numMetadataSelects = 0; hPrintf("</table>\n"); hPrintf("<input type='submit' name='%s' id='searchSubmit' value='search' style='font-size:.8em;'>\n", TRACK_SEARCH); hPrintf("<input type='button' name='clear' value='clear' class='clear' style='font-size:.8em;' onclick='findTracksClear();'>\n"); hPrintf("<input type='submit' name='submit' value='cancel' class='cancel' style='font-size:.8em;'>\n"); //hPrintf("<a target='_blank' href='../goldenPath/help/trackSearch.html'>help</a>\n"); hPrintf("</div>\n</div>\n"); hPrintf("</form>\n"); hPrintf("</div>"); // Restricts to max-width:1000px; if(descSearch != NULL && !strlen(descSearch)) descSearch = NULL; if(groupSearch != NULL && sameString(groupSearch, ANYLABEL)) groupSearch = NULL; if(typeSearch != NULL && sameString(typeSearch, ANYLABEL)) typeSearch = NULL; if(!isEmpty(descSearch)) { char *tmp = cloneString(descSearch); char *val = nextWord(&tmp); struct slName *el, *descList = NULL; int i; while (val != NULL) { slNameAddTail(&descList, val); descWordCount++; val = nextWord(&tmp); } descWords = needMem(sizeof(char *) * descWordCount); for(i = 0, el = descList; el != NULL; i++, el = el->next) descWords[i] = strLower(el->name); } if (doSearch && simpleSearch && descWordCount <= 0) doSearch = FALSE; if(doSearch) { // Now search struct slRef *tracks = NULL; if(simpleSearch) tracks = simpleSearchForTracksstruct(trix,descWords,descWordCount); else tracks = advancedSearchForTracks(conn,groupList,descWords,descWordCount,nameSearch,typeSearch,descSearch,groupSearch,numMetadataNonEmpty,numMetadataSelects,mdbVar,mdbVal); // Sort and Print results enum sortBy sortBy = cartUsualInt(cart,TRACK_SEARCH_SORT,sbRelevance); tracksFound = slCount(tracks); if(tracksFound > 1) findTracksSort(&tracks,simpleSearch,sortBy); displayFoundTracks(cart,tracks,tracksFound,sortBy); } hFreeConn(&conn); webNewSection("About Track Search"); if(metaDbExists) hPrintf("<p>Search for terms in track names, descriptions, groups, and ENCODE " "metadata. If multiple terms are entered, only tracks with all terms " "will be part of the results."); else hPrintf("<p>Search for terms in track descriptions, groups, and names. " "If multiple terms are entered, only tracks with all terms " "will be part of the results."); hPrintf("<BR><a target='_blank' href='../goldenPath/help/trackSearch.html'>more help</a></p>\n"); webEndSectionTables(); }
static struct joiner *joinerParsePassOne(char *fileName) /* Do first pass parsing of joiner file and return list of * joinerSets. */ { struct lineFile *lf = lineFileOpen(fileName, TRUE); char *line, *word; struct dyString *dyBuf = dyStringNew(0); struct joiner *joiner; struct joinerSet *js; AllocVar(joiner); joiner->fileName = cloneString(fileName); joiner->symHash = newHash(9); joiner->databasesChecked = newHash(8); joiner->databasesIgnored = newHash(8); while ((line = nextSubbedLine(lf, joiner->symHash, dyBuf)) != NULL) { if ((word = nextWord(&line)) != NULL) { if (sameString("set", word)) { char *var, *val; var = nextWord(&line); if (var == NULL) errAbort("set what line %d of %s", lf->lineIx, lf->fileName); val = trimSpaces(line); if (isEmpty(val)) errAbort("Set with no value line %d of %s", lf->lineIx, lf->fileName); hashAdd(joiner->symHash, var, cloneString(val)); } else if (sameString("identifier", word)) { js = parseIdentifierSet(lf, line, joiner->symHash, dyBuf); if (js != NULL) slAddHead(&joiner->jsList, js); } else if (sameString("exclusiveSet", word)) { struct hash *exHash = newHash(8); addDatabasesToHash(exHash, line, lf); slAddHead(&joiner->exclusiveSets, exHash); } else if (sameString("databasesChecked", word)) { addDatabasesToHash(joiner->databasesChecked, line, lf); } else if (sameString("databasesIgnored", word)) { addDatabasesToHash(joiner->databasesIgnored, line, lf); } else if (sameString("tablesIgnored", word)) { struct joinerIgnore *ig; ig = parseTablesIgnored(lf, line, joiner->symHash, dyBuf); slAddHead(&joiner->tablesIgnored, ig); } else if (sameString("dependency", word)) { struct joinerDependency *dep; dep = parseDependency(lf, line); slAddHead(&joiner->dependencyList, dep); } else if (sameString("type", word)) { struct joinerType *type; type = parseType(lf, line, joiner->symHash, dyBuf); slAddHead(&joiner->typeList, type); } else { errAbort("unrecognized '%s' line %d of %s", word, lf->lineIx, lf->fileName); } } } lineFileClose(&lf); dyStringFree(&dyBuf); slReverse(&joiner->jsList); slReverse(&joiner->tablesIgnored); slReverse(&joiner->typeList); return joiner; }
static int dimensionsChanged (BrailleDisplay *brl) { int ok = 1; const char *word; int columns1; int rows1; int columns2 = 0; int rows2 = 0; if ((word = nextWord())) { if (isInteger(&columns1, word) && (columns1 > 0)) { rows1 = 1; if ((word = nextWord())) { if (isInteger(&rows1, word) && (rows1 > 0)) { if ((word = nextWord())) { if (isInteger(&columns2, word) && (columns2 > 0)) { rows2 = 0; if ((word = nextWord())) { if (isInteger(&rows2, word) && (rows2 > 0)) { } else { logMessage(LOG_WARNING, "invalid status row count: %s", word); ok = 0; } } } else { logMessage(LOG_WARNING, "invalid status column count: %s", word); ok = 0; } } } else { logMessage(LOG_WARNING, "invalid text row count: %s", word); ok = 0; } } } else { logMessage(LOG_WARNING, "invalid text column count: %s", word); ok = 0; } } else { logMessage(LOG_WARNING, "missing text column count"); ok = 0; } if (ok) { int count1 = columns1 * rows1; int count2 = columns2 * rows2; unsigned char *braille; wchar_t *text; unsigned char *status; if ((braille = calloc(count1, sizeof(*braille)))) { if ((text = calloc(count1, sizeof(*text)))) { if ((status = calloc(count2, sizeof(*status)))) { brailleColumns = columns1; brailleRows = rows1; brailleCount = count1; statusColumns = columns2; statusRows = rows2; statusCount = count2; if (brailleCells) free(brailleCells); brailleCells = braille; memset(brailleCells, 0, count1); if (textCharacters) free(textCharacters); textCharacters = text; wmemset(textCharacters, WC_C(' '), count1); if (statusCells) free(statusCells); statusCells = status; memset(statusCells, 0, count2); memset(genericCells, 0, GSC_COUNT); brl->textColumns = brailleColumns; brl->textRows = brailleRows; brl->statusColumns = statusColumns; brl->statusRows = statusRows; return 1; } free(text); } free(braille); } } return 0; }
struct commit* getCommits() /* Get all commits from startTag to endTag */ { int numCommits = 0; safef(gitCmd,sizeof(gitCmd), "" "git log %s..%s --name-status > commits.tmp" , startTag, endTag); runShell(gitCmd); struct lineFile *lf = lineFileOpen("commits.tmp", TRUE); int lineSize; char *line; struct commit *commits = NULL, *commit = NULL; struct files *files = NULL, *f = NULL; char *sep = ""; while (lineFileNext(lf, &line, &lineSize)) { boolean isMerge = FALSE; char *w = nextWord(&line); AllocVar(commit); if (!sameString("commit", w)) errAbort("expected keyword commit parsing commits.tmp\n"); commit->commitId = cloneString(nextWord(&line)); commit->commitNumber = ++numCommits; lineFileNext(lf, &line, &lineSize); w = nextWord(&line); if (sameString("Merge:", w)) { isMerge = TRUE; lineFileNext(lf, &line, &lineSize); w = nextWord(&line); } if (!sameString("Author:", w)) errAbort("expected keyword Author: parsing commits.tmp\n"); /* by request, keep just the email account name */ char *lc = strchr(line, '<'); if (!lc) errAbort("expected '<' char in email address in Author: parsing commits.tmp\n"); ++lc; char *rc = strchr(lc, '>'); if (!rc) errAbort("expected '>' char in email address in Author: parsing commits.tmp\n"); char *ac = strchr(lc, '@'); if (ac) rc = ac; commit->author = cloneStringZ(lc, rc-lc); lineFileNext(lf, &line, &lineSize); w = nextWord(&line); if (!sameString("Date:", w)) errAbort("expected keyword Date: parsing commits.tmp\n"); commit->date = cloneString(line); lineFileNext(lf, &line, &lineSize); if (!sameString("", line)) errAbort("expected blank line parsing commits.tmp\n"); /* collect the comment-lines */ struct dyString *dy = NULL; dy = dyStringNew(0); sep = ""; files = NULL; while (lineFileNext(lf, &line, &lineSize)) { if (sameString("", line)) break; w = skipLeadingSpaces(line); dyStringPrintf(dy, "%s%s", w, sep); sep = "\n"; } commit->comment = cloneString(dy->string); freeDyString(&dy); if (!isMerge) { /* collect the files-list */ while (lineFileNext(lf, &line, &lineSize)) { if (sameString("", line)) break; AllocVar(f); w = nextWord(&line); f->type = w[0]; f->path = cloneString(line); slAddHead(&files, f); } slReverse(&files); } commit->files = files; if (!isMerge /* for now, default to filtering out the records for automatic-merges */ && !endsWith(commit->comment, "elease log update")) /* filter out automatic release log commits */ slAddHead(&commits, commit); verbose(2, "commitId: %s\n" "author: %s\n" "date: %s\n" "comment: [%s]\n" "file(s): \n" , commit->commitId , commit->author , commit->date , commit->comment); for (f=commit->files; f; f = f->next) { verbose(2, "%c %s\n", f->type, f->path); // anything other than M or A? if (f->type != 'M' && f->type != 'A' ) verbose(2, "special type: %c %s\n", f->type, f->path); } verbose(2, "------------\n"); } lineFileClose(&lf); /* We want to keep them chronological order, so do not need slReverse since the addHead reversed git log's rev chron order already */ unlink("commits.tmp"); return commits; }
void queryResponse(int sd, struct bzp *bzp, struct blatzIndex *indexList) /* Respond to query message - read options and dna from socket, * and do alignment. */ { struct bzp lbzp = *bzp; struct dnaSeq *seq = NULL; char buf[256], *line, *word; char *out = NULL, *mafT = NULL, *mafQ = NULL; /* First get options - overriding what got set at startup. */ for (;;) { if ((line = netGetString(sd, buf)) == NULL) { truncatedQuery(1); return; } word = nextWord(&line); line = skipLeadingSpaces(line); if (sameString(word, "seq")) break; else if (sameString(word, "rna")) lbzp.rna = TRUE; else if (sameString(word, "minScore")) lbzp.minScore = atoi(line); else if (sameString(word, "minGapless")) lbzp.minGapless = atoi(line); else if (sameString(word, "multiHits")) lbzp.multiHits = atoi(line); else if (sameString(word, "minChain")) lbzp.minChain = atoi(line); else if (sameString(word, "maxExtend")) lbzp.maxExtend = atoi(line); else if (sameString(word, "maxBandGap")) lbzp.maxBandGap = atoi(line); else if (sameString(word, "minExpand")) lbzp.minExpand = atoi(line); else if (sameString(word, "expandWindow")) lbzp.expandWindow = atoi(line); else if (sameString(word, "out")) lbzp.out = out = cloneString(line); else if (sameString(word, "mafQ")) lbzp.mafQ = mafQ = cloneString(line); else if (sameString(word, "mafT")) lbzp.mafT = mafT = cloneString(line); } /* Get DNA into seq*/ { char *name = netGetString(sd, buf); char *dna; if (name == NULL) { truncatedQuery(2); return; } dna = netGetHugeString(sd); if (dna == NULL) { truncatedQuery(3); return; } AllocVar(seq); seq->dna = dna; seq->size = strlen(dna); seq->name = cloneString(name); bzpTime("Received %d bases in %s", seq->size, seq->name); if (lbzp.rna) maskTailPolyA(seq->dna, seq->size); } /* Create alignments into chainList and write results. */ { FILE *f = netFileFromSocket(sd); struct chain *chainList = blatzAlign(&lbzp, indexList, seq); blatzWriteChains(&lbzp, &chainList, seq, 0, seq->size, seq->size, indexList, f); bzpTime("sent result - %d chains", slCount(chainList)); carefulClose(&f); } dnaSeqFree(&seq); freez(&out); freez(&mafQ); freez(&mafT); }
void CBatchCounter::LSLOC(results* result, string line, size_t lineNumber, string lineBak, string &strLSLOC, string &strLSLOCBak, bool &data_continue, unsigned int &temp_lines, unsigned int &phys_exec_lines, unsigned int &phys_data_lines/*, StringVector &loopLevel*/)// warning fix { size_t start, end; size_t strSize; bool trunc_flag = false; string exclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$"; string str, spc; unsigned int cnt = 0; string tmp = CUtil::TrimString(line); string tmpBak = CUtil::TrimString(lineBak); start = 0; end = tmp.length(); // skip whole line '(' or ')' if (tmp == "(" || tmp == ")") { strLSLOC = strLSLOCBak = ""; phys_exec_lines++; temp_lines = 0; return; } // there may be more than 1 logical SLOC in this line #ifdef _MSC_VER char * context = NULL; // used for strtok_s( ) below #else // #endif bool has_for = false; bool has_for_in = false; while (start < tmp.length()) { end = tmp.length(); if (start == 0) { has_for = false; has_for_in = false; } //std::cout << start <<"start\n"; // check if is a label bool isLabel = false; for (unsigned int i = 0; tmp[i] != '\0'; i++) { if (tmp[i] == ' ') { continue; } else if (tmp[i] == ':') { isLabel = true; break; } else { break; } } if(isLabel) { strLSLOC = strLSLOCBak = ""; phys_exec_lines++; temp_lines = 0; return; } char * token = NULL; // Allocate a char array that must be deleted later. char* line = new char[end - start + 1]; #ifdef _MSC_VER // Use more Secure C library API strcpy_s( line, (end - start + 1) * sizeof(char), tmp.substr(start).c_str() ); #else // Use older less Secure C library API strcpy( line, tmp.substr(start).c_str() ); #endif // check |, & bool hasPipe = false; size_t pipePos = 0; bool hasAmp = false; size_t ampPos = 0; for (int i = 0; line[i] != '\0'; i++) { if (line[i] == '|') { if (!hasPipe) { pipePos = (size_t)i; } hasPipe = true; line[i] = ' '; } if (line[i] == '&') { if (!hasAmp) { ampPos = (size_t)i; } hasAmp = true; line[i] = ' '; } } #ifdef _MSC_VER // Use more Secure C library API token = strtok_s( line, " .@:", &context ); #else // Use older less Secure C library API token = strtok( line, " .@:" ); #endif for (int i = 0; token[i] != '\0'; i++) { token[i] = (char)lowerChars[ TL_ARR( token[i] ) ]; } if (strcmp(token, "else") == 0) { #ifdef _MSC_VER // Use more Secure C library API token = strtok_s( NULL, " .@:", &context ); #else // Use older less Secure C library API token = strtok( NULL, " .@:" ); #endif } if (token == NULL) { strLSLOC = strLSLOCBak = ""; phys_exec_lines++; temp_lines = 0; delete line; return; } //first keyword //std::cout << token << "TOKEN\n"; string firstWord(token); firstWord = CUtil::ToLower(firstWord); bool checkFirstWord = false; for(std::vector<string>::iterator it = exec_name_list.begin(); it != exec_name_list.end(); ++it) { if (*it == firstWord) { checkFirstWord = true; break; } } if(!checkFirstWord) { strLSLOC = strLSLOCBak = ""; phys_exec_lines++; temp_lines = 0; delete line; return; } //if, for, choice as first word bool isComplexWord = false; bool isCall = false; size_t nextKeyWordStart = (size_t)(-1); bool isKeyWord = false; bool hasElse = false; char * nextToken = NULL; size_t tmpNextKeyWordStart = (size_t)(-1); size_t tmpEnd = (size_t)(-1); for(std::vector<string>::iterator it = cmplx_cond_list.begin(); it != cmplx_cond_list.end(); ++it) { if (*it == firstWord) { isComplexWord = true; break; } } //for as first word if (firstWord.compare("for") == 0) { has_for = true; } //call as first word if (firstWord.compare("call") == 0) { isCall = true; } // go through the rest of words #ifdef _MSC_VER // Use more Secure C library API nextToken = strtok_s( NULL, " .@:", &context ); #else // Use older less Secure C library API nextToken = strtok( NULL, " .@:" ); #endif while (nextToken != NULL) { string nextWord(nextToken); nextWord = CUtil::ToLower(nextWord); if (has_for && nextWord.compare("in") == 0) has_for_in = true; if (nextWord.compare("else") == 0) hasElse = true; if (!isKeyWord) { for(std::vector<string>::iterator it2 = exec_name_list.begin(); it2 != exec_name_list.end(); ++it2) { if (*it2 == nextWord) { isKeyWord = true; tmpNextKeyWordStart = CUtil::FindKeyword(CUtil::ToLower(tmp), nextWord, start + firstWord.length(), end); //std::cout << tmpNextKeyWordStart << "NEXT_START\n"; tmpEnd = tmpNextKeyWordStart; // !!!!! //std::cout << tmpEnd << "CURR_END\n"; break; } } } #ifdef _MSC_VER // Use more Secure C library API nextToken = strtok_s( NULL, " .@:", &context ); #else // Use older less Secure C library API nextToken = strtok( NULL, " .@:" ); #endif } if (isKeyWord) { //std::cout << pipePos << "pipePos\n"; if (hasPipe && pipePos >= tmpEnd) hasPipe = false; //std::cout << ampPos << "ampPos\n"; if (hasAmp && ampPos >= tmpEnd) hasAmp = false; } else { hasPipe = false; hasAmp = false; } if ((isComplexWord || isCall || hasElse || has_for_in || hasPipe || hasAmp) && isKeyWord) { // REMEMBER TO CHANGE THE SAME CODE BELOW nextKeyWordStart = tmpNextKeyWordStart; end = tmpEnd; } if (tmp[0] != '^') { //std::cout << "2\n"; strSize = CUtil::TruncateLine(end - start + 1, strLSLOC.length(), this->lsloc_truncate, trunc_flag); if (strSize > 0) { strLSLOC += CUtil::TrimString(tmp.substr(start, strSize)); strLSLOCBak += CUtil::TrimString(tmpBak.substr(start, strSize)); } start = end + 1; if ((isComplexWord || isCall || hasElse || has_for_in || hasPipe || hasAmp) && isKeyWord) { // REMEMBER TO CHANGE THE SAME CODE ABOVE start = nextKeyWordStart; } if (strLSLOCBak.length() > 0) { //add physical SLOC if (result->addSLOC(strLSLOCBak, lineNumber, trunc_flag)) { //add a logical SLOC cnt = 0; CUtil::CountTally(strLSLOC, data_name_list, cnt, 1, exclude, "", "", &result->data_name_count); temp_lines++; if (data_continue == true || cnt > 0) { result->data_lines[LOG]++; phys_data_lines = temp_lines; } else { result->exec_lines[LOG]++; phys_exec_lines = temp_lines; } } else if (data_continue == true) phys_data_lines = temp_lines; else phys_exec_lines = temp_lines; } data_continue = false; temp_lines = 0; strLSLOC = strLSLOCBak = ""; } delete line; line = NULL; } }
void TEditor::handleEvent( TEvent& event ) { TView::handleEvent( event ); convertEvent( event ); Boolean centerCursor = Boolean(!cursorVisible()); uchar selectMode = 0; if( selecting == True || (getShiftState() & 0x03) != 0 ) selectMode = smExtend; switch( event.what ) { case evMouseDown: if( event.mouse.doubleClick == True ) selectMode |= smDouble; do { lock(); if( event.what == evMouseAuto ) { TPoint mouse = makeLocal( event.mouse.where ); TPoint d = delta; if( mouse.x < 0 ) d.x--; if( mouse.x >= size.x ) d.x++; if( mouse.y < 0 ) d.y--; if( mouse.y >= size.y ) d.y++; scrollTo(d.x, d.y); } setCurPtr(getMousePtr(event.mouse.where), selectMode); selectMode |= smExtend; unlock(); } while( mouseEvent(event, evMouseMove + evMouseAuto) ); break; case evKeyDown: if( event.keyDown.charScan.charCode == 9 || ( event.keyDown.charScan.charCode >= 32 && event.keyDown.charScan.charCode < 255 ) ) { lock(); if( overwrite == True && hasSelection() == False ) if( curPtr != lineEnd(curPtr) ) selEnd = nextChar(curPtr); insertText( &event.keyDown.charScan.charCode, 1, False); trackCursor(centerCursor); unlock(); } else return; break; case evCommand: switch( event.message.command ) { case cmFind: find(); break; case cmReplace: replace(); break; case cmSearchAgain: doSearchReplace(); break; default: lock(); switch( event.message.command ) { case cmCut: clipCut(); break; case cmCopy: clipCopy(); // hideSelect(); // JS 12.4.94 break; case cmPaste: clipPaste(); break; case cmUndo: undo(); break; case cmClear: deleteSelect(); break; case cmCharLeft: setCurPtr(prevChar(curPtr), selectMode); break; case cmCharRight: setCurPtr(nextChar(curPtr), selectMode); break; case cmWordLeft: setCurPtr(prevWord(curPtr), selectMode); break; case cmWordRight: setCurPtr(nextWord(curPtr), selectMode); break; case cmLineStart: setCurPtr(lineStart(curPtr), selectMode); break; case cmLineEnd: setCurPtr(lineEnd(curPtr), selectMode); break; case cmLineUp: setCurPtr(lineMove(curPtr, -1), selectMode); break; case cmLineDown: setCurPtr(lineMove(curPtr, 1), selectMode); break; case cmPageUp: setCurPtr(lineMove(curPtr, -(size.y-1)), selectMode); break; case cmPageDown: setCurPtr(lineMove(curPtr, size.y-1), selectMode); break; case cmTextStart: setCurPtr(0, selectMode); break; case cmTextEnd: setCurPtr(bufLen, selectMode); break; case cmNewLine: newLine(); break; case cmBackSpace: deleteRange(prevChar(curPtr), curPtr, True); break; case cmDelChar: deleteRange(curPtr, nextChar(curPtr), True); break; case cmDelWord: deleteRange(curPtr, nextWord(curPtr), False); break; case cmDelStart: deleteRange(lineStart(curPtr), curPtr, False); break; case cmDelEnd: deleteRange(curPtr, lineEnd(curPtr), False); break; case cmDelLine: deleteRange(lineStart(curPtr), nextLine(curPtr), False); break; case cmInsMode: toggleInsMode(); break; case cmStartSelect: startSelect(); break; case cmHideSelect: hideSelect(); break; case cmIndentMode: autoIndent = Boolean(!autoIndent); break; default: unlock(); return; } trackCursor(centerCursor); unlock(); break; } case evBroadcast: switch( event.message.command ) { case cmScrollBarChanged: checkScrollBar( event, hScrollBar, delta.x ); checkScrollBar( event, vScrollBar, delta.y ); break; default: return; } } clearEvent(event); }
static void parseSteppedSection(struct lineFile *lf, char *initialLine, struct pos *pos) /* Parse out stepped section, adding info about it to pos. */ { /* Parse out first word of initial line and make sure it is something we recognize. */ char *typeWord = nextWord(&initialLine); enum bwgSectionType type = bwgTypeFixedStep; if (sameString(typeWord, "variableStep")) type = bwgTypeVariableStep; else if (sameString(typeWord, "fixedStep")) type = bwgTypeFixedStep; else errAbort("Unknown type %s\n", typeWord); /* Set up defaults for values we hope to parse out of rest of line. */ bits32 start = 0; char *chrom = NULL; /* Parse out var=val pairs. */ char *varEqVal; while ((varEqVal = nextWord(&initialLine)) != NULL) { char *wordPairs[2]; int wc = chopByChar(varEqVal, '=', wordPairs, 2); if (wc != 2) errAbort("strange var=val pair line %d of %s", lf->lineIx, lf->fileName); char *var = wordPairs[0]; char *val = wordPairs[1]; if (sameString(var, "chrom")) chrom = cloneString(val); else if (sameString(var, "start")) start = parseUnsignedVal(lf, var, val); } /* Check that we have all that are required and no more, and call type-specific routine to parse * rest of section. */ if (chrom == NULL) errAbort("Missing chrom= setting line %d of %s\n", lf->lineIx, lf->fileName); pos->chrom = chrom; if (type == bwgTypeFixedStep) { if (start == 0) errAbort("Missing start= setting line %d of %s\n", lf->lineIx, lf->fileName); for (;;) { char *line; if (!lineFileNextReal(lf, &line)) break; if (steppedSectionEnd(line, 1)) { lineFileReuse(lf); break; } } } else { for (;;) { char *line; if (!lineFileNextReal(lf, &line)) break; if (steppedSectionEnd(line, 2)) { lineFileReuse(lf); break; } bits32 s = atoi(line); if (start == 0 || s < start) start = s; } } pos->start = start-1; }
void gensatFtpImages(char *checkMd5, char *outDir) /* gensatFtpImages - Download images guided by output of gensatFtpList. */ { int err; char source[PATH_LEN], nativeImage[PATH_LEN], jpgImage[PATH_LEN]; char dir[PATH_LEN], file[PATH_LEN], ext[PATH_LEN]; struct lineFile *lf = lineFileOpen(checkMd5, TRUE); char *line, *md5, *relativePath; struct dyString *command = dyStringNew(0); while(lineFileNext(lf, &line, NULL)) { /* Parse out two columns of checkMd5 file. */ md5 = nextWord(&line); relativePath = skipLeadingSpaces(line); /* Figure out output path, and if file already exists skip it. */ safef(nativeImage, sizeof(nativeImage), "%s/%s", outDir, relativePath); strcpy(jpgImage, nativeImage); if (endsWith(jpgImage, ".bz2")) chopSuffix(jpgImage); if (endsWith(jpgImage, ".png") || endsWith(jpgImage, ".tif") || endsWith(jpgImage, ".tiff") || endsWith(jpgImage, ".jpeg") || endsWith(jpgImage, ".jpg") || endsWith(jpgImage, ".JPG") ) { chopSuffix(jpgImage); strcat(jpgImage, ".jpg"); } else if (endsWith(jpgImage, ".txt") || endsWith(jpgImage, ".zip") || endsWith(jpgImage, ".doc")) continue; else errAbort("Unrecognized image type in file %s", jpgImage); if (!fileExists(jpgImage)) { /* Create any directories needed. */ splitPath(relativePath, dir, file, ext); dyStringClear(command); dyStringPrintf(command, "mkdir -p '%s/%s'", outDir, dir); system(command->string); /* wget the file. */ safef(source, sizeof(source), "%s/%s", uri, relativePath); if (safeGetOne(source, md5, nativeImage)) { if (endsWith(nativeImage, ".bz2")) { dyStringClear(command); dyStringPrintf(command, "bunzip2 '%s'", nativeImage); verbose(1, "%s\n", command->string); err = system(command->string); if (err != 0) errAbort("err %d on %s", err, command->string); chopSuffix(nativeImage); } if (!endsWith(nativeImage, ".jpg") ) { dyStringClear(command); dyStringPrintf(command, "convert '%s' '%s'", nativeImage, jpgImage); verbose(1, "%s\n", command->string); err = system(command->string); if (err != 0) errAbort("err %d on %s", err, command->string); remove(nativeImage); } } else { if (++errCount > maxErrs) errAbort("Aborting after %d errors", errCount); } } else { verbose(1, "Already have %s\n", jpgImage); } } }
void affyPslAndAtlasToBedNew(char *pslFile, char *atlasFile, char *bedOut, char *expRecOut) /** Main function that does all the work for new-style*/ { struct lineFile *lf = lineFileOpen(atlasFile, TRUE); char *line, *name; int i, wordCount, expCount; char **row; double *data, median; double invMedian, ratio, logRatio; char *affyId; struct hash *hash = newHash(17); struct psl *psl; struct bed *bed; FILE *f = NULL; int dataCount = 0, pslCount = 0, bedCount = 0; int minExpVal = 20; /* Open Atlas file and use first line to create experiment table. */ if (!lineFileNextReal(lf, &line)) errAbort("%s is empty", lf->fileName); if (startsWith("Affy", line)) line += 4; if (line[0] != '\t') errAbort("%s doesn't seem to be a new format atlas file", lf->fileName); expCount = lineToExp(line+1, expRecOut); if (expCount <= 0) errAbort("No experiments in %s it seems", lf->fileName); warn("%d experiments\n", expCount); f = mustOpen(bedOut, "w"); /* Build up a hash keyed by affyID with an int array of data * for value. Do output in short case. */ AllocArray(row, expCount); while (lineFileNextReal(lf, &line)) { affyId = nextWord(&line); wordCount = chopByWhite(line, row, expCount); if (wordCount != expCount) errAbort("Expecting %d data points, got %d line %d of %s", expCount, wordCount, lf->lineIx, lf->fileName); if (hashLookup(hash, affyId)) { warn("Duplicate %s, skipping all but first.", affyId); continue; } AllocArray(data, expCount); for (i=0; i<expCount; ++i) { data[i] = atof(row[i]); if (data[i] < minExpVal) data[i] = minExpVal; } median = findPositiveMedian(data, expCount, minExpVal); if (median >= 0) { invMedian = 1.0/median; for (i=0; i<expCount; ++i) { double val = data[i]; val = safeLog2(invMedian*val); data[i] = val; } if (shortOut) shortDataOut(f, affyId, expCount, data); else hashAdd(hash, affyId, data); } data = NULL; ++dataCount; } lineFileClose(&lf); warn("%d rows of expression data\n", dataCount); /* Stream through psl file, converting it to bed with expression data. */ if (!shortOut) { lf = pslFileOpen(pslFile); while ((psl = pslNext(lf)) != NULL) { ++pslCount; /* get probe id from sequence name */ name=parseNameFromHgc(psl->qName); data = hashFindVal(hash, name); if (data != NULL) { struct bed *bed = bedFromPsl(psl); bed->expCount = expCount; AllocArray(bed->expIds, expCount); AllocArray(bed->expScores, expCount); for (i=0; i<expCount; ++i) { bed->expScores[i] = data[i]; bed->expIds[i] = i; } bedTabOutN(bed, 15, f); ++bedCount; bedFree(&bed); } pslFree(&psl); } warn("%d records in %s", pslCount, pslFile); warn("%d records written to %s", bedCount, bedOut); } lineFileClose(&lf); carefulClose(&f); }
void hgLoadRnaFold(char *database, char *table, char *foldDir) /* hgLoadRnaFold - Load a directory full of RNA fold files into database. */ { char path[PATH_LEN]; struct slName *dirList, *dirEl; struct lineFile *lf; char *line, *word, *s, c; FILE *f = hgCreateTabFile(tabDir, table); int count = 0; dirList = listDir(foldDir, "*"); for (dirEl = dirList; dirEl != NULL; dirEl = dirEl->next) { char *name = dirEl->name; if (sameString(name, "CVS")) continue; safef(path, sizeof(path), "%s/%s", foldDir, name); lf = lineFileOpen(path, TRUE); if (!lineFileNext(lf, &line, NULL)) { if (warnEmpty) { warn("%s is empty, skipping\n", name); lineFileClose(&lf); continue; } else errAbort("%s is empty\n", name); } if (!isupper(line[0])) notFold(path, 1); fprintf(f, "%s\t", name); /* Save name */ fprintf(f, "%s\t", line); /* Save sequence */ lineFileNeedNext(lf, &line, NULL); c = line[0]; if (c != '.' && c != '(') notFold(path, 2); word = nextWord(&line); fprintf(f, "%s\t", word); /* Save nested parenthesis */ /* Parse out (energy) term at end of line. */ s = strchr(line, '('); if (s == NULL) notFold(path, 3); word = skipLeadingSpaces(s+1); if (word == NULL || (!word[0] == '-' && !isdigit(word[0]))) notFold(path, 4); if ((s = strchr(word, ')')) == NULL) notFold(path, 5); *s = 0; fprintf(f, "%s\n", word); lineFileClose(&lf); ++count; } printf("Parsed %d files\n", count); if (doLoad) { struct sqlConnection *conn = sqlConnect(database); rnaFoldCreateTable(conn, table); hgLoadTabFile(conn, tabDir, table, &f); hgRemoveTabFile(tabDir, table); sqlDisconnect(&conn); } }
static void parseSteppedSection(struct lineFile *lf, boolean clipDontDie, struct hash *chromSizeHash, char *initialLine, struct lm *lm, int itemsPerSlot, struct bwgSection **pSectionList) /* Parse out a variableStep or fixedStep section and add it to list, breaking it up as need be. */ { /* Parse out first word of initial line and make sure it is something we recognize. */ char *typeWord = nextWord(&initialLine); enum bwgSectionType type = bwgTypeFixedStep; if (sameString(typeWord, "variableStep")) type = bwgTypeVariableStep; else if (sameString(typeWord, "fixedStep")) type = bwgTypeFixedStep; else errAbort("Unknown type %s\n", typeWord); /* Set up defaults for values we hope to parse out of rest of line. */ int span = 0; bits32 step = 0; bits32 start = 0; char *chrom = NULL; /* Parse out var=val pairs. */ char *varEqVal; while ((varEqVal = nextWord(&initialLine)) != NULL) { char *wordPairs[2]; int wc = chopByChar(varEqVal, '=', wordPairs, 2); if (wc != 2) errAbort("strange var=val pair line %d of %s", lf->lineIx, lf->fileName); char *var = wordPairs[0]; char *val = wordPairs[1]; if (sameString(var, "chrom")) chrom = cloneString(val); else if (sameString(var, "span")) span = parseUnsignedVal(lf, var, val); else if (sameString(var, "step")) step = parseUnsignedVal(lf, var, val); else if (sameString(var, "start")) { start = parseUnsignedVal(lf, var, val); } else errAbort("Unknown setting %s=%s line %d of %s", var, val, lf->lineIx, lf->fileName); } /* Check that we have all that are required and no more, and call type-specific routine to parse * rest of section. */ if (chrom == NULL) errAbort("Missing chrom= setting line %d of %s\n", lf->lineIx, lf->fileName); bits32 chromSize = (chromSizeHash ? hashIntVal(chromSizeHash, chrom) : BIGNUM); if (start > chromSize) { warn("line %d of %s: chromosome %s has %u bases, but item starts at %u", lf->lineIx, lf->fileName, chrom, chromSize, start); if (!clipDontDie) noWarnAbort(); } if (type == bwgTypeFixedStep) { if (start == 0) errAbort("Missing start= setting line %d of %s\n", lf->lineIx, lf->fileName); if (step == 0) errAbort("Missing step= setting line %d of %s\n", lf->lineIx, lf->fileName); if (span == 0) span = step; parseFixedStepSection(lf, clipDontDie, lm, itemsPerSlot, chrom, chromSize, span, start-1, step, pSectionList); } else { if (start != 0) errAbort("Extra start= setting line %d of %s\n", lf->lineIx, lf->fileName); if (step != 0) errAbort("Extra step= setting line %d of %s\n", lf->lineIx, lf->fileName); if (span == 0) span = 1; parseVariableStepSection(lf, clipDontDie, lm, itemsPerSlot, chrom, chromSize, span, pSectionList); } }
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; }