#!/usr/bin/perl -s #************************************************************************* # # Program: abnumws # File: abnumws.pl # # Version: V1.0 # Date: 08.10.14 # Function: Use web-services access to abnum to number an antibody # sequence # # Copyright: (c) Dr. Andrew C. R. Martin, UCL, 2014 # Author: Dr. Andrew C. R. Martin # Address: Institute of Structural and Molecular Biology # Division of Biosciences # University College # Gower Street # London # WC1E 6BT # EMail: andrew@bioinf.org.uk # #************************************************************************* # # This program is not in the public domain, but it may be copied # according to the conditions laid out in the accompanying file # COPYING.DOC # # The code may be modified as required, but any modifications must be # documented so that the person responsible can be identified. If # someone else breaks this code, I don't want to be blamed for code # that does not work! # # The code may not be sold commercially or included as part of a # commercial product except as described in the file COPYING.DOC. # #************************************************************************* # # Description: # ============ # #************************************************************************* # # Usage: # ====== # #************************************************************************* # # Revision History: # ================= # V1.0 08.10.14 Original By: ACRM # #************************************************************************* use strict; #use WEB; $::scheme = "-c" if(!defined($::scheme)); $::proxy = "" if(!defined($::proxy)); UsageDie() if(!defined($::seq)); my $url = "http://www.bioinf.org.uk/abs/abnum/abnum.cgi?plain=1&scheme=$::scheme&aaseq="; my $agent = WEB::CreateUserAgent($::proxy); my $query = $url . $::seq; my $request = WEB::CreateGetRequest($query); my $content = WEB::GetContent($agent, $request); $content =~ s/\r//g; my @lines = split(/\n/, $content); foreach my $line (@lines) { if(!($line =~ /\s\-/)) { print $line . "\n"; } } #************************************************************************* sub UsageDie { print <<__EOF; Usage: abnumws.pl [-scheme=xx] [-proxy=yyy] -seq=sequence -scheme - specify numbering scheme -scheme=-c Chothia (default) -scheme=-k Kabat -scheme=-a Abhi -proxy - Specify URL of proxy server if required -seq - Specify sequence to number __EOF exit 0; } package WEB; #************************************************************************* # # Program: # File: WEB.pm # # Version: V1.0 # Date: 12.01.07 # Function: Routines to support web page access from Perl # # Copyright: (c) Dr. Andrew C. R. Martin, UCL, 2007 # Author: Dr. Andrew C. R. Martin # Address: Institute of Structural and Molecular Biology # Division of Biosciences # University College # Gower Street # London # WC1E 6BT # EMail: andrew@bioinf.org.uk # #************************************************************************* # # This program is not in the public domain, but it may be copied # according and used freely providing this header is retained # #************************************************************************* # # Description: # ============ # Simplify accessing web pages from Perl using LWP # #************************************************************************* # # Usage: # ====== # Normal page requests or CGI requests using GET # my $proxy = ""; # Replace with proxy address if needed # my $url = "http://mysite.com/path/to/page"; # my $ua = WEB::CreateUserAgent($proxy); # my $req = WEB::CreateGetRequest($url); # my $content = WEB::GetContent($ua, $req); # # CGI requests using POST # my $proxy = ""; # Replace with proxy address if needed # my $url = "http://mysite.com/path/to/script"; # my $params = "key=value&key=value"; # my $ua = WEB::CreateUserAgent($proxy); # my $req = WEB::CreatePostRequest($url, $params); # my $content = WEB::GetContent($ua, $req); # #************************************************************************* # # Revision History: # ================= # V1.0 12.01.07 Original By: ACRM # #************************************************************************* use strict; use LWP; ######################################################################## #>sub GetContent($ua, $req) # ------------------------- # Input: $ua User agent # $req The packaged GET or POST request # Returns: string Result text # # Gets the content from a web page # See Usage info above # # 12.01.07 Original By: ACRM sub GetContent { my($ua, $req) = @_; my($res); $res = $ua->request($req); if($res->is_success) { return($res->content); } return(undef); } ######################################################################## #>sub CreateGetRequest($url) # -------------------------- # Input: string $url The URL to access # Returns: The packaged GET request # # Creates an HTTP GET request # See Usage info above # # 12.01.07 Original By: ACRM sub CreateGetRequest { my($url) = @_; my($req); $req = HTTP::Request->new('GET',$url); return($req); } ######################################################################## #>sub CreatePostRequest($url, $params) # ------------------------------------ # Input: string $url The URL to access # string $params Parameters in GET style # (key=value&key=value...) # Returns: The packaged POST request # # Creates an HTTP POST request # See Usage info above # # 12.01.07 Original By: ACRM sub CreatePostRequest { my($url, $params) = @_; my($req); $req = HTTP::Request->new(POST => $url); $req->content_type('application/x-www-form-urlencoded'); $req->content($params); return($req); } ######################################################################## #>sub CreateUserAgent($proxy) # --------------------------- # Input: string $proxy Address of a proxy server or a blank string # Returns: The user agent # # Creates a user agent # See Usage info above # # 12.01.07 Original By: ACRM sub CreateUserAgent { my($webproxy) = @_; my($ua); $ua = LWP::UserAgent->new; if(length($webproxy)) { $ua->proxy(['http', 'ftp'] => $webproxy); } return($ua); } 1;