hgncrest 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c2d7607a23c339f457bbdaaa0a5472ecea23253
4
+ data.tar.gz: 4e4dc696193506888f0e29c81761c5a6bad2258f
5
+ SHA512:
6
+ metadata.gz: d5a43b9ed70e6d0dc734c8efbd728982e65652651470cfb5d4ffe354169cdd679a3b6435aa31a6d7af4db3567cc51a51df20db7b0f6d9c1e33f3111991c5aeb1
7
+ data.tar.gz: 5e47c9c6113b09546ea122cdb915282db8cacccb910a0a640d888aac058f43a6a3eb6c2d504e9af13b2506ee8d62fb78f2a9bd1edc95ab24743476de015367c2
data/hgncrest.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "hgncrest/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'hgncrest'
7
+ s.version = HGNCREST::VERSION
8
+ s.date = Time.now.strftime("%Y-%m-%d")
9
+ s.platform = Gem::Platform::RUBY
10
+
11
+ s.summary = "HGNC REST Ruby API"
12
+ s.description = "HGNC REST Ruby API"
13
+ s.authors = ["Natapol Pornputtapong"]
14
+ s.email = 'natapol.por@gmail.com'
15
+
16
+ s.homepage = 'http://rubygems.org/gems/hgncrest'
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
+
26
+ end
@@ -0,0 +1,73 @@
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 HGNCREST
13
+
14
+ @@url = URI.parse('http://rest.genenames.org')
15
+ @@http_connect = Net::HTTP.new(@@url.host, @@url.port)
16
+ @@info = nil
17
+
18
+ module_function
19
+
20
+ # Connect to specific URL
21
+ #
22
+ # @param [String] Service URL
23
+ def connect(url)
24
+ @@url = URI.parse(url)
25
+ @@http_connect = Net::HTTP.new(@@url.host, @@url.port)
26
+ end
27
+
28
+ # Get response
29
+ #
30
+ # @param [String] Specific service path
31
+ # @return [JSON] request body
32
+ def get(get_path)
33
+ request = Net::HTTP::Get.new(get_path, {'Accept' => 'application/json'})
34
+ response = @@http_connect.request(request)
35
+ if response.code == "200"
36
+ return JSON.parse(response.body)
37
+ else
38
+ raise "Invalid response: #{response.code}"
39
+ end
40
+ end
41
+
42
+ # Download service information
43
+ def dl_info
44
+ @@info = HGNCREST::get('/info') if @@info == nil
45
+ end
46
+
47
+ # Return service information
48
+ #
49
+ # @param [String] Specific service path
50
+ # @return [JSON] request body
51
+ def info
52
+ HGNCREST::dl_info
53
+ return @@info
54
+ end
55
+
56
+ # Return a list containing the fields that can be used to fetch and search records
57
+ #
58
+ # @return [Array] searchableFields
59
+ def searchableFields
60
+ HGNCREST::dl_info
61
+ return @@info["searchableFields"]
62
+ end
63
+
64
+ # Return all the fields that could possibly be returned within a fetch request
65
+ #
66
+ # @return [Array] storedFields
67
+ def storedFields
68
+ HGNCREST::dl_info
69
+ return @@info["storedFields"]
70
+ end
71
+
72
+ end
73
+
@@ -0,0 +1,44 @@
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 HGNCREST
13
+
14
+ @@fetch_cache = {}
15
+
16
+ module_function
17
+
18
+ # Provide search request for detail please follow http://www.genenames.org/help/rest-web-service-help#Content_type
19
+ #
20
+ # @param [String] query string
21
+ # @param [String, Symbol] specific field to fetch for. If nil, fetch based on all fields
22
+ #
23
+ # @return [Array] request body
24
+ def fetch(query, field = nil)
25
+ if @@fetch_cache.has_key?(query)
26
+ return @@fetch_cache[query]
27
+ else
28
+ result = HGNCREST.get("/fetch#{field == nil || field.empty? ? '' : "/#{field.to_s.downcase}"}/#{URI.escape(query)}")['response']['docs']
29
+ @@fetch_cache[query] = result
30
+ return result
31
+ end
32
+ end
33
+
34
+ # Provide id conversion regarded to HGNC database
35
+ #
36
+ # @param [String, Symbol] query string
37
+ # @param [String, Symbol] convert from specified field as in searchableFields
38
+ # @param [String, Symbol] convert to specified field as in storedFields
39
+ #
40
+ # @return [Array] id
41
+ def convert(query, from, to)
42
+ HGNCREST::fetch(query, from)[0][to.to_s.downcase]
43
+ end
44
+ end
@@ -0,0 +1,34 @@
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 HGNCREST
13
+
14
+ @@search_cache = {}
15
+
16
+ module_function
17
+
18
+ # Provide search request for detail please follow http://www.genenames.org/help/rest-web-service-help#Content_type
19
+ #
20
+ # @param [String] query string
21
+ # @param [String, Symbol] specific field to search for. If nil, search all fields
22
+ #
23
+ # @return [Array] request body
24
+ def search(query, field = nil)
25
+ if @@search_cache.has_key?(query)
26
+ return @@search_cache[query]
27
+ else
28
+ result = HGNCREST.get("/search#{field == nil || field.empty? ? '' : "/#{field.to_s.downcase}"}/#{URI.escape(query)}")['response']['docs']
29
+ @@search_cache[query] = result
30
+ return result
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,15 @@
1
+ #
2
+ # Exodus
3
+ # Copyright (C) 2015
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 HGNCREST
14
+ VERSION = "1.0.0"
15
+ end
data/lib/hgncrest.rb ADDED
@@ -0,0 +1,30 @@
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
+
21
+ require 'hgncrest/version'
22
+ require 'hgncrest/connect'
23
+ require 'hgncrest/fetch'
24
+ require 'hgncrest/search'
25
+
26
+ #p HGNCREST::storedFields
27
+ #p HGNCREST::searchableFields
28
+ #p HGNCREST::search('BRAF')
29
+ #p HGNCREST::fetch('BRAF', :symbol)
30
+ #p HGNCREST::convert('BRAF', :symbol, :entrez_id)
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hgncrest
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Natapol Pornputtapong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: HGNC REST Ruby API
14
+ email: natapol.por@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - hgncrest.gemspec
20
+ - lib/hgncrest.rb
21
+ - lib/hgncrest/connect.rb
22
+ - lib/hgncrest/fetch.rb
23
+ - lib/hgncrest/search.rb
24
+ - lib/hgncrest/version.rb
25
+ homepage: http://rubygems.org/gems/hgncrest
26
+ licenses:
27
+ - GPL
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.0.14
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: HGNC REST Ruby API
49
+ test_files: []
50
+ has_rdoc: