3c529301c2900f3b03ea89955426db75b9b631f9 angie Mon Feb 7 10:08:54 2011 -0800 Track #1684 (SNPs 132 (dbSNP)): Added coloring by allele frequency:items are shaded on a scale of red (rare) to blue (common), or black when no frequencies were given. Now I'm wondering if I should have used a log scale, but this works so I'm checking it in. diff --git src/hg/hgTrackUi/hgTrackUi.c src/hg/hgTrackUi/hgTrackUi.c index c979892..c8a063b 100644 --- src/hg/hgTrackUi/hgTrackUi.c +++ src/hg/hgTrackUi/hgTrackUi.c @@ -215,30 +215,34 @@ boolean foundInCart = FALSE; struct slName *selectedAttributes = snp125FilterFromCart(cart, track, attributeVar, &foundInCart); // Include all by default: if (! foundInCart) selectedAttributes = slNameListFromStringArray(values, menuSize); cgiMakeCheckboxGroupWithVals(cartVar, labels, values, menuSize, selectedAttributes, SNP125_FILTER_COLUMNS); printf("\n"); } static void snp125PrintColorSpec(char *track, char *attribute, char *vars[], boolean varsAreOld, char *labels[], char *defaults[], int varCount) /* Print a table displaying snp125 attribute color selects. */ { int i; +printf("If a SNP has more than one of these attributes, the stronger color will override the\n" + "weaker color. The order of colors, from strongest to weakest, is red,\n" + "green, blue, gray, and black.\n" + "

\n"); printf("\n"); for (i=0; i < varCount; i++) { if (i % SNP125_FILTER_COLUMNS == 0) { if (i > 0) printf("\n"); printf(""); } printf("\n"); jsBeginCollapsibleSection(cart, tdb->track, "colorByAttribute", "Color by Attribute", FALSE); char defaultButtonVar[512]; safef(defaultButtonVar, sizeof(defaultButtonVar), "%s_coloring", SNP125_DEFAULTS); stripChar(defaultButtonVar, ' '); snp125ResetColorVarsIfNecessary(tdb, defaultButtonVar, version); printf("
SNP Feature for Color Specification:\n"); -char cartVar[512]; -safef(cartVar, sizeof(cartVar), "%s.colorSource", tdb->track); -char *snp125ColorSourceDefault = snp125ColorSourceLabels[SNP125_DEFAULT_COLOR_SOURCE]; -char *colorSourceCart = cartUsualString(cart, cartVar, - cartUsualString(cart, snp125ColorSourceOldVar, - snp125ColorSourceDefault)); char **labels = snp132ColorSourceLabels; int arraySize = snp132ColorSourceArraySize; if (version <= 127) { labels = snp125ColorSourceLabels; arraySize = snp125ColorSourceArraySize; } else if (version <= 131) { labels = snp128ColorSourceLabels; arraySize = snp128ColorSourceArraySize; } -if (stringArrayIx(colorSourceCart, labels, arraySize) < 0) - colorSourceCart = snp125ColorSourceDefault; // It would be preferable for Javascript to handle changing the color selection // menus when the color source selection changes, but for now we do a submit that // returns to the current vertical position: char autoSubmit[2048]; safef(autoSubmit, sizeof(autoSubmit), "onchange=\"" "document."MAIN_FORM".action = '%s'; %s" "document."MAIN_FORM".submit();\"", cgiScriptName(), jsSetVerticalPosition(MAIN_FORM)); cgiContinueHiddenVar("g"); cgiContinueHiddenVar("c"); -cgiMakeDropListFull(cartVar, labels, labels, arraySize, colorSourceCart, autoSubmit); +char cartVar[512]; +safef(cartVar, sizeof(cartVar), "%s.colorSource", tdb->track); +enum snp125ColorSource colorSourceCart = snp125ColorSourceFromCart(cart, tdb); +char *colorSourceSelected = snp125ColorSourceToLabel(tdb, colorSourceCart); +cgiMakeDropListFull(cartVar, labels, labels, arraySize, colorSourceSelected, autoSubmit); printf(" \n"); char javascript[2048]; safef(javascript, sizeof(javascript), "document."MAIN_FORM".action='%s'; %s document."MAIN_FORM".submit();", cgiScriptName(), jsSetVerticalPosition(MAIN_FORM)); cgiMakeOnClickSubmitButton(javascript, defaultButtonVar, JS_DEFAULTS_BUTTON_LABEL); printf("

\n" "The selected "Feature for Color Specification" above has the\n" "selection of colors below for each attribute. Only the color\n" "options for the feature selected above will be used to color items;\n" - "color options for other features will not be shown. If a SNP has more\n" - "than one of these attributes, the stronger color will override the\n" - "weaker color. The order of colors, from strongest to weakest, is red,\n" - "green, blue, gray, and black.\n" - "

\n"); + "color options for other features will not be shown.\n"); -if (sameString(colorSourceCart, "Location Type")) +if (version > 127 && colorSourceCart == snp125ColorSourceLocType) + colorSourceCart = SNP125_DEFAULT_COLOR_SOURCE; +switch (colorSourceCart) { - if (version <= 127) + int funcArraySize; + case snp125ColorSourceLocType: snp125PrintColorSpec(tdb->track, "locType", snp125LocTypeOldColorVars, TRUE, snp125LocTypeLabels, snp125LocTypeDefault, snp125LocTypeArraySize); - } -else if (sameString(colorSourceCart, "Class")) + break; + case snp125ColorSourceClass: snp125PrintColorSpec(tdb->track, "class", snp125ClassOldColorVars, TRUE, snp125ClassLabels, snp125ClassDefault, snp125ClassArraySize); -else if (sameString(colorSourceCart, "Validation")) + break; + case snp125ColorSourceValid: snp125PrintColorSpec(tdb->track, "valid", snp125ValidOldColorVars, TRUE, snp125ValidLabels, snp125ValidDefault, snp125ValidArraySize); -else if (sameString(colorSourceCart, "Function")) - { - int funcArraySize = (version < 130) ? snp125FuncArraySize : (snp125FuncArraySize - 1); + break; + case snp125ColorSourceFunc: + funcArraySize = (version < 130) ? snp125FuncArraySize : (snp125FuncArraySize - 1); snp125PrintColorSpec(tdb->track, "func", snp125FuncOldColorVars, TRUE, snp125FuncLabels, snp125FuncDefault, funcArraySize); - } -else if (sameString(colorSourceCart, "Molecule Type")) + break; + case snp125ColorSourceMolType: snp125PrintColorSpec(tdb->track, "molType", snp125MolTypeOldColorVars, TRUE, snp125MolTypeLabels, snp125MolTypeDefault, snp125MolTypeArraySize); -else if (sameString(colorSourceCart, "Unusual Conditions (UCSC)")) + break; + case snp125ColorSourceExceptions: snp125PrintColorSpec(tdb->track, "exceptions", snp132ExceptionVarName, FALSE, snp132ExceptionLabels, snp132ExceptionDefault, snp132ExceptionArraySize); -else if (sameString(colorSourceCart, "Miscellaneous Attributes (dbSNP)")) + break; + case snp125ColorSourceBitfields: snp125PrintColorSpec(tdb->track, "bitfields", snp132BitfieldVarName, FALSE, snp132BitfieldLabels, snp132BitfieldDefault, snp132BitfieldArraySize); + break; + case snp125ColorSourceAlleleFreq: + printf("

Items are be colored by allele frequency on a red-blue spectrum, " + "with red representing rare alleles and blue representing common alleles. " + "Items with no allele frequency data are colored black.

"); + break; + default: + errAbort("Unrecognized value of enum snp125ColorSource (%d)", colorSourceCart); + } jsEndCollapsibleSection(); } void snp125Ui(struct trackDb *tdb) /* UI for dbSNP version 125 and later. */ { char *orthoTable = snp125OrthoTable(tdb, NULL); int version = snpVersion(tdb->track); char cartVar[512]; jsInit(); if (version < 130) snp125ValidArraySize--; // no by-1000genomes if (isNotEmpty(orthoTable) && hTableExists(database, orthoTable))
%s", labels[i]); char cartVar[512]; safef(cartVar, sizeof(cartVar), "%s.%s%s", track, attribute, (varsAreOld ? snp125OldColorVarToNew(vars[i], attribute) : vars[i])); char *defaultCol = defaults[i]; if (varsAreOld) @@ -297,106 +301,113 @@ } void snp125PrintColorControlSection(struct trackDb *tdb, int version) /* Print a collapsible section of color controls: user selects an attribute to color by, * and then a color for each possible value of the selected attribute. */ { printf("