void processExcludes(char *exclude) /* Combine alwaysExclude and command like -exclude arg (if given), and * process into a list. If it contains "genbank", add genbankExclude. */ { struct dyString *allExcludes = newDyString(512); char *patterns[128]; int numPats = 0, i = 0; dyStringAppend(allExcludes, alwaysExclude); if (exclude != NULL) dyStringPrintf(allExcludes, ",%s", exclude); numPats = chopCommas(allExcludes->string, patterns); for (i=0; i < numPats; i++) { if (sameWord(patterns[i], "genbank")) { char *gbPatterns[128]; int gbNumPats = 0, j = 0; char *gbExclude = cloneString(genbankExclude); gbNumPats = chopCommas(gbExclude, gbPatterns); for (j=0; j < gbNumPats; j++) { struct slName *pat = newSlName(gbPatterns[j]); slAddHead(&excludePatterns, pat); } freeMem(gbExclude); } else { struct slName *pat = newSlName(patterns[i]); slAddHead(&excludePatterns, pat); } } dyStringFree(&allExcludes); }
void readPairFile(struct lineFile *prf) /* Read in pairs and initialize clone list */ { int lineSize, i; char *line; char *words[4]; char *names[16]; int wordCount, nameCount; struct clone *clone; struct cloneName *cloneName; while (lineFileNext(prf, &line, &lineSize)) { wordCount = chopTabs(line,words); if (wordCount != 3) errAbort("Bad line %d of %s\n", prf->lineIx, prf->fileName); if (!hashLookup(clones, words[2])) { clone = createClone(words[2],NULL,NULL); hashAdd(clones, words[2], clone); slAddHead(&cloneList,clone); } AllocVar(cloneName); sprintf(cloneName->name, "%s", words[2]); nameCount = chopCommas(words[0],names); for (i = 0; i < nameCount; i++) hashAdd(leftNames, names[i], cloneName); nameCount = chopCommas(words[1],names); for (i = 0; i < nameCount; i++) hashAdd(rightNames, names[i], cloneName); } }
static struct slName *getBedFieldSlNameList(struct hTableInfo *hti, char *db, char *table) /* Return the bed-compat field list for the given table, as * slName list of "$db.$table.$field". */ { struct slName *snList = NULL, *sn = NULL; int fieldCount = 0; char *fields = NULL; char *words[16]; char dtf[256]; int i; if (hti == NULL) errAbort("Can't find table info for table %s.%s", db, table); bedSqlFieldsExceptForChrom(hti, &fieldCount, &fields); /* Update our notion of fieldCount -- the chrom field is omitted, and * (if applicable) the reserved field is omitted too: */ fieldCount = chopCommas(fields, words); for (i=fieldCount-1; i >= 0; i--) { if (sameString(words[i], "0")) continue; safef(dtf, sizeof(dtf), "%s.%s.%s", db, table, words[i]); sn = slNameNew(dtf); slAddHead(&snList, sn); } safef(dtf, sizeof(dtf), "%s.%s.%s", db, table, hti->chromField); sn = slNameNew(dtf); slAddHead(&snList, sn); freez(&fields); return snList; }
void getNiceSizes(char *niceSizeList, int **retNiceSizes, int *retCount) /* Parse out comma separated list. */ { char *words[256]; int i, wordCount = chopCommas(niceSizeList, words); int *niceSizes; AllocArray(niceSizes, wordCount); for (i=0; i<wordCount; ++i) niceSizes[i] = atoi(words[i]); *retNiceSizes = niceSizes; *retCount = wordCount; }
void getSamples(char *sampleList, int **retSamples, int *retCount) /* Parse out comma separated list. */ { char *words[256]; int i, wordCount = chopCommas(sampleList, words); int *samples; AllocArray(samples, wordCount); for (i=0; i<wordCount; ++i) samples[i] = atoi(words[i]); *retSamples = samples; *retCount = wordCount; }
/* Return is an array of integers, last one of value zero to indicate the * end of the array. In case of nothing found in trackDb, return * a NULL pointer indicating no results. * * If the value is 'first' then use the first span value from the table. * Assumes that all values in the table are the same. */ int *wiggleSpanList(struct sqlConnection *conn, struct trackDb *tdb) { char *tdbDefault = cloneString(trackDbSettingOrDefault(tdb, SPANLIST, "NONE")); int *ret = (int *)NULL; if (sameWord("NONE",tdbDefault)) { struct hashEl *hel; /* if not found in trackDb, maybe it is in tdb->settings * (custom tracks keep settings here) */ if ((tdb->settings != (char *)NULL) && (tdb->settingsHash != (struct hash *)NULL)) { if ((hel = hashLookup(tdb->settingsHash, SPANLIST)) != NULL) { freeMem(tdbDefault); tdbDefault = cloneString((char *)hel->val); } } } /* if we still don't have a spanList, or we got "first" for spanList, * make up spanList by choosing the first span we find in the table */ //if (sameWord("NONE",tdbDefault) || sameWord("first",tdbDefault)) else if( sameWord("first",tdbDefault)) { char query[1024]; snprintf(query, sizeof(query), "SELECT span FROM %s limit 1", tdb->table ); char *tmpSpan = sqlQuickString(conn, query); AllocArray(ret,2); ret[0] = sqlUnsigned(tmpSpan); ret[1] = 0; freeMem(tmpSpan); } else { /* If something found, let's parse it */ int i; char *words[MAX_SPAN_COUNT]; int wc; wc = chopCommas(tdbDefault,words); AllocArray(ret,wc+1); /* + 1 for the extra zero */ for ( i = 0; i < wc; ++i ) ret[i] = sqlUnsigned(words[i]); intSort(wc,ret); ret[wc] = 0; /* end of list */ } freeMem(tdbDefault); return(ret); } /* int *wiggleSpanList(struct trackDb *tdb) */
static struct hash *hashFromCommaString(char *commaString) /* Return a hash that stores words in comma-separated string, or NULL if string is NULL or empty. */ { struct hash *hash = NULL; if (isNotEmpty(commaString)) { hash = hashNew(0); char *words[1024]; int i, wordCount = chopCommas(commaString, words); for (i = 0; i < wordCount; i++) hashStoreName(hash, words[i]); } return hash; }
static void parseRefAndAlt(struct vcfFile *vcff, struct vcfRecord *record, char *ref, char *alt) /* Make an array of alleles, ref first, from the REF and comma-sep'd ALT columns. * Use the length of the reference sequence to set record->chromEnd. * Note: this trashes the alt argument, since this is expected to be its last use. */ { char *altAlleles[VCF_MAX_INFO]; int altCount = chopCommas(alt, altAlleles); record->alleleCount = 1 + altCount; record->alleles = vcfFileAlloc(vcff, record->alleleCount * sizeof(record->alleles[0])); record->alleles[0] = vcfFilePooledStr(vcff, ref); int i; for (i = 0; i < altCount; i++) record->alleles[1+i] = vcfFilePooledStr(vcff, altAlleles[i]); int refLen = strlen(ref); if (refLen == dnaFilteredSize(ref)) record->chromEnd = record->chromStart + refLen; }
static int parseInfoValue(struct vcfRecord *record, char *infoKey, enum vcfInfoType type, char *valStr, union vcfDatum **pData, bool **pMissingData) /* Parse a comma-separated list of values into array of union vcfInfoDatum and return count. */ { char *valWords[VCF_MAX_INFO]; int count = chopCommas(valStr, valWords); struct vcfFile *vcff = record->file; union vcfDatum *data = vcfFileAlloc(vcff, count * sizeof(union vcfDatum)); bool *missingData = vcfFileAlloc(vcff, count * sizeof(*missingData)); int j; for (j = 0; j < count; j++) { if (type != vcfInfoString && type != vcfInfoCharacter && sameString(valWords[j], ".")) missingData[j] = TRUE; switch (type) { case vcfInfoInteger: data[j].datInt = atoi(valWords[j]); break; case vcfInfoFloat: data[j].datFloat = atof(valWords[j]); break; case vcfInfoFlag: // Flag key might have a value in older VCFs e.g. 3.2's DB=0, DB=1 data[j].datString = vcfFilePooledStr(vcff, valWords[j]); break; case vcfInfoCharacter: data[j].datChar = valWords[j][0]; break; case vcfInfoString: data[j].datString = vcfFilePooledStr(vcff, valWords[j]); break; default: errAbort("invalid vcfInfoType (uninitialized?) %d", type); break; } } // If END is given, use it as chromEnd: if (sameString(infoKey, vcfInfoEnd)) record->chromEnd = data[0].datInt; *pData = data; *pMissingData = missingData; return count; }
struct tomRough *loadAllRough(char *fileName) /* Load up all bands from database. */ { struct tomRough *list = NULL, *el; struct lineFile *lf = lineFileOpen(fileName, TRUE); char *words[16], *line; int wordCount, lineSize; while (lineFileNext(lf, &line, &lineSize)) { wordCount = chopCommas(line, words); lineFileExpectWords(lf, 5, wordCount); el = tomRoughLoad(words); slAddHead(&list, el); } slReverse(&list); lineFileClose(&lf); printf("Loaded %d rough lines\n", slCount(list)); return list; }
static void makeEnumValMenu(char *type, char ***pMenu, int *pMenuSize) /* Given a SQL type description of an enum or set, parse out the list of * values and turn them into a char array for menu display, with "*" as * the first item (no constraint). * This assumes that the values do not contain the ' character. * This will leak a little mem unless you free *pMenu[1] and *pMenu * when done. */ { static char *noop = "*"; char *dup = NULL; char *words[256]; int wordCount = 0; int len = 0, i = 0; if (startsWith("enum(", type)) dup = cloneString(type + strlen("enum(")); else if (startsWith("set(", type)) dup = cloneString(type + strlen("set(")); else errAbort("makeEnumValMenu: expecting a SQL type description that begins " "with \"enum(\" or \"set(\", but got \"%s\".", type); stripChar(dup, '\''); wordCount = chopCommas(dup, words); len = strlen(words[wordCount-1]); if (words[wordCount-1][len-1] == ')') words[wordCount-1][len-1] = 0; else errAbort("makeEnumValMenu: expecting a ')' at the end of the last word " "of SQL type, but got \"%s\"", type); *pMenuSize = wordCount + 1; AllocArray(*pMenu, wordCount+1); *pMenu[0] = noop; for (i = 1; i < wordCount + 1; i++) { (*pMenu)[i] = words[i-1]; } }
void doGvf(struct trackDb *tdb, char *item) /* Show details for variants represented as GVF, stored in a bed8Attrs table */ { struct sqlConnection *conn = hAllocConn(database); int start = cartInt(cart, "o"); char query[1024]; sqlSafef(query, sizeof(query), "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d", tdb->table, item, seqName, start); struct sqlResult *sr = sqlGetResult(conn, query); char **row; if ((row = sqlNextRow(sr)) == NULL) errAbort("doGvfDetails: can't find item '%s' in %s at %s:%d", item, database, seqName, start); int rowOffset = hOffsetPastBin(database, seqName, tdb->table); struct bed8Attrs *ba = bed8AttrsLoad(row+rowOffset); bedPrintPos((struct bed *)ba, 3, tdb); int i = 0; // Note: this loop modifies ba->attrVals[i], assuming we won't use them again: for (i = 0; i < ba->attrCount; i++) { // The ID is the bed8Attrs name and has already been displayed: if (sameString(ba->attrTags[i], "ID")) continue; cgiDecode(ba->attrVals[i], ba->attrVals[i], strlen(ba->attrVals[i])); char *tag = ba->attrTags[i]; // User-defined keywords used in dbVar's GVF: if (sameString(tag, "var_type")) // This one isn't anymore, but I add it back (hg18.txt). tag = "Variant type"; else if (sameString(tag, "clinical_int")) tag = "Clinical interpretation"; else if (sameString(tag, "var_origin")) tag = "Variant origin"; else if (islower(tag[0])) // Uppercase for nice display, assuming user doesn't care which keywords are // user-defined vs. GVF standard: tag[0] = toupper(tag[0]); // GVF standard Start_range and End_range tags (1-based coords): if (sameString(tag, "Start_range") || sameString(tag, "End_range")) { char *copy = cloneString(ba->attrVals[i]); char *words[3]; int wordCount = chopCommas(copy, words); if (wordCount == 2 && (sameString(".", words[0]) || isInteger(words[0])) && (sameString(".", words[1]) || isInteger(words[1]))) { boolean isStartRange = sameString(tag, "Start_range"); char *rangeStart = words[0], *rangeEnd = words[1]; if (sameString(".", rangeStart)) rangeStart = "unknown"; if (sameString(".", rangeEnd)) rangeEnd = "unknown"; if (isStartRange) printf("<B>Start range</B>: outer start %s, inner start %s<BR>\n", rangeStart, rangeEnd); else printf("<B>End range</B>: inner end %s, outer end %s<BR>\n", rangeStart, rangeEnd); } else // not formatted as expected, just print as-is: printf("<B>%s</B>: %s<BR>\n", tag, htmlEncode(ba->attrVals[i])); } // Parent sounds like mom or dad (as in var_origin)... tweak it too: else if (sameString(tag, "Parent")) { printf("<B>Variant region:</B> " "<A HREF=\"http://www.ncbi.nlm.nih.gov/dbvar/variants/%s/\" " "TARGET=_BLANK>%s</A><BR>\n", ba->attrVals[i], htmlEncode(ba->attrVals[i])); } else if (sameString(tag, "Name")) { char *url = trackDbSetting(tdb, "url"); // Show the Name only if it hasn't already appeared in the URL: if (url == NULL || !stringIn("$$", url)) printf("<B>%s</B>: %s<BR>\n", tag, htmlEncode(ba->attrVals[i])); } else if (sameWord(tag, "Phenotype_id") && startsWith("HPO:HP:", ba->attrVals[i])) { subChar(tag, '_', ' '); printf("<B>%s</B>: <A HREF=\"http://www.berkeleybop.org/obo/%s\" " "TARGET=_BLANK>%s</A><BR>\n", tag, ba->attrVals[i]+strlen("HPO:"), htmlEncode(ba->attrVals[i])); } else { subChar(tag, '_', ' '); printf("<B>%s</B>: %s<BR>\n", tag, htmlEncode(ba->attrVals[i])); } } sqlFreeResult(&sr); hFreeConn(&conn); /* printTrackHtml is done in genericClickHandlerPlus. */ }
void doMiddle() { struct hash *cvHash = raReadAll((char *)cvFile(), CV_TERM); struct hashCookie hc = hashFirst(cvHash); struct hashEl *hEl; struct slList *termList = NULL; struct hash *ra; int totalPrinted = 0; boolean excludeDeprecated = (cgiOptionalString("deprecated") == NULL); // Prepare an array of selected terms (if any) int requestCount = 0; char **requested = NULL; char *requestVal = termOpt; char *queryBy = CV_TERM; if (tagOpt) { requestVal = tagOpt; queryBy = CV_TAG; } else if (targetOpt) { requestVal = targetOpt; queryBy = CV_TERM; // request target is special: lookup term, convert to target, display target } else if (labelOpt) { requestVal = labelOpt; queryBy = CV_LABEL; } if (requestVal) { (void)stripChar(requestVal,'\"'); requestCount = chopCommas(requestVal,NULL); requested = needMem(requestCount * sizeof(char *)); chopByChar(requestVal,',',requested,requestCount); } char *org = NULL; // if the org is specified in the type (eg. cell line) // then use that for the org, otherwise use the command line option, // otherwise use human. char *type = findType(cvHash,requested,requestCount,&queryBy, &org, FALSE); if (org == NULL) org = organismOptLower; if (org == NULL) org = ORG_HUMAN; // Special logic for requesting antibody by target if (targetOpt && requestCount > 0 && sameWord(queryBy,CV_TERM) && sameWord(type,CV_TERM_ANTIBODY)) { // Several antibodies may have same target. // requested target={antibody} and found antibody // Must now convert each of the requested terms to its target before displaying all targets char **targets = convertAntibodiesToTargets(cvHash,requested,requestCount); if (targets != NULL) { freeMem(requested); requested = targets; queryBy = CV_TARGET; } } //warn("Query by: %s = '%s' type:%s",queryBy,requestVal?requestVal:"all",type); // Get just the terms that match type and requested, then sort them if (differentWord(type,CV_TOT) || typeOpt != NULL ) // If type resolves to typeOfTerm and { // typeOfTerm was not requested, while ((hEl = hashNext(&hc)) != NULL) // then just show definition { ra = (struct hash *)hEl->val; char *thisType = (char *)cvTermNormalized(hashMustFindVal(ra,CV_TYPE)); if (differentWord(thisType,type) && (requested == NULL || differentWord(thisType,CV_TERM_CONTROL))) continue; // Skip all rows that do not match queryBy param if specified if (requested) { char *val = hashFindVal(ra, queryBy); if (val == NULL) { // Special case for input that has no target if (sameString(queryBy, CV_TARGET)) val = hashMustFindVal(ra, CV_TERM); else continue; } if (-1 == stringArrayIx(val,requested,requestCount)) continue; } else if (excludeDeprecated) { if (hashFindVal(ra, "deprecated") != NULL) continue; } slAddTail(&termList, ra); } } slSort(&termList, termCmp); boolean described = doTypeDefinition(type,FALSE,(slCount(termList) == 0)); boolean sortable = (slCount(termList) > 5); if (sortable) { webIncludeResourceFile("HGStyle.css"); jsIncludeFile("jquery.js",NULL); jsIncludeFile("utils.js",NULL); printf("<TABLE class='sortable' border=1 CELLSPACING=0 style='border: 2px outset #006600; " "background-color:%s;'>\n",COLOR_BG_DEFAULT); } else printf("<TABLE BORDER=1 BGCOLOR=%s CELLSPACING=0 CELLPADDING=2>\n",COLOR_BG_DEFAULT); if (slCount(termList) > 0) { doTypeHeader(type, org,sortable); // Print out the terms while ((ra = slPopHead(&termList)) != NULL) { if (doTypeRow( ra, org )) totalPrinted++; } } puts("</TBODY></TABLE><BR>"); if (sortable) jsInline("{$(document).ready(function() " "{sortTable.initialize($('table.sortable')[0],true,true);});}\n"); if (totalPrinted == 0) { if (!described) warn("Error: Unrecognised type (%s)\n", type); } else if (totalPrinted > 1) printf("Total = %d\n", totalPrinted); }