mizlab 0.1.0 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/deploy.yml +1 -1
- data/Gemfile +4 -7
- data/README.md +4 -4
- data/Rakefile +20 -0
- data/lib/mizlab/version.rb +1 -1
- data/lib/mizlab.rb +89 -21
- data/mizlab.gemspec +8 -2
- metadata +73 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0997e1a56ba6b17aa4eedc2fd89e84462e3ac2d3f51c1c251221a0fc7613ff66'
|
4
|
+
data.tar.gz: aaac55320663e3b8fef03c5518d73156ea3a1880736936c8debb1a6eb9d60935
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5e073bceea54fd25ad99e80c35052732c265a6e827b8e23bcf4f2bc21f3b03095243d5e9b718bf6b521ae8097f5059b72a15cc32ec67e7bfe534e3b8c7d35bc
|
7
|
+
data.tar.gz: 61f1545fd3218ce1a74b030a6a64718964a8129f30587deaebeb038cadfe82991b9d7356751129ba92df751278193d5a1cf92c147790e8a88008bb285fa665c8
|
data/Gemfile
CHANGED
@@ -5,10 +5,7 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in mizlab.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem "rake", "~> 13.0"
|
9
|
-
|
10
|
-
gem "
|
11
|
-
|
12
|
-
gem "yard", "~> 0.9"
|
13
|
-
|
14
|
-
gem "bio"
|
8
|
+
# gem "rake", "~> 13.0"
|
9
|
+
# gem "minitest", "~> 5.0"
|
10
|
+
# gem "yard", "~> 0.9"
|
11
|
+
# gem "bio", "~> 2.0.0"
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
[![Test](https://github.com/MizLab/Mizlab-ruby/actions/workflows/minitest.yml/badge.svg)](https://github.com/MizLab/Mizlab-ruby/actions/workflows/minitest.yml)
|
2
2
|
[![Build page](https://github.com/MizLab/Mizlab-ruby/actions/workflows/yardoc.yml/badge.svg)](https://github.com/MizLab/Mizlab-ruby/actions/workflows/yardoc.yml)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/mizlab.svg)](https://badge.fury.io/rb/mizlab)
|
3
4
|
|
4
5
|
# Mizlab-ruby
|
5
6
|
|
6
|
-
This gem is for easy handling of the processes used in our
|
7
|
-
|
7
|
+
This gem is for easy handling of the processes used in our laboratory.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -14,7 +14,7 @@ Install it yourself as:
|
|
14
14
|
gem install mizlab
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
Or add below to your application's Gemfile:
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
gem 'mizlab'
|
@@ -38,7 +38,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
38
38
|
|
39
39
|
## Contributing
|
40
40
|
|
41
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/MizLab/Mizlab-ruby
|
42
42
|
|
43
43
|
## License
|
44
44
|
|
data/Rakefile
CHANGED
@@ -16,4 +16,24 @@ YARD::Rake::YardocTask.new do |t|
|
|
16
16
|
t.stats_options = ["--list-undoc"]
|
17
17
|
end
|
18
18
|
|
19
|
+
desc "Version up"
|
20
|
+
task :versionup do
|
21
|
+
version = ""
|
22
|
+
File.open("./lib/mizlab/version.rb") do |f|
|
23
|
+
version = f.read[(/(\d+\.\d+\.\d+)/)]
|
24
|
+
end
|
25
|
+
ver, minor_ver, hotfix = version.split(".")
|
26
|
+
hotfix = hotfix.to_i + 1
|
27
|
+
new_version = "#{ver}.#{minor_ver}.#{hotfix}"
|
28
|
+
cmd = "sed -E -i 's/[0-9]+\\.[0-9]+\\.[0-9]+/#{new_version}/' ./lib/mizlab/version.rb"
|
29
|
+
puts(cmd)
|
30
|
+
system(cmd)
|
31
|
+
cmd = "git add ./lib/mizlab/version.rb && git commit -m ':rocket: Version up'"
|
32
|
+
puts(cmd)
|
33
|
+
system(cmd)
|
34
|
+
cmd = "git tag v#{new_version}"
|
35
|
+
puts(cmd)
|
36
|
+
system(cmd)
|
37
|
+
end
|
38
|
+
|
19
39
|
task default: :test
|
data/lib/mizlab/version.rb
CHANGED
data/lib/mizlab.rb
CHANGED
@@ -3,28 +3,68 @@
|
|
3
3
|
require_relative "mizlab/version"
|
4
4
|
require "set"
|
5
5
|
require "bio"
|
6
|
+
require "stringio"
|
7
|
+
require "rexml/document"
|
6
8
|
|
7
9
|
module Mizlab
|
8
10
|
class << self
|
9
|
-
#
|
10
|
-
# @param [String]
|
11
|
-
# @
|
12
|
-
# @
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
# Get entry as String. You can also give a block.
|
12
|
+
# @param [String/Array] accessions Accession numbers like ["NC_012920", ...].
|
13
|
+
# @return [String] Entry as string.
|
14
|
+
# @yield [String] Entry as string.
|
15
|
+
def getent(accessions, is_protein = false)
|
16
|
+
accessions = accessions.is_a?(String) ? [accessions] : accessions
|
17
|
+
accessions.each do |acc|
|
18
|
+
ret = is_protein ? fetch_protein(acc) : fetch_nucleotide(acc)
|
19
|
+
if block_given?
|
20
|
+
yield ret
|
21
|
+
else
|
22
|
+
return ret
|
23
|
+
end
|
24
|
+
sleep(0.37) # Using 0.333... seconds, sometimes hit the NCBI rate limit
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
20
|
-
# Fetch
|
21
|
-
# @param [Array] accessions
|
28
|
+
# Fetch data via genbank. You can also give a block.
|
29
|
+
# @param [String/Array] accessions Accession numbers Like ["NC_012920", ...].
|
22
30
|
# @param [Bool] is_protein wheather the accession is protein. Default to true.
|
31
|
+
# @return [Bio::GenBank] GenBank object.
|
23
32
|
# @yield [Bio::GenBank] GenBank object.
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
33
|
+
def getobj(accessions, is_protein = false)
|
34
|
+
getent(accessions, is_protein) do |entry|
|
35
|
+
parse(entry) do |o|
|
36
|
+
if block_given?
|
37
|
+
yield o
|
38
|
+
else
|
39
|
+
return o
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Save object.
|
46
|
+
# @param [String] filename Filepath from executed source.
|
47
|
+
# @param [Bio::DB] obj Object which inherits from `Bio::DB`.
|
48
|
+
# @return [nil]
|
49
|
+
def savefile(filename, obj)
|
50
|
+
if File.exists?(filename)
|
51
|
+
yes = Set.new(["N", "n", "no"])
|
52
|
+
no = Set.new(["Y", "y", "yes"])
|
53
|
+
loop do
|
54
|
+
print("#{filename} exists already. Overwrite? [y/n] ")
|
55
|
+
inputed = gets.rstrip
|
56
|
+
if yes.include?(inputed)
|
57
|
+
return
|
58
|
+
elsif no.include?(inputed)
|
59
|
+
break
|
60
|
+
end
|
61
|
+
puts("You should input 'y' or 'n'")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
File.open(filename, "w") do |f|
|
65
|
+
obj.tags.each do |t|
|
66
|
+
f.puts(obj.get(t))
|
67
|
+
end
|
28
68
|
end
|
29
69
|
end
|
30
70
|
|
@@ -99,6 +139,23 @@ module Mizlab
|
|
99
139
|
return local_pattern_list
|
100
140
|
end
|
101
141
|
|
142
|
+
# Fetch Taxonomy information from Taxonomy ID. can be give block too.
|
143
|
+
# @param [String/Integer] taxonid Taxonomy ID, or Array of its.
|
144
|
+
# @return [Hash] Taxonomy informations.
|
145
|
+
# @yield [Hash] Taxonomy informations.
|
146
|
+
def fetch_taxon(taxonid)
|
147
|
+
taxonid = taxonid.is_a?(Array) ? taxonid : [taxonid]
|
148
|
+
taxonid.each do |id|
|
149
|
+
obj = Bio::NCBI::REST::EFetch.taxonomy(id, "xml")
|
150
|
+
hashed = xml_to_hash(REXML::Document.new(obj).root)
|
151
|
+
if block_given?
|
152
|
+
yield hashed[:TaxaSet][:Taxon][:LineageEx][:Taxon]
|
153
|
+
else
|
154
|
+
return hashed[:TaxaSet][:Taxon][:LineageEx][:Taxon]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
102
159
|
private
|
103
160
|
|
104
161
|
def fetch_protein(accession)
|
@@ -106,7 +163,7 @@ module Mizlab
|
|
106
163
|
end
|
107
164
|
|
108
165
|
def fetch_nucleotide(accession)
|
109
|
-
return Bio::NCBI::REST::EFetch.
|
166
|
+
return Bio::NCBI::REST::EFetch.nucleotide(accession)
|
110
167
|
end
|
111
168
|
|
112
169
|
# get patterns from filled pixs.
|
@@ -200,14 +257,25 @@ module Mizlab
|
|
200
257
|
# @param [String] entries Entries as string
|
201
258
|
# @yield [Object] Object that match entry format.
|
202
259
|
def parse(entries)
|
203
|
-
|
204
|
-
File.open(tmp_file_name, "w") do |f|
|
205
|
-
f.puts entries
|
206
|
-
end
|
207
|
-
Bio::FlatFile.auto(tmp_file_name).each_entry do |e|
|
260
|
+
Bio::FlatFile.auto(StringIO.new(entries)).each_entry do |e|
|
208
261
|
yield e
|
209
262
|
end
|
210
|
-
|
263
|
+
end
|
264
|
+
|
265
|
+
# Convert XML to Hash.
|
266
|
+
# @param [REXML::Document] element XML object.
|
267
|
+
# @return [Hash] Hash that converted from xml.
|
268
|
+
def xml_to_hash(element)
|
269
|
+
value = (if element.has_elements?
|
270
|
+
children = {}
|
271
|
+
element.each_element do |e|
|
272
|
+
children.merge!(xml_to_hash(e)) { |k, v1, v2| v1.is_a?(Array) ? v1 << v2 : [v1, v2] }
|
273
|
+
end
|
274
|
+
children
|
275
|
+
else
|
276
|
+
element.text
|
277
|
+
end)
|
278
|
+
return { element.name.to_sym => value }
|
211
279
|
end
|
212
280
|
end
|
213
281
|
end
|
data/mizlab.gemspec
CHANGED
@@ -29,8 +29,14 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
|
-
#
|
33
|
-
|
32
|
+
# Dependency
|
33
|
+
spec.add_dependency "bio", "~> 2.0.0"
|
34
|
+
spec.add_dependency "rexml", ">= 0"
|
35
|
+
|
36
|
+
# Dependency (for development)
|
37
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
38
|
+
spec.add_development_dependency "yard", "~> 0.9"
|
39
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
34
40
|
|
35
41
|
# For more information and examples about making a new gem, checkout our
|
36
42
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
@@ -1,15 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mizlab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Omochice
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-10-28 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: 2.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rexml
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
13
83
|
description: The tools for our laboratory
|
14
84
|
email:
|
15
85
|
- mochice.mls.ntl@gmail.com
|