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/lib/snp125Ui.c src/hg/lib/snp125Ui.c index 05c0a4e..407e9af 100644 --- src/hg/lib/snp125Ui.c +++ src/hg/lib/snp125Ui.c @@ -1,20 +1,20 @@ /* snp125Ui.c - enums & char arrays for snp UI features and shared util code */ #include "snp125Ui.h" +#include "snp125.h" #include "common.h" -static char const rcsid[] = "$Id: snp125Ui.c,v 1.33 2010/05/28 18:48:07 angie Exp $"; char *snp125OrthoTable(struct trackDb *tdb, int *retSpeciesCount) /* Look for a setting that specifies a table with orthologous alleles. * If retSpeciesCount is not null, set it to the number of other species * whose alleles are in the table. Do not free the returned string. */ { char *table = trackDbSetting(tdb, "chimpMacaqueOrthoTable"); int speciesCount = 2; if (table == NULL) { table = trackDbSetting(tdb, "chimpOrangMacOrthoTable"); speciesCount = 3; } if (retSpeciesCount != NULL) *retSpeciesCount = speciesCount; @@ -59,30 +59,31 @@ "Validation", "Function", "Molecule Type", }; int snp128ColorSourceArraySize = ArraySize(snp128ColorSourceLabels); /* As of dbSNP 132, we have some new choices: */ char *snp132ColorSourceLabels[] = { "Class", "Validation", "Function", "Molecule Type", "Unusual Conditions (UCSC)", "Miscellaneous Attributes (dbSNP)", + "Allele Frequencies", }; int snp132ColorSourceArraySize = ArraySize(snp132ColorSourceLabels); /****** MolType related controls *******/ /* Types: unknown, genomic, cDNA */ char *snp125MolTypeLabels[] = { "Unknown", "Genomic", "cDNA", }; char *snp125MolTypeOldColorVars[] = { "snp125MolTypeUnknown", "snp125MolTypeGenomic", @@ -575,15 +576,52 @@ /* Abbreviate an old cart var name -- new name is based on track plus this. Don't free result. */ { char *ptr = oldVar; if (startsWith("snp125", oldVar)) { ptr += strlen("snp125"); char upCaseAttribute[256]; safecpy(upCaseAttribute, sizeof(upCaseAttribute), attribute); upCaseAttribute[0] = toupper(upCaseAttribute[0]); if (startsWith(upCaseAttribute, ptr)) ptr += strlen(upCaseAttribute); } return ptr; } +enum snp125ColorSource snp125ColorSourceFromCart(struct cart *cart, struct trackDb *tdb) +/* Look up color source in cart, keeping backwards compatibility with old cart var names. */ +{ +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)); +int cs = stringArrayIx(colorSourceCart, snp125ColorSourceLabels, snp125ColorSourceArraySize); +int version = snpVersion(tdb->table); +if (version >= 132) + // The enum begins with locType, which is not in the array, so add 1 to enum: + cs = 1 + stringArrayIx(colorSourceCart, snp132ColorSourceLabels, snp132ColorSourceArraySize); +if (cs < 0) + cs = SNP125_DEFAULT_COLOR_SOURCE; +return (enum snp125ColorSource)cs; +} + +char *snp125ColorSourceToLabel(struct trackDb *tdb, enum snp125ColorSource cs) +/* Due to availability of different color sources in several different versions, + * this is not just an array lookup, hence the encapsulation. Don't modify return value. */ +{ +int version = snpVersion(tdb->table); +if (version >= 132) + { + if (cs < 1 || cs >= snp132ColorSourceArraySize+1) + errAbort("Bad color source for build 132 or later (%d)", cs); + return snp132ColorSourceLabels[cs-1]; + } +else + { + if (cs < 0 || cs >= snp125ColorSourceArraySize) + errAbort("Bad color source for build 131 or earlier (%d)", cs); + return snp125ColorSourceLabels[cs]; + } +}