From: martinahansen Date: Fri, 25 Jul 2008 05:00:01 +0000 (+0000) Subject: fixed zero entry tmp file bug in soap_seq X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=d317442d373d2dfdb3971147bdfafdfdc4ee5dc9;hp=8bbe2c1dfb89cb9161e233f3cb23b15823236a91;p=biopieces.git fixed zero entry tmp file bug in soap_seq git-svn-id: http://biopieces.googlecode.com/svn/trunk@196 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index 372c269..b57f279 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -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; }