strain-code 0.1.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 +7 -0
- data/Gemfile +8 -0
- data/LICENSE +21 -0
- data/README.md +30 -0
- data/Rakefile +17 -0
- data/lib/strain_code/catalogue.rb +34 -0
- data/lib/strain_code/common.rb +16 -0
- data/lib/strain_code/parser.rb +32 -0
- data/lib/strain_code/strain_number.rb +25 -0
- data/lib/strain_code/version.rb +7 -0
- data/lib/strain_code.rb +3 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fbe9591da2d7fce715f51eb5feff73430504f364ffdb73529e6e85e6a15313d7
|
4
|
+
data.tar.gz: d97547ba94d0f03383b033d93ffe05ca60e41321ed6f824b7b50c9cd72af07ad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df47aa92e10200150fd2519dbf3413fda9a6341ab07812e730e7b53affc547208dcdec058e106dd604d0855667ff124b0b508109fba84885055a8f043cc62655
|
7
|
+
data.tar.gz: 1f0556e43867774968ac6832395f254737291477a5c59d291cff2e4c59323ad16e3d13b38b8cc5e607ca68aaf8fe83921368be86fcaabbe43dea378bb6e99261
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 The SeqCode Initiative
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# StrainCode
|
2
|
+
|
3
|
+
A gem for parsing and formatting strain numbers
|
4
|
+
from microbiological culture collections
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
```bash
|
9
|
+
gem install strain-code
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'strain_code'
|
16
|
+
|
17
|
+
# Parse one or more numbers in a variety of formats
|
18
|
+
str_no = StrainCode.parse <<STR_NO
|
19
|
+
ATCC 33152 = CCUG 9568 = CIP 103854 ;
|
20
|
+
DSM 25069 = DSM_7513 = JCM:7571;
|
21
|
+
NBIMCC:8848 = NCTC 11192, Strain Philadelphia 1
|
22
|
+
STR_NO
|
23
|
+
|
24
|
+
# Get the URLs to the entry in the corresponding catalogues
|
25
|
+
str_no.map(&:url)
|
26
|
+
|
27
|
+
# Get the name and country of each catalogue (if available)
|
28
|
+
str_no.map(&:catalogue).map { |i| [i.name, i.country_code] if i }
|
29
|
+
```
|
30
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
5
|
+
|
6
|
+
require 'strain_code/version'
|
7
|
+
|
8
|
+
SOURCES = FileList['lib/**/*.rb']
|
9
|
+
|
10
|
+
desc 'Default Task'
|
11
|
+
task :default => :test
|
12
|
+
|
13
|
+
Rake::TestTask.new do |t|
|
14
|
+
t.libs << 'test'
|
15
|
+
t.pattern = 'test/*_test.rb'
|
16
|
+
t.verbose = true
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
class StrainCode::Catalogue
|
3
|
+
class << self
|
4
|
+
def catalogues_path
|
5
|
+
File.join(StrainCode.data_path, 'catalogues.yaml')
|
6
|
+
end
|
7
|
+
|
8
|
+
def catalogues_source
|
9
|
+
@catalogues_source ||= YAML.load_file(
|
10
|
+
catalogues_path,
|
11
|
+
permitted_classes: [OpenStruct, Symbol, Date]
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def catalogue_hash(code)
|
16
|
+
hsh = catalogues_source['catalogues'].find do |i|
|
17
|
+
i['codes'].include? code.to_s.upcase
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def catalogue(code)
|
22
|
+
hsh = catalogue_hash(code)
|
23
|
+
new(hsh) if hsh
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_accessor :codes, :country_code, :name, :name_en, :organization
|
28
|
+
attr_accessor :url, :url_pattern
|
29
|
+
|
30
|
+
def initialize(code)
|
31
|
+
code = self.class.catalogue_hash(code) unless code.is_a?(Hash)
|
32
|
+
code.each { |k, v| self.send("#{k}=", v) unless k =~ /^_/ } if code
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'strain_code/version'
|
4
|
+
require 'strain_code/catalogue'
|
5
|
+
|
6
|
+
class StrainCode
|
7
|
+
class << self
|
8
|
+
def root_path
|
9
|
+
File.expand_path('../../..', __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
def data_path
|
13
|
+
File.join(root_path, 'data')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'strain_code/strain_number'
|
2
|
+
|
3
|
+
class StrainCode::Parser
|
4
|
+
class << self
|
5
|
+
def clean(numbers)
|
6
|
+
numbers.to_s.strip.gsub(/\s+/, ' ').gsub(/ *[=;,] */, ' = ')
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse(numbers)
|
10
|
+
clean(numbers).split(' = ').map do |number|
|
11
|
+
StrainCode::StrainNumber.new(number)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class StrainCode
|
18
|
+
class << self
|
19
|
+
def parse(numbers)
|
20
|
+
StrainCode::Parser.parse(numbers)
|
21
|
+
end
|
22
|
+
|
23
|
+
def number(number)
|
24
|
+
StrainCode::StrainNumber.new(StrainCode::Parser.clean(number))
|
25
|
+
end
|
26
|
+
|
27
|
+
def catalogue(code)
|
28
|
+
c = StrainCode::Catalogue.new(code)
|
29
|
+
c.codes ? c : nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class StrainCode::StrainNumber
|
2
|
+
attr_accessor :ori_number, :code, :accession
|
3
|
+
|
4
|
+
def initialize(number)
|
5
|
+
@ori_number = number.to_s.strip
|
6
|
+
@code, @accession = ori_number.split(/[ :_]+/, 2)
|
7
|
+
@code, @accession = @accession, @code if @accession.nil?
|
8
|
+
end
|
9
|
+
|
10
|
+
def number
|
11
|
+
catalogue ? [code, accession].compact.join(' ') : ori_number
|
12
|
+
end
|
13
|
+
|
14
|
+
def url
|
15
|
+
catalogue.url_pattern % accession if catalogue&.url_pattern
|
16
|
+
end
|
17
|
+
|
18
|
+
def catalogue
|
19
|
+
@catalogue ||= StrainCode.catalogue(code)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
number
|
24
|
+
end
|
25
|
+
end
|
data/lib/strain_code.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strain-code
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luis M. Rodriguez-R
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: test-unit
|
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
|
+
description: Strain numbers are microbiological culture collection identifiers
|
42
|
+
email: lmrodriguezr@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files:
|
46
|
+
- README.md
|
47
|
+
files:
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/strain_code.rb
|
53
|
+
- lib/strain_code/catalogue.rb
|
54
|
+
- lib/strain_code/common.rb
|
55
|
+
- lib/strain_code/parser.rb
|
56
|
+
- lib/strain_code/strain_number.rb
|
57
|
+
- lib/strain_code/version.rb
|
58
|
+
homepage: https://github.com/seq-code/strain-code
|
59
|
+
licenses: []
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- lib
|
64
|
+
- README.md
|
65
|
+
- "--main"
|
66
|
+
- README.md
|
67
|
+
- "--title"
|
68
|
+
- Parsing and formatting of strain numbers
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubygems_version: 3.1.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Parsing and formatting of strain numbers
|
86
|
+
test_files: []
|