my $number = @genbank_na_acc;

print $number."\n";



my $factory = Bio::DB::EUtilities-> new(-eutil => 'esearch',

						-email => $adminEmail,

						-db => 'nucleotide',

						-term => join(',', @genbank_na_acc),

						-usehistory => 'y');



my $record_count = $factory -> get_count;

print $record_count."\n";



my $hist = $factory-> next_History || die 'No History Data returned';

print "History Returned\n";





$factory -> set_parameters(-eutil => 'efetch',

						-rettype => 'gbwithparts',

						-retmode => 'text',

						-history => $hist);



my $retry1 = 0;						

my $retmax1 = 500;

my $retstart1 = 0;



open (WRITE, ">$file3") || die "Can't open file!\n";



RETRIEVE_SEQS:

while ($retstart1 < $record_count){

	$factory -> set_parameters(-retmax => $retmax1,

								-retstart => $retstart1);

	eval{

		$factory->get_Response(-cb => sub {my($data)=@_; print WRITE $data});

	};

	if ($@){

	die "Server error: $@. Try again later" if $retry1 == 5;

	print STDERR "Server error redo #$retry1\n";

	$retry1++ && redo RETRIEVE_SEQS;

	}

	print "Retrieved $retstart1.\n";

	$retstart1 += $retmax1;

}

close WRITE;



print "Finished Eutilities nucleic acid record recovery.\n";