static void rTsWriteAsFlatTab(struct tagStanza *list, struct slName *fieldList, FILE *f, char *idTag, boolean withParent, int maxDepth, int depth) /* Recursively write out list to file */ { if (depth > maxDepth) return; struct tagStanza *stanza; for (stanza = list; stanza != NULL; stanza = stanza->next) { char *idVal = NULL; if (idTag != NULL) { idVal = slPairFindVal(stanza->tagList, idTag); } if (idTag == NULL || idVal != NULL) { struct hash *uniq = hashNew(0); if (withParent && stanza->parent != NULL && idTag != NULL) { char *parentVal = slPairFindVal(stanza->parent->tagList, idTag); if (parentVal != NULL) { hashAdd(uniq, "parent", parentVal); } } struct tagStanza *family; for (family = stanza; family != NULL; family = family->parent) { struct slPair *pair; for (pair = family->tagList; pair != NULL; pair = pair->next) { if (!hashLookup(uniq, pair->name)) { hashAdd(uniq, pair->name, pair->val); } } } struct slName *field; for (field = fieldList; field != NULL; field = field->next) { if (field != fieldList) fputc('\t', f); char *val = naForNull(hashFindVal(uniq, field->name)); fputs(val, f); } fputc('\n', f); hashFree(&uniq); } rTsWriteAsFlatTab(stanza->children, fieldList, f, idTag, withParent, maxDepth, depth+1); } }
static void rAddIndex(struct tagStorm *tagStorm, struct tagStanza *list, struct hash *hash, char *tag, char *parentVal, boolean unique) /* Add stanza to hash index if it has a value for tag, or if val is passed in. */ { struct tagStanza *stanza; for (stanza = list; stanza != NULL; stanza = stanza->next) { char *val = slPairFindVal(stanza->tagList, tag); if (val == NULL) val = parentVal; if (val != NULL) { if (unique) { struct tagStanza *oldStanza = hashFindVal(hash, val); if (oldStanza != NULL) errAbort("tag %s value %s not unique in %s", tag, val, tagStorm->fileName); } hashAdd(hash, val, stanza); } if (stanza->children != NULL) rAddIndex(tagStorm, stanza->children, hash, tag, val, unique); } }
static char *mustFindVal(struct slPair *list, char *tag, struct lineFile *lf) /* Look for tag in list and return value. If none complain and abort. */ { char *val = slPairFindVal(list, tag); if (val == NULL) errAbort("missing required %s tag near line %d of %s", tag, lf->lineIx, lf->fileName); return val; }
static void rTsWriteAsFlatRa(struct tagStanza *list, FILE *f, char *idTag, boolean withParent, int maxDepth, int depth) /* Recursively write out list to file */ { if (depth > maxDepth) return; struct tagStanza *stanza; for (stanza = list; stanza != NULL; stanza = stanza->next) { char *idVal = NULL; if (idTag != NULL) idVal = slPairFindVal(stanza->tagList, idTag); struct hash *uniq = hashNew(0); if (idVal != NULL) { fprintf(f, "%s %s\n", idTag, idVal); hashAdd(uniq, idTag, idVal); } if (withParent && stanza->parent != NULL && idTag != NULL) { char *parentVal = slPairFindVal(stanza->parent->tagList, idTag); if (parentVal != NULL) { fprintf(f, "parent %s\n", parentVal); hashAdd(uniq, "parent", parentVal); } } struct tagStanza *family; for (family = stanza; family != NULL; family = family->parent) { struct slPair *pair; for (pair = family->tagList; pair != NULL; pair = pair->next) { if (!hashLookup(uniq, pair->name)) { fprintf(f, "%s %s\n", pair->name, (char*)(pair->val)); hashAdd(uniq, pair->name, pair->val); } } } fputc('\n', f); hashFree(&uniq); rTsWriteAsFlatRa(stanza->children, f, idTag, withParent, maxDepth, depth+1); } }
char *mustFindInPairList(struct slPair *list, char *name, struct lineFile *lf) /* Look through list for one with given name, and return associated value. Use * lf for error reporting if not found. */ { char *val = slPairFindVal(list, name); if (val == NULL) errAbort("Could not find required tag '%s' in stanza ending line %d of %s", name, lf->lineIx, lf->fileName); return val; }
char *tagFindVal(struct tagStanza *stanza, char *name) /* Return value of tag of given name within stanza or any of it's parents. */ { struct tagStanza *ancestor; for (ancestor = stanza; ancestor != NULL; ancestor = ancestor->parent) { char *val = slPairFindVal(ancestor->tagList, name); if (val != NULL) return val; } return NULL; }
char *tagStanzaVal(struct tagStanza *stanza, char *tag) /* Return value associated with tag in stanza or any of parent stanzas */ { while (stanza != NULL) { char *val = slPairFindVal(stanza->tagList, tag); if (val != NULL) return val; stanza = stanza->parent; } return NULL; }
struct slPair *mdbSelectPairs(struct cart *cart, struct slPair *mdbVars) // Returns the current mdb vars and vals in the table of drop down selects { // figure out how many metadata selects are visible. int numMetadataSelects = 0; struct slPair *mdbSelectPairs = NULL; if (mdbVars == NULL) return 0; // Get the current number of rows in the table of mdb selects for (;;) { char buf[256]; safef(buf, sizeof(buf), "%s%d", METADATA_NAME_PREFIX, numMetadataSelects + 1); char *str = cartOptionalString(cart, buf); if (isEmpty(str)) break; else numMetadataSelects++; } // Requesting to add or delete any? int delSearchSelect = cartUsualInt(cart, TRACK_SEARCH_DEL_ROW, 0); // 1-based row to delete int addSearchSelect = cartUsualInt(cart, TRACK_SEARCH_ADD_ROW, 0); // 1-based row to insert after if (delSearchSelect) numMetadataSelects--; if (addSearchSelect) numMetadataSelects++; if (numMetadataSelects) { int ix; char buf[256]; for (ix = 0; ix < numMetadataSelects; ix++) { int offset; // used to handle additions/deletions if (addSearchSelect > 0 && ix >= addSearchSelect) offset = 0; // do nothing to offset (i.e. copy data from previous row) else if (delSearchSelect > 0 && ix + 1 >= delSearchSelect) offset = 2; else offset = 1; safef(buf, sizeof(buf), "%s%d", METADATA_NAME_PREFIX, ix + offset); char *var = cartOptionalString(cart, buf); char *val = NULL; // We need to make sure var is valid in this assembly; if it isn't, reset it to "cell". if (slPairFindVal(mdbVars,var) == NULL) var = "cell"; else { safef(buf, sizeof(buf), "%s%d", METADATA_VALUE_PREFIX, ix + offset); enum cvSearchable searchBy = cvSearchMethod(var); if (searchBy == cvSearchByMultiSelect) { // Multi-selects as comma delimited list of values struct slName *vals = cartOptionalSlNameList(cart,buf); if (vals) { val = slNameListToString(vals,','); // A comma delimited list of values slNameFreeList(&vals); } } else if (searchBy == cvSearchBySingleSelect || searchBy == cvSearchByFreeText || searchBy == cvSearchByWildList) val = cloneString(cartUsualString(cart, buf,ANYLABEL)); //else if (searchBy == cvSearchByDateRange || searchBy == cvSearchByIntegerRange) // { // // TO BE IMPLEMENTED // } if (val != NULL && sameString(val, ANYLABEL)) val = NULL; } slPairAdd(&mdbSelectPairs,var,val); // val already cloned } if (delSearchSelect > 0) { safef(buf, sizeof(buf), "%s%d", METADATA_NAME_PREFIX, numMetadataSelects + 1); cartRemove(cart, buf); safef(buf, sizeof(buf), "%s%d", METADATA_VALUE_PREFIX, numMetadataSelects + 1); cartRemove(cart, buf); } } else { // create defaults slPairAdd(&mdbSelectPairs,"cell", NULL); slPairAdd(&mdbSelectPairs,"antibody",NULL); } slReverse(&mdbSelectPairs); return mdbSelectPairs; }
char *tagFindLocalVal(struct tagStanza *stanza, char *name) /* Return value of tag of given name within stanza, or NULL * if tag does not exist. * This does *not* look at parent tags. */ { return slPairFindVal(stanza->tagList, name); }