use strict;
use Maasha::Biopieces;
+use Maasha::Common;
use Maasha::Fasta;
use Maasha::Filesys;
use Maasha::Patscan;
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-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(
[
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 );
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 );
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();
$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;
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 );
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 );
}
# 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;