[BioRuby-cvs] bioruby/lib/bio/io ensembl.rb,1.3,1.4

Katayama Toshiaki k at dev.open-bio.org
Wed Mar 28 10:31:50 UTC 2007


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

Modified Files:
	ensembl.rb 
Log Message:
* modified to use Bio::Command.post_form
* newly introduced Bio::Ensembl.new accepts organism and server url as its
  argument, so that user does not need to create subclass.
* several bug fixed


Index: ensembl.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/io/ensembl.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ensembl.rb	14 Jul 2006 14:28:44 -0000	1.3
--- ensembl.rb	28 Mar 2007 10:31:48 -0000	1.4
***************
*** 39,53 ****
  # == Examples
  #
! #  seq = Bio::Ensembl::Human.exportview(1, 1000, 100000)
! #  gff = Bio::Ensembl::Human.exportview(1, 1000, 100000, ['gene'])
  #
! #  seq = Bio::Ensembl::Mouse.exportview(1, 1000, 100000)
! #  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
--- 39,52 ----
  # == Examples
  #
! #  human = Bio::Ensembl.new('Homo_sapiens')
! #  seq = human.exportview(1, 1000, 100000)
! #  gff = human.exportview(1, 1000, 100000, ['gene'])
  #
! #  mouse = Bio::Ensembl.new('Mus_musculus')
! #  seq = mouse.exportview(1, 1000, 100000)
! #  gff = mouse.exportview(1, 1000, 100000, ['gene', 'variation', 'genscan'])
  #
! #  rice = Bio::Enesmbl.new('Oryza_sativa', 'http://www.gramene.org')
! #  seq = rice.exportview(1, 1000, 100000)
  #
  # == References
***************
*** 61,258 ****
  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
  
  
!   # Ensembl Genome Browser Client Super Class
    #
    # == Examples
-   #   
-   #   module Bio
-   #     class Ensembl::Kumamushi < Base
-   #       Organism = 'Milnesium_tardigradum'
-   #     end
-   #   end
-   #   fna = Bio::Ensembl::Kumamushi.exportview(1, 1000, 20000)
    #
!   class Base
! 
!     # Ensembl ExportView Client.
!     #
!     # Retrieve genomic sequence/features from Ensembl ExportView in plain text.
!     # Ensembl ExportView exports genomic data (sequence and features) in 
!     # several file formats including fasta, GFF and tab.
!     #
!     # * ExportViwe (http://www.ensembl.org/Homo_sapiens/exportview).
!     #
!     # == Examples
!     #
!     #   # 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
!     #
!     # Bio::Ensembl::Base#exportview method allow both orderd arguments and 
!     # named arguments. 
!     # Note: mandatory arguments marked '*'.
!     #
!     # === Orderd Arguments
!     #
!     # 1. seq_region_name - Chromosome number (*)
!     # 2. anchor1         - From coordination (*)
!     # 3. anchor2         - To coordination (*)
!     # 4. options         - Features to export (in :format => 'gff' or 'tab')
!     #                      ['similarity', 'repeat', 'genscan', 'variation', 
!     #                       'gene']
!     #
!     # === Named Arguments
!     # 
!     # * :seq_region_name - Chromosome number (*)
!     # * :anchor1         - From coordination (*)
!     # * :anchor2         - To coordination (*)
!     # * :type1           - From coordination type ['bp', ]
!     # * :type2           - To coordination type ['bp', ]
!     # * :upstream        - Bp upstream
!     # * :downstream      - Bp downstream
!     # * :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 => '', 
-                :upstream => '', 
-                :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.start_http(@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
! 
!   end # class Base
! 
! 
!   # Ensembl Human Genome
!   # 
!   # See Bio::Ensembl::Base class.
!   # 
!   class Human < Base
!     Organism = 'Homo_sapiens'
!   end # class Human
! 
!   # Ensembl Mouse Genome
!   #
!   # See Bio::Ensembl::Base class.
!   #
!   class Mouse < Base
!     Organism = 'Mus_musculus'
!   end # class Mouse
  
  end # class Ensembl
--- 60,167 ----
  class Ensembl
  
!   ENSEMBL_URL = 'http://www.ensembl.org'
  
!   def initialize(organism, server = nil)
!     @server = server || ENSEMBL_URL
!     @organism = organism
!     @uri = [ server.chomp('/'), @organism ].join('/')
!   end
  
!   def self.human
!     self.new("Homo_sapiens")
    end
  
+   def self.mouse
+     self.new("Mus_musculus")
+   end
  
!   # Ensembl ExportView Client.
!   #
!   # Retrieve genomic sequence/features from Ensembl ExportView in plain text.
!   # Ensembl ExportView exports genomic data (sequence and features) in 
!   # several file formats including fasta, GFF and tab.
!   #
!   # * ExportViwe (http://www.ensembl.org/Homo_sapiens/exportview).
    #
    # == Examples
    #
!   #   human = Bio::Ensembl.new('Homo_sapiens')
!   #     or
!   #   human = Bio::Ensembl.human
!   #
!   #   # Genomic sequence in Fasta format
!   #   human.exportview(:seq_region_name => 1, 
!   #                    :anchor1 => 1149206, :anchor2 => 1149229)
!   #   human.exportview(1, 1149206, 1149229)
!   #
!   #   # Feature in GFF
!   #   human.exportview(:seq_region_name => 1, 
!   #                    :anchor1 => 1149206, :anchor2 => 1150000, 
!   #                    :options => ['similarity', 'repeat', 
!   #                                 'genscan', 'variation', 'gene'])
!   #   human.exportview(1, 1149206, 1150000, ['variation', 'gene'])
!   #
!   # == Arguments
!   #
!   # Bio::Ensembl#exportview method allow both orderd arguments and 
!   # named arguments. (Note: mandatory arguments are marked by '*').
!   #
!   # === Orderd Arguments
!   #
!   # 1. seq_region_name - Chromosome number (*)
!   # 2. anchor1         - From coordination (*)
!   # 3. anchor2         - To coordination (*)
!   # 4. options         - Features to export (in :format => 'gff' or 'tab')
!   #                      ['similarity', 'repeat', 'genscan', 'variation', 
!   #                       'gene']
!   #
!   # === Named Arguments
!   # 
!   # * :seq_region_name - Chromosome number (*)
!   # * :anchor1         - From coordination (*)
!   # * :anchor2         - To coordination (*)
!   # * :type1           - From coordination type ['bp', ]
!   # * :type2           - To coordination type ['bp', ]
!   # * :upstream        - Bp upstream
!   # * :downstream      - Bp downstream
!   # * :format          - File format ['fasta', 'gff', 'tab']
!   # * :options         - Features to export (for :format => 'gff' or 'tab')
!   #                      ['similarity', 'repeat', 'genscan', 'variation', 
!   #                       'gene']
!   # 
!   def exportview(*args)
!     if args.first.class == Hash
!       options = 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
+     
+     defaults = {
+       :type1 => 'bp', 
+       :type2 => 'bp', 
+       :downstream => '', 
+       :upstream => '', 
+       :format => 'fasta',
+       :options => [],
+       :action => 'export', 
+       :_format => 'Text', 
+       :output => 'txt', 
+       :submit => 'Continue >>'
+     }
  
+     params = defaults.update(options)
  
!     Bio::Command.post_form("#{@uri}/exportview", params)
!   end
  
  end # class Ensembl




More information about the bioruby-cvs mailing list