]> git.donarmstrong.com Git - rsem.git/blobdiff - convert-sam-for-rsem
Renamed makefile as Makefile
[rsem.git] / convert-sam-for-rsem
index decf86195f25d65a9cdacddb98d272d25c160df3..812c8b9ca6ce1e295d62752974588a419182b195 100755 (executable)
@@ -1,9 +1,17 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
 
 use Getopt::Long;
 use Pod::Usage;
 use File::Basename;
 use File::Path 'rmtree';
+
+use FindBin;
+use lib $FindBin::RealBin;
+use rsem_perl_utils;
+
+use Env qw(@PATH);
+@PATH = ($FindBin::RealBin, "$FindBin::RealBin/sam", @PATH);
+
 use strict;
 
 my ($in_file, $out_file) = ();
@@ -29,8 +37,6 @@ $suf = lc(substr($suf, 1));
 pod2usage(-msg => "Input file's suffix is neither sam nor bam!", -exitval => 2, -verbose => 2) if (($suf ne "sam") && ($suf ne "bam"));
 my $isSam = ($suf eq "sam");
 
-($fn, $dir, $suf) = fileparse($0);
-
 my $temp_dir = "$out_file.temp";
 if (-d $temp_dir) { print "Warning: $temp_dir exists, convert-sam-for-rsem will write temporary files into this folder and delete it after it finishes!\n"; }
 else {
@@ -43,7 +49,7 @@ my $sam_file;
 
 if (!$isSam) {
     $sam_file = "$temp_dir/input.sam";
-    $command = $dir."sam/samtools view -h -o $sam_file $in_file";
+    $command = "samtools view -h -o $sam_file $in_file";
     &runCommand($command); 
 }
 else {
@@ -66,7 +72,7 @@ $command .= " >> $tmp_sam";
 
 # Phase II, parse the temporary SAM file to make paired-end alignments' two mates adjacent to each other
 
-$command = $dir."rsem-scan-for-paired-end-reads $tmp_sam $out_file";
+$command = "rsem-scan-for-paired-end-reads $tmp_sam $out_file";
 &runCommand($command);
 
 # delete temporary directory
@@ -76,24 +82,9 @@ print STDERR "Conversion is completed. $out_file will be checked by 'rsem-sam-va
 
 # Phase III, validate if the resulting bam file is correct
 
-$command = $dir."rsem-sam-validator $out_file";
+$command = "rsem-sam-validator $out_file";
 &runCommand($command);
 
-
-# command, {err_msg}
-sub runCommand {
-    print $_[0]."\n";
-    my $status = system($_[0]);
-    if ($status != 0) { 
-       my $errmsg;
-       if (scalar(@_) > 1) { $errmsg = $_[1]; }
-       else { $errmsg = "\"$command\" failed! Plase check if you provide correct parameters/options for the pipeline!"; }
-       print $errmsg."\n";
-       exit(-1);
-    }
-    print "\n";
-}
-
 __END__
 
 =head1 NAME
@@ -102,11 +93,7 @@ convert-sam-for-rsem
 
 =head1 SYNOPSIS
 
-=over
-
- convert-sam-for-rsem [options] <input.sam/input.bam> output_file_name
-
-=back
+convert-sam-for-rsem [options] <input.sam/input.bam> output_file_name
 
 =head1 ARGUMENTS