Prospect
view release on metacpan or search on metacpan
Prospect/LocalClient.pm view on Meta::CPAN
=head1 SYNOPSIS
my $in = new Bio::SeqIO( -format=> 'Fasta', '-file' => $ARGV[0] );
my $po = new Prospect::Options( seq=>1, svm=>1, global_local=>1,
templates=>['1alu', '1bgc','1eera']);
my $pf = new Prospect::LocalClient( {options=>$po );
while ( my $s = $in->next_seq() ) {
my @threads = $pf->thread( $s );
}
=head1 DESCRIPTION
B<Prospect::LocalClient> is runs Prospect locally. It is intended to be
used to facilitate high-throughput protein sequence threading and as the
server-side component of B<Prospect::SoapClient>, with which it is API
compatible.
=head1 ROUTINES & METHODS
=cut
package Prospect::LocalClient;
use base Prospect::Client;
use warnings;
use strict;
use File::Temp qw( tempfile tempdir );
use Carp qw(cluck);
use IO::File;
use Prospect::Exceptions;
use Prospect::utilities;
use Prospect::ThreadSummary;
use Prospect::Init;
use Digest::MD5;
use vars qw( $VERSION );
$VERSION = sprintf( "%d.%02d", q$Revision: 1.30 $ =~ /(\d+)\.(\d+)/ );
#-------------------------------------------------------------------------------
# new()
#-------------------------------------------------------------------------------
=head2 new()
Name: new()
Purpose: constructor
Arguments: hash reference with following key/value pairs
options => Prospect::Options object (required)
Returns: Prospect::LocalClient
=cut
sub new(;%) {
my $self = shift->SUPER::new(@_);
$self->_setenv();
$self->_prepare_options();
$self->{'xmlCacheName'} = 'xmlCache'; # name of xml file cache
$self->{'sortCacheName'} = 'sortCache'; # name of sort file cache
return $self;
}
#-------------------------------------------------------------------------------
# thread()
#-------------------------------------------------------------------------------
=head2 thread()
Name: thread()
Purpose: return a list of Thread objects
Arguments: scalar sequence or Bio::PrimarySeqI-derived object
Returns: list of Prospect::Thread objects
=cut
sub thread($$) {
my ($self,$s) = @_;
if ( not defined $s or (ref $s and not $s->isa('Bio::PrimarySeqI')) ) {
throw Prospect::BadUsage(
"Prospect::LocalClient::thread() requires one Bio::PrimarySeqI subclass or " .
"scalar sequence argument" );
}
my $seq = ref $s ? $s->seq() : $s;
my $xfn = $self->_thread_to_file( $seq );
my $pf = new Prospect::File;
$pf->open( "<$xfn" ) || throw Prospect::RuntimeError("$xfn: $!\n");
$self->{'threads'} = [];
while( my $t = $pf->next_thread() ) {
push @{$self->{'threads'}}, $t;
}
return( @{$self->{'threads'}} );
}
#-------------------------------------------------------------------------------
# thread_summary()
#-------------------------------------------------------------------------------
=head2 thread_summary()
Name: thread_summary()
Purpose: return a list of ThreadSummary objects
Arguments: Bio::Seq object
Returns: list of rospect2::ThreadSummary objects
=cut
sub thread_summary($$) {
my ($self,$s) = @_;
my @summary;
foreach my $t ( $self->thread($s) ) {
Prospect/LocalClient.pm view on Meta::CPAN
my $out = new IO::File ">$outFile" or throw Prospect::RuntimeError("can't open $outFile for reading");
local $/ = '</threading>';
while(<$in>) {
next if ! m/threading/; # make sure that we have valid prospect thread
m#template="(\w+)"#;
my $t = $1;
if ( ! defined $svm{$t} or $svm{$t} eq '') {
throw Prospect::RuntimeError
( 'Unable to retrieve svm sort',
"no svm score for template=$t" );
}
s#(<rawScore>.*?</rawScore>)#$1\n<svmScore>$svm{$t}</svmScore>#g;
print $out $_;
}
close($in);
return( $outFile );
}
#-------------------------------------------------------------------------------
# _sort1()
#-------------------------------------------------------------------------------
=head2 _sort1()
Name: _sort1()
Purpose: run sortProspect on threading file
Arguments: prospect xml file
Returns: filename of sortProspect results
=cut
sub _sort1($$) {
my ($self,$xfn) = @_;
my $sfn = "$xfn.sort";
my $cmd = "sortProspect $xfn 2>/dev/null 1>$sfn";
print(STDERR "about to $cmd\n") if $ENV{DEBUG};
if ( eval { system("$cmd") } )
{
my $s = $?;
if ($s & 127)
{
$s &= 127;
my $sn = Prospect::utilities::signame($s);
throw Prospect::RuntimeError
( 'failed to execute Prospect',
"received signal $s ($sn)" );
}
$s >>= 8;
throw Prospect::RuntimeError
( 'failed to execute Prospect',
"system($cmd) exited with status $s",
'check your prospect installation manually' );
}
# sanity checks on the sort output??
return $sfn;
}
sub _setenv {
if (not -d $Prospect::Init::PROSPECT_PATH ) {
throw Prospect::Exception
( "PROSPECT_PATH is not set correctly",
"PROSPECT_PATH ($Prospect::Init::PROSPECT_PATH}) is not a valid directory",
"Check your prospect installation and set PROSPECT_PATH in Prospect::Init or as an environment variable" );
} else {
$ENV{'PROSPECT_PATH'} = $Prospect::Init::PROSPECT_PATH;
}
if (not -d $Prospect::Init::PDB_PATH) {
throw Prospect::Exception
( "PDB_PATH is not set correctly",
"PDB_PATH ($Prospect::Init::PDB_PATH) is not a valid directory",
"Check your prospect installation and set PDB_PATH in Prospect::Init or as an environment variable" );
} else {
$ENV{'PDB_PATH'} = $Prospect::Init::PDB_PATH;
}
}
sub _prepare_options($$) {
my $self = shift;
my $opts = $self->{options};
(ref $opts eq 'Prospect::Options')
|| throw Prospect::BadUsage('Prospect::Options argument is missing');
my @cl = ( "$Prospect::Init::PROSPECT_PATH/bin/prospect" );
if (exists $opts->{phd}) {
throw Exception::NotYetSupported
( "phd threading isn't implemented" );
} elsif (exists $opts->{ssp}) {
throw Exception::NotYetSupported
( "ssp threading isn't implemented" );
} elsif (exists $opts->{seq}) {
push( @cl, '-seqfile %s' );
} else {
throw Prospect::BadUsage("Prospect::Options doesn't specify input type");
}
push(@cl, '-o %s');
push(@cl, '-ncpus '.($opts->{ncpus}||2) );
push(@cl, '-freqfile',$opts->{freqfile} ) if ( exists $opts->{freqfile} );
push(@cl, '-reliab') if $opts->{zscore};
push(@cl, $opts->{global_local} ? '-global_local' : '-global');
# template set selection
# ONE of -scop, -tfile, -templates (array), or -fssp (default)
if ($opts->{scop}) {
push(@cl, '-scop')
} elsif (exists $opts->{tfile}) {
push(@cl, '-tfile', $opts->{tfile})
} elsif (exists $opts->{templates}) {
my ($fh,$fn) = $self->_tempfile('lst');
$fh->print(join("\n",@{$opts->{templates}}),"\n");
$fh->close();
push(@cl, '-tfile', $fn);
} else {
push(@cl, '-fssp');
}
( run in 0.393 second using v1.01-cache-2.11-cpan-39bf76dae61 )