From 598974ae103b3edc99208cdd0c4b22e1a0be086f Mon Sep 17 00:00:00 2001 From: ebanks Date: Wed, 16 Sep 2009 19:02:46 +0000 Subject: [PATCH] perl script to make batching jobs easier git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1638 348d0f76-0448-11de-a6fe-93d51630548a --- perl/batchGATKjobsWithRegExp.pl | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 perl/batchGATKjobsWithRegExp.pl diff --git a/perl/batchGATKjobsWithRegExp.pl b/perl/batchGATKjobsWithRegExp.pl new file mode 100755 index 000000000..d17597d99 --- /dev/null +++ b/perl/batchGATKjobsWithRegExp.pl @@ -0,0 +1,57 @@ +#!/usr/bin/perl -w + +# Runs a given (GATK) command as specified, except that a single '*' +# in the -I argument field is replaced with the appropriate shell +# expansion and all other instances of the '*' in other arguments are +# replaced with the correct expansion accordingly. +# IMPORTANT: remember to surround your command with quotes (\"\") so +# that the shell doesn't try to expand out your regular expression! + +use strict; +use Getopt::Long; + +my $dry; +my $inArg = "I"; +GetOptions( "dry!" => \$dry, + "inArg=s" => \$inArg); + +if (scalar(@ARGV) != 1) { + print "Usage: batchGATKjobsWithRegExp\n\t[-inArg ]\n\t[-dry]\n\t\"GATK command\"\n"; + exit(1); +} + +my @args = split(/ /, $ARGV[0]); +chomp(@args); + +my $argcount = scalar(@args); +my $IargIdx = undef; +for (my $i = 0; $i < $argcount; $i++) { + if ($args[$i] eq "-$inArg") { + $IargIdx = $i + 1; + } +} +my $Iarg = "$args[$IargIdx]\n"; +if ($Iarg =~ m/(.*),(.*),(.*)/) { + $Iarg = $3; +} +my @matches = glob($Iarg); +$Iarg =~ s/\*/(.*)/; +chomp($Iarg); + +foreach my $match (@matches) { + $match =~ m/$Iarg/; + my $piece = $1; + + my $cmd = ""; + for (my $i = 0; $i < $argcount; $i++) { + my $arg = $args[$i]; + $arg =~ s/\*/$piece/; + $cmd .= "$arg "; + } + + if ($dry) { + print "$cmd\n"; + } else { + system($cmd); + } +}