$options = get_options( $script );
+ $options->{ "SCRIPT" } = $script;
+
if ( $script ne "list_biopieces" and $script ne "list_genomes" ) {
$script = "print_usage" if ( -t STDIN and keys %{ $options } <= 1 or $options->{ 'help' } );
}
close $in if defined $in;
close $out;
-
- # unset status - missing
- # write log file - missing
}
);
# print STDERR Dumper( \@options );
-
+
GetOptions(
\%options,
@options,
);
- $options{ "script" } = $script;
-
# print STDERR Dumper( \%options );
if ( -t STDIN && scalar( keys %options ) == 1 or $options{ "help" } ) {
if ( $options->{ 'data_in' } ) {
$file = $options->{ 'data_in' };
} else {
- $file = join "", $ENV{ 'BP_DIR' }, "/bp_usage/", $options->{ 'script' }, ".wiki";
+ $file = join "", $ENV{ 'BP_DIR' }, "/bp_usage/", $options->{ 'SCRIPT' }, ".wiki";
}
$wiki = Maasha::Gwiki::gwiki_read( $file );
@{ $wiki } = grep { $_->[ 0 ]->{ 'FORMAT' } =~ /paragraph/ } @{ $wiki };
$synopsis = $wiki->[ 0 ]->[ 0 ]->{ 'TEXT' };
+ $synopsis =~ s/!(\w)/$1/g;
printf( "%-30s%s\n", $program, $synopsis );
}
close $fh_out;
- Maasha::Common::run( "soap", "-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 );
+ Maasha::Common::run( "soap", "-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 );
unlink $tmp_in;
$record->{ "SCORE" } = $fields[ 3 ];
$record->{ "STRAND" } = $fields[ 6 ];
$record->{ "S_ID" } = $fields[ 7 ];
- $record->{ "S_BEG" } = $fields[ 8 ] - 1; # soap is one based
+ $record->{ "S_BEG" } = $fields[ 8 ] - 1; # soap is 1-based
$record->{ "S_END" } = $fields[ 8 ] + $fields[ 5 ] - 2;
put_record( $record, $out );
}
-sub get_status
-{
- # Martin A. Hansen, July 2008.
-
- # Gets the first record in the stream, the status record,
- # which is returned. An error is raised if no status record
- # was found.
-
- my ( $fh, # handle to stream
- ) = @_;
-
- # Returns a hash.
-
- my ( $record );
-
- $record = get_record( $fh );
-
- Maasha::Common::error( "No status record found in stream." ) if not $record->{ "REC_TYPE" } eq "STATUS";
-
- return wantarray ? %{ $record } : $record;
-}
-
-
-sub put_status
-{
- # Martin A. Hansen, July 2008.
-
- # Output the status record to STDOUT.
-
- # Should it ever go to file?
-
- my ( $record, # status record.
- $fh, # handle to file or stream - OPTIONAL
- ) = @_;
-
- # Returns nothing.
-
- put_record( $record, $fh );
-}
-
-
-sub check_status
-{
- # Martin A. Hansen, July 2008.
-
-}
-
-
-sub status_new
-{
- # Martin A. Hansen, July 2008.
-
- # Create a new status record which
- # is returned.
-
- my ( $fisk
-
- );
-
- my ( $record );
- return wantarray ? %{ $record } : $record;
-}
-
-
-sub status_update
-{
- # Martin A. Hansen, July 2008.
-
-}
-
-
sub getopt_files
{
# Martin A. Hansen, November 2007.
print STDERR "\nProgram '$script' died->$sig" . " - Please wait for temporary data to be removed\n";
}
- # This is a really bad solution, potentially, anyone can include this module and set
- # the BP_TMP to point at any dir and thus take out the machine !!!
-
- Maasha::Common::dir_remove( $BP_TMP );
+ clean_tmp();
}
exit( 0 );
}
-END
+sub clean_tmp
{
- # This is a really bad solution, potentially, anyone can include this module and set
- # the BP_TMP to point at any dir and thus take out the machine !!!
+ # Martin A. Hansen, July 2008.
- Maasha::Common::dir_remove( $BP_TMP );
+ # Cleans out any unused temporary files and direcotries in BP_TMP.
+
+ # Returns nothing.
+
+ my ( $tmpdir, @dirs, $curr_pid, $dir, $user, $sid, $pid );
+
+ $tmpdir = $ENV{ 'BP_TMP' } || Maasha::Common::error( 'No BP_TMP variable in environment.' );
+
+ $curr_pid = Maasha::Common::get_processid();
+
+ @dirs = Maasha::Common::ls_dirs( $tmpdir );
+
+ foreach $dir ( @dirs )
+ {
+ if ( $dir =~ /(.+)_(\d+)_(\d+)_bp_tmp/ )
+ {
+ $user = $1;
+ $sid = $2;
+ $pid = $3;
+
+ if ( not Maasha::Common::process_running( $pid ) )
+ {
+ # print STDERR "Removing stale dir: $dir\n";
+ Maasha::Common::dir_remove( $dir );
+ }
+ elsif ( $pid == $curr_pid )
+ {
+ # print STDERR "Removing current dir: $dir\n";
+ Maasha::Common::dir_remove( $dir );
+ }
+ }
+ }
+}
+
+
+END
+{
+ clean_tmp();
}
}
+sub get_time
+{
+ # Martin A. Hansen, July 2008.
+
+ # Get current time as a number.
+
+ # Returns a number.
+
+ return time;
+}
+
+
+sub get_processid
+{
+ # Martin A. Hansen, July 2008.
+
+ # Get process id for current process.
+
+ # Returns a number.
+
+ return $$;
+}
+
+
sub get_sessionid
{
# Martin A. Hansen, April 2008.
# Returns a number
- return time . $$;
+ return get_time . get_processid;
+}
+
+
+sub get_user
+{
+ # Martin A. Hansen, July 2008.
+
+ # Return the user name of the current user.
+
+ # Returns a string.
+
+ return $ENV{ 'USER' };
}
# Create a temporary directory based on
# $ENV{ 'BP_TMP' } and sessionid.
+ # this thing is a really bad solution and needs to be removed.
+
# Returns a path.
- my ( $user, $sid, $path );
+ my ( $user, $sid, $pid, $path );
Maasha::Common::error( qq(no BP_TMP set in %ENV) ) if not -d $ENV{ 'BP_TMP' };
- $user = $ENV{ 'USER' };
- $user =~ s/\.//g;
-
+ $user = Maasha::Common::get_user();
$sid = Maasha::Common::get_sessionid();
+ $pid = Maasha::Common::get_processid();
- $path = "$ENV{ 'BP_TMP' }/$user\_$sid";
+ $path = "$ENV{ 'BP_TMP' }/" . join( "_", $user, $sid, $pid, "bp_tmp" );
Maasha::Common::dir_create( $path );
}
+sub process_running
+{
+ # Martin A. Hansen, July 2008.
+
+ # Given a process ID check if it is running
+ # on the system. Return 1 if the process is
+ # running else 0.
+
+ my ( $pid, # process ID to check.
+ ) = @_;
+
+ # Returns boolean
+
+ my ( @ps_table );
+
+ @ps_table = run_and_return( "ps", " a" );
+
+ if ( grep /^\s*$pid\s+/, @ps_table ) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+
sub wrap_line
{
# Martin A. Hansen, May 2005
use Maasha::Common;
use Maasha::Fasta;
use Maasha::Seq;
+use Maasha::Biopieces;
use vars qw ( @ISA @EXPORT );
use constant {
# Returns a string.
- my ( $query_file, $result_file, @result_files, $fh_in, $fh_out, $line, @fields, $i, $record, $vmatch_args, @index_names, @seq_names, $count_list );
+ my ( $query_file, $result_file, @result_files, $fh_in, $fh_out, $line, @fields, $i, $record, $vmatch_args, @index_names, @seq_names, $count_list, $entry );
$query_file = "$tmp_dir/query.seq";
$result_file = "$tmp_dir/vmatch.out";
foreach $record ( @{ $records } )
{
- if ( $record->{ "SEQ_NAME" } and $record->{ "SEQ" } )
+ if ( $entry = record2fasta( $record ) )
{
- next if length $record->{ "SEQ" } < 12; # assuming that the index is created for 12 as minimum length
+ next if length $entry->[ SEQ ] < 12; # assuming that the index is created for 12 as minimum length
- push @seq_names, $record->{ "SEQ_NAME" };
+ push @seq_names, $entry->[ SEQ_NAME ];
- Maasha::Fasta::put_entry( [ $record->{ "SEQ_NAME" }, $record->{ "SEQ" } ], $fh_out, 80 );
+ Maasha::Fasta::put_entry( $entry, $fh_out, 100 );
}
}