forked from tomas-pluskal/TPSdownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREST.pl
33 lines (26 loc) · 1.06 KB
/
REST.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
my $list = $ARGV[0]; # File containg list of UniProt identifiers.
my $base = 'https://www.uniprot.org';
my $tool = 'uploadlists';
my $contact = ''; # Please set a contact email address here to help us debug in case of problems (see https://www.uniprot.org/help/privacy).
my $agent = LWP::UserAgent->new(agent => "libwww-perl $contact");
push @{$agent->requests_redirectable}, 'POST';
my $response = $agent->post("$base/$tool/",
[ 'file' => [$list],
'format' => 'xml',
'from' => 'ACC+ID',
'to' => 'ACC',
],
'Content_Type' => 'form-data');
while (my $wait = $response->header('Retry-After')) {
print STDERR "Waiting ($wait)...\n";
sleep $wait;
$response = $agent->get($response->base);
}
$response->is_success ?
print $response->content :
die 'Failed, got ' . $response->status_line .
' for ' . $response->request->uri . "\n";