Created
July 6, 2012 19:14
-
-
Save cjfields/3062213 to your computer and use it in GitHub Desktop.
eutil test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Modern::Perl; | |
use Bio::DB::EUtilities; | |
# set optional history queue | |
my $factory = Bio::DB::EUtilities->new(-eutil => 'esearch', | |
-email => 'cjfields@bioperl.org', | |
-db => 'nuccore', | |
-term => 'Nasonia vitripennis[organism] NOT 13660[BioProject] NOT WGS[Keyword]', | |
-usehistory => 'y'); | |
my $count = $factory->get_count; | |
# get history from queue | |
my $hist = $factory->next_History || die 'No history data returned'; | |
print "History returned\n"; | |
# note db carries over from above | |
$factory->set_parameters(-eutil => 'efetch', | |
-rettype => 'fasta', | |
-history => $hist); | |
my $retry = 1; | |
my ($retmax, $retstart) = (500,0); | |
open (my $out, '>', 'seqs.fa') || die "Can't open file:$!"; | |
RETRIEVE_SEQS: | |
while ($retstart < $count) { | |
$factory->set_parameters(-retmax => $retmax, | |
-retstart => $retstart); | |
my $res = ''; | |
eval{ | |
$factory->get_Response( | |
-cb => sub { | |
my ($data) = @_; | |
$res .= $data; | |
} ); | |
die "FASTA efetch error found in data chunk" if $res =~ /<ERROR>/; | |
}; | |
if ($@) { | |
die "Server error: $@. Try again later" if $retry > 5; | |
print STDERR "Server error: $@ redo #$retry\n"; | |
$retry++; | |
redo RETRIEVE_SEQS; | |
} | |
my $ct = $res =~ tr/>/>/; | |
print $out $res; | |
say "Retrieved $ct"; | |
$retstart += $retmax; | |
} | |
close $out; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment