genome-rb 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ebe497996e7d2598a811469a808fa9998e0a6593
4
- data.tar.gz: 8fe4e3d8de204dfa36f4c708c7b1b3906ad7886b
2
+ SHA256:
3
+ metadata.gz: 82e81a4278f56a5ac9272fcbf7e46bbf1975b4f24c6a03a2a5bf717edc19878f
4
+ data.tar.gz: 9f830a3008836bcc3841babb8436b5231df84fee50f1b9f14937cb97842d0c29
5
5
  SHA512:
6
- metadata.gz: 66210100b671742260a4aef410a825200fa31d9dace732fba1bad31c5f064538899e5f2e56084faeb3fccdcee16604e555c09c7140fc5654a7ef4fd98bca2835
7
- data.tar.gz: 500afeca789a91b7f0644b2fa93d4882148fece885d83999214d240be026f7904ab28cc93bffa7ef26f6bcea0c5c70d5f317bfd53f9c6009318c3b383de3090d
6
+ metadata.gz: a22e8b43f9ee00ca751a0a50902b9d9d44c53df3bfc49654d6efdf3ff4a5cb35c39c3abd6b44916acd454dae5bacdb1a63d0f69797c24ac48134678b0ac1e184
7
+ data.tar.gz: 7ecc2890129173cfcb083a89de5be221caeec2373c9ffb1b1cab533c54cc564821bbbab38265be222ed0f2dc0c7ac7fcfe4401592308f0e2d6a53e887c926060
data/.travis.yml CHANGED
@@ -6,7 +6,7 @@ rvm:
6
6
  - 2.4.6
7
7
  - 2.5.5
8
8
  - 2.6.3
9
- before_install: gem install bundler -v 2.0.1
9
+ before_install: gem install bundler -v 2.0.2
10
10
  deploy:
11
11
  provider: rubygems
12
12
  api_key:
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ genome-rb (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.11.3)
10
+ rake (10.5.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 2.0)
17
+ genome-rb!
18
+ minitest (~> 5.0)
19
+ rake (~> 10.0)
20
+
21
+ BUNDLED WITH
22
+ 2.0.2
data/exe/genome CHANGED
File without changes
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FileTypeError < StandardError
4
+ def initialize(message = 'FileTypeError')
5
+ super(message)
6
+ end
7
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open-uri'
4
+
5
+ class Reader
6
+ attr_reader :genome
7
+
8
+ def initialize(filename)
9
+ @filename = filename
10
+ @genome = GENOME::Genome.new @filename
11
+ end
12
+
13
+ def validate?(*)
14
+ raise NotImplementedError, 'Reader must define validate?.'
15
+ end
16
+
17
+ def parse(*)
18
+ raise NotImplementedError, 'Reader must parse validate?.'
19
+ end
20
+
21
+ def load
22
+ validate? @filename
23
+ open(@filename) do |f|
24
+ f.each_line do |line|
25
+ next if line.start_with?('#') || line.downcase.start_with?('rsid')
26
+
27
+ rsid, snp = parse line
28
+ @genome[rsid] = snp
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ module GENOME
35
+ class TwentyThreeAndMeReader < Reader
36
+ def validate?(filename)
37
+ magic_line = File.open(filename, &:readline)
38
+ unless magic_line.downcase.include? '23'.downcase
39
+ raise FileTypeError, 'format is not correct'
40
+ end
41
+ end
42
+
43
+ def parse(line)
44
+ rsid, chromosome, position, genotype = line.split
45
+ snp = SNP.new(chromosome = chromosome,
46
+ position = position,
47
+ genotype = Genotype.new(genotype))
48
+ [rsid, snp]
49
+ end
50
+ end
51
+ end
52
+
53
+ module GENOME
54
+ class AncestryReader < Reader
55
+ def validate?(filename)
56
+ magic_line = File.open(filename, &:readline)
57
+ unless magic_line.downcase.include? 'ancestry'.downcase
58
+ raise FileTypeError, 'format is not correct'
59
+ end
60
+ end
61
+
62
+ def parse(line)
63
+ rsid, chromosome, position, allele1, allele2 = line.split
64
+ genotype = allele1 + allele2
65
+ snp = SNP.new(chromosome = chromosome,
66
+ position = position,
67
+ genotype = Genotype.new(genotype))
68
+ [rsid, snp]
69
+ end
70
+ end
71
+ end
72
+
73
+ module GENOME
74
+ class MyHeritageReader < Reader
75
+ def validate?(filename)
76
+ magic_line = File.open(filename, &:readline)
77
+ unless magic_line.downcase.include? 'MyHeritage'.downcase
78
+ raise FileTypeError, 'format is not correct'
79
+ end
80
+ end
81
+
82
+ def parse(line)
83
+ rsid, chromosome, position, genotype = line.gsub(/"/, '').gsub("\n", '').split(',')
84
+ snp = SNP.new(chromosome = chromosome,
85
+ position = position,
86
+ genotype = Genotype.new(genotype))
87
+ [rsid, snp]
88
+ end
89
+ end
90
+ end
@@ -1,3 +1,3 @@
1
1
  module GENOME
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/genome.rb CHANGED
@@ -1,68 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'genome/version'
4
- require 'open-uri'
5
-
6
- class ProviderError < StandardError
7
- def initialize(message = 'ProviderError')
8
- super(message)
9
- end
10
- end
11
-
12
- class FileTypeError < StandardError
13
- def initialize(message = 'FileTypeError')
14
- super(message)
15
- end
16
- end
17
-
18
3
  module GENOME
19
- # Your code goes here...
20
- autoload :Genome, 'genome/genome'
21
- autoload :SNP, 'genome/snp'
22
- autoload :Genotype, 'genome/genotype'
23
-
24
- def self.ttandme_reader(line)
25
- rsid, chromosome, position, genotype = line.split
26
- snp = SNP.new(chromosome = chromosome,
27
- position = position,
28
- genotype = Genotype.new(genotype))
29
- [rsid, snp]
30
- end
31
-
32
- def self.ancestry_reader(line)
33
- rsid, chromosome, position, allele1, allele2 = line.split
34
- genotype = allele1 + allele2
35
- snp = SNP.new(chromosome = chromosome,
36
- position = position,
37
- genotype = Genotype.new(genotype))
38
- [rsid, snp]
39
- end
40
-
41
- def self.validate?(_filename, _provider = '23andme')
42
- raise ProviderError, "provider is not supported." unless %w[23andme ancestry].include? _provider
43
-
44
- first_line = File.open(_filename, &:readline)
45
- if _provider == '23andme'
46
- raise FileTypeError, "format is not correct" unless first_line.downcase.include? '23'.downcase
47
- elsif _provider == 'ancestry'
48
- raise FileTypeError, "format is not correct" unless first_line.downcase.include? 'ancestry'.downcase
49
- end
50
- end
51
-
52
- def self.load(_filename, _provider = '23andme')
53
- genome = Genome.new(name = _filename)
54
- reader = if _provider == '23andme'
55
- :ttandme_reader
56
- elsif _provider == 'ancestry'
57
- :ancestry_reader
58
- end
59
- open(_filename) {|f|
60
- f.each_line do |line|
61
- next if line.start_with?('#') || line.start_with?('rsid')
62
- rsid, snp = send reader, line
63
- genome[rsid] = snp
64
- end
65
- }
66
- genome
67
- end
68
- end
4
+ require 'genome/genome'
5
+ require 'genome/snp'
6
+ require 'genome/genotype'
7
+ require 'genome/errors'
8
+ require 'genome/reader'
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genome-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Lai
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-29 00:00:00.000000000 Z
11
+ date: 2019-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,6 +65,7 @@ files:
65
65
  - CHANGELOG.md
66
66
  - CODE_OF_CONDUCT.md
67
67
  - Gemfile
68
+ - Gemfile.lock
68
69
  - LICENSE.txt
69
70
  - README.md
70
71
  - Rakefile
@@ -73,8 +74,10 @@ files:
73
74
  - exe/genome
74
75
  - genome-rb.gemspec
75
76
  - lib/genome.rb
77
+ - lib/genome/errors.rb
76
78
  - lib/genome/genome.rb
77
79
  - lib/genome/genotype.rb
80
+ - lib/genome/reader.rb
78
81
  - lib/genome/snp.rb
79
82
  - lib/genome/version.rb
80
83
  homepage: https://github.com/marigenhq/genome-rb
@@ -96,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
99
  - !ruby/object:Gem::Version
97
100
  version: '0'
98
101
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.5.2.3
102
+ rubygems_version: 3.0.4
101
103
  signing_key:
102
104
  specification_version: 4
103
105
  summary: ruby library to read genome data