Skip to content
This repository
Browse code

Hmmer: Prevent errors caused by the presence of whitespace

in paths by adding double quotes if detected before running
the program. Also in Windows NUL is the equivalent of /dev/null
  • Loading branch information...
commit b50b4c8a39aa73869ea11bc34a564000ab794bb7 1 parent e103aec
Francisco J. Ossandon authored December 27, 2013
20  lib/Bio/Tools/Run/Hmmer.pm
@@ -396,8 +396,18 @@ sub _setinput {
396 396
 
397 397
 sub _run {
398 398
     my ($self, $file) = @_;
  399
+
  400
+    # Use double quotes if file path have empty spaces
  401
+    if ($file =~ m/ /) {
  402
+        $file = "\"$file\"";
  403
+    }
399 404
     
400 405
     my $str = $self->executable;
  406
+    # Use double quotes if executable path have empty spaces
  407
+    if ($str =~ m/ /) {
  408
+        $str = "\"$str\"";
  409
+    }
  410
+
401 411
     $str .= $self->_setparams;
402 412
     $str .= ' '.$file if $file;
403 413
     $self->debug("HMMER command = $str");
@@ -409,7 +419,8 @@ sub _run {
409 419
     if ($progname =~ /align|build|emit/) {
410 420
         my $outfile = $self->o;
411 421
         if ($outfile || $progname eq 'hmmbuild') {
412  
-            $str .= " > /dev/null" if $self->quiet;
  422
+            my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
  423
+            $str .= " > $null" if $self->quiet;
413 424
             
414 425
             if ($progname eq 'hmmbuild') {
415 426
                 my $status = system($str);
@@ -444,7 +455,8 @@ sub _run {
444 455
                                -format => 'fasta');
445 456
     }
446 457
     elsif ($progname =~ /calibrate/) {
447  
-        $str .= " > /dev/null 2> /dev/null" if $self->quiet;
  458
+        my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
  459
+        $str .= " > $null 2> $null" if $self->quiet;
448 460
         my $status = system($str);
449 461
         return $status ? 0 : 1;
450 462
     }
@@ -491,6 +503,10 @@ sub _setparams {
491 503
                                                 -mixed_dash => 1);
492 504
     
493 505
     my $hmm = $self->hmm || $self->throw("Need to specify either HMM file or Database");
  506
+    # Use double quotes if hmm path have empty spaces
  507
+    if ($hmm =~ m/ /) {
  508
+        $hmm = "\"$hmm\"";
  509
+    }
494 510
     $param_string .= ' '.$hmm;
495 511
     
496 512
     return $param_string;
4  t/Hmmer.t
@@ -73,7 +73,7 @@ SKIP: {
73 73
         }
74 74
       }
75 75
       
76  
-      isa_ok $feat[0], 'Bio::SeqFeatureI';
  76
+      isa_ok $feat[0], 'Bio::SeqFeatureI';#Bio::Search::HSP::HMMERHSP
77 77
       is ($feat[0]->feature1->start,1);
78 78
       is ($feat[0]->feature1->end,124);
79 79
       is ($feat[0]->feature2->start,25);
@@ -141,4 +141,6 @@ SKIP: {
141 141
       is @seqs, 10; # emits 10 seqs by default
142 142
    }
143 143
 
  144
+   # Delete temporary file
  145
+   unlink($hmmout);
144 146
 }

0 notes on commit b50b4c8

Please sign in to comment.
Something went wrong with that request. Please try again.