8ea61fe719baa254eb7411b93cdd3de71c9cc7f3
angie
Thu Aug 13 13:32:18 2020 -0700
Suppress diploid-specific descriptions when species is not diploid. refs #25409
diff --git src/hg/hgc/vcfClick.c src/hg/hgc/vcfClick.c
index eb6f2b6..a7ad5f3 100644
--- src/hg/hgc/vcfClick.c
+++ src/hg/hgc/vcfClick.c
@@ -247,64 +247,74 @@
}
static void vcfGenotypeTable(struct vcfRecord *rec, char *track, char **displayAls)
/* Put the table containing details about each genotype into a collapsible section. */
{
static struct dyString *tmp1 = NULL;
if (tmp1 == NULL)
tmp1 = dyStringNew(0);
jsBeginCollapsibleSection(cart, track, "genotypes", "Detailed genotypes", FALSE);
dyStringClear(tmp1);
dyStringAppend(tmp1, rec->format);
struct vcfFile *vcff = rec->file;
enum vcfInfoType formatTypes[256];
char *formatKeys[256];
int formatCount = chopString(tmp1->string, ":", formatKeys, ArraySize(formatKeys));
-puts("Genotype info key:
");
+boolean firstInfo = TRUE;
int i;
for (i = 0; i < formatCount; i++)
{
if (sameString(formatKeys[i], vcfGtGenotype))
continue;
+ if (firstInfo)
+ {
+ puts("Genotype info key:
");
+ firstInfo = FALSE;
+ }
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 ? def->type : vcfInfoString;
}
hTableStart();
-puts("
Sample ID | Genotype | Phased? | ");
+boolean isDiploid = sameString(vcfHaplotypeOrSample(cart), "Haplotype");
+puts("
---|
Sample ID | Genotype | ");
+if (isDiploid)
+ puts("Phased? | ");
for (i = 0; i < formatCount; i++)
{
if (sameString(formatKeys[i], vcfGtGenotype))
continue;
printf("%s | ", formatKeys[i]);
}
puts("
\n");
for (i = 0; i < vcff->genotypeCount; i++)
{
struct vcfGenotype *gt = &(rec->genotypes[i]);
char *hapA = ".", *hapB = ".";
if (gt->hapIxA >= 0)
hapA = displayAls[(unsigned char)gt->hapIxA];
if (gt->isHaploid)
hapB = "";
else if (gt->hapIxB >= 0)
hapB = displayAls[(unsigned char)gt->hapIxB];
char sep = gt->isHaploid ? ' ' : gt->isPhased ? '|' : '/';
char *phasing = gt->isHaploid ? NA : gt->isPhased ? "Y" : "n";
- printf("%s | %s%c%s | %s | ", vcff->genotypeIds[i],
- hapA, sep, hapB, phasing);
+ printf("
%s | %s%c%s | ", vcff->genotypeIds[i],
+ hapA, sep, hapB);
+ if (isDiploid)
+ printf("%s | ", phasing);
int j;
for (j = 0; j < gt->infoCount; j++)
{
if (sameString(formatKeys[j], vcfGtGenotype))
continue;
printf("");
struct vcfInfoElement *el = &(gt->infoElements[j]);
int k;
for (k = 0; k < el->count; k++)
{
if (k > 0)
printf(", ");
if (el->missingData[k])
printf(".");
else
@@ -327,38 +337,45 @@
static void vcfGenotypesDetails(struct vcfRecord *rec, struct trackDb *tdb, char **displayAls)
/* Print summary of allele and genotype frequency, plus collapsible section
* with table of genotype details. */
{
struct vcfFile *vcff = rec->file;
if (vcff->genotypeCount == 0)
return;
// Wrapper table for collapsible section:
puts("");
pushWarnHandler(ignoreEm);
vcfParseGenotypes(rec);
popWarnHandler();
int *gtCounts = NULL, *alCounts = NULL;;
int phasedGts = 0, diploidCount = 0;
vcfCountGenotypes(rec, >Counts, &alCounts, &phasedGts, &diploidCount);
+boolean isDiploid = sameString(vcfHaplotypeOrSample(cart), "Haplotype");
+if (isDiploid)
+ {
printf("Genotype count: %d", vcff->genotypeCount);
if (diploidCount == 0)
printf(" (haploid)");
else if (diploidCount != vcff->genotypeCount)
printf(" (%d phased, %d diploid, %d haploid)", phasedGts, diploidCount,
vcff->genotypeCount - diploidCount);
else
printf(" (%d phased)", phasedGts);
+ }
+else
+ printf("Sample count: %d", vcff->genotypeCount);
+
puts(" ");
int totalAlleles = vcff->genotypeCount + diploidCount;
double refAf = (double)alCounts[0]/totalAlleles;
printf("Alleles: %s: %d (%.3f%%)", displayAls[0], alCounts[0], 100*refAf);
int i;
for (i = 1; i < rec->alleleCount; i++)
{
double altAf = (double)alCounts[i]/totalAlleles;
printf("; %s: %d (%.3f%%)", displayAls[i], alCounts[i], 100*altAf);
}
if (alCounts[rec->alleleCount] > 0)
printf("; unknown: %d (%.3f%%)", alCounts[rec->alleleCount],
100 * (double)alCounts[rec->alleleCount]/totalAlleles);
puts(" ");
if (vcff->genotypeCount > 1 && diploidCount > 0)
|