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 +4 -4
- data/ensembl.gemspec +1 -0
- data/lib/ensembl/variation/activerecord.rb +42 -6
- data/lib/ensembl/variation/tableless.rb +3 -1
- data/lib/ensembl/version.rb +1 -1
- data/lib/ensembl.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f643d5fd17097e73e1556a8e722410572d1f9a4c
|
4
|
+
data.tar.gz: c522eb0b8e1ea26ffa138237807ba8783bbf114a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93adb22a4770ee822b65ac3e183368f5462db87acdc691ce6f7ed717e75e2904bd0c403f2878cba669271f52a75f0b04eff5e53790dbda4b6f88bc2a86de13b9
|
7
|
+
data.tar.gz: 7927a1042a1cf6b7eed99c799551d5a39694efb912d89d348b40c809dc2ec3b38bb3ed06e45e874630ffd3addfd1eb14d281722cf3caab48b7cc2197f3051813
|
data/ensembl.gemspec
CHANGED
@@ -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
|
-
|
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|
|
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 :
|
194
|
-
has_many :attrib_types, through: :
|
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(
|
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
|
-
|
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
|
data/lib/ensembl/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|