static boolean mdbSelectsAddFoundComposites(struct slPair **pMdbSelects,struct trackDb *tdbsFound) // Adds a composite mdbSelect (if found in tdbsFound) to the head of the pairs list. // If tdbsFound is NULL, then add dummy composite search criteria { // create comma separated list of composites struct dyString *dyComposites = dyStringNew(256); struct trackDb *tdb = tdbsFound; for (;tdb != NULL; tdb = tdb->next) { if (tdbIsComposite(tdb)) dyStringPrintf(dyComposites,"%s,",tdb->track); else if (tdbIsCompositeChild(tdb)) { struct trackDb *composite = tdbGetComposite(tdb); dyStringPrintf(dyComposites,"%s,",composite->track); } } if (dyStringLen(dyComposites) > 0) { char *composites = dyStringCannibalize(&dyComposites); composites[strlen(composites) - 1] = '\0'; // drop the last ',' slPairAdd(pMdbSelects,MDB_VAR_COMPOSITE,composites); // Composite should not already be in the list, because it is only indirectly sortable return TRUE; } //warn("No composites found"); dyStringFree(&dyComposites); return FALSE; }
struct slPair *fileFormatSearchWhiteList() // Gets the whitelist of approved file formats that is allowed for search { char *crudeTypes[] = { "bam", // "bam.bai" is now alway selected with bam, "tagAlign", "bed.gz", "bigBed", "broadPeak", "narrowPeak", "fastq", "bigWig", "wig" // TODO: Add "other" category. TODO: make into multi-select }; char *nicerTypes[] = { "Alignment binary (bam) - binary SAM", // "Alignment binary index (bai) - binary SAM index", "Alignment tags (tagAlign)", "bed - browser extensible data", "bigBed - self index, often remote bed format", "Peaks Broad (broadPeak) - ENCODE large region peak format", "Peaks Narrow (narrowPeak) - ENCODE small region peak format", "Raw Sequence (fastq) - High throughput sequence format", "Signal (bigWig) - self index, often remote wiggle format", "Signal (wig) - wiggle format" }; struct slPair *fileTypes = NULL; int ix = 0, count = sizeof(crudeTypes)/sizeof(char *); for (ix=0;ix<count;ix++) slPairAdd(&fileTypes, crudeTypes[ix],cloneString(nicerTypes[ix])); return fileTypes; }
struct slPair *raNextStanzaLinesAndUntouched(struct lineFile *lf) // Return list of lines starting from current position, up through last line of next stanza. // May return a few blank/comment lines at end with no real stanza. // Will join continuation lines, allocating memory as needed. // returns pairs with name=joined line and if joined, // val will contain raw lines '\'s and linefeeds, else val will be NULL. { struct slPair *pairs = NULL; boolean stanzaStarted = FALSE; char *line, *raw; int lineLen,rawLen; while (lineFileNextFull(lf, &line, &lineLen, &raw, &rawLen)) // Joins continuation lines { char *clippedText = skipLeadingSpaces(line); if (stanzaStarted && clippedText[0] == 0) { lineFileReuse(lf); break; } if (!stanzaStarted && clippedText[0] != 0 && clippedText[0] != '#') stanzaStarted = TRUE; // Comments don't start stanzas and may be followed by blanks slPairAdd(&pairs, line,(raw != NULL?cloneString(raw):NULL)); } slReverse(&pairs); return pairs; }
struct slPair *wildHashMakeList(struct hash *hash) /* Makes a sub hash containing a list of hash elements whose names contain wildcards ('*', '?'). The sub hash will be put into WILD_CARD_HASH_BIN for use by wildHashLookup(). */ { struct slPair *wildList = NULL; struct hashEl* hel = NULL; struct hashCookie cookie = hashFirst(hash); while ((hel = hashNext(&cookie)) != NULL) { if (strchr(hel->name,'*') != NULL || strchr(hel->name,'?') != NULL) slPairAdd(&wildList, hel->name, hel); } if (wildList == NULL) // Note: adding an "empty" pair will slPairAdd(&wildList, WILD_CARD_HASH_EMPTY, NULL); // prevent rebuilding this list else if (slCount(wildList) > 1) slSort(&wildList,wildExpressionCmp); // sort on length, so the most restrictive // wildcard match goes first? hashAdd(hash, WILD_CARD_HASH_BIN, wildList); return wildList; }
struct slPair *slPairTwoColumnFile(char *fileName) /* Read in a two column file into an slPair list */ { char *row[2]; struct slPair *list = NULL; struct lineFile *lf = lineFileOpen(fileName, TRUE); while (lineFileRow(lf, row)) slPairAdd(&list, row[0], cloneString(row[1])); lineFileClose(&lf); slReverse(&list); return list; }
struct slPair *raNextStanzAsPairs(struct lineFile *lf) // Return ra stanza as an slPair list instead of a hash. Handy to preserve the // order. Will ignore '#' comments and joins continued lines (ending in '\'). { struct slPair *list = NULL; char *key, *val; if (!raSkipLeadingEmptyLines(lf, NULL)) return NULL; while (raNextTagVal(lf, &key, &val, NULL)) { slPairAdd(&list, key, cloneString(val)); // key gets cloned by slPairAdd } slReverse(&list); return list; }
void doMiddle(struct cart *theCart) /* Set up globals and make web plabel */ { cart = theCart; char *db = cartUsualString(cart, "db", hDefaultDb()); cartWebStart(cart, db, "Try and get some simple D3 things running inside of Genome Browser web framework."); printf("<script src=\"//cdnjs.cloudflare.com/ajax/libs/d3/3.4.4/d3.min.js\"></script>"); printf("<script src=\"/js/d3pie.min.js\"></script>"); struct slPair *data= slPairNew("A","100"); slPairAdd(&data, "B", "10"); slPairAdd(&data, "C", "1"); slReverse(&data); printf("<div id=\"pieChart1\">\n"); drawPrettyPieGraph(data, "pieChart1", "Title", "Subtitle"); printf("</div>\n"); slPairAdd(&data, "D", "10"); printf("<div id=\"pieChart2\">\n"); drawPrettyPieGraph(data, "pieChart1", "A new title", "cool subtitle!"); printf("</div>\n"); slPairAdd(&data, "W", "15"); printf("<div id=\"pieChart3\">\n"); drawPrettyPieGraph(data, "pieChart1", "Title", "Testing out what a much longer subtitle will look like... How many characters can I put here?"); printf("</div>\n"); slPairAdd(&data, "Z", "30"); printf("<div id=\"pieChart4\">\n"); drawPrettyPieGraph(data, "pieChart1", "How do much largers titles look?", "Subtitle"); printf("</div>\n"); printf("<style>\npieChart1{\n align:center;} </style>"); #ifdef SOON drawPieGraph(data); drawPieGraph(data); slPairAdd(&data, "E", "15"); drawPieGraph(data); slPairAdd(&data, "F", "25"); drawPieGraph(data); slPairAdd(&data, "G", "50"); drawPieGraph(data); #endif /* SOON */ cartWebEnd(); }
struct slPair *tagListIncludingParents(struct tagStanza *stanza) /* Return a list of all tags including ones defined in parents. */ { struct hash *uniq = hashNew(0); struct slPair *list = NULL; struct tagStanza *ts; for (ts = stanza; ts != NULL; ts = ts->parent) { struct slPair *pair; for (pair = ts->tagList; pair != NULL; pair = pair->next) { if (!hashLookup(uniq, pair->name)) { slPairAdd(&list, pair->name, pair->val); hashAdd(uniq, pair->name, pair); } } } hashFree(&uniq); slReverse(&list); return list; }
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; }