#!/usr/bin/perl # Description: This script runs the TargetP 1.1 ws0 Web Service. It reads FASTA from STDIN and produces predictions in a simple tables. # Author: Edita Bartaseviciute # Email: edita@cbs.dtu.dk # Version: 1.1 ws0 # Date: 2009-10-07 # usage: perl targetp.pl -P|-N [-t float] < 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 #taking options from a command line my ($organism, $cutoff); for (my $i = 0; $i <= $#ARGV; $i++) { if ($ARGV[$i] eq "-P" or $ARGV[$i] eq "-N") { $organism = substr ($ARGV[$i], 1, 1); } if ($ARGV[$i] eq "-t") { $cutoff = $ARGV[$i+1]; } } # create proxy to TargetP Web Service my $targetp = WSDL2proxy ( 'http://www.cbs.dtu.dk/ws/TargetP/TargetP_1_1_ws0.wsdl' ); # append schema definitions $targetp = appendSchemas ( $targetp , "http://www.cbs.dtu.dk/ws/common/ws_common_1_0b.xsd" , "http://www.cbs.dtu.dk/ws/TargetP/ws_targetp_1_1_ws0.xsd" ); # create hash of operations from proxy my %ops = addOperations ( $targetp ) ; # Get sequence in fasta format from STDIN my @fasta; my $entry = -1; while () { 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; if (defined $cutoff) { $response = $ops{runService}->( parameters => { parameters => { organism => $organism, mTP => $cutoff, sequencedata => {sequence => [@sequence]} } }); } else { $response = $ops{runService}->( parameters => { parameters => { organism => $organism, 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 $version = substr($response->{parameters}->{anndata}->{annsource}->{version}, 0, 3); print "### $response->{parameters}->{anndata}->{annsource}->{method} $version prediction results ##################################\n"; if ($organism eq "P") { print "Name\t\tLen\tcTP\tmTP\tSP\tother\tLoc\tRC\n", "----------------------------------------------------------------------\n" } elsif ($organism eq "N") { print "Name\t\tLen\tmTP\tSP\tother\tLoc\tRC\n", "----------------------------------------------------------------------\n" } foreach my $ann (@{$response->{parameters}->{anndata}->{ann}}) { my $seq; for ( my $i = 0 ; $i < scalar ( @sequence ) ; $i ++ ){ if ($sequence[$i]->{id} eq $ann->{sequence}->{id}){ $seq = $sequence[$i]->{seq}; } } my $length = length ($seq); foreach my $annrecord (@{$ann->{annrecords}->{annrecord}}) { my $loc = substr ($annrecord->{comment}, 0, 1); print "$ann->{sequence}->{id}\t$length\t"; if ($organism eq "P") { print "$annrecord->{score}[0]->{value}\t$annrecord->{score}[1]->{value}\t$annrecord->{score}[2]->{value}\t$annrecord->{score}[3]->{value}\t$annrecord->{comment}\t$annrecord->{score}[4]->{value}\n"; } elsif ($organism eq "N") { print "$annrecord->{score}[0]->{value}\t$annrecord->{score}[1]->{value}\t$annrecord->{score}[2]->{value}\t$annrecord->{comment}\t$annrecord->{score}[3]->{value}\n"; } } } print "----------------------------------------------------------------------\n";