#!/usr/bin/perl -w

# Very simple Perl client script for FuncNet prediction services

use strict;
use warnings;

use Data::Dumper;

use XML::Compile::WSDL11;
use XML::Compile::Transport::SOAPHTTP;
use XML::Compile::Schema;

my $geco_wsdl = "GecoService.wsdl"; # You must download this yourself (or use the full CPAN client)

# warn "XML::Compile::WSDL11->new( $geco_wsdl )";

my $wsdl = XML::Compile::WSDL11->new( $geco_wsdl );

# warn "got: $wsdl";

my @op_defs = $wsdl->operations();

# warn "operations: ", join (", ", Dumper( @op_defs ) );

# warn "\$wsdl->compileClient( '{http://cathdb.info/FuncNet_0_1/}GecoService' );";

my $op   = $wsdl->operation( 
                operation   => 'ScorePairwiseRelations', 
                port        => 'GecoPort', 
                service     => '{http://cathdb.info/FuncNet_0_1/}GecoService' ,
                binding     => '{http://cathdb.info/FuncNet_0_1/}GecoBinding'
             );

my $op_call = $op->compileClient();

# proteins1 is query set, proteins2 is reference set
my $parameters = {
    proteins1 => { p => [ 'A3EXL0', 'A4D2E0', 'Q8NFN7', 'O75865', 'A8K8W3', 'A8K3I6' ] },
    proteins2 => { p => [ 'Q5SR05', 'Q9H8H3', 'P22676', 'Q9UHT8', 'P56277', 'P49366' ] } 
};

my ( $answer, $trace ) = $op_call->( parameters => $parameters );

# warn Dumper( $trace );

# warn "Answer:", Dumper(  $answer->{ parameters } );

print "Prot 1\tProt 2\tP-value\n";

foreach my $result ( @{ $answer->{ parameters }->{ s } } )
{
    print $result->{ p1 } . "\t" . $result->{ p2 } . "\t" . $result->{ pv } . "\n";
}