biocgem 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bioc_gem/command.rb +17 -7
- data/lib/bioc_gem/options.rb +2 -0
- data/lib/bioc_gem/parser.rb +41 -27
- data/lib/bioc_gem/version.rb +1 -1
- data/template/newgem/Rakefile.tt +33 -7
- data/template/newgem/lib/new_gem_entry.rb.tt +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42cd5ff623873b8031d52cb669f1e5c8f5893a4d6c4744c49012bc570d145871
|
4
|
+
data.tar.gz: ad395c534ceb64ad0dc6493120ce7870a02ad09dab4a804cc88599dc71363184
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc5968031537f5057914f724500dbe9a162d95f3da4bc488edfb1df59f4412ae733a4a434c2e2a1ea75bfb32b1f6ef9f26797bc295a65ac268501b8c8cfa0645
|
7
|
+
data.tar.gz: 9db05fb3944a0cecc5985f6a794ae678329241b2989db2a14d7386583eb63f673bee4b6a887f92f25d0a62b305755f44f4f538be3a20bf4b894950131dd98f5a
|
data/lib/bioc_gem/command.rb
CHANGED
@@ -8,16 +8,26 @@ module BiocGem
|
|
8
8
|
attr_accessor :parser
|
9
9
|
|
10
10
|
def initialize(argv = ARGV)
|
11
|
-
@argv = argv
|
11
|
+
@argv = argv.clone
|
12
12
|
@parser = Parser.new
|
13
13
|
end
|
14
14
|
|
15
15
|
def run
|
16
|
-
parser.
|
16
|
+
parser.parse!(@argv)
|
17
17
|
|
18
|
-
|
18
|
+
command = parser.command
|
19
|
+
options = parser.options
|
19
20
|
|
20
|
-
|
21
|
+
public_send("run_#{command}", options) if [:new].include?(command)
|
22
|
+
end
|
23
|
+
|
24
|
+
def run_new(options)
|
25
|
+
config = parser.options
|
26
|
+
require_name = config.gem_require_name
|
27
|
+
package_name = config.bioc_package_name
|
28
|
+
output_directory = config.output_directory
|
29
|
+
|
30
|
+
target = File.join(output_directory, package_name)
|
21
31
|
|
22
32
|
base = File.expand_path("../../template/newgem", __dir__)
|
23
33
|
|
@@ -26,21 +36,21 @@ module BiocGem
|
|
26
36
|
src = File.expand_path(f, base)
|
27
37
|
next unless File.file?(src)
|
28
38
|
|
29
|
-
warn " - #{f}"
|
30
|
-
|
31
39
|
str = File.read(src)
|
32
40
|
erb = ERB.new(str)
|
33
41
|
str = erb.result(binding)
|
34
42
|
|
35
43
|
trg = File.expand_path(f, tmpdir)
|
36
44
|
fname = File.basename(trg, ".tt")
|
37
|
-
fname.gsub!("new_gem_entry", config
|
45
|
+
fname.gsub!("new_gem_entry", config.gem_require_name)
|
38
46
|
dirname = File.dirname(trg)
|
39
47
|
FileUtils.mkdir_p(dirname)
|
40
48
|
File.write(File.join(dirname, fname), str)
|
41
49
|
end
|
42
50
|
FileUtils.cp_r(tmpdir, target)
|
43
51
|
end
|
52
|
+
|
53
|
+
warn "Created #{target}"
|
44
54
|
end
|
45
55
|
end
|
46
56
|
end
|
data/lib/bioc_gem/options.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module BiocGem
|
2
2
|
Options = Struct.new(
|
3
|
+
:output_directory,
|
3
4
|
:bioc_package_name,
|
4
5
|
:bioc_sqlite_database_name,
|
5
6
|
:gem_icon,
|
6
7
|
:gem_constant_name,
|
7
8
|
:gem_require_name,
|
9
|
+
:bioc_package_md5sum,
|
8
10
|
:bioc_package_sha256sum,
|
9
11
|
:bioc_version,
|
10
12
|
:bioc_package_version
|
data/lib/bioc_gem/parser.rb
CHANGED
@@ -5,56 +5,70 @@ module BiocGem
|
|
5
5
|
class Parser
|
6
6
|
attr_reader :command, :options
|
7
7
|
|
8
|
-
def initialize
|
8
|
+
def initialize(args = nil)
|
9
9
|
@comand = nil
|
10
10
|
|
11
11
|
@options = Options.new
|
12
|
+
parse_options(args) if args
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
+
def parse!(args = ARGV)
|
15
16
|
@command = args.shift&.to_sym
|
17
|
+
if [:new].include?(command)
|
18
|
+
public_send("parse_options_#{command}", args)
|
19
|
+
else
|
20
|
+
warn "Unknown command #{command}"
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
16
24
|
|
17
|
-
|
18
|
-
|
25
|
+
def parse_options_new(args)
|
19
26
|
opt_parser = OptionParser.new do |parser|
|
20
27
|
parser.banner = "Usage: biocgem new [options]"
|
21
28
|
|
22
|
-
parser.on("-
|
23
|
-
options
|
29
|
+
parser.on("-o", "--output [DIR]", "Output directory") do |dir|
|
30
|
+
options.output_directory = dir
|
31
|
+
end
|
32
|
+
parser.on("-n", "--bioc_package_name VAL", "e.g. org.Hs.eg.db") do |n|
|
33
|
+
options.bioc_package_name = n
|
24
34
|
end
|
25
|
-
parser.on("-s", "--bioc_sqlite_database_name VAL", "e.g. org.Hs.eg.sqlite") do |
|
26
|
-
options
|
35
|
+
parser.on("-s", "--bioc_sqlite_database_name VAL", "e.g. org.Hs.eg.sqlite") do |db|
|
36
|
+
options.bioc_sqlite_database_name = db
|
27
37
|
end
|
28
|
-
parser.on("--gem_icon [VAL]", "e.g. :family:") do |
|
29
|
-
options
|
38
|
+
parser.on("--gem_icon [VAL]", "e.g. :family:") do |icon|
|
39
|
+
options.gem_icon = icon
|
30
40
|
end
|
31
|
-
parser.on("--gem_constant_name [VAL]", "e.g. OrgHsEgDb") do |
|
32
|
-
options
|
41
|
+
parser.on("--gem_constant_name [VAL]", "e.g. OrgHsEgDb") do |c|
|
42
|
+
options.gem_constant_name = c
|
33
43
|
end
|
34
|
-
parser.on("--gem_require_name [VAL]", "e.g. org_hs_eg_db") do |
|
35
|
-
options
|
44
|
+
parser.on("--gem_require_name [VAL]", "e.g. org_hs_eg_db") do |rname|
|
45
|
+
options.gem_require_name = rname
|
36
46
|
end
|
37
|
-
parser.on("--
|
38
|
-
options
|
47
|
+
parser.on("-m", "--bioc_package_md5sum [VAL]", "check md5sum") do |md5|
|
48
|
+
options.bioc_package_md5sum = md5
|
39
49
|
end
|
40
|
-
parser.on("--
|
41
|
-
options
|
50
|
+
parser.on("--bioc_package_sha256sum [VAL]", "check sha256sum") do |sha256|
|
51
|
+
options.bioc_package_sha256sum = sha256
|
52
|
+
end
|
53
|
+
parser.on("--bioc_version [VAL]", "e.g. 3.14") do |bv|
|
54
|
+
options.bioc_version = bv
|
42
55
|
end
|
43
56
|
parser.on("-v", "--bioc_package_version VAL", "e.g. 3.14.0") do |v|
|
44
|
-
options
|
57
|
+
options.bioc_package_version = v
|
45
58
|
end
|
46
59
|
end
|
47
60
|
|
48
61
|
opt_parser.parse!(args)
|
49
62
|
|
50
|
-
options.gem_icon
|
51
|
-
|
52
|
-
options.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
63
|
+
options.gem_icon ||= ":notes:"
|
64
|
+
options.gem_constant_name ||= \
|
65
|
+
options.bioc_package_name
|
66
|
+
.split(".").map(&:capitalize).join
|
67
|
+
options.gem_require_name.nil?
|
68
|
+
options.gem_require_name ||= \
|
69
|
+
options.bioc_package_name
|
70
|
+
.split(".").map(&:downcase).join("_")
|
71
|
+
options.bioc_version ||= "release"
|
58
72
|
|
59
73
|
options
|
60
74
|
end
|
data/lib/bioc_gem/version.rb
CHANGED
data/template/newgem/Rakefile.tt
CHANGED
@@ -36,16 +36,23 @@ def bioc_package_version
|
|
36
36
|
"<%= config[:bioc_package_version] %>"
|
37
37
|
end
|
38
38
|
|
39
|
+
def bioc_package_md5sum
|
40
|
+
"<%= config[:bioc_package_md5sum] %>"
|
41
|
+
end
|
42
|
+
|
39
43
|
def bioc_package_sha256sum
|
40
|
-
|
41
|
-
sha256 == "" ? nil : sha256
|
44
|
+
"<%= config[:bioc_package_sha256sum] %>"
|
42
45
|
end
|
43
46
|
|
44
47
|
def bioc_package_file_name
|
45
48
|
"#{bioc_package_name}_#{bioc_package_version}.tar.gz"
|
46
49
|
end
|
47
50
|
|
48
|
-
def
|
51
|
+
def gem_require_name
|
52
|
+
"<%= config[:gem_require_name] %>"
|
53
|
+
end
|
54
|
+
|
55
|
+
def download_annotation(src, database, file, md5sum, sha256)
|
49
56
|
require "fileutils"
|
50
57
|
require "open-uri"
|
51
58
|
require "tmpdir"
|
@@ -54,11 +61,17 @@ def download_annotation(database, src, file, sha256)
|
|
54
61
|
puts "Downloading #{url}"
|
55
62
|
contents = URI.open(url).read
|
56
63
|
|
57
|
-
|
64
|
+
unless md5sum == ""
|
65
|
+
computed_md5sum = Digest::MD5.hexdigest(contents)
|
66
|
+
raise "MD5 checksum mismatch for #{url}" unless md5sum == computed_md5sum
|
67
|
+
end
|
68
|
+
|
69
|
+
unless sha256 == ""
|
58
70
|
computed_sha256 = Digest::SHA256.hexdigest(contents)
|
59
|
-
raise "
|
71
|
+
raise "SHA256 checksum mismatch for #{url}" unless sha256 == computed_sha256
|
60
72
|
end
|
61
73
|
|
74
|
+
|
62
75
|
Dir.chdir(Dir.mktmpdir) do
|
63
76
|
File.binwrite(file, contents)
|
64
77
|
command = "tar xf"
|
@@ -67,6 +80,18 @@ def download_annotation(database, src, file, sha256)
|
|
67
80
|
|
68
81
|
FileUtils.mkdir_p(dest)
|
69
82
|
|
83
|
+
if database == ""
|
84
|
+
databases = Dir.glob("#{src}/inst/extdata/*.sqlite")
|
85
|
+
raise "No database found in #{src}/inst/extdata" if databases.empty?
|
86
|
+
raise "Multiple databases found in #{src}/inst/extdata" if databases.size > 1
|
87
|
+
|
88
|
+
database = File.basename(databases.first)
|
89
|
+
require_path = File.expand_path("lib/#{gem_require_name}.rb", __dir__)
|
90
|
+
str = File.read(require_path)
|
91
|
+
.sub!("*", File.basename(database, ".sqlite"))
|
92
|
+
File.write(require_path, str)
|
93
|
+
end
|
94
|
+
|
70
95
|
FileUtils.cp("#{src}/inst/extdata/#{database}", "#{dest}/#{database}")
|
71
96
|
puts "Saved extdata/#{database}"
|
72
97
|
|
@@ -78,9 +103,10 @@ end
|
|
78
103
|
namespace :extdata do
|
79
104
|
desc "download #{bioc_sqlite_database_name}"
|
80
105
|
task :download do
|
81
|
-
download_annotation(
|
82
|
-
|
106
|
+
download_annotation(bioc_package_name,
|
107
|
+
bioc_sqlite_database_name,
|
83
108
|
bioc_package_file_name,
|
109
|
+
bioc_package_md5sum,
|
84
110
|
bioc_package_sha256sum)
|
85
111
|
end
|
86
112
|
end
|
@@ -2,6 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'sequel'
|
4
4
|
<%= config[:gem_constant_name] %> = Sequel.sqlite(
|
5
|
-
File.expand_path('../extdata/<%= config[:bioc_sqlite_database_name] %>', __dir__),
|
5
|
+
File.expand_path('../extdata/<%= config[:bioc_sqlite_database_name] || "*.sqlite" %>', __dir__),
|
6
6
|
readonly: true
|
7
7
|
)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: biocgem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: biocgem command line tools
|
14
14
|
email:
|
@@ -39,7 +39,7 @@ homepage: https://github.com/ruby-on-bioc/biocgem
|
|
39
39
|
licenses:
|
40
40
|
- MIT
|
41
41
|
metadata: {}
|
42
|
-
post_install_message:
|
42
|
+
post_install_message:
|
43
43
|
rdoc_options: []
|
44
44
|
require_paths:
|
45
45
|
- lib
|
@@ -54,8 +54,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
rubygems_version: 3.
|
58
|
-
signing_key:
|
57
|
+
rubygems_version: 3.2.22
|
58
|
+
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: biocgem command line tools
|
61
61
|
test_files: []
|