[Bio] / FigKernelPackages / FFserver.pm Repository:
ViewVC logotype

View of /FigKernelPackages/FFserver.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Tue Apr 28 21:03:25 2009 UTC (10 years, 7 months ago) by olson
Branch: MAIN
FF server inteface module

package FFserver;

use LWP::UserAgent;
use FIG_Config;
use Data::Dumper;

use strict;

sub new
{
    my($class, $server_url) = @_;

    $server_url = $FIG_Config::FFserver_url unless $server_url;
    $server_url = "http://bio-macpro-1.mcs.anl.gov/~disz/FIG/figfam_server.cgi" unless $server_url;


    my $self = {
	server_url => $server_url,
	ua => LWP::UserAgent->new(),
    };

    return bless $self, $class;
}

sub assign_function_to_prot
{
    my($self, $input) = @_;

    my $handle;
    if (ref($input) eq 'ARRAY')
    {
	$handle = ListInputHandle->new($input, sub { $self->assign_function_to_prot_one(@_); });
    }
    elsif (ref($input))
    {
	$handle = FileInputHandle->new($input, sub { $self->assign_function_to_prot_one(@_); });
    }
    else
    {
	$handle = FileInputHandle->new($input, sub { $self->assign_function_to_prot_one(@_); });
    }
}

sub assign_function_to_prot_one
{
    my($self, $dat) = @_;

    my($id, undef, $seq) = @$dat;

    my $form = [function => 'assign_function_to_prot',
		id_seq => "$id,$seq"];

    print Dumper($self->{server_url}, $form);
    
    my $res = $self->{ua}->post($self->{server_url}, $form);
    if ($res->is_success)
    {
	my $txt = $res->content;
	return $txt;
    }
    else
    {
	die "error on post " . $res->content;
    }
    
}

package ListInputHandle;
use strict;

sub new
{
    my($class, $list, $handler) = @_;
    my $self = {
	list => $list,
	handler => $handler,
    };
    return bless $self, $class;
}

sub get_next
{
    my($self) = @_;

    my $l = $self->{list};

    if (@$l)
    {
	my $ent = shift @$l;
	my $res = &{$self->{handler}}($ent);
	my($id, $val) = split(/\t/, $res);
	chomp $val;
	return $val;
    }
    else
    {
	return undef;
    }
}

package FileInputHandle;
use strict;
use FileHandle;
use FIG;

sub new
{
    my($class, $input, $handler) = @_;

    my $fh;
    if (ref($input))
    {
	$fh = $input;
    }
    else
    {
	$fh = new FileHandle("<$input");
    }
    
    my $self = {
	fh => $fh,
	handler => $handler,
    };
    return bless $self, $class;
}

sub get_next
{
    my($self) = @_;

    my($id, $seqp) = &FIG::read_fasta_record($self->{fh});

    if ($id)
    {
	my $ent = [$id, undef, $$seqp];
	my $res = &{$self->{handler}}($ent);
	my($id, $val) = split(/\t/, $res);
	chomp $val;
	return $val;
    }
    else
    {
	close($self->{fh});
	return undef;
    }
}
1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3