src/hg/utils/automation/Encode.pm 1.36

1.36 2009/03/22 02:38:12 larrym
refactor openUtil from doEncodeValidate.pl
Index: src/hg/utils/automation/Encode.pm
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/utils/automation/Encode.pm,v
retrieving revision 1.35
retrieving revision 1.36
diff -b -B -U 4 -r1.35 -r1.36
--- src/hg/utils/automation/Encode.pm	7 Mar 2009 22:59:58 -0000	1.35
+++ src/hg/utils/automation/Encode.pm	22 Mar 2009 02:38:12 -0000	1.36
@@ -11,8 +11,9 @@
 use warnings;
 use strict;
 
 use File::stat;
+use IO::File;
 use Cwd;
 
 use RAFile;
 use HgAutomate;
@@ -423,5 +424,20 @@
     my ($str) = @_;
     return lc($str) eq 'control' || lc($str) eq 'input';
 }
 
+sub openUtil
+{
+# Handles opening gzipped, tar gzipped, tar, as well as plain files
+# $path is the optional path of $file.
+    my ($file, $path) = @_;
+    my $fh = new IO::File;
+    my $filePath = defined($path) ? "$path/$file" : $file;
+    open($fh, Encode::isTar($filePath) ? "/bin/tar -Oxf $filePath |"
+	      : ( Encode::isTarZipped($filePath) ? "/bin/tar -Ozxf $filePath |"
+	          : ( Encode::isZipped($filePath) ? "/bin/gunzip -c $filePath |"
+		      : $filePath ))
+	) or die "Couldn't open file '$file'; error: $!\n";
+    return $fh;
+}
+
 1;