be6fe9e15b29b963f5e32280821368f60c7957e2
angie
  Fri Aug 31 16:11:02 2018 -0700
Check range of -bedPlus argument, errAbort if out of range.  refs #22004

diff --git src/hg/liftOver/liftOver.c src/hg/liftOver/liftOver.c
index e48e7d1..8bb41a6 100644
--- src/hg/liftOver/liftOver.c
+++ src/hg/liftOver/liftOver.c
@@ -63,31 +63,31 @@
   "***********************************************************************\n"
   "WARNING: liftOver was only designed to work between different\n"
   "         assemblies of the same organism. It may not do what you want\n"
   "         if you are lifting between different organisms. If there has\n"
   "         been a rearrangement in one of the species, the size of the\n"
   "         region being mapped may change dramatically after mapping.\n"
   "***********************************************************************\n\n"
   "options:\n"
   "   -minMatch=0.N Minimum ratio of bases that must remap. Default %3.2f\n"
   "   -gff  File is in gff/gtf format.  Note that the gff lines are converted\n"
   "         separately.  It would be good to have a separate check after this\n"
   "         that the lines that make up a gene model still make a plausible gene\n"
   "         after liftOver\n"
   "   -genePred - File is in genePred format\n"
   "   -sample - File is in sample format\n"
-  "   -bedPlus=N - File is bed N+ format\n"
+  "   -bedPlus=N - File is bed N+ format (i.e. first N fields conform to bed format)\n"
   "   -positions - File is in browser \"position\" format\n"
   "   -hasBin - File has bin value (used only with -bedPlus)\n"
   "   -tab - Separate by tabs rather than space (used only with -bedPlus)\n"
   "   -pslT - File is in psl format, map target side only\n"
   "   -ends=N - Lift the first and last N bases of each record and combine the\n"
   "             result. This is useful for lifting large regions like BAC end pairs.\n" 
   "   -minBlocks=0.N Minimum ratio of alignment blocks or exons that must map\n"
   "                  (default %3.2f)\n"
   "   -fudgeThick    (bed 12 or 12+ only) If thickStart/thickEnd is not mapped,\n"
   "                  use the closest mapped base.  Recommended if using \n"
   "                  -minBlocks.\n"
   "   -multiple               Allow multiple output regions\n"
   "   -noSerial               In -multiple mode, do not put a serial number in the 5th BED column\n"
   "   -minChainT, -minChainQ  Minimum chain size in target/query, when mapping\n" 
   "                           to multiple output regions (default 0, 0)\n"
@@ -170,30 +170,35 @@
 minMatch = optionFloat("minMatch", minMatch);
 minBlocks = optionFloat("minBlocks", minBlocks);
 fudgeThick = optionExists("fudgeThick");
 multiple = optionExists("multiple");
 noSerial = optionExists("noSerial");
 if ((!multiple) && (optionExists("minSizeT")  || optionExists("minSizeQ") ||
 		    optionExists("minChainT") || optionExists("minChainQ") ||
 		    optionExists("chainTable") || optionExists("noSerial")))
     errAbort("minSizeT/Q, minChainT/Q, noSerial and chainTable can only be used with -multiple.");
 if (optionExists("minSizeT") && optionExists("minChainT"))
     errAbort("minSizeT is currently a deprecated synonym for minChainT. Can't set both.");
 minSizeT = optionInt("minSizeT", minChainT); /* note: we're setting minChainT */
 minSizeQ = optionInt("minSizeQ", minSizeQ);
 minChainT = optionInt("minChainT", minChainT);
 minChainQ = optionInt("minChainQ", minChainQ);
+if (optionExists("bedPlus"))
+    {
     bedPlus = optionInt("bedPlus", bedPlus);
+    if (bedPlus < 3 || bedPlus > 15)
+        errAbort("-bedPlus=%d is out of range -- BED has between 3 and 15 fields.", bedPlus);
+    }
 ends = optionInt("ends", ends);
 hasBin = optionExists("hasBin");
 tabSep = optionExists("tab") || optionExists("tabSep");
 if ((hasBin || tabSep) && !bedPlus)
     usage();
 chainTable = optionVal("chainTable", chainTable);
 if (optionExists("errorHelp"))
     errAbort("%s", liftOverErrHelp());
 if (argc != 5)
     usage();
 liftOver(argv[1], argv[2], minMatch, minBlocks, minSizeT, minSizeQ, 
 	 minChainT, minChainQ, multiple, noSerial, chainTable, argv[3], argv[4]);
 return 0;
 }