ensemblrest 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ensemblrest.gemspec +27 -0
- data/lib/ensemblrest.rb +38 -0
- data/lib/ensemblrest/connect.rb +109 -0
- data/lib/ensemblrest/map.rb +32 -0
- data/lib/ensemblrest/sequence.rb +23 -0
- data/lib/ensemblrest/version.rb +15 -0
- metadata +64 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: a85972ee3e540b01b703eabba40b18b86a0c9846
         | 
| 4 | 
            +
              data.tar.gz: 6b5317110ad84500394cf550835271ed6d6a7fd3
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: bf53774dad64eb9032f1a75f56ffe0ff98c4c4e1fa3100d868d008e0b9e0eb08df99b346b6cebfdab8477b06a69551b2f13850854c21ec9d5a2de8c7fc6a645e
         | 
| 7 | 
            +
              data.tar.gz: 6409a4555e6acdf7ae5a455a37f54585f761a78d37abba9bd98426b7454d62431a183f7060a8512e05c6aaa47cad726661fecb6a338349d7419692a51e936633
         | 
    
        data/ensemblrest.gemspec
    ADDED
    
    | @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            $:.push File.expand_path("../lib", __FILE__)
         | 
| 3 | 
            +
            require "ensemblrest/version"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |s|
         | 
| 6 | 
            +
                s.name          = 'ensemblrest'
         | 
| 7 | 
            +
                s.version       = EnsemblREST::VERSION
         | 
| 8 | 
            +
                s.date          = Time.now.strftime("%Y-%m-%d")
         | 
| 9 | 
            +
                s.platform      = Gem::Platform::RUBY
         | 
| 10 | 
            +
                
         | 
| 11 | 
            +
                s.summary       = "Ensembl REST Ruby API"
         | 
| 12 | 
            +
                s.description   = "Ensembl REST Ruby API"
         | 
| 13 | 
            +
                s.authors       = ["Natapol Pornputtapong"]
         | 
| 14 | 
            +
                s.email         = 'natapol.por@gmail.com'
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                s.homepage      = 'http://rubygems.org/gems/ensemblrest'
         | 
| 17 | 
            +
                s.license       = 'GPL'
         | 
| 18 | 
            +
                
         | 
| 19 | 
            +
                
         | 
| 20 | 
            +
                s.files         = `git ls-files`.split("\n")
         | 
| 21 | 
            +
                s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 22 | 
            +
                s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| 23 | 
            +
                s.require_paths = ["lib"]
         | 
| 24 | 
            +
                
         | 
| 25 | 
            +
                s.add_dependency "bio", "~> 1.4"
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            end
         | 
    
        data/lib/ensemblrest.rb
    ADDED
    
    | @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            # 
         | 
| 2 | 
            +
            # Bio
         | 
| 3 | 
            +
            # Copyright (C) 2014
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # author: Natapol Pornputtapong <natapol.por@gmail.com>
         | 
| 6 | 
            +
            #
         | 
| 7 | 
            +
            # Documentation: Natapol Pornputtapong (RDoc'd and embellished by William Webber)
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            $: << File.join(File.expand_path(File.dirname(__FILE__)))
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            #Internal library
         | 
| 15 | 
            +
            require 'bio'
         | 
| 16 | 
            +
            require 'open-uri'
         | 
| 17 | 
            +
            require 'net/http'
         | 
| 18 | 
            +
            require 'uri'
         | 
| 19 | 
            +
            require 'json'
         | 
| 20 | 
            +
            require 'csv'
         | 
| 21 | 
            +
            require 'digest'
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            require 'ensemblrest/connect'
         | 
| 24 | 
            +
            require 'ensemblrest/sequence'
         | 
| 25 | 
            +
            require 'ensemblrest/map'
         | 
| 26 | 
            +
            require 'ensemblrest/version'
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            #p EnsemblREST::sequence_id("ENSP00000288602")
         | 
| 29 | 
            +
            #p EnsemblREST::sequence_region("X:1000000..1000100:1", 'human')
         | 
| 30 | 
            +
            #
         | 
| 31 | 
            +
            #p EnsemblREST::assembly_cdna("ENST00000288602", "100..300")
         | 
| 32 | 
            +
            #p EnsemblREST::assembly_cds('ENST00000288602', '1..1000')
         | 
| 33 | 
            +
            #p EnsemblREST::assembly_map('human', 'GRCh37' , 'X:1000000..1000100:1', 'GRCh38')
         | 
| 34 | 
            +
            #p EnsemblREST::assembly_translation('ENSP00000288602', '100..300')
         | 
| 35 | 
            +
            #EnsemblREST.use37
         | 
| 36 | 
            +
            #
         | 
| 37 | 
            +
            #p EnsemblREST::sequence_id('ENST00000288602', type: 'cdna').seq.length
         | 
| 38 | 
            +
            #p EnsemblREST::sequence_id('ENST00000288602', type: 'cds').seq.length
         | 
| @@ -0,0 +1,109 @@ | |
| 1 | 
            +
            # 
         | 
| 2 | 
            +
            # Bio-ensemblrest
         | 
| 3 | 
            +
            # Copyright (C) 2014
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # author: Natapol Pornputtapong <natapol.por@gmail.com>
         | 
| 6 | 
            +
            #
         | 
| 7 | 
            +
            # Documentation: Natapol Pornputtapong (RDoc'd and embellished by William Webber)
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            module EnsemblREST
         | 
| 13 | 
            +
            	
         | 
| 14 | 
            +
            	@@url = URI.parse('http://rest.ensembl.org')
         | 
| 15 | 
            +
            	@@http_connect = Net::HTTP.new(@@url.host, @@url.port)
         | 
| 16 | 
            +
            	
         | 
| 17 | 
            +
            	SUPPOTEDFORMATS = {
         | 
| 18 | 
            +
            		'text' => 'text/plain',
         | 
| 19 | 
            +
            		'fasta' => 'text/x-fasta',
         | 
| 20 | 
            +
            		'gff3' => 'ext/x-gff3',
         | 
| 21 | 
            +
            		'json' => 'application/json',
         | 
| 22 | 
            +
            		'msgpack' => 'application/x-msgpack',
         | 
| 23 | 
            +
            		'nh' => 'text/x-nh',
         | 
| 24 | 
            +
            		'seqxml' => 'text/x-seqxml+xml', 
         | 
| 25 | 
            +
            		'sereal' => 'application/x-sereal',
         | 
| 26 | 
            +
            		'phyloxml' => 'text/x-phyloxml+xml',
         | 
| 27 | 
            +
            		'xml' => 'text/xml',
         | 
| 28 | 
            +
            		'yaml' => 'text/x-yaml'
         | 
| 29 | 
            +
            	}
         | 
| 30 | 
            +
            		
         | 
| 31 | 
            +
            	
         | 
| 32 | 
            +
            	module_function
         | 
| 33 | 
            +
            	
         | 
| 34 | 
            +
            	def connect(server)
         | 
| 35 | 
            +
            		@@url = URI.parse(server)
         | 
| 36 | 
            +
            		@@http_connect = Net::HTTP.new(@@url.host, @@url.port)
         | 
| 37 | 
            +
            	end
         | 
| 38 | 
            +
            	
         | 
| 39 | 
            +
            	def use_GRCh37
         | 
| 40 | 
            +
            		@@url = URI.parse('http://grch37.rest.ensembl.org/')
         | 
| 41 | 
            +
            		@@http_connect = Net::HTTP.new(@@url.host, @@url.port)
         | 
| 42 | 
            +
            	end
         | 
| 43 | 
            +
            	
         | 
| 44 | 
            +
            	def use37
         | 
| 45 | 
            +
            		EnsemblREST::use_GRCh37
         | 
| 46 | 
            +
            	end
         | 
| 47 | 
            +
            	
         | 
| 48 | 
            +
            	def use_GRCh38
         | 
| 49 | 
            +
            		@@url = URI.parse('http://rest.ensembl.org/')
         | 
| 50 | 
            +
            		@@http_connect = Net::HTTP.new(@@url.host, @@url.port)
         | 
| 51 | 
            +
            	end
         | 
| 52 | 
            +
            	
         | 
| 53 | 
            +
            	def use38
         | 
| 54 | 
            +
            		EnsemblREST::use_GRCh38
         | 
| 55 | 
            +
            	end
         | 
| 56 | 
            +
            	
         | 
| 57 | 
            +
            	def parse_options(options)
         | 
| 58 | 
            +
            		parsed_options = {opts: [], format: {}}
         | 
| 59 | 
            +
            		options.each do |k, v|
         | 
| 60 | 
            +
            			if k.to_s == 'format'
         | 
| 61 | 
            +
            				parsed_options[:format] = {'content-type' => EnsemblREST::SUPPOTEDFORMATS.has_key?(v) ? EnsemblREST::SUPPOTEDFORMATS[v] : v}
         | 
| 62 | 
            +
            			elsif k.to_s == 'content-type'
         | 
| 63 | 
            +
            				parsed_options[:format] = {'content-type' => v}
         | 
| 64 | 
            +
            			else
         | 
| 65 | 
            +
            				parsed_options[:opts].push case v.class
         | 
| 66 | 
            +
            				when TrueClass
         | 
| 67 | 
            +
            					"#{k}=1"
         | 
| 68 | 
            +
            				when FalseClass
         | 
| 69 | 
            +
            					"#{k}=0"
         | 
| 70 | 
            +
            				else
         | 
| 71 | 
            +
            					"#{k}=#{v}"
         | 
| 72 | 
            +
            				end
         | 
| 73 | 
            +
            			end
         | 
| 74 | 
            +
            			
         | 
| 75 | 
            +
            		end
         | 
| 76 | 
            +
            		return parsed_options
         | 
| 77 | 
            +
            	end
         | 
| 78 | 
            +
            	
         | 
| 79 | 
            +
            	def parse_response(response, type)
         | 
| 80 | 
            +
            		case response.code
         | 
| 81 | 
            +
            		when '200'
         | 
| 82 | 
            +
            			case type
         | 
| 83 | 
            +
            			when 'application/json'
         | 
| 84 | 
            +
            				return JSON.parse(response.body)
         | 
| 85 | 
            +
            			when 'ext/x-gff3'
         | 
| 86 | 
            +
            				return Bio::GFF::GFF3.new(response.body)
         | 
| 87 | 
            +
            			when 'text/x-fasta'
         | 
| 88 | 
            +
            				return Bio::FastaFormat.new(response.body)
         | 
| 89 | 
            +
            			when 'text/x-phyloxml+xml'
         | 
| 90 | 
            +
            				return Bio::PhyloXML::Parser.new(response.body)
         | 
| 91 | 
            +
            			else
         | 
| 92 | 
            +
            				return response.body
         | 
| 93 | 
            +
            			end
         | 
| 94 | 
            +
            		else
         | 
| 95 | 
            +
            			raise "Invalid response: #{response.code}"
         | 
| 96 | 
            +
            		end
         | 
| 97 | 
            +
            	end
         | 
| 98 | 
            +
            	
         | 
| 99 | 
            +
            	def get(get_path, options)
         | 
| 100 | 
            +
            		parsed_options = EnsemblREST::parse_options(options)
         | 
| 101 | 
            +
            		request = Net::HTTP::Get.new("#{get_path}#{parsed_options[:opts].empty? ? '' : "?#{parsed_options[:opts].join(';')}"}", parsed_options[:format])
         | 
| 102 | 
            +
            		return EnsemblREST::parse_response(@@http_connect.request(request), parsed_options[:format]['content-type'])
         | 
| 103 | 
            +
            	end
         | 
| 104 | 
            +
            	
         | 
| 105 | 
            +
            	#def post(get_path, request_body, options)
         | 
| 106 | 
            +
            	#	request = Net::HTTP::Get.new(get_path, EnsemblREST::parse_format(options))
         | 
| 107 | 
            +
            	#	return EnsemblREST::parse_response(@@http_connect.request(request), options['Content-Type'])
         | 
| 108 | 
            +
            	#end
         | 
| 109 | 
            +
            end
         | 
| @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            # 
         | 
| 2 | 
            +
            # Bio-ensemblrest
         | 
| 3 | 
            +
            # Copyright (C) 2014
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # author: Natapol Pornputtapong <natapol.por@gmail.com>
         | 
| 6 | 
            +
            #
         | 
| 7 | 
            +
            # Documentation: Natapol Pornputtapong (RDoc'd and embellished by William Webber)
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            module EnsemblREST
         | 
| 13 | 
            +
            	
         | 
| 14 | 
            +
            	module_function
         | 
| 15 | 
            +
            	
         | 
| 16 | 
            +
            	def assembly_cdna(id, region, options = {})
         | 
| 17 | 
            +
            		return EnsemblREST.get("map/cdna/#{id}/#{region}", {format: 'json'}.merge(options))
         | 
| 18 | 
            +
            	end
         | 
| 19 | 
            +
            	
         | 
| 20 | 
            +
            	def assembly_cds(id, region, options = {})
         | 
| 21 | 
            +
            		return EnsemblREST.get("map/cds/#{id}/#{region}", {format: 'json'}.merge(options))
         | 
| 22 | 
            +
            	end
         | 
| 23 | 
            +
            	
         | 
| 24 | 
            +
            	def assembly_map(species, asm_one, region, asm_two, options = {})
         | 
| 25 | 
            +
            		return EnsemblREST.get("map/#{species}/#{asm_one}/#{region}/#{asm_two}", {format: 'json'}.merge(options))
         | 
| 26 | 
            +
            	end
         | 
| 27 | 
            +
            	
         | 
| 28 | 
            +
            	def assembly_translation(id, region, options = {})
         | 
| 29 | 
            +
            		return EnsemblREST.get("map/translation/#{id}/#{region}", {format: 'json'}.merge(options))
         | 
| 30 | 
            +
            	end
         | 
| 31 | 
            +
            	
         | 
| 32 | 
            +
            end
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            # 
         | 
| 2 | 
            +
            # Bio-ensemblrest
         | 
| 3 | 
            +
            # Copyright (C) 2014
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # author: Natapol Pornputtapong <natapol.por@gmail.com>
         | 
| 6 | 
            +
            #
         | 
| 7 | 
            +
            # Documentation: Natapol Pornputtapong (RDoc'd and embellished by William Webber)
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            module EnsemblREST
         | 
| 13 | 
            +
            	
         | 
| 14 | 
            +
            	module_function
         | 
| 15 | 
            +
            	
         | 
| 16 | 
            +
            	def sequence_id(id, options = {})
         | 
| 17 | 
            +
            		return EnsemblREST.get("sequence/id/#{id}", {format: 'fasta'}.merge(options))
         | 
| 18 | 
            +
            	end
         | 
| 19 | 
            +
            	
         | 
| 20 | 
            +
            	def sequence_region(region, species, options = {})
         | 
| 21 | 
            +
            		return EnsemblREST.get("sequence/region/#{species}/#{region}", {format: 'fasta'}.merge(options))
         | 
| 22 | 
            +
            	end
         | 
| 23 | 
            +
            end
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            # 
         | 
| 2 | 
            +
            # Exodus
         | 
| 3 | 
            +
            # Copyright (C) 2014
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # author: Natapol Pornputtapong <natapol.por@gmail.com>
         | 
| 6 | 
            +
            #
         | 
| 7 | 
            +
            # Documentation: Natapol Pornputtapong (RDoc'd and embellished by William Webber)
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
         | 
| 11 | 
            +
             | 
| 12 | 
            +
             | 
| 13 | 
            +
            module EnsemblREST
         | 
| 14 | 
            +
            	VERSION = "0.0.5"
         | 
| 15 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,64 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: ensemblrest
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.5
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Natapol Pornputtapong
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2015-04-14 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bio
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '1.4'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '1.4'
         | 
| 27 | 
            +
            description: Ensembl REST Ruby API
         | 
| 28 | 
            +
            email: natapol.por@gmail.com
         | 
| 29 | 
            +
            executables: []
         | 
| 30 | 
            +
            extensions: []
         | 
| 31 | 
            +
            extra_rdoc_files: []
         | 
| 32 | 
            +
            files:
         | 
| 33 | 
            +
            - ensemblrest.gemspec
         | 
| 34 | 
            +
            - lib/ensemblrest.rb
         | 
| 35 | 
            +
            - lib/ensemblrest/connect.rb
         | 
| 36 | 
            +
            - lib/ensemblrest/map.rb
         | 
| 37 | 
            +
            - lib/ensemblrest/sequence.rb
         | 
| 38 | 
            +
            - lib/ensemblrest/version.rb
         | 
| 39 | 
            +
            homepage: http://rubygems.org/gems/ensemblrest
         | 
| 40 | 
            +
            licenses:
         | 
| 41 | 
            +
            - GPL
         | 
| 42 | 
            +
            metadata: {}
         | 
| 43 | 
            +
            post_install_message: 
         | 
| 44 | 
            +
            rdoc_options: []
         | 
| 45 | 
            +
            require_paths:
         | 
| 46 | 
            +
            - lib
         | 
| 47 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 48 | 
            +
              requirements:
         | 
| 49 | 
            +
              - - ">="
         | 
| 50 | 
            +
                - !ruby/object:Gem::Version
         | 
| 51 | 
            +
                  version: '0'
         | 
| 52 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 53 | 
            +
              requirements:
         | 
| 54 | 
            +
              - - ">="
         | 
| 55 | 
            +
                - !ruby/object:Gem::Version
         | 
| 56 | 
            +
                  version: '0'
         | 
| 57 | 
            +
            requirements: []
         | 
| 58 | 
            +
            rubyforge_project: 
         | 
| 59 | 
            +
            rubygems_version: 2.0.14
         | 
| 60 | 
            +
            signing_key: 
         | 
| 61 | 
            +
            specification_version: 4
         | 
| 62 | 
            +
            summary: Ensembl REST Ruby API
         | 
| 63 | 
            +
            test_files: []
         | 
| 64 | 
            +
            has_rdoc: 
         |