06d7be056190c14b85e71bc12523f18ea6815b5e
markd
  Mon Dec 7 00:50:29 2020 -0800
BLAT mmap index support merge with master

diff --git src/hg/utils/vcfRenameAndPrune/vcfRenameAndPrune.c src/hg/utils/vcfRenameAndPrune/vcfRenameAndPrune.c
index 04071cf..a43f84b 100644
--- src/hg/utils/vcfRenameAndPrune/vcfRenameAndPrune.c
+++ src/hg/utils/vcfRenameAndPrune/vcfRenameAndPrune.c
@@ -1,34 +1,34 @@
 /* vcfRenameAndPrune - Rename or remove samples from VCF with genotypes. */
 #include "common.h"
 #include "linefile.h"
 #include "hash.h"
 #include "obscure.h"
 #include "options.h"
 #include "vcf.h"
 
 void usage()
 /* Explain usage and exit. */
 {
 errAbort(
   "vcfRenameAndPrune - Rename samples in VCF; if new name not found, remove sample.\n"
   "usage:\n"
-  "   vcfRenameAndPrune vcfIn.vcf[.gz] renaming.tab vcfOut.vcf\n"
+  "   vcfRenameAndPrune vcfIn.vcf[.gz] renaming.txt vcfOut.vcf\n"
 //  "options:\n"
 //  "   -xxx=XXX\n"
-  "renaming.tab has two columns: old name (must uniquely match some sample\n"
-  "named in #CHROM header line) and new name.\n"
+  "renaming.txt has two whitespace-separated columns: old name (must uniquely match\n"
+  "some sample named in #CHROM header line) and new name.\n"
   );
 }
 
 /* Command line validation table. */
 static struct optionSpec options[] = {
    {NULL, 0},
 };
 
 void vcfRenameAndPrune(char *vcfInFile, char *renamingFile, char *vcfOutFile)
 /* vcfRenameAndPrune - Rename or remove samples from VCF with genotypes. */
 {
 struct hash *renaming = hashTwoColumnFile(renamingFile);
 struct lineFile *lf = lineFileOpen(vcfInFile, TRUE);
 FILE *outF = mustOpen(vcfOutFile, "w");
 int headerColCount = 0;
@@ -118,31 +118,37 @@
                     // Alternate allele; if this is the first time we've seen this one, add it to
                     // newAlts.
                     int oldAltIx = alIx - 1;
                     int newAltIx = altIxOldToNew[oldAltIx];
                     if (newAltIx < 0)
                         {
                         newAltIx = newAltCount++;
                         newAlts[newAltIx] = alts[oldAltIx];
                         newAltCounts[newAltIx] = 1;
                         altIxOldToNew[oldAltIx] = newAltIx;
                         }
                     else
                         newAltCounts[newAltIx]++;
                     // Update gt, i.e. words[keeperColumns[i]], with the new allele index.
                     int newAlIx = newAltIx + 1;
-                    safef(gt, strlen(gt)+1, "%d", newAlIx);
+                    char newGt[16];
+                    safef(newGt, sizeof newGt, "%d", newAlIx);
+                    if (strlen(newGt) <= strlen(gt))
+                        safecpy(gt, strlen(gt)+1, newGt);
+                    else
+                        // Extremely rare: single-digit ix to double-digit ix.  Leak a little mem.
+                        words[keeperColumns[i]] = cloneString(newGt);
                     }
                 }
             }
         if (newAltCount > 0)
             {
             // Write out line with updated alts, info, genotype columns
             fprintf(outF, "%s\t%s\t%s\t%s\t%s", words[0], words[1], words[2], words[3],
                     newAlts[0]);
             for (i = 1;  i < newAltCount;  i++)
                 fprintf(outF, ",%s", newAlts[i]);
             fprintf(outF, "\t%s\t%s\tAC=%d", words[5], words[6], newAltCounts[0]);
             for (i = 1;  i < newAltCount;  i++)
                 fprintf(outF, ",%d", newAltCounts[i]);
             fprintf(outF, ";AN=%d\tGT", totalCalls);
             for (i = 0;  i < keeperCount;  i++)