[BioRuby-cvs] bioruby/lib/bio/io ensembl.rb,1.1,1.2

Mitsuteru C. Nakao nakao at dev.open-bio.org
Thu Apr 27 05:38:52 UTC 2006


Update of /home/repository/bioruby/bioruby/lib/bio/io
In directory dev.open-bio.org:/tmp/cvs-serv2667/lib/bio/io

Modified Files:
	ensembl.rb 
Log Message:
* ensembl.rb: Use Bio::Command::NetTools.net_http_start for proxy server.
* ensembl.rb: Added Ensembl.server_uri method.



Index: ensembl.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/io/ensembl.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ensembl.rb	14 Apr 2006 06:28:09 -0000	1.1
--- ensembl.rb	27 Apr 2006 05:38:50 -0000	1.2
***************
*** 27,31 ****
  #
  
! require 'bio'
  require 'cgi'
  
--- 27,32 ----
  #
  
! require 'bio/command'
! require 'uri'
  require 'cgi'
  
***************
*** 44,47 ****
--- 45,54 ----
  #  gff = Bio::Ensembl::Mouse.exportview(1, 1000, 100000, ['gene', 'variation', 'genscan'])
  #
+ #  Bio::Enesmbl.server_uri("http://www.gramene.org")
+ #  class Rice < Base
+ #    Organism = 'Oryza_sativa'
+ #  end
+ #  seq = Bio::Ensembl::Rice.exportview(1, 1000, 100000)
+ #
  # == References
  #
***************
*** 49,56 ****
  #   http:/www.ensembl.org/
  #
  class Ensembl
  
!   # Hostname of Ensembl Genome Browser.
!   ServerName = 'www.ensembl.org'
  
  
--- 56,86 ----
  #   http:/www.ensembl.org/
  #
+ # * GRAMENE
+ #   http://www.gramene.org/
+ #
  class Ensembl
  
!   # Hostname of the Ensembl Genome Browser.
!   EBIServerURI = 'http://www.ensembl.org'
! 
!   # An Alternative Hostname for Ensembl Genome Browser.
!   @@server_uri = nil
! 
!   # Sets and uses an alternative hostname for ensembl genome browser.
!   #
!   # == Example
!   #
!   #   require 'bio'
!   #   p Bio::Enesmbl.server_uri #=> 'http://www.ensembl.org'
!   #   Bio::Enesmbl.server_uri("http://www.gramene.org")
!   #   p Bio::Enesmbl.server_uri #=> "http://www.gramene.org"
!   #
!   def self.server_uri(uri = nil)
!     if uri
!       @@server_uri = uri
!     else
!       @@server_uri || EBIServerURI
!     end
!   end
  
  
***************
*** 79,89 ****
      #
      #   # Genomic sequence in Fasta format
!     #   Bio::Ensembl::Human.exportview(:seq_region_name => 1, :anchor1 => 1149206, :anchor2 => 1149229)
      #   Bio::Ensembl::Human.exportview(1, 1149206, 1149229)
      #
      #   # Feature in GFF
!     #   Bio::Ensembl::Human.exportview(:seq_region_name => 1, :anchor1 => 1149206, :anchor2 => 1150000, 
!     #                                  :options => ['similarity', 'repeat', 'genscan', 'variation', 'gene'])
!     #   Bio::Ensembl::Human.exportview(1, 1149206, 1150000, ['variation', 'gene'])
      #
      # == Arguments
--- 109,124 ----
      #
      #   # Genomic sequence in Fasta format
!     #   Bio::Ensembl::Human.exportview(:seq_region_name => 1, 
!     #                                  :anchor1 => 1149206, :anchor2 => 1149229)
      #   Bio::Ensembl::Human.exportview(1, 1149206, 1149229)
      #
      #   # Feature in GFF
!     #   Bio::Ensembl::Human.exportview(:seq_region_name => 1, 
!     #                                  :anchor1 => 1149206, :anchor2 => 1150000, 
!     #                                  :options => ['similarity', 'repeat', 
!     #                                               'genscan', 'variation', 
!     #                                               'gene'])
!     #   Bio::Ensembl::Human.exportview(1, 1149206, 1150000, 
!     #                                  ['variation', 'gene'])
      #
      # == Arguments
***************
*** 99,103 ****
      # 3. anchor2         - To coordination (*)
      # 4. options         - Features to export (in :format => 'gff' or 'tab')
!     #                      ['similarity', 'repeat', 'genscan', 'variation', 'gene']
      #
      # === Named Arguments
--- 134,139 ----
      # 3. anchor2         - To coordination (*)
      # 4. options         - Features to export (in :format => 'gff' or 'tab')
!     #                      ['similarity', 'repeat', 'genscan', 'variation', 
!     #                       'gene']
      #
      # === Named Arguments
***************
*** 112,128 ****
      # * :format          - File format ['fasta', 'gff', 'tab']
      # * :options         - Features to export (for :format => 'gff' or 'tab')
!     #                      ['similarity', 'repeat', 'genscan', 'variation', 'gene']
      # 
      def self.exportview(*args)
-       cgi = Client.new('exportview', self::Organism)
- 
        if args.first.class == Hash then opts = args.first
        else
!         opts = {:seq_region_name => args[0], :anchor1 => args[1], :anchor2 => args[2]}
          case args.size
!         when 3 then opts.update({:format => 'fasta'})
!         when 4 then opts.update({:format => 'gff', :options => args[3]}) ;        end
        end
!       @hash = {:type1 => 'bp', 
                 :type2 => 'bp', 
                 :downstream => '', 
--- 148,169 ----
      # * :format          - File format ['fasta', 'gff', 'tab']
      # * :options         - Features to export (for :format => 'gff' or 'tab')
!     #                      ['similarity', 'repeat', 'genscan', 'variation', 
!     #                       'gene']
      # 
      def self.exportview(*args)
        if args.first.class == Hash then opts = args.first
        else
!         options = {:seq_region_name => args[0], 
!                    :anchor1 => args[1], 
!                    :anchor2 => args[2]}
          case args.size
!         when 3 then 
!           options.update({:format => 'fasta'})
!         when 4 then 
!           options.update({:format => 'gff', :options => args[3]})
!         end
        end
! 
!       @data = {:type1 => 'bp', 
                 :type2 => 'bp', 
                 :downstream => '', 
***************
*** 130,169 ****
                 :format => 'fasta',
                 :options => [],
!                :action => 'export', :_format => 'Text', :output => 'txt', :submit => 'Continue >>'}
  
!       cgi.exec(@hash.update(opts))
      end
  
      # An Ensembl CGI client class
      # 
      # === Examples
      #
!     #  cgi = Client('martview', 'Homo_sapiens')
!     #  cgi.exec(hash_data)
      #
!     class Client < PSORT::CGIDriver
        def initialize(cgi_name, genome_name)
!         super(Ensembl::ServerName, ['', genome_name, cgi_name].join('/'))
        end
  
!       private
  
!       def make_args(query)
!         @args = {}
!         query.each { |k, v| @args[k.to_s] = v }
!         nested_args_join(query)
        end
  
!       def nested_args_join(hash)
          tmp = []
          hash.each do |key, value|
!           if value.class == Array then value.each { |val| tmp << [key, val] } else tmp << [key, value] end
          end
!         tmp.map {|x| x.map {|x| CGI.escape(x.to_s) }.join("=") }.join('&')
        end
  
-       def parse_report(result_body)
-         result_body
-       end
      end # class Client
  
--- 171,238 ----
                 :format => 'fasta',
                 :options => [],
!                :action => 'export', 
!                :_format => 'Text', 
!                :output => 'txt', 
!                :submit => 'Continue >>'}
  
!       cgi = Client.new('exportview', self::Organism)
!       cgi.exec(@data.update(options))
      end
  
+ 
+ 
      # An Ensembl CGI client class
+     #
+     # Enable the use of HTTP access via a proxy by setting the proxy address up
+     # as the 'http_proxy' enviroment variable. 
      # 
      # === Examples
      #
!     #  cgi = Client.new('martview', 'Homo_sapiens')
!     #  result_body = cgi.exec(hash_data)
      #
!     class Client
! 
!       # Sets cgi_name and genome_name.
!       #
!       # === Example
!       #
!       #  cgi = Client.new('martview', 'Homo_sapiens')
!       #
        def initialize(cgi_name, genome_name)
!         @uri = URI.parse(Ensembl.server_uri)
!         @path = ['', genome_name, cgi_name].join('/')
        end
  
!       # Executes query with data.
!       #
!       # === Example
!       #
!       #  result_body = cgi.exec(hash_data)
!       #
!       def exec(data_hash)
!         data = make_args(data_hash)
  
!         result = nil      
!         Bio::Command::NetTools.net_http_start(@uri.host, @uri.port) {|http|
!           result, = http.post(@path, data)
!         }
!         result.body
        end
  
!       private
! 
!       def make_args(hash)
          tmp = []
          hash.each do |key, value|
!           if value.class == Array then 
!             value.each { |val| tmp << [key, val] } 
!           else 
!             tmp << [key, value] 
!           end
          end
!         tmp.map {|e| e.map {|x| CGI.escape(x.to_s) }.join("=") }.join('&')
        end
  
      end # class Client
  




More information about the bioruby-cvs mailing list