699bca4f7cfa87c4b5f78cb9c16b442f24251465 angie Tue Feb 26 11:26:01 2013 -0800 For Track #7043 (SNPs for mm10): Luvina noticed that mm10.snp137 hasseveral items that use a molType we haven't seen before, "mito"; added filter and color options for that. diff --git src/hg/hgTrackUi/hgTrackUi.c src/hg/hgTrackUi/hgTrackUi.c index 0408163..139ce9b 100644 --- src/hg/hgTrackUi/hgTrackUi.c +++ src/hg/hgTrackUi/hgTrackUi.c @@ -280,31 +280,32 @@ int i; for (i = 0; i < valCount; i++) { if (sameString(values[i], "unknown")) labels[i] = "Unknown"; else labels[i] = snpMisoLinkFromFunc(values[i]); } snp125PrintFilterControls(tdb->track, "Function", "func", labels, values, valCount); return;; } } errAbort("Didn't find definition of func field in %s", tdb->table); } -static void snp125PrintFilterControlSection(struct trackDb *tdb, int version) +static void snp125PrintFilterControlSection(struct trackDb *tdb, int version, + boolean molTypeHasMito) /* Print a collapsible section of filtering controls on SNP properties, first numeric * and then enum/set. */ { char cartVar[512]; printf("<TR><TD colspan=2><A name=\"filterControls\"></TD></TR>\n"); jsBeginCollapsibleSection(cart, tdb->track, "filterByAttribute", "Filtering Options", FALSE); printf("<BR>\n"); safef(cartVar, sizeof(cartVar), "%s.minAvHet", tdb->track); double minAvHet = cartUsualDouble(cart, cartVar, // Check old cart var name: cartUsualDouble(cart, "snp125AvHetCutoff", SNP125_DEFAULT_MIN_AVHET)); printf("<B>Minimum <A HREF=\"#AvHet\">Average Heterozygosity</A>:</B> "); cgiMakeDoubleVar(cartVar, minAvHet, 6); printf("<BR>\n"); @@ -359,32 +360,35 @@ if (version <= 127) snp125PrintFilterControls(tdb->track, "Location Type", "locType", snp125LocTypeLabels, snp125LocTypeDataName, snp125LocTypeArraySize); snp125PrintFilterControls(tdb->track, "Class", "class", snp125ClassLabels, snp125ClassDataName, snp125ClassArraySize); snp125PrintFilterControls(tdb->track, "Validation", "valid", snp125ValidLabels, snp125ValidDataName, snp125ValidArraySize); if (version < 137) { int funcArraySize = (version < 130) ? snp125FuncArraySize : (snp125FuncArraySize - 1); snp125PrintFilterControls(tdb->track, "Function", "func", snp125FuncLabels, snp125FuncDataName, funcArraySize); } else snp137PrintFunctionFilterControls(tdb); +int molTypeArraySize = snp125MolTypeArraySize; +if (! molTypeHasMito) + molTypeArraySize--; snp125PrintFilterControls(tdb->track, "Molecule Type", "molType", snp125MolTypeLabels, - snp125MolTypeDataName, snp125MolTypeArraySize); + snp125MolTypeDataName, molTypeArraySize); if (version >= 132) { int excArraySize = snp132ExceptionArraySize; if (version < 135) excArraySize -= 2; snp125PrintFilterControls(tdb->track, "Unusual Conditions (UCSC)", "exceptions", snp132ExceptionLabels, snp132ExceptionVarName, excArraySize); snp125PrintFilterControls(tdb->track, "Miscellaneous Attributes (dbSNP)", "bitfields", snp132BitfieldLabels, snp132BitfieldDataName, snp132BitfieldArraySize); } printf("</TABLE>\n"); jsEndCollapsibleSection(); } static void snp125PrintColorSpec(char *track, char *attribute, char *vars[], boolean varsAreOld, @@ -453,31 +457,31 @@ tdb->track, "class"); snp125RemoveColorVars(cart, snp125ValidOldColorVars, TRUE, snp125ValidArraySize, tdb->track, "valid"); int funcArraySize = (version < 130) ? snp125FuncArraySize : (snp125FuncArraySize - 1); snp125RemoveColorVars(cart, snp125FuncOldColorVars, TRUE, funcArraySize, tdb->track, "func"); snp125RemoveColorVars(cart, snp125MolTypeOldColorVars, TRUE, snp125MolTypeArraySize, tdb->track, "molType"); snp125RemoveColorVars(cart, snp132ExceptionVarName, FALSE, snp132ExceptionArraySize, tdb->track, "exceptions"); snp125RemoveColorVars(cart, snp132BitfieldVarName, FALSE, snp132BitfieldArraySize, tdb->track, "bitfields"); } } -void snp125PrintColorControlSection(struct trackDb *tdb, int version) +void snp125PrintColorControlSection(struct trackDb *tdb, int version, boolean molTypeHasMito) /* 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("<TR><TD colspan=2><A name=\"colorSpec\"></TD></TR>\n"); jsBeginCollapsibleSection(cart, tdb->track, "colorByAttribute", "Coloring Options", FALSE); char defaultButtonVar[512]; safef(defaultButtonVar, sizeof(defaultButtonVar), "%s_coloring", SNP125_DEFAULTS); stripChar(defaultButtonVar, ' '); snp125ResetColorVarsIfNecessary(tdb, defaultButtonVar, version); printf("<BR><B>SNP Feature for Color Specification:</B>\n"); char **labels = snp132ColorSourceLabels; int arraySize = snp132ColorSourceArraySize; if (version <= 127) @@ -511,113 +515,134 @@ 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("<BR><BR>\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.\n"); if (version > 127 && colorSourceCart == snp125ColorSourceLocType) colorSourceCart = SNP125_DEFAULT_COLOR_SOURCE; switch (colorSourceCart) { - int funcArraySize, excArraySize; + int funcArraySize, excArraySize, molTypeArraySize; case snp125ColorSourceLocType: snp125PrintColorSpec(tdb->track, "locType", snp125LocTypeOldColorVars, TRUE, snp125LocTypeLabels, snp125LocTypeDefault, snp125LocTypeArraySize); break; case snp125ColorSourceClass: snp125PrintColorSpec(tdb->track, "class", snp125ClassOldColorVars, TRUE, snp125ClassLabels, snp125ClassDefault, snp125ClassArraySize); break; case snp125ColorSourceValid: snp125PrintColorSpec(tdb->track, "valid", snp125ValidOldColorVars, TRUE, snp125ValidLabels, snp125ValidDefault, snp125ValidArraySize); break; case snp125ColorSourceFunc: funcArraySize = (version < 130) ? snp125FuncArraySize : (snp125FuncArraySize - 1); snp125PrintColorSpec(tdb->track, "func", snp125FuncOldColorVars, TRUE, snp125FuncLabels, snp125FuncDefault, funcArraySize); break; case snp125ColorSourceMolType: + molTypeArraySize = snp125MolTypeArraySize; + if (! molTypeHasMito) + molTypeArraySize--; snp125PrintColorSpec(tdb->track, "molType", snp125MolTypeOldColorVars, TRUE, - snp125MolTypeLabels, snp125MolTypeDefault, - snp125MolTypeArraySize); + snp125MolTypeLabels, snp125MolTypeDefault, molTypeArraySize); break; case snp125ColorSourceExceptions: excArraySize = snp132ExceptionArraySize; if (version < 135) excArraySize -= 2; snp125PrintColorSpec(tdb->track, "exceptions", snp132ExceptionVarName, FALSE, snp132ExceptionLabels, snp132ExceptionDefault, excArraySize); break; case snp125ColorSourceBitfields: snp125PrintColorSpec(tdb->track, "bitfields", snp132BitfieldVarName, FALSE, snp132BitfieldLabels, snp132BitfieldDefault, snp132BitfieldArraySize); break; case snp125ColorSourceAlleleFreq: printf("<P>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.</P>"); break; default: errAbort("Unrecognized value of enum snp125ColorSource (%d)", colorSourceCart); } jsEndCollapsibleSection(); } +boolean snp125CheckMolTypeForMito(struct trackDb *tdb) +/* Can't use version to determine whether the molType enum includes "mito" -- + * check SQL column def. */ +{ +boolean gotMito = FALSE; +struct sqlConnection *conn = hAllocConn(database); +char **enumVals = sqlGetEnumDef(conn, tdb->table, "molType"); +while (*enumVals != NULL && !gotMito) + { + if (sameString(*enumVals, "mito")) + gotMito = TRUE; + enumVals++; + } +hFreeConn(&conn); +return gotMito; +} + 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)) { printf("<BR><B>Include Chimp state and observed human alleles in name: </B> "); safef(cartVar, sizeof(cartVar), "%s.extendedNames", tdb->track); snp125ExtendedNames = cartUsualBoolean(cart, cartVar, // Check old cart var name for backwards compatibility w/ old sessions: cartUsualBoolean(cart, "snp125ExtendedNames", FALSE)); cgiMakeCheckBox(cartVar, snp125ExtendedNames); printf("<BR>(If enabled, chimp allele is displayed first, then '>', then human alleles)."); printf("<BR><BR>\n"); } else puts("<BR>"); // Make wrapper table for collapsible sections: puts("<TABLE border=0 cellspacing=0 cellpadding=0>"); snp125OfferGeneTracksForFunction(tdb); +boolean molTypeHasMito = snp125CheckMolTypeForMito(tdb); + puts("<TR><TD colspan=2><BR></TD></TR>"); -snp125PrintFilterControlSection(tdb, version); +snp125PrintFilterControlSection(tdb, version, molTypeHasMito); puts("<TR><TD colspan=2><BR></TD></TR>"); -snp125PrintColorControlSection(tdb, version); +snp125PrintColorControlSection(tdb, version, molTypeHasMito); // End wrapper table for collapsible sections: puts("</TABLE>"); } void snpUi(struct trackDb *tdb) /* Put up UI snp data. */ { int snpSource = 0; int snpMolType = 0; int snpClass = 0; int snpValid = 0; int snpFunc = 0; int snpLocType = 0; /* It would be nice to add a 'reset' button here to reset the snp