<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/env perl

################################################################
## This Perl script shows how to use the Web services
## "fetch-sequences" from the Regulatory Sequence Analysis Tools
## (RSAT, http://www.rsat.eu/). 
##
## The interface relies on the SOAP/SWDL standard, which requires to
## pre-install some libraries.
##
## This script sends the URL of a bed file to the RSAT Web services,
## which run fetch-sequences in order to collect the sequences from
## UCSC. The sequences are then transferred from the RSAT Web services
## to the current client.
##
## This tester program only collects the two first sequences of the
## bed file (option -top 2), checks if the first sequence of the
## result matches the expected sequence and issue a message "Passed".

use strict;

# import the modules we need for this test; XML::Compile is included on the server
# by default.
use XML::Compile::SOAP11;
use XML::Compile::WSDL11;
use XML::Compile::Transport::SOAPHTTP;
use Data::Dumper;

eval
{
  ## Choosing the RSAT server
# my $wsdl  = XML::LibXML-&gt;new-&gt;parse_file('http://www.rsat.eu/web_services/RSATWS.wsdl');
  my $wsdl  = XML::LibXML-&gt;new-&gt;parse_file('http://pedagogix-tagc.univ-mrs.fr/rsat/web_services/RSATWS.wsdl');
# my $wsdl  = XML::LibXML-&gt;new-&gt;parse_file('http://www.rsat.fr/web_services/RSATWS.wsdl');
# my $wsdl  = XML::LibXML-&gt;new-&gt;parse_file('http://localhost/rsat/web_services/RSATWS.wsdl');
  
  ## Retriving and processing the WSDL
  my $proxy = XML::Compile::WSDL11-&gt;new($wsdl);
  
  ## Generating a request message based on the WSDL
  my $method = 'fetch_sequences';
  my $client = $proxy-&gt;compileClient($method);
  
  ## Defining the parameters for fetch-sequences
  my %args = ( 
      output =&gt; "both", ## Return both the URL of the result file on the server, and the result itself.  Alternatives: "server", "client"
#     url =&gt; "http://www.rsat.eu/demo_files/fetch-sequences_Schmidt_2011_mm9_CEBPA_SWEMBL_R0.12_702peaks.bed",
      url =&gt; "http://pedagogix-tagc.univ-mrs.fr/rsat/demo_files/fetch-sequences_Schmidt_2011_mm9_CEBPA_SWEMBL_R0.12_702peaks.bed",
      genome =&gt; "mm9",
      header_format =&gt; "", ## Header format
      upstr_ext =&gt; 0, ## Upstream extension
      downstr_ext =&gt; 0, ## Downstream extension
      extend =&gt; 0, ## Extension (alternative to the two previous arguments, since it applies downstream + upstream)
      reference =&gt; "segment",
      top =&gt; 2, ## For this test, we only fetch the two first sequences
      );
  
  # Calling the service and getting the response
  my $answer = $client-&gt;( request =&gt; {%args});

  # If the response arrived, look for a specific match
  # If the match is correct, return 0 because the test passed.
  # If the result is something else, return 2 to indicate a warning.
  # If no answer has arrived, return 1 to indicate the test failed.
  if ( defined $answer ) {
      warn ("Server command : ".$answer-&gt;{output}-&gt;{response}-&gt;{command}."\n");
      
      
      ## Note: this currently does not work. In debugging
      #    warn ("Server command : ".$answer-&gt;{output}-&gt;{response}-&gt;{server}."\n");
      #    my $response = $answer-&gt;get_response();
      #    my $server_file = $response-&gt;get_server();
      #    warn ("Result path on the server : ".$server_file."\n");
      
      if ($answer-&gt;{output}-&gt;{response}-&gt;{client} =~ 'CTGTCTATATGCCAC'){
	  print "Passed\n";
	  print "\nResult :\n\n", $answer-&gt;{output}-&gt;{response}-&gt;{client}, "\n";
	  print "\nServer :\n\n", $answer-&gt;{output}-&gt;{response}-&gt;{server}, "\n";
	  exit 0;
      } else {
	  print "Unexpected data\n";
	  print "\nResult : ", Dumper($answer), "\n";
	  exit 2;
      }
  } else {    
      print "Failed\n";
      exit 1;
  }
};

if ($@)
{
  print "Caught an exception\n";
  print $@."\n";
  exit 1;
}
</pre></body></html>