]> git.donarmstrong.com Git - biopieces.git/commitdiff
fixes done to tmp_dir
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sat, 6 Jun 2009 17:27:31 +0000 (17:27 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sat, 6 Jun 2009 17:27:31 +0000 (17:27 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@489 74ccb610-7750-0410-82ae-013aeee3265d

16 files changed:
bp_bin/assemble_tag_contigs
bp_bin/blast_seq
bp_bin/blat_seq
bp_bin/calc_fixedstep
bp_bin/count_vals
bp_bin/get_genome_align
bp_bin/match_seq
bp_bin/merge_records
bp_bin/patscan_seq
bp_bin/plot_matches
bp_bin/plot_phastcons_profiles
bp_bin/random_records
bp_bin/soap_seq
bp_bin/upload_to_ucsc
bp_bin/write_2bit
code_perl/Maasha/Biopieces.pm

index 9236586f351b7ad6bc999a1ce25fc5de95c5611e..06f4110abbcf635c0e2d5b9b5743fa7fd00b90c5 100755 (executable)
@@ -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 );
 
index 2d06389d45132df3dbf92da07cede06537265bc8..00270a3fa341987110c8a1635a703da37a436fa7 100755 (executable)
@@ -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 );
 
index 4f68e0ebd720912b4ce43becf5c336adeb4ea0c9..e7dbc3a725e2d67b2065157cbcfcbbd34da657f7 100755 (executable)
@@ -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 );
 
index 27cae9f22fb64ca3a247800a5e8f26316d9d3f52..08f673e22eb4cd2a94f56a4723756242d6f2dc97 100755 (executable)
@@ -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 );
 
index 7f0fe503676d1a4bb2105815f14d390b16eacd95..fdd10a20eaa75e32ba91b2bb05aa7987f6c12b4a 100755 (executable)
@@ -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 );
 
index b1e5c1d31a140637b515eb139c36dc6b4b19b173..07876b59838f889432e007864e80ea0a6fb08891 100755 (executable)
@@ -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 );
 
index b418f3c1ff91bb832dab5afa3dffd5ec61983e5c..0900097c8417e596cf6e1710cb43d78a21fbedfd 100755 (executable)
@@ -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 );
 
index ad0d06e435827275e12735650d744a01bbe40ccc..7b33bc1e50e10b7d58479e11001bb03ba92c7a07 100755 (executable)
@@ -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 );
 
index d6b9c1b60322b13824f5a25bc61f0d59d00a8f9b..611481c8123258ae574855c599dcaacf89fa943e 100755 (executable)
@@ -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 );
 
index 9bdb0874693885ffb9ce5bdadfeb991c42ab5ec2..cc6a345ef45e41ed0154fd6e2a74b68344401379 100755 (executable)
@@ -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 );
 
index b1af87bb4f8e2b1325cdd57939e70d7ef37889e6..d50b0bbd480c72942fbf96f6fdf16d4a1e515bc1 100755 (executable)
@@ -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 );
 
index 83ac80d858b8dfb942f6a801c4e683800e18e0bc..af0b8fc8e9a9513e4c91d68aa8d47df09de38f45 100755 (executable)
@@ -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 );
index 7adb6a969e5f91f0a2ddf4738692e1f3343f01ff..ffe9b577a2702ae6eaa2126beaf095cfae55a00e 100755 (executable)
@@ -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 );
 
index 25c310358555e31c72ffab5dd25b0d31736d43ec..69a4c3e4c759529b9a27ac1b8110aad05cffb5d3 100755 (executable)
@@ -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 );
 
index 3929bba7ec509b5a4d48d6e06e9c3829e9653061..bea78f3e5ecd42df18ec49f7c9d2fdc6f0329ab0 100755 (executable)
@@ -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 );
 
index 414c630a44a74763a0943258a32efdc13da2fcbc..98e5f223a2cbc33187c2c85681c685deb6643bfe 100644 (file)
@@ -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;