ensembl 0.0.5 → 0.0.6

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: 1b0618223d20c9cb1f0f508faddc5707238f2b2f
4
- data.tar.gz: 5448bf0f6e4fc28e05051be6a62deaa04d3c2b9d
3
+ metadata.gz: f643d5fd17097e73e1556a8e722410572d1f9a4c
4
+ data.tar.gz: c522eb0b8e1ea26ffa138237807ba8783bbf114a
5
5
  SHA512:
6
- metadata.gz: 7e54bfca14adacc0f0638b166291358df6d1374898faed897ffbc44ae7e2d5175b4fdcdb96b815a0f6d56c3e72220e474e83a08f762950db757dc4b487bde51a
7
- data.tar.gz: c4f615f25b5e7b1deac38d456e50600f2dd1dede15f6d4fa0b13a85b0ec28211efdd50c62298a009fa7aca46e510f977d0c3bcaefd2a14a4745f984d1a69ca9d
6
+ metadata.gz: 93adb22a4770ee822b65ac3e183368f5462db87acdc691ce6f7ed717e75e2904bd0c403f2878cba669271f52a75f0b04eff5e53790dbda4b6f88bc2a86de13b9
7
+ data.tar.gz: 7927a1042a1cf6b7eed99c799551d5a39694efb912d89d348b40c809dc2ec3b38bb3ed06e45e874630ffd3addfd1eb14d281722cf3caab48b7cc2197f3051813
data/ensembl.gemspec CHANGED
@@ -27,4 +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
  end
@@ -42,6 +42,8 @@ module Ensembl
42
42
  end
43
43
 
44
44
  class Attrib < ModelBase
45
+ self.extend SearchByAttribute
46
+
45
47
  belongs_to :attrib_type
46
48
  end
47
49
 
@@ -70,9 +72,14 @@ module Ensembl
70
72
 
71
73
  # To decrease number of DB queries needed
72
74
  # FIXME: Should be in GenotypeCodes class or should use caching
73
- genotype_codes=genotype_code_ids.uniq.inject({}) { |hsh, gc_id | hsh[gc_id]=GenotypeCode.find gc_id;hsh }
75
+ 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
+
77
+ #genotype_code_ids.uniq.inject({}) { |hsh, gc_id | hsh[gc_id]=GenotypeCode.find(gc_id).allele_code.allele;hsh }
74
78
 
75
- @igs||=unpacked_genotypes.map{|s| IndividualGenotype.new({ individual_id: s[0],genotype_code_id:s[1]})}
79
+ @igs||=unpacked_genotypes.map{|s|
80
+ IndividualGenotype.new({ individual_id: s[0],
81
+ genotype_code_id:s[1],
82
+ allele: allele_codes[s[1]] })}
76
83
  end
77
84
 
78
85
  def unpacked_genotypes
@@ -153,6 +160,9 @@ module Ensembl
153
160
  class IndividualPopulation < Connection
154
161
  belongs_to :individual
155
162
  belongs_to :population
163
+
164
+ scope :displayable, -> { joins(:population).where(population: {display:true})}
165
+ scope :by_ids, ->(ids) { where(individual_id: ids) }
156
166
  end
157
167
 
158
168
  class IndividualSynonym < Connection
@@ -185,13 +195,15 @@ module Ensembl
185
195
  # FIXME: Hack because using type column in the database
186
196
  self.inheritance_column = ':_no_inheritance_column'
187
197
 
198
+ alias_attribute :object_id_column, :object_id
199
+
188
200
  belongs_to :phenotype
189
201
  belongs_to :source
190
202
  belongs_to :study
191
203
  belongs_to :seq_region, class_name: 'Ensembl::Core::SeqRegion'
192
204
 
193
- has_many :phenotype_feature_attrib
194
- has_many :attrib_types, through: :phenotype_feature_attrib
205
+ has_many :phenotype_feature_attribs
206
+ has_many :attrib_types, through: :phenotype_feature_attribs
195
207
 
196
208
  def variation
197
209
  Variation.find_by name: object_id
@@ -405,20 +417,44 @@ module Ensembl
405
417
  has_many :compressed_genotype_vars
406
418
 
407
419
  def phenotype_features
408
- PhenotypeFeature.where(object_id: name, type: 'Variation')
420
+ PhenotypeFeature.eager_load(:phenotype).where(object_id_column: name, type: 'Variation')
409
421
  end
410
422
 
411
423
  def synonyms
412
424
  variation_synonyms.map{ |vs| vs.name }
413
425
  end
414
426
 
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}
432
+
433
+ counts=Hash.new 0
434
+
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 }
440
+
441
+ counts.group_by{|k,v| k[0]}
442
+ end
443
+
444
+ def individual_populations(individual_ids)
445
+ IndividualPopulation
446
+ .joins(:population)
447
+ .where(population: { display:true })
448
+ .where(individual_population: { individual_id: individual_ids })
449
+ end
415
450
 
416
451
  # Find Variation by also using VariationSynonyms
417
452
  # @name: name of the variation
418
453
  # @return: [Variation]
419
454
  def self.find_by_name(name)
420
455
  v = self.find_by(name: name)
421
- vs = VariationSynonym.eager_load(:variation).find_by(name: name) if v.nil?
456
+ return v unless v.nil?
457
+ vs = VariationSynonym.eager_load(:variation).find_by(name: name)
422
458
  vs.variation unless vs.nil?
423
459
  end
424
460
 
@@ -8,15 +8,17 @@ module Ensembl
8
8
 
9
9
  column :individual_id, :integer
10
10
  column :genotype_code_id, :integer
11
+ column :allele, :string
11
12
 
12
13
  belongs_to :individual
13
14
  belongs_to :genotype_code
14
15
 
15
- has_one :allele_code, through: :genotype_code
16
+ #has_one :allele_code, through: :genotype_code
16
17
 
17
18
  delegate :individual_populations, to: :individual
18
19
  delegate :populations, to: :individual
19
20
 
21
+
20
22
  end
21
23
  end
22
24
  end
@@ -1,3 +1,3 @@
1
1
  module Ensembl
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
data/lib/ensembl.rb CHANGED
@@ -57,6 +57,13 @@ module Ensembl
57
57
  end
58
58
  end
59
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
+
60
67
  # class BaseConnection < ActiveRecord::Base
61
68
  # self.extend TableNameOverrides
62
69
  # self.abstract_class = true
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.5
4
+ version: 0.0.6
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-24 00:00:00.000000000 Z
11
+ date: 2014-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2