#!/usr/bin/perl
# Description: This script runs the TMHMM 2.0 ws0 Web Service. It reads FASTA file from STDIN and produces predictions in a simple table
# Author: Edita Bartaseviciute
# Version: 2.0 ws0
# Date: 2009-09-24
# usage: perl tmhmm.pl < example.fsa
use strict;
# include standard XML::Compile helper functions (used to initiate WSDL proxys)
require "xml-compile.pl"; # downloadable from the same site as this script
# create proxy to TMHMM Web Service
my $tmhmm = WSDL2proxy ( 'http://www.cbs.dtu.dk/ws/TMHMM/TMHMM_2_0_ws0.wsdl' );
# append schema definitions
$tmhmm = appendSchemas ( $tmhmm ,
"http://www.cbs.dtu.dk/ws/common/ws_common_1_0b.xsd" ,
"http://www.cbs.dtu.dk/ws/TMHMM/ws_tmhmm_2_0_ws0.xsd"
);
# create hash of operations from proxy
my %ops = addOperations ( $tmhmm ) ;
# Get sequence in fasta format from STDIN
my @fasta;
my $entry = -1;
while (<STDIN>) {
if (/^>(.*)/) {
my ($id , $comment) = split (" ",$1);
$entry++;
$fasta[$entry]->{id} = $id;
$fasta[$entry]->{comment} = $comment if defined $comment;
} elsif (/^([A-Za-z]+)/) {
$fasta[$entry]->{seq} .= $1;
}
}
# Create sequence for request
my @sequence;
for ( my $i = 0 ; $i < scalar ( @fasta ) ; $i ++ ) {
push @sequence , { id => $fasta[$i]->{id} , comment => $fasta[$i]->{comment} , seq => $fasta[$i]->{seq} };
}
# Do the request
my $response = $ops{runService}->(
parameters => {
parameters => {
sequencedata => {sequence => [@sequence]} } });
# uncomment the two following lines to inspect the structure of $response
#use Data::Dumper;
#print Dumper($response);
#get job id which can be used to get the results later
my $jobid;
if ( ! defined ( $response->{parameters}->{queueentry}) ) {
die "error obtaining jobid\n";
} else {
$jobid = $response->{parameters}->{queueentry}->{jobid};
print STDERR "# waiting for job $jobid";
my $status = "UNKNOWN";;
# poll the queue
while ( $status =~ /ACTIVE|RUNNING|QUEUED|WAITING|PENDING|UNKNOWN/ ) {
my $response = $ops{pollQueue}->( job => { job => { jobid => $jobid } }) ;
$status = $response->{queueentry}->{queueentry}->{status};
print STDERR ".";
}
die "\nunexpected job status '$status'\n" unless $status eq "FINISHED";
print STDERR "\n# job has finished\n";
}
# when the job is done, fetch the result
$response = $ops{fetchResult}->(job => { jobid => $jobid });
# uncomment the two following lines to inspect the structure of $response
use Data::Dumper;
print Dumper($response);
#printing the results
my $method = substr ($response->{parameters}->{anndata}->{annsource}->{method}, 0, 5) . substr ($response->{parameters}->{anndata}->{annsource}->{version}, 0, 3);
print "_______________________________________________________________\n";
foreach my $ann (@{$response->{parameters}->{anndata}->{ann}}) {
foreach my $annrecord (@{$ann->{annrecords}->{annrecord}}) {
print "$ann->{sequence}->{id}\t$method\t$annrecord->{comment}\t\t$annrecord->{range}->{begin}\t$annrecord->{range}->{end}\n";
}
print "_______________________________________________________________\n";
}