c85802ccef6bba0d6159c20950a01094e817c56c
angie
  Thu Dec 15 11:15:23 2016 -0800
Add env var UDC_CACHEDIR to override hg.conf udc.cacheDir for command-line use of CGI.  Add -udcCache option to vai.pl using UDC_CACHEDIR.  refs #12216 note-32

diff --git src/hg/utils/vai.pl src/hg/utils/vai.pl
index a7ffece..e5cd4cd 100755
--- src/hg/utils/vai.pl
+++ src/hg/utils/vai.pl
@@ -7,37 +7,39 @@
 # See README in this or parent directory for licensing information.
 
 use Cwd;
 use File::Basename;
 use Getopt::Long;
 use warnings;
 use strict;
 
 # Constants
 my $doQueryParam = "hgva_startQuery";
 
 # Command line option variables with default values
 my $hgVai = '/usr/local/apache/cgi-bin/hgVai';
 my $position = '';
 my $rsId = 0;
+my $udcCache;
 my $debug = '';
 
 # GetOpt option configuration for options that don't directly map to hgva_... CGI params,
 # and references to the corresponding global variables or handlers:
 my %optionConfig = ('hgVai=s' => \$hgVai,
                     'position=s' => \$position,
                     'rsId' => \$rsId,
+                    'udcCache' => \$udcCache,
                     'dry-run|n|debug' => \$debug,
                     'help|h' => sub { usage(0) },
                    );
 
 # Command line options that map directly to hgva_... CGI params, with their default values
 # and descriptions
 my %paramOptions = ( geneTrack => ['refGene', '=track',
                                    'Genome Browser track with transcript predictions'],
                      variantLimit => [10000, '=N',
                                       'Maximum number of variants to process'],
                    );
 
 
 # CGI params and values to be passed to hgVai are collected here:
 my %hgVaiParams = ( $doQueryParam => 'go',
@@ -55,30 +57,32 @@
 add functional effect predictions (e.g. does the variant fall within a
 regulatory region or part of a gene) and other data relevant to function.
 
 input.(...) must be a file or URL containing either variants formatted as VCF
 or pgSnp, or a sequence of dbSNP rs# IDs, optionally compressed by gzip.
 Output is printed to stdout.
 
 options:
   --hgVai=/path/to/hgVai          Path to hgVai executable
                                   (default: $hgVai)
   --position=chrX:N-M             Sequence name, start and end of range to query
                                   (default: genome-wide query)
   --rsId                          Attempt to match dbSNP rs# ID with variant
                                   position at the expense of performance.
                                   (default: don't attempt to match dbSNP rs# ID)
+  --udcCache=/path/to/udcCache    Path to udc cache, overriding hg.conf setting
+                                  (default: use value in hg.conf file)
 EOF
   ;
   foreach my $param (sort keys %paramOptions) {
     my ($default, $optArg, $desc) = @{$paramOptions{$param}};
     print STDERR sprintf("  --%-29s $desc\n%34s(default: $default)\n", $param . $optArg, '');
   }
   print STDERR <<EOF
   -n, --dry-run                   Display hgVai command, but don't execute it
   -h, --help                      Display this message
 EOF
     ;
   exit $status;
 } # usage
 
 
@@ -104,32 +108,32 @@
     # Strip commas and whitespace from position; abort if it doesn't look like a position.
     my $trimmedPos = $position;
     $trimmedPos =~ s/,//g;
     $trimmedPos =~ s/\s//g;
     if ($trimmedPos =~ /^[^:]+(:\d+-\d+)?$/) {
       $position = $trimmedPos;
     } else {
       print STDERR "position argument should be like chrX:N-M (sequence name, colon,\n" .
         "starting base offset, ending base offset), not '$position'\n";
       usage(-1);
     }
   }
 
   my $db = shift @ARGV;
   if (! $db) {
-    print STDERR "Missing first argument db.";
-    usage(-1);
+    # No args -- just show usage.
+    usage(0);
   }
   if ($db !~ /^\w+$/) {
     print STDERR "First argument must be a database identifier.\n";
     usage(-1);
   }
 
   my $inputFile = shift @ARGV;
   if (! $inputFile) {
     print STDERR "Missing second argument inputFile";
     usage(-1);
   }
   if (@ARGV) {
     print STDERR "Please provide only one input file.\n";
     usage(-1);
   }
@@ -268,30 +272,35 @@
     if (-e $joinerFile) {
       $ENV{ALL_JOINER_FILE} = $joinerFile};
   }
 }
 
 # If env var HGDB_CONF is not already set, try to find an hg.conf to set it to.
 if (! $ENV{HGDB_CONF}) {
   if (! -e "hg.conf" && ! -e $ENV{HOME}."/.hg.conf") {
     my $hgConf = "$hgVaiDir/hg.conf";
     if (-e $hgConf) {
       $ENV{HGDB_CONF} = $hgConf;
     }
   }
 }
 
+# If -udcCache arg is given, set env var UDC_CACHEDIR to its value.
+if ($udcCache) {
+  $ENV{UDC_CACHEDIR} = $udcCache;
+}
+
 my @params = map { "$_=" . $hgVaiParams{$_} } keys %hgVaiParams;
 my $command = "$hgVai '" . join('&', @params) . "'";
 if ($debug) {
   print "$command\n";
 } else {
   delete $ENV{HTTP_COOKIE};
   if (! $ENV{JKTRASH}) {
     # If user has not set JKTRASH, but TMPDIR is defined, then use TMPDIR instead of cwd.
     my $tmpDir = $ENV{TMPDIR};
     if ($tmpDir) {
       $ENV{JKTRASH} = $tmpDir;
     }
   }
   exit runHgVai($command);
 }