]> git.donarmstrong.com Git - biopieces.git/commitdiff
fixed zero entry tmp file bug in soap_seq
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 25 Jul 2008 05:00:01 +0000 (05:00 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 25 Jul 2008 05:00:01 +0000 (05:00 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@196 74ccb610-7750-0410-82ae-013aeee3265d

code_perl/Maasha/Biopieces.pm

index 372c2699551a2ff17756da289dc98e11434b0e79..b57f279213dc98c3c105142e192e889b18b54cec 100644 (file)
@@ -3581,24 +3581,31 @@ sub script_soap_seq
 
     # Returns nothing.
 
-    my ( $genome, $tmp_in, $tmp_out, $fh_in, $fh_out, $record, $line, @fields, $entry );
+    my ( $genome, $tmp_in, $tmp_out, $fh_in, $fh_out, $record, $line, @fields, $entry, $count, $args );
 
     $options->{ "seed_size" }  ||= 10;
     $options->{ "mismatches" } ||= 2;
     $options->{ "gap_size" }   ||= 0;
     $options->{ "cpus" }       ||= 1;
 
-    $options->{ "in_file" } = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/fasta/$options->{ 'genome' }.fna" if $options->{ 'genome' };
+    if ( $options->{ "genome" } ) {
+        $options->{ "in_file" } = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/fasta/$options->{ 'genome' }.fna";
+    }
 
     $tmp_in  = "$BP_TMP/soap_query.seq";
     $tmp_out = "$BP_TMP/soap.result";
 
     $fh_out = Maasha::Common::write_open( $tmp_in );
+    $count = 0;
 
     while ( $record = get_record( $in ) ) 
     {
-        if ( $entry = record2fasta( $record ) ) {
+        if ( $entry = record2fasta( $record ) )
+        {
             Maasha::Fasta::put_entry( $entry, $fh_out );
+
+            $count++;
         }
 
         put_record( $record, $out );
@@ -3606,32 +3613,48 @@ sub script_soap_seq
 
     close $fh_out;
 
-    Maasha::Common::run( "soap", "-s $options->{ 'seed_size' } -r 2 -a $tmp_in -v $options->{ 'mismatches' } -g $options->{ 'gap_size' } -p $options->{ 'cpus' } -d $options->{ 'in_file' } -o $tmp_out > /dev/null 2>&1", 1 );
+    if ( $count > 0 )
+    {
+        $args = join( " ",
+            "-s $options->{ 'seed_size' }",
+            "-r 2",
+            "-a $tmp_in",
+            "-v $options->{ 'mismatches' }",
+            "-g $options->{ 'gap_size' }",
+            "-p $options->{ 'cpus' }",
+            "-d $options->{ 'in_file' }",
+            "-o $tmp_out",
+        );
 
-    unlink $tmp_in;
+        $args .= " > /dev/null 2>&1" if not $options->{ 'verbose' };
 
-    $fh_out = Maasha::Common::read_open( $tmp_out );
+        Maasha::Common::run( "soap", $args, 1 );
 
-    undef $record;
+        unlink $tmp_in;
 
-    while ( $line = <$fh_out> )
-    {
-        chomp $line;
+        $fh_out = Maasha::Common::read_open( $tmp_out );
 
-        @fields = split /\t/, $line;
+        undef $record;
 
-        $record->{ "REC_TYPE" }   = "SOAP";
-        $record->{ "Q_ID" }       = $fields[ 0 ];
-        $record->{ "SCORE" }      = $fields[ 3 ];
-        $record->{ "STRAND" }     = $fields[ 6 ];
-        $record->{ "S_ID" }       = $fields[ 7 ];
-        $record->{ "S_BEG" }      = $fields[ 8 ] - 1; # soap is 1-based
-        $record->{ "S_END" }      = $fields[ 8 ] + $fields[ 5 ] - 2;
+        while ( $line = <$fh_out> )
+        {
+            chomp $line;
 
-        put_record( $record, $out );
-    }
+            @fields = split /\t/, $line;
 
-    close $fh_out;
+            $record->{ "REC_TYPE" }   = "SOAP";
+            $record->{ "Q_ID" }       = $fields[ 0 ];
+            $record->{ "SCORE" }      = $fields[ 3 ];
+            $record->{ "STRAND" }     = $fields[ 6 ];
+            $record->{ "S_ID" }       = $fields[ 7 ];
+            $record->{ "S_BEG" }      = $fields[ 8 ] - 1; # soap is 1-based
+            $record->{ "S_END" }      = $fields[ 8 ] + $fields[ 5 ] - 2;
+
+            put_record( $record, $out );
+        }
+
+        close $fh_out;
+    }
 
     unlink $tmp_out;
 }