31e329985b6c6aef1cb2f399299ce1deed3ff4c8
angie
Mon Aug 8 16:33:57 2011 -0700
Feature #2823 (VCF track handler): Added summaries of genotype and allele freqs to details page.
diff --git src/hg/hgc/vcfClick.c src/hg/hgc/vcfClick.c
index 00fa4b0..1ad1a7c 100644
--- src/hg/hgc/vcfClick.c
+++ src/hg/hgc/vcfClick.c
@@ -135,39 +135,74 @@
return NULL;
}
static void vcfGenotypesDetails(struct vcfRecord *rec, char *track)
/* Print genotypes in some kind of table... */
{
struct vcfFile *vcff = rec->file;
if (vcff->genotypeCount == 0)
return;
static struct dyString *tmp1 = NULL, *tmp2 = NULL;
if (tmp1 == NULL)
{
tmp1 = dyStringNew(0);
tmp2 = dyStringNew(0);
}
-jsBeginCollapsibleSection(cart, track, "genotypes", "Detailed genotypes", FALSE);
vcfParseGenotypes(rec);
+// Tally genotypes and alleles for summary:
+// Note: this lumps all alternate alleles together.
+int refs = 0, alts = 0, refRefs = 0, refAlts = 0, altAlts = 0, phasedGts = 0;
+int i;
+for (i = 0; i < vcff->genotypeCount; i++)
+ {
+ struct vcfGenotype *gt = &(rec->genotypes[i]);
+ if (gt->isPhased)
+ phasedGts++;
+ if (gt->hapIxA == 0)
+ refs++;
+ else
+ alts++;
+ if (!gt->isHaploid)
+ {
+ if (gt->hapIxB == 0)
+ refs++;
+ else
+ alts++;
+ if (gt->hapIxA == 0 && gt->hapIxB == 0)
+ refRefs++;
+ else if (gt->hapIxA != 0 && gt->hapIxB != 0)
+ altAlts++;
+ else
+ refAlts++;
+ }
+ }
+printf("Genotype count: %d (%d phased)
\n", vcff->genotypeCount, phasedGts);
+printf("Alleles: %s: %d (%.2f); %s: %d (%.2f)
\n",
+ rec->ref, refs, (double)refs/(2*vcff->genotypeCount),
+ rec->alt, alts, (double)alts/(2*vcff->genotypeCount));
+if (vcff->genotypeCount > 1)
+ printf("Genotypes: %s/%s: %d (%.2f); %s/%s: %d (%.2f); %s/%s: %d (%.2f)
\n",
+ rec->ref, rec->ref, refRefs, (double)refRefs/vcff->genotypeCount,
+ rec->ref, rec->alt, refAlts, (double)refAlts/vcff->genotypeCount,
+ rec->alt, rec->alt, altAlts, (double)altAlts/vcff->genotypeCount);
+jsBeginCollapsibleSection(cart, track, "genotypes", "Detailed genotypes", FALSE);
dyStringClear(tmp1);
dyStringAppend(tmp1, rec->format);
enum vcfInfoType formatTypes[256];
char *formatKeys[256];
int formatCount = chopString(tmp1->string, ":", formatKeys, ArraySize(formatKeys));
puts("Genotype info key:
");
-int i;
for (i = 0; i < formatCount; i++)
{
if (sameString(formatKeys[i], vcfGtGenotype))
continue;
const struct vcfInfoDef *def = vcfInfoDefForGtKey(vcff, formatKeys[i]);
char *desc = def ? def->description : "not described in VCF header";
printf(" %s: %s
\n", formatKeys[i], desc);
formatTypes[i] = def->type;
}
hTableStart();
puts("