void cartJsonExecute(struct cartJson *cj) /* Get commands from cgi, print Content-type, execute commands, print results as JSON. */ { cartJsonPushErrHandlers(); puts("Content-Type:text/javascript\n"); // Initialize response JSON object: jsonWriteObjectStart(cj->jw, NULL); // Always send back hgsid: jsonWriteString(cj->jw, cartSessionVarName(), cartSessionId(cj->cart)); char *commandJson = cgiOptionalString(CARTJSON_COMMAND); if (commandJson) { struct jsonElement *commandObj = jsonParse(commandJson); struct hash *commandHash = jsonObjectVal(commandObj, "commandObj"); // change* commands need to go first! Really we need an ordered map type here... // for now, just make a list and sort to put change commands at the front. struct slPair *commandList = NULL, *cmd; struct hashCookie cookie = hashFirst(commandHash); struct hashEl *hel; while ((hel = hashNext(&cookie)) != NULL) slAddHead(&commandList, slPairNew(hel->name, hel->val)); slSort(&commandList, commandCmp); for (cmd = commandList; cmd != NULL; cmd = cmd->next) doOneCommand(cj, cmd->name, (struct jsonElement *)cmd->val); } cartJsonPrintWarnings(cj->jw); jsonWriteObjectEnd(cj->jw); puts(cj->jw->dy->string); cartJsonPopErrHandlers(); }
struct slPair *cdwFormatList() /* Return list of formats. The name of the list items are the format names. * The vals are short descriptions. */ { static struct slPair *list = NULL; if (list == NULL) { static char *array[] = { "2bit Two bit per base DNA format", "bam Short read mapping format", "bed Genome browser compatible format for genes and other discrete elements", "bigBed Compressed BED recommended for files with more than 100,000 elements", "bigWig Compressed base by base signal graphs", "cram More highly compressed short read format, currently with less validations", "csv Comma-Separated-Values", "fasta Standard DNA format. Must be gzipped", "fastq Illumina or sanger formatted short read format. Must be gzipped", "gtf GFF family format for gene and transcript predictions", "html A file in web page format", "idat An Illumina IDAT file", "jpg JPEG image format", "pdf Postscripts common document format", "png PNG image format", "rcc A Nanostring RCC file", "text Unicode 8-bit formatted text file", "vcf Variant call format", "kallisto_abundance abundance.txt file output from Kallisto containing RNA abundance info", "expression_matrix Genes/transcripts are rows, samples are columns", "unknown File is in format unknown to the data hub. No validations are applied", }; int i; for (i=0; i<ArraySize(array); ++i) { char *buf = cloneString(array[i]); char *val = buf; char *tag = nextWord(&val); assert(tag != NULL && val != NULL); struct slPair *pair = slPairNew(tag, cloneString(val)); slAddHead(&list, pair); freeMem(buf); } 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(); }