gene_names 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d6cef66a7dcf6fe253dcde653c2d70cd8e77a24
4
+ data.tar.gz: 6882686de1ba7e41e89ea8b6c64533212a448653
5
+ SHA512:
6
+ metadata.gz: 7723a539fb9c710be56bc454ef4eb779d22555a5ac1c19e1867beb807a2e8acf09b930b67ac35efb6a4359075b56fc1a7f8757649411163677a2f01022948b80
7
+ data.tar.gz: b589f0118d050d95ab2be2fff8ddcb7723f95c891e5891c3e5fc1dba7e3fe78f5671323226a6b6ab171d2546f5498379de8267c15826301ac27faad2110521e8
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gene_names.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Eric Harrison
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ GeneNames
2
+ ====================
3
+
4
+ A sall little gem used for fetching gene information from genenames.org's REST api
5
+
6
+ ## Installation
7
+ ``` bash
8
+ gem install gene_names
9
+ ```
10
+
11
+ ## Usage
12
+ ```ruby
13
+ require 'gene_names'
14
+ gene = GeneNames.fetch('TOP2A')
15
+ gene.inspect
16
+ ```
17
+
18
+ ## Copyright
19
+
20
+ Copyright (c) 2014 SmashTank Apps, LLC.
21
+
22
+ This program is free software: you can redistribute it and/or modify
23
+ it under the terms of the GNU General Public License as published by
24
+ the Free Software Foundation, either version 3 of the License, or
25
+ (at your option) any later version.
26
+
27
+ This program is distributed in the hope that it will be useful,
28
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
29
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
+ GNU General Public License for more details.
31
+
32
+ You should have received a copy of the GNU General Public License
33
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gene_names/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gene_names"
8
+ spec.version = GeneNames::VERSION
9
+ spec.authors = ["Eric Harrison", "SmashTank Apps"]
10
+ spec.email = ["eharrison@smashtankapps.com"]
11
+ spec.summary = %q{Gem for access to genenames.org api}
12
+ spec.description = %q{}
13
+ spec.homepage = "http://github.com/smashtank/gene_names"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,7 @@
1
+ require "gene_names/version"
2
+ require "gene_names/constants"
3
+ require "gene_names/http"
4
+ require "gene_names/record"
5
+
6
+ module GeneNames
7
+ end
@@ -0,0 +1,3 @@
1
+ module GeneNames
2
+ SERVER = 'http://rest.genenames.org'
3
+ end
@@ -0,0 +1,89 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ module GeneNames
6
+ class HTTP
7
+ class InvalidResponse < StandardError; end;
8
+ def self.fetch(value, type)
9
+ do_request('/' + ['',:fetch, type, value].collect(&:to_s).join('/'))['response']['docs'].collect{|doc| GeneNames::Record.new(doc)}
10
+ end
11
+
12
+ def self.info
13
+ do_request('/info')
14
+ end
15
+
16
+ def self.search
17
+ #TODO
18
+ end
19
+
20
+ def self.searchable_fields=(*fields)
21
+ @searchable_fields = fields
22
+ end
23
+
24
+ def self.searchable_fields
25
+ return @search_fields || load_searchable_fields
26
+ end
27
+
28
+ def self.stored_fields=(*fields)
29
+ @searchable_fields = fields
30
+ end
31
+
32
+ def self.stored_fields
33
+ return @stored_fields || load_stored_fields
34
+ end
35
+
36
+ private
37
+
38
+ def self.load_searchable_fields
39
+ self.searchable_fields = self.info['searchableFields']
40
+ end
41
+
42
+ def self.load_stored_fields
43
+ self.searchable_fields = self.info['storedFields']
44
+ end
45
+
46
+ def self.do_request(path, response_type = :json)
47
+ http = build_http
48
+ response = get_response(http, path, response_type)
49
+ return parse_response(response)
50
+ end
51
+
52
+ def self.build_http
53
+ url = URI.parse(GeneNames::SERVER)
54
+ Net::HTTP.new(url.host, url.port)
55
+ end
56
+
57
+ def self.get_response(http, path, response_type)
58
+ response = http.request(self.build_request(path, response_type))
59
+ raise InvalidResponse, "Invalid response: #{response.code}" unless response.code == '200'
60
+ return response
61
+ end
62
+
63
+ def self.build_request(path, response_type)
64
+ Net::HTTP::Get.new(path, {'Accept' => accept_for_type(response_type)})
65
+ end
66
+
67
+ def self.parse_response(response)
68
+ return case response.content_type
69
+ when 'application/json'
70
+ JSON.parse(response.body)
71
+ when 'text/xml'
72
+ #TODO
73
+ else
74
+ raise "Unknown content type: '#{response.content_type.to_s}'"
75
+ end
76
+ end
77
+
78
+ def self.accept_for_type(response_type)
79
+ case response_type
80
+ when :json, 'json'
81
+ 'application/json'
82
+ when :xml, xml
83
+ 'text/xml'
84
+ else
85
+ raise "Unknown response type: '#{response_type.to_s}'"
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,19 @@
1
+ module GeneNames
2
+ class Record
3
+ GeneNames::HTTP.stored_fields.each do |f|
4
+ attr_accessor f.to_sym rescue nil
5
+ end
6
+
7
+ def initialize(params = {})
8
+ params.map{|k,v| self.send(k + '=', v)}
9
+ end
10
+
11
+ def self.find_all(value, type = :symbol)
12
+ GeneNames::HTTP.fetch(value, type)
13
+ end
14
+
15
+ def chromosome
16
+ self.location.gsub(/^(\d+).*$/, '\1')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module GeneNames
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gene_names
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric Harrison
8
+ - SmashTank Apps
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.6'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.6'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: ''
43
+ email:
44
+ - eharrison@smashtankapps.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - gene_names.gemspec
55
+ - lib/gene_names.rb
56
+ - lib/gene_names/constants.rb
57
+ - lib/gene_names/http.rb
58
+ - lib/gene_names/record.rb
59
+ - lib/gene_names/version.rb
60
+ homepage: http://github.com/smashtank/gene_names
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.2
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Gem for access to genenames.org api
84
+ test_files: []