in progress...
[jalview.git] / forester / ruby / evoruby / lib / evo / io / web / uniprotkb.rb
index 81f0c76..c63b1df 100644 (file)
@@ -2,22 +2,33 @@
 require 'net/http'
 require 'uri'
 
+require 'lib/evo/io/parser/uniprot_parser'
+
 module Evoruby
 
 
   class UniprotKB
-    def initialize
 
-    end
+    BASE_URL = "http://www.ebi.ac.uk/Tools/dbfetch/dbfetch?db=uniprotkb;"
 
-    def get
-      require 'net/http'
-      require 'uri'
 
-      uri = URI.parse("http://www.ebi.ac.uk/Tools/dbfetch/dbfetch?db=uniprotkb;id=1433X_MAIZE;format=uniprot;style=raw")
+    def UniprotKB::get_by_id( id, style = "raw", format = "uniprot" )
+      url_str = BASE_URL + "id=#{id};format=#{format};style=#{style}"
+      uri = URI.parse url_str
       response = Net::HTTP.get_response uri
-      puts response.body
+      lines = []
+      response.body.each_line do |line|
+        lines << line
+        puts line
+      end
+      lines
+    end
+
 
+    def UniprotKB::get_entry_by_id( id  )
+      lines = get_by_id( id,  "raw", "uniprot" )
+      p = UniprotParser.new
+      return p.parse( lines )
     end
 
   end