From bb8bde10a78fa8fe9a2ce5620788beb3ee5226f0 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Sat, 6 Jun 2009 17:27:31 +0000 Subject: [PATCH] fixes done to tmp_dir git-svn-id: http://biopieces.googlecode.com/svn/trunk@489 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/assemble_tag_contigs | 2 - bp_bin/blast_seq | 2 - bp_bin/blat_seq | 2 - bp_bin/calc_fixedstep | 2 - bp_bin/count_vals | 2 - bp_bin/get_genome_align | 3 -- bp_bin/match_seq | 3 -- bp_bin/merge_records | 2 - bp_bin/patscan_seq | 9 ++-- bp_bin/plot_matches | 2 - bp_bin/plot_phastcons_profiles | 2 - bp_bin/random_records | 1 - bp_bin/soap_seq | 2 - bp_bin/upload_to_ucsc | 2 - bp_bin/write_2bit | 2 - code_perl/Maasha/Biopieces.pm | 81 ++++++++++++++++++++++++---------- 16 files changed, 62 insertions(+), 57 deletions(-) diff --git a/bp_bin/assemble_tag_contigs b/bp_bin/assemble_tag_contigs index 9236586..06f4110 100755 --- a/bp_bin/assemble_tag_contigs +++ b/bp_bin/assemble_tag_contigs @@ -91,8 +91,6 @@ foreach $chr ( sort keys %{ $file_hash } ) unlink $tag_file; } -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/blast_seq b/bp_bin/blast_seq index 2d06389..00270a3 100755 --- a/bp_bin/blast_seq +++ b/bp_bin/blast_seq @@ -139,8 +139,6 @@ close $fh_out; unlink $tmp_out; -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/blat_seq b/bp_bin/blat_seq index 4f68e0e..e7dbc3a 100755 --- a/bp_bin/blat_seq +++ b/bp_bin/blat_seq @@ -103,8 +103,6 @@ while ( $entry = Maasha::UCSC::PSL::psl_entry_get( $fh_in ) ) close $fh_in; unlink $result_file; -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/calc_fixedstep b/bp_bin/calc_fixedstep index 27cae9f..08f673e 100755 --- a/bp_bin/calc_fixedstep +++ b/bp_bin/calc_fixedstep @@ -93,8 +93,6 @@ foreach $chr ( sort keys %{ $file_hash } ) unlink $fixedstep_file; } -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/count_vals b/bp_bin/count_vals index 7f0fe50..fdd10a2 100755 --- a/bp_bin/count_vals +++ b/bp_bin/count_vals @@ -105,8 +105,6 @@ foreach $record ( @records ) unlink $tmp_file; -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/get_genome_align b/bp_bin/get_genome_align index b1e5c1d..07876b5 100755 --- a/bp_bin/get_genome_align +++ b/bp_bin/get_genome_align @@ -30,7 +30,6 @@ use strict; use Maasha::Biopieces; use Maasha::Common; use Maasha::UCSC; -use Maasha::Filesys; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @@ -117,8 +116,6 @@ while ( $record = Maasha::Biopieces::get_record( $in ) ) $align_num++; } -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/match_seq b/bp_bin/match_seq index b418f3c..0900097 100755 --- a/bp_bin/match_seq +++ b/bp_bin/match_seq @@ -29,7 +29,6 @@ use strict; use Maasha::Biopieces; use Maasha::Match; -use Maasha::Filesys; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @@ -71,8 +70,6 @@ elsif ( @entries == 2 ) map { Maasha::Biopieces::put_record( $_, $out ) } @{ $results }; } -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/merge_records b/bp_bin/merge_records index ad0d06e..7b33bc1 100755 --- a/bp_bin/merge_records +++ b/bp_bin/merge_records @@ -201,8 +201,6 @@ if ( $num2 > 0 and $options->{ 'merge' } =~ /^(BorA|BnotA)$/ ) Maasha::Biopieces::put_record( $record, $out ); } -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/patscan_seq b/bp_bin/patscan_seq index d6b9c1b..611481c 100755 --- a/bp_bin/patscan_seq +++ b/bp_bin/patscan_seq @@ -28,6 +28,7 @@ use strict; use Maasha::Biopieces; +use Maasha::Common; use Maasha::Fasta; use Maasha::Filesys; use Maasha::Patscan; @@ -41,8 +42,8 @@ use constant { # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $options, $in, $out, $record, @args, $arg, $type, $tmp_dir, - $seq_file, $pat_file, $out_file, $fh_in, $fh_out, $patterns, $pattern, $entry, $result, %head_hash, $i ); +my ( $options, $in, $out, $record, @args, $arg, $type, $tmp_dir, $seq_file, $pat_file, $out_file, + $fh_in, $fh_out, $patterns, $pattern, $entry, $result, %head_hash, $i ); $options = Maasha::Biopieces::parse_options( [ @@ -104,7 +105,7 @@ foreach $pattern ( @{ $patterns } ) pat_write( $pat_file, $pattern ); `scan_for_matches $arg $pat_file < $seq_file > $out_file`; - # Maasha::Common::run( "scan_for_matches", "$arg $pat_file < $seq_file > $out_file" ); +# Maasha::Common::run( "scan_for_matches", "$arg $pat_file < $seq_file > $out_file" ); $fh_in = Maasha::Filesys::file_read_open( $out_file ); @@ -137,8 +138,6 @@ unlink $pat_file; unlink $out_file; unlink $seq_file if not $options->{ 'genome' }; -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/plot_matches b/bp_bin/plot_matches index 9bdb087..cc6a345 100755 --- a/bp_bin/plot_matches +++ b/bp_bin/plot_matches @@ -78,8 +78,6 @@ print $fh "$_\n" foreach @{ $result }; close $fh; -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/plot_phastcons_profiles b/bp_bin/plot_phastcons_profiles index b1af87b..d50b0bb 100755 --- a/bp_bin/plot_phastcons_profiles +++ b/bp_bin/plot_phastcons_profiles @@ -99,8 +99,6 @@ print $fh "$_\n" foreach @{ $plot }; close $fh; -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/random_records b/bp_bin/random_records index 83ac80d..af0b8fc 100755 --- a/bp_bin/random_records +++ b/bp_bin/random_records @@ -96,7 +96,6 @@ while ( $record = Maasha::Biopieces::get_record( $fh_in ) ) close $fh_in; unlink $tmp_file; -Maasha::Filesys::dir_remove( $tmp_dir ); Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/soap_seq b/bp_bin/soap_seq index 7adb6a9..ffe9b57 100755 --- a/bp_bin/soap_seq +++ b/bp_bin/soap_seq @@ -124,8 +124,6 @@ if ( $count > 0 ) unlink $tmp_out; -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/upload_to_ucsc b/bp_bin/upload_to_ucsc index 25c3103..69a4c3e 100755 --- a/bp_bin/upload_to_ucsc +++ b/bp_bin/upload_to_ucsc @@ -226,8 +226,6 @@ unlink $file; Maasha::UCSC::ucsc_update_config( $options, $type ); -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/bp_bin/write_2bit b/bp_bin/write_2bit index 3929bba..bea78f3 100755 --- a/bp_bin/write_2bit +++ b/bp_bin/write_2bit @@ -82,8 +82,6 @@ close $fh_out; unlink $tmp_file; -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out ); diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index 414c630..98e5f22 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -76,7 +76,19 @@ sub status_set sub status_log { - my ( $time0, $time1, $script, $user, $pid, $file, $fh, $elap, $fh_global, $fh_local, $line, $args ); + # Martin A. Hansen, June 2009. + + # Retrieves initial status information written with status_set and uses this + # to write a status entry to the log file. + + my ( $status, # status - OPTIONAL + ) = @_; + + # Returns nothing. + + my ( $time0, $time1, $script, $user, $pid, $file, $fh, $elap, $fh_global, $fh_local, $line, $args, $tmp_dir ); + + $status ||= "OK"; $time1 = Maasha::Common::time_stamp(); $user = Maasha::Common::get_user(); @@ -84,6 +96,9 @@ sub status_log $pid = Maasha::Common::get_processid(); $file = "$ENV{ 'BP_TMP' }/" . join( ".", $user, $script, $pid ) . ".status"; + + return if not -f $file; + $fh = Maasha::Filesys::file_read_open( $file ); $line = <$fh>; chomp $line; @@ -91,15 +106,17 @@ sub status_log unlink $file; - ( $time0, $args ) = split /;/, $line; + ( $time0, $args, $tmp_dir ) = split /;/, $line; + + Maasha::Filesys::dir_remove( $tmp_dir ); $elap = Maasha::Common::time_stamp_diff( $time0, $time1 ); $fh_global = Maasha::Filesys::file_append_open( "$ENV{ 'BP_LOG' }/biopieces.log" ); $fh_local = Maasha::Filesys::file_append_open( "$ENV{ 'HOME' }/.biopieces.log" ); - print $fh_global join( "\t", $time0, $time1, $elap, $user, $script, $args ) . "\n"; - print $fh_local join( "\t", $time0, $time1, $elap, $user, "$script $args" ) . "\n"; + print $fh_global join( "\t", $time0, $time1, $elap, $user, $status, "$script $args" ) . "\n"; + print $fh_local join( "\t", $time0, $time1, $elap, $user, $status, "$script $args" ) . "\n"; $fh_global->autoflush( 1 ); $fh_local->autoflush( 1 ); @@ -717,21 +734,29 @@ sub sig_handler sleep 1; -# if ( -d $BP_TMP ) + if ( $sig =~ /MAASHA_ERROR/ ) { - if ( $sig =~ /MAASHA_ERROR/ ) { - print STDERR "\nProgram '$script' had an error" . " - Please wait for temporary data to be removed\n"; - } elsif ( $sig eq "INT" ) { - print STDERR "\nProgram '$script' interrupted (ctrl-c was pressed)" . " - Please wait for temporary data to be removed\n"; - } elsif ( $sig eq "TERM" ) { - print STDERR "\nProgram '$script' terminated (someone used kill?)" . " - Please wait for temporary data to be removed\n"; - } else { - print STDERR "\nProgram '$script' died->$sig" . " - Please wait for temporary data to be removed\n"; - } - - clean_tmp(); + print STDERR "\nProgram '$script' had an error" . " - Please wait for temporary data to be removed\n"; + status_log( "ERROR" ); + } + elsif ( $sig eq "INT" ) + { + print STDERR "\nProgram '$script' interrupted (ctrl-c was pressed)" . " - Please wait for temporary data to be removed\n"; + status_log( "INTERUPTED" ); + } + elsif ( $sig eq "TERM" ) + { + print STDERR "\nProgram '$script' terminated (someone used kill?)" . " - Please wait for temporary data to be removed\n"; + status_log( "TERMINATED" ); + } + else + { + print STDERR "\nProgram '$script' died->$sig" . " - Please wait for temporary data to be removed\n"; + status_log( "DIED" ); } + clean_tmp(); + exit( 0 ); } @@ -817,22 +842,32 @@ sub get_tmpdir # Martin A. Hansen, April 2008. # Create a temporary directory based on - # $ENV{ 'BP_TMP' } and sessionid. - - # this thing is a really bad solution and needs to be removed. + # $ENV{ 'BP_TMP' } and sessionid. The directory + # name is written to the status file. # Returns a path. - my ( $user, $sid, $pid, $path ); + my ( $user, $sid, $pid, $script, $path, $file, $fh, $line ); Maasha::Common::error( qq(no BP_TMP set in %ENV) ) if not -d $ENV{ 'BP_TMP' }; - $user = Maasha::Common::get_user(); - $sid = Maasha::Common::get_sessionid(); - $pid = Maasha::Common::get_processid(); + $user = Maasha::Common::get_user(); + $sid = Maasha::Common::get_sessionid(); + $pid = Maasha::Common::get_processid(); + $script = Maasha::Common::get_scriptname(); $path = "$ENV{ 'BP_TMP' }/" . join( "_", $user, $sid, $pid, "bp_tmp" ); + $file = "$ENV{ 'BP_TMP' }/" . join( ".", $user, $script, $pid ) . ".status"; + $fh = Maasha::Filesys::file_read_open( $file ); + $line = <$fh>; + chomp $line; + close $fh; + + $fh = Maasha::Filesys::file_write_open( $file ); + print $fh "$line;$path\n"; + close $fh; + Maasha::Filesys::dir_create( $path ); return $path; -- 2.39.5