-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathuniprot2tax.pl
executable file
·62 lines (53 loc) · 1.76 KB
/
uniprot2tax.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
# Script: uniprot2tax.pl
# Description: Takes file with uniprot IDs
# Author: Steven Ahrendt
# email: [email protected]
# Date: 04.06.2015
##################################
use warnings;
use strict;
use Getopt::Long;
use lib '/rhome/sahrendt/Scripts';
use SeqAnalysis;
use LWP::UserAgent;
use Bio::DB::SwissProt;
#####-----Global Variables-----#####
my $input;
my ($help,$verb);
my $NCBI = initNCBI("flatfile");
GetOptions ('i|input=s' => \$input,
'h|help' => \$help,
'v|verbose' => \$verb);
my $usage = "Usage: uniprot2tax.pl -i input\nTakes file with uniprot IDs and prints uniprot file to be parsed with parseUniprot\n";
die $usage if $help;
die "No input.\n$usage" if (!$input);
#####-----Main-----#####
printUniprotFile($input);
warn "Done.\n";
exit(0);
#####-----Subroutines-----#####
sub printUniprotFile {
my $list = shift @_; # File containg list of UniProt identifiers.
# print $list,"\n";
my $base = 'http://www.uniprot.org';
my $tool = 'batch';
my $contact = ''; # Please set your email address here to help us debug in case of problems.
my $agent = LWP::UserAgent->new(agent => "libwww-perl $contact");
push @{$agent->requests_redirectable}, 'POST';
my $response = $agent->post("$base/$tool/",
[ 'file' => [$list],
'format' => 'txt',
],
'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";
}