56cb4713291318cb0b4ea752fe54201628118cce
[jpred.git] / jpred / lib / PSIBLAST / Run.pm
1 package PSIBLAST::Run;
2
3 use Carp;
4 use base qw(Root);
5 use Run qw(check);
6
7 sub new {
8   my ( $class, %args ) = @_;
9   my $self = {};
10   bless $self, ref($class) || $class;
11
12   # -a number of CPUs used (default 1)
13   # -e e-value threshold for reporting sequences (default 10)
14   # -h e-value threshold for including sequences in PSSM (default 0.002)
15   # -m type of output
16   # -b max number of alignments reported (default 250)
17   # -v max number of sequences described (default 500)
18   # -j max number of itterations (default 1)
19   # $self->args("-e0.05 -h0.01 -m6 -b10000 -v10000 -j3");
20   # $self->args("-a2 -e0.05 -h0.01 -m6 -b20000 -v20000 -j15");
21
22   # Automatically run any arguments passed to the constructor
23   for ( keys %args ) {
24     croak "No such method '$_' of object $class" unless $self->can($_);
25     $self->$_( $args{$_} );
26   }
27
28   return $self;
29 }
30
31 sub path     { defined $_[1] ? $_[0]->{path}   = $_[1]      : $_[0]->{path} }
32 sub args     { defined $_[1] ? $_[0]->{args}   = $_[1]      : $_[0]->{args} }
33 sub database { defined $_[1] ? $_[0]->{data}   = "-d $_[1]" : $_[0]->{data} }
34 sub input    { defined $_[1] ? $_[0]->{input}  = "-i $_[1]" : $_[0]->{input} }
35 sub output   { defined $_[1] ? $_[0]->{output} = "-o $_[1]" : $_[0]->{output} }
36 sub matrix   { defined $_[1] ? $_[0]->{matrix} = "-Q $_[1]" : $_[0]->{matrix} }
37 sub debug    { defined $_[1] ? $_[0]->{debug}  = $_[1]      : $_[0]->{debug} }
38 sub BLASTMAT { $ENV{BLASTMAT} = $_[1] }
39 sub BLASTDB  { $ENV{BLASTDB}  = $_[1] }
40
41 sub run {
42   my ($self) = @_;
43
44   # Required arguments
45   for (qw(path output database input)) {
46     croak "Method '$_' needs to be set" unless defined $self->$_;
47   }
48
49   # Construct the command line
50   my @cmd;
51   for (qw(path args database input matrix output)) {
52     next unless $self->$_;
53     push @cmd, $self->$_;
54   }
55
56   my $cmd = join " ", @cmd;
57
58   # Execute PSIBLAST and check it ran okay
59   warn "$cmd\n" if ( $self->debug );
60
61   system($cmd) == 0 or check( "blastpgp", $? ) and die "blastpgp was naughty";
62
63   # Clean up the error.log file it produces
64   if   ( -z "error.log" ) { unlink "error.log" }
65   else                    { warn "blastpgp error.log file was not empty\n" }
66 }
67
68 1;