genecache 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +1 -0
- data/genecache.gemspec +27 -0
- data/lib/genecache.rb +65 -0
- data/lib/genecache/version.rb +3 -0
- data/spec/genecache_spec.rb +8 -0
- data/spec/spec_helper.rb +8 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 15de64a20d8f2335e5c101e3d93045ad3a78c6be
|
4
|
+
data.tar.gz: 35c7e5cdb8309c2ac1d1ce775ee8bad258d3128f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e95d8bc1be6881cb5464c70ee6d0c5d7ee41a9bf15bf99d762c283f89f8d6926786030a1ae623fe7cd33036e26b846059b12fbab6f070c37f0b4e63e374f8a4
|
7
|
+
data.tar.gz: 129d3188032666eafa3903ad92092a6bb03f2139c66f7a1537e436bc4f72088fea453598d1819c9af2b6b1af0b01f24b30f16c557185747336a485bad78e207c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Fedor Gusev
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Genecache
|
2
|
+
|
3
|
+
Simple and fast conversion of GENE IDs. Major source of data is http://biodb.jp. Conversion tables are downloaded and stored in local SQLite database for very fast access.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'genecache'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install genecache
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'genecache'
|
22
|
+
|
23
|
+
GeneCache.convert('hsa', 'ensg_id', 'omim_id', 'ENSG00000142192') # APP
|
24
|
+
# returns ['104300', '104760', '605714']
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/genecache.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'genecache/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "genecache"
|
8
|
+
spec.version = Genecache::VERSION
|
9
|
+
spec.authors = ["Fedor Gusev"]
|
10
|
+
spec.email = ["gusevfe@gmail.com"]
|
11
|
+
spec.description = %q{Very simple GENE ID conversion tool with a local SQLite3 DB for caching}
|
12
|
+
spec.summary = %q{Simple and fast conversion of GENE IDs. Major source of data is http://biodb.jp. Conversion tables are downloaded and stored in local SQLite database for very fast access.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_dependency 'sqlite3'
|
26
|
+
spec.add_dependency 'zipruby'
|
27
|
+
end
|
data/lib/genecache.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "genecache/version"
|
2
|
+
require 'open-uri'
|
3
|
+
require 'zipruby'
|
4
|
+
require 'csv'
|
5
|
+
require 'tempfile'
|
6
|
+
require 'sqlite3'
|
7
|
+
require 'logger'
|
8
|
+
require 'fileutils'
|
9
|
+
|
10
|
+
$log = Logger.new STDERR
|
11
|
+
|
12
|
+
# TODO: check we have working sqlite3 executable for fast import of data
|
13
|
+
|
14
|
+
class GeneCache
|
15
|
+
def self.db_path
|
16
|
+
FileUtils.mkdir_p ENV['HOME'] + "/.genecache"
|
17
|
+
return ENV['HOME'] + "/.genecache/db.sqlite3"
|
18
|
+
end
|
19
|
+
|
20
|
+
@@db = SQLite3::Database.new GeneCache.db_path
|
21
|
+
@@tables = @@db.execute("SELECT name FROM sqlite_master where type = 'table'")
|
22
|
+
|
23
|
+
def self.convert(species, from, to, id)
|
24
|
+
table = "#{species}_#{from}_#{to}"
|
25
|
+
unless @@tables.include?([table])
|
26
|
+
# TODO: Update table sometimes!
|
27
|
+
self.download!(species, from, to)
|
28
|
+
end
|
29
|
+
|
30
|
+
r = @@db.execute "select #{to} from #{table} where #{from} = '#{id}'"
|
31
|
+
r.flatten
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.download!(species, from, to)
|
35
|
+
table = "#{species}_#{from}_#{to}"
|
36
|
+
$log.info "Downloading table: #{table}"
|
37
|
+
@@db.execute "drop table if exists #{table}"
|
38
|
+
@@db.execute "drop index if exists from_index"
|
39
|
+
@@db.execute "drop index if exists to_index"
|
40
|
+
|
41
|
+
url = "http://biodb.jp/tmp/#{table}.zip"
|
42
|
+
zip_data = open(url).read
|
43
|
+
|
44
|
+
Zip::Archive.open_buffer(zip_data) do |ar|
|
45
|
+
ar.fopen(0) do |f|
|
46
|
+
tmp = Tempfile.new 'biodb'
|
47
|
+
data = f.read.split("\n")
|
48
|
+
header = data.first.split
|
49
|
+
throw "Invalid header!" if header.sort != [from, to].sort
|
50
|
+
@@db.execute "create table #{table} (#{header.first} VARCHAR(255), #{header.last} VARCHAR(255))"
|
51
|
+
|
52
|
+
rest = data[1..-5] * "\n"
|
53
|
+
tmp.write rest
|
54
|
+
tmp.close
|
55
|
+
|
56
|
+
system(%$echo -e ".mode tabs \\n.import #{File.expand_path(tmp.path)} #{table}" | sqlite3 #{self.db_path}$)
|
57
|
+
@@db.execute "create index from_index on #{table} (#{header.first})"
|
58
|
+
@@db.execute "create index to_index on #{table} (#{header.last})"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Update local list of tables
|
62
|
+
@@tables = @@db.execute("SELECT name FROM sqlite_master where type = 'table' and name = '#{table}'")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: genecache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fedor Gusev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: zipruby
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Very simple GENE ID conversion tool with a local SQLite3 DB for caching
|
84
|
+
email:
|
85
|
+
- gusevfe@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- genecache.gemspec
|
96
|
+
- lib/genecache.rb
|
97
|
+
- lib/genecache/version.rb
|
98
|
+
- spec/genecache_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
homepage: ''
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.0.2
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Simple and fast conversion of GENE IDs. Major source of data is http://biodb.jp.
|
124
|
+
Conversion tables are downloaded and stored in local SQLite database for very fast
|
125
|
+
access.
|
126
|
+
test_files:
|
127
|
+
- spec/genecache_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
has_rdoc:
|