ensembl 0.0.6 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f643d5fd17097e73e1556a8e722410572d1f9a4c
4
- data.tar.gz: c522eb0b8e1ea26ffa138237807ba8783bbf114a
3
+ metadata.gz: 16d2860f71a33c2c465b0fccf217377d71d583d9
4
+ data.tar.gz: bb8022c713d11e6fcc6c5baed00676bb3d9edd93
5
5
  SHA512:
6
- metadata.gz: 93adb22a4770ee822b65ac3e183368f5462db87acdc691ce6f7ed717e75e2904bd0c403f2878cba669271f52a75f0b04eff5e53790dbda4b6f88bc2a86de13b9
7
- data.tar.gz: 7927a1042a1cf6b7eed99c799551d5a39694efb912d89d348b40c809dc2ec3b38bb3ed06e45e874630ffd3addfd1eb14d281722cf3caab48b7cc2197f3051813
6
+ metadata.gz: cdf044fbd9e8c20534d035448afc3b2ee272ed229ebdca887e66f982f17881039b91e3ea8cc1186993893c45a130a9900f48e019046143807bf8d39dd47b3d95
7
+ data.tar.gz: 8f0aba8e3951d048296d4baab25e65e82d3c4244918856bd5890e43c9be2262d191a37b5e7c0d42e6ddc32659983ea34b28167a957021b04158d73b58e26bb1f
data/.gitignore CHANGED
@@ -22,3 +22,5 @@ tmp
22
22
  mkmf.log
23
23
 
24
24
  .idea
25
+
26
+ config/database.yml
data/Gemfile CHANGED
@@ -2,6 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in ensembl.gemspec
4
4
  gemspec
5
-
6
- gem 'pry', group: :pry
7
- gem 'pry-doc', group: :pry
data/README.md CHANGED
@@ -20,25 +20,13 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- require 'ensembl'
23
+ Copy config/database.yml.example to database.yml and change parameters if needed
24
24
 
25
- ### ENSEMBL.ORG database - Default configuration
25
+ ### Using
26
26
 
27
27
  Ensembl::Variation::Variation.first
28
28
 
29
29
  Ensembl::Variation::Variation.first.source
30
-
31
- ### Custom database
32
-
33
- # Set following values before using - Only Human databases is somewhat tested.
34
-
35
- Ensembl.host = 'myhost.example.com'
36
- Ensembl.port = 3306 # default
37
- Ensembl.username = 'anonymous' # default
38
- Ensembl.password = '' # default
39
- Ensembl.species = 'homo_sapiens' # default
40
- Ensembl.version = 75 # default
41
- Ensembl.hg_version = 37 # default
42
30
 
43
31
 
44
32
  ## Contributing
@@ -0,0 +1,17 @@
1
+ default: &default
2
+ adapter: mysql2
3
+ host: ensembldb.ensembl.org
4
+ port: 3306
5
+ username: anonymous
6
+ password: ''
7
+ reconnect: true
8
+ timeout: 1000
9
+ pool: 5
10
+
11
+ core:
12
+ <<: *default
13
+ database: homo_sapiens_core_75_37
14
+
15
+ variation:
16
+ <<: *default
17
+ database: homo_sapiens_variation_75_37
data/ensembl.gemspec CHANGED
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "bundler", "~> 1.6"
28
28
  spec.add_development_dependency "rake", '~> 10.3'
29
29
  spec.add_development_dependency "pry", '~> 0.10'
30
- # spec.add_development_dependency "pry-byebug", '~> 1.3'
30
+
31
31
  end
@@ -12,13 +12,7 @@ module Ensembl
12
12
 
13
13
  self.abstract_class = true
14
14
 
15
- self.establish_connection :adapter => "mysql2",
16
- :host => Ensembl.host,
17
- :username => Ensembl.username,
18
- :password => Ensembl.password,
19
- :database => Ensembl.species+'_core_'+Ensembl.version+'_'+Ensembl.hg_version,
20
- :reconnect => true
21
-
15
+ self.establish_connection :core
22
16
  end
23
17
 
24
18
  class ModelBase < Connection
@@ -0,0 +1,22 @@
1
+ module ActiveRecord
2
+ module LikeSearch
3
+ def table
4
+ self.arel_table
5
+ end
6
+
7
+ def starts_with(attribute, string)
8
+ where(table[attribute].matches("#{string}%"))
9
+ end
10
+
11
+ def ends_with(attribute,string)
12
+ where(table[attribute].matches("%#{string}"))
13
+ end
14
+
15
+ def contains(attribute,string)
16
+ where(table[attribute].matches("%#{string}%"))
17
+ end
18
+
19
+ end
20
+
21
+ Base.extend LikeSearch
22
+ end
@@ -0,0 +1,30 @@
1
+ module Ensembl
2
+ module Helpers
3
+ #TODO: Implement phased
4
+ class Genotype
5
+ def initialize(attrib)
6
+ @left=attrib[1]
7
+ @right=attrib[2]
8
+ end
9
+ end
10
+
11
+ class VariationPosition
12
+ attr_reader :chromosome,:start_pos,:end_pos
13
+
14
+ def initialize(row)
15
+ @chromosome,@start_pos,@end_pos,@strand=row
16
+ end
17
+
18
+ def strand
19
+ if @strand==1
20
+ return 'forward'
21
+ end
22
+ 'reverse'
23
+ end
24
+
25
+ def to_s
26
+ 'Chromosome: ' + @chromosome + ' ' + @start_pos.to_s + ':' + @end_pos.to_s
27
+ end
28
+ end
29
+ end
30
+ end
@@ -7,12 +7,7 @@ module Ensembl
7
7
 
8
8
  self.abstract_class = true
9
9
 
10
- self.establish_connection :adapter => "mysql2",
11
- :host => Ensembl.host,
12
- :username => Ensembl.username,
13
- :password => Ensembl.password,
14
- :database => Ensembl.species+'_variation_'+Ensembl.version+'_'+Ensembl.hg_version,
15
- :reconnect => true
10
+ self.establish_connection :variation
16
11
 
17
12
  end
18
13
 
@@ -42,7 +37,7 @@ module Ensembl
42
37
  end
43
38
 
44
39
  class Attrib < ModelBase
45
- self.extend SearchByAttribute
40
+ # self.extend AttributeLike
46
41
 
47
42
  belongs_to :attrib_type
48
43
  end
@@ -52,10 +47,24 @@ module Ensembl
52
47
  end
53
48
 
54
49
  class AttribType < ModelBase
50
+
55
51
  has_many :attribs, class_name: 'Attrib'
56
52
  has_many :pheotype_feature_attrib
57
53
  has_many :phenotype_features, through: :phenotype_feature_attrib
58
54
 
55
+ scope :common_values, -> { where(attrib_type_id: self.mapping_hash.keys)}
56
+
57
+ def self.mapping_hash
58
+ @mapping_hash||={14=>:risk_allele,15=>:p_value,23=>:odds_ratio,24=>:beta}
59
+ end
60
+
61
+ def self.key(value)
62
+ mapping_hash.key(value)
63
+ end
64
+
65
+ def self.symbol(key)
66
+ mapping_hash[key]
67
+ end
59
68
  end
60
69
 
61
70
  class CompressedGenotypeRegion < Connection
@@ -74,11 +83,9 @@ module Ensembl
74
83
  # FIXME: Should be in GenotypeCodes class or should use caching
75
84
  allele_codes=GenotypeCode.eager_load(:allele_code).where(:genotype_code_id=>genotype_code_ids.uniq).inject({}){|hsh,gc|hsh[gc.genotype_code_id]=gc.allele_code.allele;hsh}
76
85
 
77
- #genotype_code_ids.uniq.inject({}) { |hsh, gc_id | hsh[gc_id]=GenotypeCode.find(gc_id).allele_code.allele;hsh }
78
-
79
86
  @igs||=unpacked_genotypes.map{|s|
80
87
  IndividualGenotype.new({ individual_id: s[0],
81
- genotype_code_id:s[1],
88
+ genotype_code_id: s[1],
82
89
  allele: allele_codes[s[1]] })}
83
90
  end
84
91
 
@@ -127,9 +134,19 @@ module Ensembl
127
134
  end
128
135
 
129
136
  class GenotypeCode < ModelBase
130
-
131
137
  belongs_to :allele_code
132
138
 
139
+ def self.genotype_for(genotype_code_id)
140
+ joins(:allele_code).where(genotype_code_id: genotype_code_id).order(:haplotype_id).pluck('allele_code.allele').join('|')
141
+ end
142
+
143
+ def self.genotypes_for(genotype_code_ids)
144
+ includes(:allele_code).where(genotype_code_id: genotype_code_ids).pluck('genotype_code.genotype_code_id','genotype_code.haplotype_id','allele_code.allele').group_by{|r| r[0]}.map{|k,v| [k,v.sort_by{|f,s| f[1]<=>s[1]}.map{|v| v[2]}.join('|')]}
145
+ end
146
+
147
+ def self.genotypes_hash_for(genotype_code_ids)
148
+ genotypes_for(genotype_code_ids).to_h
149
+ end
133
150
  end
134
151
 
135
152
  class Individual < ModelBase
@@ -161,8 +178,12 @@ module Ensembl
161
178
  belongs_to :individual
162
179
  belongs_to :population
163
180
 
164
- scope :displayable, -> { joins(:population).where(population: {display:true})}
165
- scope :by_ids, ->(ids) { where(individual_id: ids) }
181
+ scope :displayable, -> { joins(:population).merge(Population.displayable) }
182
+ scope :thousand_genomes, -> { joins(:population).merge(Population.thousand_genomes)}
183
+
184
+ scope :by_individual_ids, ->(ids) { where(individual_id: ids) }
185
+
186
+
166
187
  end
167
188
 
168
189
  class IndividualSynonym < Connection
@@ -189,6 +210,17 @@ module Ensembl
189
210
 
190
211
  class Phenotype < ModelBase
191
212
  has_many :phenotype_features
213
+
214
+ def studies
215
+ ids=phenotype_features
216
+ .with_studies
217
+ .uniq
218
+ .pluck(:study_id)
219
+
220
+ return nil unless ids.size > 0 #
221
+
222
+ Study.where(study_id: ids)
223
+ end
192
224
  end
193
225
 
194
226
  class PhenotypeFeature < ModelBase
@@ -205,19 +237,53 @@ module Ensembl
205
237
  has_many :phenotype_feature_attribs
206
238
  has_many :attrib_types, through: :phenotype_feature_attribs
207
239
 
240
+ scope :significant, -> { where(is_significant: true )}
241
+ scope :with_studies, -> { where.not(study_id:nil)}
242
+
208
243
  def variation
209
244
  Variation.find_by name: object_id
210
245
  end
211
246
 
247
+ def risk_allele
248
+ pf=phenotype_feature_attribs.risk_alleles.first
249
+ pf.value unless pf.nil?
250
+ end
251
+
252
+ def p_value
253
+ pf=phenotype_feature_attribs.p_values.first
254
+ pf.value unless pf.nil?
255
+ end
256
+
257
+ def odds_ratio
258
+ pf=phenotype_feature_attribs.odds_ratios.first
259
+ pf.value unless pf.nil?
260
+ end
261
+
262
+ def description
263
+ phenotype.description
264
+ end
265
+
212
266
  end
213
267
 
214
268
  class PhenotypeFeatureAttrib < Connection
215
269
  belongs_to :attrib_type
216
270
  belongs_to :phenotype_feature
271
+
272
+ scope :risk_alleles, -> {
273
+ where(attrib_type_id: AttribType.key(:risk_allele)) }
274
+
275
+ scope :p_values, -> {
276
+ where(attrib_type_id: AttribType.key(:p_value)) }
277
+
278
+ scope :odds_ratios, -> {
279
+ where(attrib_type_id: AttribType.key(:odds_ratio))}
280
+
281
+ scope :betas, -> {
282
+ where(attrib_type_id: AttribType.key(:beta))}
217
283
  end
218
284
 
219
285
  class Population < ModelBase
220
- self.extend Ensembl::SearchByName
286
+ # self.extend Ensembl::AttributeLike
221
287
 
222
288
  has_many :alleles
223
289
  has_many :population_synonyms
@@ -234,6 +300,7 @@ module Ensembl
234
300
  has_many :population_genotypes
235
301
 
236
302
  scope :displayable, -> { where(display:'LD')}
303
+ scope :thousand_genomes, -> { displayable.starts_with(:name,'1000GENOMES')}
237
304
 
238
305
  def all_individual_populations
239
306
  IndividualPopulation.where(population_id: sub_population_ids(self)<<id)
@@ -289,16 +356,8 @@ module Ensembl
289
356
  belongs_to :variation_feature
290
357
  end
291
358
 
292
- # class SeqRegion < Ensembl::Core::SeqRegion
293
- # belongs_to :coord_system
294
- # has_many :compressed_genotype_regions
295
- # has_many :phenotype_features
296
- # has_many :structureal_variation_features
297
- # end
298
-
299
359
  class StrainGtypePoly < Connection
300
360
  belongs_to :variation
301
-
302
361
  end
303
362
 
304
363
  class StructuralVariation < ModelBase
@@ -347,15 +406,25 @@ module Ensembl
347
406
  end
348
407
 
349
408
  class Source < ModelBase
409
+ has_many :studies
410
+
411
+ scope :no_db_gap, -> { where.not(source_id: 46)}
350
412
  end
351
413
 
352
414
  class Study < ModelBase
415
+ # include AttributeLike
416
+
417
+ default_scope -> { includes(:source) }
418
+
419
+ belongs_to :source
420
+
353
421
  has_many :associate_studies, foreign_key: 'study1_id'
354
422
  has_many :associated_studies, through: :associate_studies, source: :associated_study
355
423
 
356
424
  # FIXME: No data in database
357
425
  has_many :study_variations
358
426
  has_many :variations, through: :study_variations
427
+
359
428
  end
360
429
 
361
430
  # FIXME: No data in database
@@ -394,7 +463,6 @@ module Ensembl
394
463
  end
395
464
 
396
465
  class Variation < ModelBase
397
- self.extend Ensembl::SearchByName
398
466
 
399
467
  belongs_to :source
400
468
 
@@ -420,32 +488,91 @@ module Ensembl
420
488
  PhenotypeFeature.eager_load(:phenotype).where(object_id_column: name, type: 'Variation')
421
489
  end
422
490
 
423
- def synonyms
424
- variation_synonyms.map{ |vs| vs.name }
491
+ def all_phenotype_features
492
+ object_ids = synonyms
493
+ object_ids<<name
494
+ PhenotypeFeature.eager_load(:phenotype).where(object_id: object_ids, type: 'Variation')
495
+ end
496
+
497
+ # Made because of the need to cut down database queries
498
+ # @return
499
+ # { phenotype_feature_id =>
500
+ # { :phenotype=> "Phenotype description" ,
501
+ # :phenotype_id => _ ,
502
+ # :p_value => _ ,
503
+ # :odds_ratio => _,
504
+ # :risk_allele => _ },
505
+ # phenotype_feature_id =>
506
+ # { :phenotype=> "Phenotype description" ,
507
+ # :phenotype_id => _ ,
508
+ # :p_value => _ ,
509
+ # :odds_ratio => _,
510
+ # :risk_allele => _ }}
511
+ def phenotype_features_hash
512
+
513
+ # Do enable two level inserts hsh[:first][:second]
514
+ hash=Hash.new{ |hsh,key| hsh[key] = Hash.new {} }
515
+
516
+ all_phenotype_features
517
+ .joins(:phenotype)
518
+ .pluck(
519
+ :phenotype_feature_id,
520
+ 'phenotype.description',
521
+ :phenotype_id)
522
+ .each{ |r| hash[r[0]][:phenotype]=r[1]; hash[r[0]][:phenotype_id]=r[2]}
523
+
524
+ PhenotypeFeatureAttrib
525
+ .where(phenotype_feature_id: hash.keys)
526
+ .pluck(
527
+ 'phenotype_feature_attrib.phenotype_feature_id',
528
+ 'phenotype_feature_attrib.value',
529
+ 'phenotype_feature_attrib.attrib_type_id')
530
+ .each{ |v| hash[v[0]][AttribType.symbol(v[2])]=v[1] }
531
+
532
+ hash
533
+ end
534
+
535
+ def synonym_names
536
+ variation_synonyms.map{|vs| vs.name}
425
537
  end
426
538
 
427
- def genotype_frequencies
428
- igs=compressed_genotype_vars
429
- .map{|cgv| cgv.individual_genotypes }
430
- .flatten
431
- .each_with_object(Hash.new){ |o,hsh| hsh[o.individual_id] = o.allele;hsh}
539
+ # Genotype counts for each population
540
+ # @returns {"CSHL-HAPMAP:HapMap-CEU"=>{"C|T"=>59, "C|C"=>102, "T|T"=>12},
541
+ # "CSHL-HAPMAP:HapMap-YRI"=>{"C|C"=>172, "C|T"=>1}}
542
+ def genotype_counts
543
+ counts = Hash.new{ |hsh,k| hsh[k] = Hash.new 0 }
544
+
545
+ individual_populations.pluck('population.name',:individual_id).map{|ip| [ip[0],genotype_codes[individual_genotypes[ip[1]]]] }.each{|r| counts[r[0]][r[1]]+=1}
546
+
547
+ return counts
548
+ end
549
+
550
+ # Individual and genotype_code id's related to variation
551
+ # @returns
552
+ # Example:
553
+ # [[1,2],[2,3],[<individual_id>,<genotype_code_id>]]
554
+ def individual_genotypes
555
+ @individual_genotypes||=compressed_genotype_vars.map{|cgv| cgv.unpacked_genotypes }.flatten(1).to_h
556
+ end
432
557
 
433
- counts=Hash.new 0
558
+ def individual_genotype_ids
559
+ individual_genotypes.keys
560
+ end
434
561
 
435
- IndividualPopulation
436
- .displayable
437
- .by_ids(igs.keys)
438
- .map{|ip| [ip.population_id,igs[ip.individual_id]] }
439
- .each{|pig| counts[pig]+=1 }
562
+ # IndividualPopulations from individual_genotypes
563
+ # @returns [IndividualPopulation,IndividualPopulation,...]
564
+ def individual_populations
565
+ IndividualPopulation.where(individual_id: individual_genotype_ids)
566
+ end
440
567
 
441
- counts.group_by{|k,v| k[0]}
568
+ def genotype_code_ids
569
+ @genotype_code_ids||=individual_genotypes.values.uniq
442
570
  end
443
571
 
444
- def individual_populations(individual_ids)
445
- IndividualPopulation
446
- .joins(:population)
447
- .where(population: { display:true })
448
- .where(individual_population: { individual_id: individual_ids })
572
+ # Unique genotype codes from individual_genotypes
573
+ # @returns [<genotype_code_id>=>'G|C',2=>'A|A']
574
+ def genotype_codes
575
+ @genotype_codes||=GenotypeCode.genotypes_hash_for(genotype_code_ids)
449
576
  end
450
577
 
451
578
  # Find Variation by also using VariationSynonyms
@@ -455,18 +582,27 @@ module Ensembl
455
582
  v = self.find_by(name: name)
456
583
  return v unless v.nil?
457
584
  vs = VariationSynonym.eager_load(:variation).find_by(name: name)
458
- vs.variation unless vs.nil?
585
+ return vs.variation unless vs.nil?
586
+ nil
459
587
  end
460
588
 
461
- def all_phenotype_features
462
- object_ids = variation_synonyms.pluck :name
463
- object_ids<<name
464
- PhenotypeFeature.where(object_id: object_ids, type: 'Variation')
589
+ def self.find_all_by_name(name)
590
+ v_ids = where(name: name).pluck(:variation_id)
591
+ v_ids = variation_synonyms.where(name: name).pluck(:variation_id) if v_ids.nil?
592
+
593
+ return nil if v_ids.nil?
594
+
595
+ where(variation_id: v_ids).order(:name)
596
+ end
597
+
598
+ def genes
599
+ variation_genenames.pluck(:gene_name)
600
+ end
601
+
602
+ def positions
603
+ variation_features.includes(:seq_region).pluck('seq_region.name',:seq_region_start,:seq_region_end,:seq_region_strand).map{|r| Ensembl::Helpers::VariationPosition.new(r)}
465
604
  end
466
605
 
467
- # def population_genotypes
468
- # PopulationGenotype.where(variation_id: id)
469
- # end
470
606
  end
471
607
 
472
608
  class VariationCitation < Connection
@@ -488,6 +624,15 @@ module Ensembl
488
624
  VariationSets.where[variation_set_id: [variation_set_id.split(',').map{|id| id.to_i }]] unless variation_set_id.nil?
489
625
  end
490
626
 
627
+ def strand_name(id)
628
+ case(id)
629
+ when 1
630
+ 'forward'
631
+ else
632
+ 'reverse'
633
+ end
634
+ end
635
+
491
636
  def class_type
492
637
  Attrib.find(class_attrib_id) unless class_attrib_id.nil?
493
638
  end
@@ -502,7 +647,7 @@ module Ensembl
502
647
  end
503
648
 
504
649
  class VariationSet < ModelBase
505
- self.extend Ensembl::SearchByName
650
+ # self.extend Ensembl::SearchByName
506
651
 
507
652
  belongs_to :short_name, foreign_key: 'short_name_attrib_id', class_name: 'Attrib'
508
653
  has_many :structural_variations
@@ -536,6 +681,19 @@ module Ensembl
536
681
  class VariationSynonym < ModelBase
537
682
  belongs_to :variation
538
683
  belongs_to :source
684
+
685
+ scope :name_like, ->(name, search_type=:starts_with){
686
+ at=self.arel_table
687
+
688
+ if search_type == :ends_with
689
+ where(at[:name].matches("%#{name}"))
690
+ elsif search_type == :starts_with
691
+ where(at[:name].matches("#{name}%"))
692
+ else
693
+ where(at[:name].matches("%#{name}%"))
694
+ end
695
+
696
+ }
539
697
  end
540
698
  end
541
699
  end
@@ -3,6 +3,7 @@ require 'activerecord-tableless'
3
3
 
4
4
  module Ensembl
5
5
  module Variation
6
+
6
7
  class IndividualGenotype < ActiveRecord::Base
7
8
  has_no_table
8
9
 
@@ -13,12 +14,9 @@ module Ensembl
13
14
  belongs_to :individual
14
15
  belongs_to :genotype_code
15
16
 
16
- #has_one :allele_code, through: :genotype_code
17
-
18
17
  delegate :individual_populations, to: :individual
19
18
  delegate :populations, to: :individual
20
-
21
-
22
19
  end
20
+
23
21
  end
24
22
  end
@@ -1,3 +1,3 @@
1
1
  module Ensembl
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/lib/ensembl.rb CHANGED
@@ -1,42 +1,11 @@
1
1
  require "ensembl/version"
2
2
  require 'active_record'
3
+ require 'yaml'
3
4
  require 'active_support/core_ext'
4
5
 
5
6
  module Ensembl
6
-
7
- class << self
8
-
9
- attr_accessor :host, :port, :database, :username, :password
10
-
11
- def host
12
- @host||='ensembldb.ensembl.org'
13
- end
14
-
15
- def port
16
- @port||=3306
17
- end
18
-
19
- def username
20
- @username||='anonymous'
21
- end
22
-
23
- def password
24
- @password||=''
25
- end
26
-
27
- def hg_version
28
- @hg_version||='37'
29
- end
30
-
31
- def version
32
- @version||='75'
33
- end
34
-
35
- def species
36
- @species||='homo_sapiens'
37
- end
38
-
39
- end
7
+ # Load configuration from database.yml
8
+ ActiveRecord::Base.configurations = YAML::load(IO.read('config/database.yml'))
40
9
 
41
10
  module TableNameOverrides
42
11
  def table_name
@@ -50,71 +19,22 @@ module Ensembl
50
19
  end
51
20
  end
52
21
 
53
- module SearchByName
54
- def search(name)
55
- table=self.arel_table
56
- self.where(table[:name].matches("%#{name}%"))
57
- end
58
- end
59
-
60
- module SearchByAttribute
61
- def search(attribute, string)
62
- table=self.arel_table
63
- self.where(table[attribute].matches("%#{string}%"))
64
- end
65
- end
66
-
67
- # class BaseConnection < ActiveRecord::Base
68
- # self.extend TableNameOverrides
69
- # self.abstract_class = true
70
- # end
71
-
72
- # module Core
73
- # class Connection < ActiveRecord::Base
74
- # self.extend TableNameOverrides
75
- #
76
- # self.abstract_class = true
77
- #
78
- # self.establish_connection :adapter => "mysql2",
79
- # :host => Ensembl.host,
80
- # :username => Ensembl.username,
81
- # :password => Ensembl.password,
82
- # :database => Ensembl.species+'_core_'+Ensembl.version+'_'+Ensembl.hg_version,
83
- # :reconnect => true
84
- #
85
- # end
86
- #
87
- # class ModelBase < Connection
88
- # self.extend PrimaryKeyOverrides
89
- #
90
- # self.abstract_class = true
22
+ # module AttributeLike
23
+ # def a_like(attribute, string, search_type=:between)
24
+ # at=self.arel_table
25
+ # if search_type == :ends_with
26
+ # where(at[attribute].matches("%#{string}"))
27
+ # elsif search_type == :starts_with
28
+ # where(at[attribute].matches("#{string}%"))
29
+ # else
30
+ # where(at[attribute].matches("%#{string}%"))
31
+ # end
91
32
  # end
92
33
  # end
93
- #
94
- # module Variation
95
- # class Connection < ActiveRecord::Base
96
- # self.extend TableNameOverrides
97
- #
98
- # self.abstract_class = true
99
- #
100
- # self.establish_connection :adapter => "mysql2",
101
- # :host => Ensembl.host,
102
- # :username => Ensembl.username,
103
- # :password => Ensembl.password,
104
- # :database => Ensembl.species+'_variation_'+Ensembl.version+'_'+Ensembl.hg_version,
105
- # :reconnect => true
106
- #
107
- # end
108
- #
109
- # class ModelBase < Connection
110
- # self.extend PrimaryKeyOverrides
111
- #
112
- # self.abstract_class = true
113
- # end
114
- # end
115
-
116
34
  end
117
35
 
36
+ require File.dirname(__FILE__) + '/ensembl/helpers/like_search.rb'
118
37
  require File.dirname(__FILE__) + '/ensembl/core/activerecord.rb'
38
+ require File.dirname(__FILE__) + '/ensembl/helpers/variation_position.rb'
119
39
  require File.dirname(__FILE__) + '/ensembl/variation/activerecord.rb'
120
40
  require File.dirname(__FILE__) + '/ensembl/variation/tableless.rb'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ensembl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristjan Metsalu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-28 00:00:00.000000000 Z
11
+ date: 2014-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -106,9 +106,12 @@ files:
106
106
  - LICENSE.txt
107
107
  - README.md
108
108
  - Rakefile
109
+ - config/database.yml.example
109
110
  - ensembl.gemspec
110
111
  - lib/ensembl.rb
111
112
  - lib/ensembl/core/activerecord.rb
113
+ - lib/ensembl/helpers/like_search.rb
114
+ - lib/ensembl/helpers/variation_position.rb
112
115
  - lib/ensembl/variation/activerecord.rb
113
116
  - lib/ensembl/variation/tableless.rb
114
117
  - lib/ensembl/version.rb