JPRED-2 Move Jpred 3.0.1 to public Git
[jpred.git] / jpred / lib / Pairwise.pm
1 package Pairwise;
2
3 use strict;
4 use warnings;
5 use Carp;
6 use IPC::Open3;
7 use UNIVERSAL qw(isa);
8 use File::Temp;
9 use base qw(Root Common);
10
11 use Run qw(check);
12
13 sub path {
14         my ($self, $path) = @_;
15         if (defined $path) { $self->{path}= $path }
16         else {
17                 if (defined $self->{path}) { return $self->{path} }
18                 else { croak "Path not defined" }
19         }
20 }
21
22 sub run {
23         my ($self, $fasta) = @_;
24
25         croak "Non FASTA::File object passed to Pairwise::run" unless isa $fasta, 'FASTA::File';
26
27         local ($/, $?) = (undef, 0);
28
29         my $f = File::Temp->new->filename;
30         $fasta->write_file($f);
31
32         my $pid = open my $fh, $self->path." $f |" or die $!;
33
34         my @output = join "\n", split "\n", <$fh>;
35
36         waitpid $pid, 0;
37         check($self->path, $?) or die "Pairwise was naughty\n";
38
39         return @output;
40 }
41
42 1;