#!/usr/bin/perl # Description: This script runs the NetChop 3.1.ws0 Web Service. It reads a FASTA file from STDIN and produces predictions. # Author: Edita Bartaseviciute # Email: edita@cbs.dtu.dk # Version: 3.1 ws0 # Date: 2009-07-06 # usage: perl netchop.pl [-v integer] [-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 ($method, $threshold); for (my $i = 0; $i <= $#ARGV; $i ++) { if ($ARGV[$i] eq "-v") { $method = $ARGV[$i+1]; } elsif ($ARGV[$i] eq "-t") { $threshold = $ARGV[$i+1]; } } # create proxy to NetChop Web Service my $netchop = WSDL2proxy ( 'http://www.cbs.dtu.dk/ws/NetChop/NetChop_3_1_ws0.wsdl' ); # append schema definitions $netchop = appendSchemas ( $netchop , "http://www.cbs.dtu.dk/ws/common/ws_common_1_0b.xsd" , "http://www.cbs.dtu.dk/ws/NetChop/ws_netchop_3_1_ws0.xsd" ); # create hash of operations from proxy my %ops = addOperations ( $netchop ) ; # 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 $method) and (defined $threshold)) { $response = $ops{runService}->( parameters => { parameters => { method => $method , threshold => $threshold , sequencedata => {sequence => [@sequence]} } }); } elsif ((defined $method) and !(defined $threshold)) { $response = $ops{runService}->( parameters => { parameters => { method => $method , sequencedata => {sequence => [@sequence]} } }); $threshold = 0.5; #default value, assigned here and used later for printing results } elsif (!(defined $method) and (defined $threshold)) { $response = $ops{runService}->( parameters => { parameters => { threshold => $threshold , sequencedata => {sequence => [@sequence]} } }); $method = 0; #default value, assigned here and used later for printing results } else { $response = $ops{runService}->( parameters => { parameters => { sequencedata => {sequence => [@sequence]} } }); $method = 0; $threshold = 0.5; #default values, assigned here and used later for printing results } # 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 (suitable for one sequence) my $version_name; if ($method == 0) { $version_name = 'C-term'; } elsif ($method == 1) { $version_name = '20S'; } print "NetChop-3.1 predictions using version $version_name. Threshold " . sprintf ("%.6f", $threshold) . "\n\n"; foreach my $ann (@{$response->{parameters}->{anndata}->{ann}}) { print "--------------------------------------\n pos AA C\t score", " Ident\n--------------------------------------\n"; my $sequence = $sequence[0]->{seq}; my $length = length ($sequence); my $no_cleavage = 0; my $no_aa = 0; foreach my $annrecord (@{$ann->{annrecords}->{annrecord}}) { my $pos = sprintf ("%4s", $annrecord->{pos}); my $aa = substr($sequence, $pos-1, 1); my $comment; if (exists $annrecord->{comment}) { $comment = "S"; $no_cleavage++; } else { $comment = "."; } my $score = sprintf ("%.6f", $annrecord->{score}[0]->{value}); print "$pos $aa $comment $score $ann->{sequence}->{id}\n"; } print "--------------------------------------\n\n". "Number of cleavage sites $no_cleavage. Number of amino acids $length. Protein name $ann->{sequence}->{id}\n\n". "--------------------------------------\n"; }