lib/gi.rb in mspire-0.1.7 vs lib/gi.rb in mspire-0.2.0

- old
+ new

@@ -38,22 +38,27 @@ class GI BATCH_SIZE = 500 # takes an array of gi numbers and returns an array of annotation # This allows use of the batch search mode on NCBI + # returns nil if no internet connection def self.gi2annot(list_of_gi_numbers) + annots = [] loop do batch = list_of_gi_numbers.slice!(0..BATCH_SIZE) if batch.size == 0 then break end string = batch.join(",") url = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=protein&retmode=xml&id=#{string}" #puts url - annots = [] - open(url) do |handle| - annots = parse_etool_output(handle) + begin + open(url) do |handle| + annots.push( *(parse_etool_output(handle)) ) + end + rescue SocketError + return nil end - annots end + annots end protected # Returns a list of Annotation strings def self.parse_etool_output(handle)