From 76def23cfaf543f2a55dcb2a57b40cecae71687a Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Wed, 12 Dec 2007 00:28:41 +0000 Subject: [PATCH] * Handle when NCBI has remote server errors "gracefully" * Fix pubmed/ncbi typo git-svn-id: file:///srv/svn/function2gene/trunk@19 a0738b58-4706-0410-8799-fb830574a030 --- bin/get_ncbi_results | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/bin/get_ncbi_results b/bin/get_ncbi_results index 3e1a625..313ecad 100755 --- a/bin/get_ncbi_results +++ b/bin/get_ncbi_results @@ -87,9 +87,9 @@ my %options = (debug => 0, name => 'ncbi_${search}_results.$format', terms => '-', orgn => 'homo', - pubmed_site => 'http://www.ncbi.nlm.nih.gov', - pubmed_search_url => '/entrez/query.fcgi?cmd=search&doptcmdl=Brief&dispmax=1000', - pubmed_get_url => '/entrez/query.fcgi?cmd=Text', + ncbi_site => 'http://www.ncbi.nlm.nih.gov', + ncbi_search_url => '/entrez/query.fcgi?cmd=search&doptcmdl=Brief&dispmax=1000', + ncbi_get_url => '/entrez/query.fcgi?cmd=Text', ); GetOptions(\%options,'format|f=s','database|b=s','name|n=s', @@ -121,7 +121,7 @@ while (<$terms>) { chomp; my $search = $_; my $format = $options{format}; - my $uri = URI->new($options{pubmed_site}.$options{pubmed_search_url}); + my $uri = URI->new($options{ncbi_site}.$options{ncbi_search_url}); $uri->query_form($uri->query_form(), term => $search.' AND '.$options{orgn}.'[Orgn]', db => $options{database}, @@ -145,7 +145,7 @@ while (<$terms>) { my @current_ids; print {$xml_file} "\n"; while (@current_ids = splice(@gene_ids,0,5)) { - $uri = URI->new($options{pubmed_site}.$options{pubmed_get_url}); + $uri = URI->new($options{ncbi_site}.$options{ncbi_get_url}); $uri->query_form($uri->query_form(), dopt => uc($options{format}), db => $options{database}, @@ -155,6 +155,15 @@ while (<$terms>) { print STDERR "url: $url\n"; $mech->get($url); my $response = $mech->content; + my $retry_count=5; + while ($response =~ /Error reading from remote server/ and $retry_count > 0) { + $mech->get($url); + $response = $mech->content; + $retry_count--; + } + if ($rety_count <= 0) { + die 'Unable to retreive ids ['.join(',',@current_ids).'] because of a remote server error'; + } # For some dumb reason, they send us xml with html # entities. Ditch them. #$response = decode_entities($response); -- 2.39.2