This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to specify columns in Uniprot batch query from Uniprot IDs?

Dear all,

My question is relatively similar to How To Programmatically Retrieve A Batch Of Fasta Sequences From For A List Of Uniprot Accession Ids?, in which someone tries to retrieve fasta sequences from Uniprot from a list of Uniprot Protein IDs.

In my case, I also have a list of Uniprot IDs, and I tried the perl script of the example (see link above). Being a complete perl layman, I managed to retrieve the main result table in Excel. However, I would like to add some more columns (i.e. sequences), something possible to do in the web service. Is there an easy way to modify that perl code example in order to specify the columns I want?

A related question: Is it possible to retrieve the same information but using R instead? I found a couple Uniprot-related packages in Bioconductor, but by reading the manuals I don't think they can do the trick...

Thank you very much!

uniprot perl batch proteinid

Hi Pierre! I'll give it a try, even though I'm afraid that my knowledge of Java is even more limited than Perl... Thanks!

1 answer

You can try something like this below - and note that the column names are documented at https://www.uniprot.org/help/uniprotkb_column_names :

use strict;
use warnings;
use LWP::UserAgent;

my $list = $ARGV[0]; # File containg list of UniProt identifiers.

my $base = 'http://www.uniprot.org';
my $tool = 'uploadlists';

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' => 'tab',
     'columns'=> 'id,protein_names,genes,length',
     '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);
}

It worked! For some reason it wasn't working at first, so I tried to add the example chunk:

    $response->is_success ?
  print $response->content :
  die 'Failed, got ' . $response->status_line .
    ' for ' . $response->request->uri . "\n";

and it worked like a charm!

Log in to answer this question.