ab4c9a8a3f243d64d5c2f02ea3e1ec48dececfe4
angie
  Wed Dec 7 23:00:47 2011 -0800
Fixing some dumb non-reentrant code that caused a race condition whenmultiple VCF tracks are translating VCF to pgSnp in different threads.
This led to a sporadic error reported by Greg and caught in a session
by Brooke in #2823 (VCF track handler, notes 12 & 14).

diff --git src/hg/lib/pgSnp.c src/hg/lib/pgSnp.c
index f54fadf..1283a52 100644
--- src/hg/lib/pgSnp.c
+++ src/hg/lib/pgSnp.c
@@ -760,35 +760,31 @@
 	alCounts[gt->hapIxA]++;
 	if (! gt->isHaploid)
 	    alCounts[gt->hapIxB]++;
 	}
     dyStringPrintf(dy, "%d", alCounts[0]);
     for (i = 1;  i < alDescCount;  i++)
 	dyStringPrintf(dy, ",%d", alCounts[i]);
     }
 return cloneStringZ(dy->string, dy->stringSize+1);
 }
 
 struct pgSnp *pgSnpFromVcfRecord(struct vcfRecord *rec)
 /* Convert VCF rec to pgSnp; don't free rec->file (vcfFile) until
  * you're done with pgSnp because pgSnp points to rec->chrom. */
 {
-static struct dyString *dy = NULL;
-if (dy == NULL)
-    dy = dyStringNew(0);
-else
-    dyStringClear(dy);
+struct dyString *dy = dyStringNew(0);
 struct pgSnp *pgs;
 AllocVar(pgs);
 pgs->chrom = rec->chrom;
 pgs->chromStart = rec->chromStart;
 pgs->chromEnd = rec->chromEnd;
 // Build up slash-separated allele string from rec->alleles, starting with ref allele:
 dyStringAppend(dy, rec->alleles[0]);
 int alCount = rec->alleleCount, i;
 if (rec->alleleCount == 2 && sameString(rec->alleles[1], "."))
     // ignore N/A alternate allele
     alCount = 1;
 else if (rec->alleleCount >= 2)
     {
     // append /-sep'd alternate alleles, unless/until it gets too long:
     for (i = 1;  i < rec->alleleCount;  i++)
@@ -804,19 +800,19 @@
 pgs->alleleCount = alCount;
 pgs->alleleFreq = alleleCountsFromVcfRecord(rec, alCount);
 // Build up comma-sep list... supposed to be per-allele quality scores but I think
 // the VCF spec only gives us one BQ... for the reference position?  should ask.
 dyStringClear(dy);
 for (i = 0;  i < rec->infoCount;  i++)
     if (sameString(rec->infoElements[i].key, "BQ"))
 	{
 	float qual = rec->infoElements[i].values[0].datFloat;
 	dyStringPrintf(dy, "%.1f", qual);
 	int j;
 	for (j = 1;  j < rec->alleleCount;  j++)
 	    dyStringPrintf(dy, ",%.1f", qual);
 	break;
 	}
-pgs->alleleScores = cloneStringZ(dy->string, dy->stringSize+1);
+pgs->alleleScores = dyStringCannibalize(&dy);
 return pgs;
 }