ensembl 0.0.3 → 0.0.4

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: 5d7e2d87ed64e9bcaaf5cf1f7ab6c62c93125d25
4
- data.tar.gz: 7664f3c4da6c783a44f370c1b9f3e32f5a1353a8
3
+ metadata.gz: 0d611b86a6388c3b9f18b20afc620fec340c4dcb
4
+ data.tar.gz: f31b33ac5b62dfd3d31bec25bf81c17ca000d2d9
5
5
  SHA512:
6
- metadata.gz: 12be2709f3002ddb140f12953141a79fde88b1523a98935cbec4ed4d627af18316c1144c0f6e3a19314b3a33f5392651d97573bd89d2fe5af08e591ec50e9fe6
7
- data.tar.gz: a95df0febf00e18ef76565af71baf1661612a21e9eb022957ca048d8d76a2a29bfaead27b3dad9ec41bee38cb2852a1b930212e88c994a75026a0f6064adcd9f
6
+ metadata.gz: 05b85ee36ab9423a3e769c618c72836cb67188b7b00f5559a3bb23aab3505f4680a82cddf54b3cf297e681144573fe920dc781e47e1e2ed1cb6f0a6450fdc320
7
+ data.tar.gz: 51318a992a372d690148e9ddde1adced896a3bdeb1dfe12e5f393d1689b3deb801325383ff9aedfbe0dce0d7b188a0166998ddb5ad306d0c95f65f35b86d6e46
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ 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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem to access ensembl.org database. Currently only supports Variation database tables and latest version.
4
4
 
5
- Some of the work is inspired of [ruby-ensembl-api] project
5
+ Some of the work is inspired of [ruby-ensembl-api] project.
6
6
 
7
7
  ## Installation
8
8
 
@@ -30,14 +30,16 @@ Or install it yourself as:
30
30
 
31
31
  ### Custom database
32
32
 
33
- # Set following values before using
33
+ # Set following values before using - Only Human databases is somewhat tested.
34
34
 
35
35
  Ensembl.host = 'myhost.example.com'
36
36
  Ensembl.port = 3306 # default
37
37
  Ensembl.username = 'anonymous' # default
38
38
  Ensembl.password = '' # default
39
- Ensembl.database = 'homo_sapiens_variation_75_37' # default
40
-
39
+ Ensembl.species = 'homo_sapiens' # default
40
+ Ensembl.version = 75 # default
41
+ Ensembl.hg_version = 37 # default
42
+
41
43
 
42
44
  ## Contributing
43
45
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
3
  task :console do
4
- exec "irb -r ensembl -I ./lib"
4
+ exec "pry -r ensembl -I ./lib"
5
5
  end
6
6
 
data/ensembl.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Kristjan Metsalu"]
10
10
  spec.email = ["kristjan.metsalu@ut.ee"]
11
11
  spec.summary = %q{ Gem to access Ensembl.org databases through API }
12
- spec.description = %q{ ensembl provides an ruby API to connect to ensembl databases. }
12
+ spec.description = %q{ ensembl provides an ruby API to connect to Ensembl.org databases. }
13
13
  spec.homepage = "https://github.com/kmetsalu/ensembl"
14
14
  spec.license = "MIT"
15
15
 
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.6"
27
27
  spec.add_development_dependency "rake", '~> 10.3'
28
+ spec.add_development_dependency "pry", '~> 0.10'
28
29
  end
@@ -0,0 +1,462 @@
1
+ module Ensembl
2
+ module Core
3
+ module StableIdHistory
4
+ def previous_stable_ids
5
+ StableIdEvent.where(new_stable_id: stable_id)
6
+ end
7
+ end
8
+
9
+ class Connection < ActiveRecord::Base
10
+ self.extend TableNameOverrides
11
+
12
+ self.abstract_class = true
13
+
14
+ self.establish_connection :adapter => "mysql2",
15
+ :host => Ensembl.host,
16
+ :username => Ensembl.username,
17
+ :password => Ensembl.password,
18
+ :database => Ensembl.species+'_core_'+Ensembl.version+'_'+Ensembl.hg_version,
19
+ :reconnect => true
20
+
21
+ end
22
+
23
+ class ModelBase < Connection
24
+ self.extend PrimaryKeyOverrides
25
+
26
+ self.abstract_class = true
27
+ end
28
+
29
+ class AltAllele < ModelBase
30
+ belongs_to :gene
31
+ belongs_to :alt_allele_group
32
+ end
33
+
34
+ class AltAlleleAttrib < ModelBase
35
+ belongs_to :alt_allele
36
+ end
37
+
38
+ class AltAlleleGroup < ModelBase
39
+ has_many :alt_alleles
40
+ end
41
+
42
+ # TODO: Verify that is working
43
+ class Analysis < ModelBase
44
+ has_one :analysis_description
45
+ end
46
+
47
+ class AnalysisDescription < Connection
48
+ has_one :analysis
49
+ end
50
+
51
+ class AssociatedGroup < ModelBase
52
+ has_many :associated_xrefs
53
+ end
54
+
55
+ class AssociatedXref < ModelBase
56
+ belongs_to :object_xref
57
+ belongs_to :xref
58
+ belongs_to :source_xref, foreign_key: 'source_xref_id', class_name: 'Xref'
59
+ belongs_to :associated_group
60
+ end
61
+
62
+ class AttribType < ModelBase
63
+ has_many :seq_region_attrib
64
+ end
65
+
66
+ class Assembly < Connection
67
+ self.primary_key = 'asm_seq_region_id'
68
+
69
+ belongs_to :seq_region
70
+ end
71
+
72
+ class AssemblyException < ModelBase
73
+ belongs_to :seq_region
74
+ belongs_to :exc_seq_region, foreign_key: 'ex_seq_region_id', class_name: 'SeqRegion'
75
+ end
76
+
77
+ class CoordSystem < ModelBase
78
+ has_many :data_files
79
+ end
80
+
81
+ class DataFile < ModelBase
82
+ belongs_to :coord_system
83
+ end
84
+
85
+ class DensityFeature < ModelBase
86
+ belongs_to :seq_region
87
+ belongs_to :density_type
88
+ end
89
+
90
+ class DensityType < ModelBase
91
+ has_many :density_features
92
+ end
93
+
94
+ class Ditag < ModelBase
95
+ has_many :ditag_features
96
+ end
97
+
98
+ class DitagFeature < ModelBase
99
+ belongs_to :ditag
100
+ belongs_to :seq_region
101
+ belongs_to :analysis
102
+ end
103
+
104
+ class Dna < Connection
105
+ has_one :seq_region
106
+ end
107
+
108
+ class DnaAlignFeature < ModelBase
109
+ belongs_to :seq_region
110
+ belongs_to :analysis
111
+ belongs_to :external_db
112
+ end
113
+
114
+ class DependentXref < ModelBase
115
+ belongs_to :object_xref
116
+ belongs_to :master, foreign_key: 'master_xref_id', class_name: 'Xref'
117
+ belongs_to :dependent, foreign_key: 'dependent_xref_id', class_name: 'Xref'
118
+ end
119
+
120
+ class Exon < ModelBase
121
+ belongs_to :seq_region
122
+
123
+ has_many :exon_transcripts
124
+ has_many :transcripts, through: :exon_transcript
125
+
126
+ end
127
+
128
+ class ExonTranscript < Connection
129
+ belongs_to :exon
130
+ belongs_to :transcript
131
+ end
132
+
133
+ class ExternalDb < ModelBase
134
+ # FIXME: Hack because using type column in the database
135
+ self.inheritance_column = ':_no_inheritance_column'
136
+
137
+ has_many :seq_region_synonyms
138
+
139
+ scope :with_seq_region_synonyms, -> { where.not(seq_regions_synonyms.nil?)}
140
+ end
141
+
142
+ class ExternalSynonym < Connection
143
+ self.primary_key = 'xref_id'
144
+ end
145
+
146
+ class Gene < ModelBase
147
+ include StableIdHistory
148
+
149
+ belongs_to :analysis
150
+ belongs_to :seq_region
151
+ belongs_to :display_xref, foreign_key: 'display_xref_id', class_name: 'Xref'
152
+ belongs_to :transcript, foreign_key: 'canonical_transcript_id', class_name: 'Transcript'
153
+
154
+ has_many :gene_attribs
155
+ has_many :attrib_types, through: :gene_attribs
156
+
157
+ has_many :operon_transcript_genes
158
+ has_many :operon_transcripts, through: :operon_transcript_genes
159
+
160
+ end
161
+
162
+ # FIXME: Set up relations with stable IDs
163
+ class GeneArchive < Connection
164
+ belongs_to :peptide_archive
165
+ belongs_to :mapping_session
166
+ end
167
+
168
+ class GeneAttrib < ModelBase
169
+ belongs_to :gene
170
+ belongs_to :attrib_type
171
+ end
172
+
173
+ # TODO: Inspect relation with ObjectXref
174
+ class IdentityXref < Connection
175
+ self.primary_key = 'object_xref_id'
176
+ end
177
+
178
+ class Interpro < Connection
179
+
180
+ end
181
+
182
+ class IntronSupportingEvidence < ModelBase
183
+ belongs_to :analysis
184
+ belongs_to :seq_region
185
+
186
+ end
187
+
188
+ class GenomeStatistics < ModelBase
189
+
190
+ end
191
+
192
+ class Karyotype < ModelBase
193
+ belongs_to :seq_region
194
+
195
+ end
196
+
197
+ class Map < ModelBase
198
+
199
+ end
200
+
201
+ class MappingSession < ModelBase
202
+ has_many :stable_id_events
203
+ end
204
+
205
+ class MappingSet < ModelBase
206
+ has_many :seq_region_mappings
207
+ end
208
+
209
+ class Marker < ModelBase
210
+ has_many :marker_features
211
+ has_many :marker_synonyms
212
+ has_many :marker_map_locations
213
+ end
214
+
215
+ class MarkerFeature < ModelBase
216
+ belongs_to :marker
217
+ belongs_to :seq_region
218
+ belongs_to :analysis
219
+ end
220
+
221
+ class MarkerMapLocation < Connection
222
+ belongs_to :marker
223
+ belongs_to :map
224
+ belongs_to :marker_synonym
225
+ end
226
+
227
+ class MarkerSynonym < ModelBase
228
+ belongs_to :marker
229
+ end
230
+
231
+ class Meta < ModelBase
232
+
233
+ end
234
+
235
+ class MetaCoord < Connection
236
+ belongs_to :coord_system
237
+
238
+ end
239
+
240
+ class MiscAttrib < Connection
241
+ belongs_to :misc_feature
242
+ belongs_to :attrib_type
243
+ end
244
+
245
+ class MiscFeature < ModelBase
246
+ belongs_to :seq_region
247
+
248
+ has_many :misc_attrib
249
+ has_many :misc_feature_misc_sets
250
+ has_many :misc_sets, through: :misc_feature_misc_sets
251
+ end
252
+
253
+ class MiscFeatureMiscSet < Connection
254
+ belongs_to :misc_feature
255
+ belongs_to :misc_set
256
+ end
257
+
258
+ class MiscSet < ModelBase
259
+ has_many :misc_feature_misc_sets
260
+ has_many :misc_sets, through: :misc_feature_misc_sets
261
+ end
262
+
263
+ class ObjectXref < ModelBase
264
+ belongs_to :xref
265
+ belongs_to :analysis
266
+ end
267
+
268
+ class OntologyXref < ModelBase
269
+ belongs_to :object_xref
270
+ belongs_to :source, foreign_key: 'source_xref_id', class_name: 'Xref'
271
+ end
272
+
273
+ class Operon < ModelBase
274
+ belongs_to :analysis
275
+ belongs_to :seq_region
276
+ end
277
+
278
+ class OperonTranscript < ModelBase
279
+ belongs_to :analysis
280
+ belongs_to :seq_region
281
+ belongs_to :operon
282
+
283
+ has_many :operon_transcript_genes
284
+ has_many :genes, through: :operon_transcript_genes
285
+ end
286
+
287
+ class PeptideArchive < ModelBase
288
+
289
+ end
290
+
291
+ class PredictionExon < ModelBase
292
+ belongs_to :seq_region
293
+ belongs_to :prediction_transcript
294
+ end
295
+
296
+ class PredictionTranscript < ModelBase
297
+ belongs_to :seq_region
298
+ belongs_to :analysis
299
+
300
+ has_many :prediction_exons
301
+ end
302
+
303
+ class ProteinAlignFeature < ModelBase
304
+ belongs_to :seq_region
305
+ belongs_to :analysis
306
+ belongs_to :external_db
307
+ end
308
+
309
+ class ProteinFeature < ModelBase
310
+ belongs_to :translation
311
+ belongs_to :analysis
312
+ end
313
+
314
+ class RepeatConsensus < ModelBase
315
+ has_many :repeat_features
316
+ end
317
+
318
+ class RepeatFeature < ModelBase
319
+ belongs_to :seq_region
320
+ belongs_to :repeat_consensus
321
+ belongs_to :analysis
322
+ end
323
+
324
+ class SeqRegion < ModelBase
325
+ has_one :dna
326
+ belongs_to :coord_system
327
+
328
+ has_many :genes
329
+ has_many :density_features
330
+ has_many :prediction_exons
331
+ has_many :prediction_transcripts
332
+ has_many :repeat_features
333
+ has_many :protein_align_features
334
+ has_many :seq_region_attribs
335
+ has_many :seq_region_synonyms
336
+ has_many :simple_features
337
+ has_many :splicing_events
338
+ has_many :transcripts
339
+
340
+ end
341
+
342
+ class SeqRegionAttrib < Connection
343
+ belongs_to :seq_region
344
+ belongs_to :attrib_type
345
+ end
346
+
347
+ class SeqRegionMapping < Connection
348
+ belongs_to :current, foreign_key: 'external_seq_region_id', class_name: 'SeqRegion'
349
+ belongs_to :previous, foreign_key: 'internal_seq_region_id', class_name: 'SeqRegion'
350
+ belongs_to :mapping_set
351
+ end
352
+
353
+ class SeqRegionSynonym < ModelBase
354
+ belongs_to :seq_region
355
+ belongs_to :external_db
356
+ end
357
+
358
+ class SimpleFeature < ModelBase
359
+ belongs_to :seq_region
360
+ belongs_to :analysis
361
+ end
362
+
363
+ class SplicingEvent < ModelBase
364
+ belongs_to :seq_region
365
+ belongs_to :attrib_type
366
+ belongs_to :gene
367
+
368
+ has_many :splicing_event_features
369
+ end
370
+
371
+ class SplicingEventFeature < ModelBase
372
+ belongs_to :splicing_event
373
+ belongs_to :exon
374
+ belongs_to :transcript
375
+ end
376
+
377
+ class SplicingTranscriptPair < ModelBase
378
+ belongs_to :splicing_event
379
+ belongs_to :transcript1, foreign_key: 'transcript_id_1', class_name: 'Transcript'
380
+ belongs_to :transcript2, foreign_key: 'transcript_id_2', class_name: 'Transcript'
381
+ end
382
+
383
+ # TODO: Fix inheritance
384
+ class SupportingFeature < Connection
385
+ belongs_to :exon
386
+
387
+ end
388
+
389
+ # FIXME: Setup stable ids
390
+ class StableIdEvent < Connection
391
+ # FIXME: Hack because using type column in the database
392
+ self.inheritance_column = ':_no_inheritance_column'
393
+
394
+ belongs_to :mapping_session
395
+ end
396
+
397
+ class Transcript < ModelBase
398
+ include StableIdHistory
399
+
400
+ belongs_to :gene
401
+ belongs_to :analysis
402
+ belongs_to :seq_region
403
+ belongs_to :display_xref, foreign_key: 'display_xref_id', class_name: 'Xref'
404
+ belongs_to :canonical_translation, foreign_key: 'canonical_translation_id', class_name: 'Translation'
405
+
406
+
407
+ has_many :transcript_attribs
408
+ has_many :translations
409
+
410
+ end
411
+
412
+ class TranscriptAttrib < Connection
413
+ belongs_to :transcript
414
+ belongs_to :attrib_type
415
+ end
416
+
417
+ # TODO: Fix inheritance
418
+ class TranscriptSupportingFeature < Connection
419
+ belongs_to :transcript
420
+ end
421
+
422
+ class TranscriptIntronSupportingEvidence < ModelBase
423
+ belongs_to :transcript
424
+ belongs_to :previous_exon
425
+ belongs_to :next_exon
426
+ end
427
+
428
+ class Translation < ModelBase
429
+ include StableIdHistory
430
+
431
+ belongs_to :transcript
432
+ belongs_to :start_exon, foreign_key: 'start_exon_id', class_name: 'Exon'
433
+ belongs_to :end_exon, foreign_key: 'end_exon_id', class_name: 'Exon'
434
+
435
+ has_many :protein_features
436
+ has_many :translation_attribs
437
+ end
438
+
439
+ class TranslationAttrib < Connection
440
+ belongs_to :translation
441
+ belongs_to :attrib_type
442
+ end
443
+
444
+ # TODO: inspect ensembl_object_type and ensembl_id
445
+ class UnmappedObject < ModelBase
446
+ belongs_to :analysis
447
+ belongs_to :external_db
448
+ belongs_to :unmapped_reason
449
+ end
450
+
451
+ class UnmappedReason < ModelBase
452
+ has_many :unmapped_objects
453
+ end
454
+
455
+ class Xref < ModelBase
456
+ belongs_to :external_db
457
+
458
+ has_many :object_xrefs
459
+
460
+ end
461
+ end
462
+ end
@@ -2,7 +2,27 @@ require 'active_record'
2
2
 
3
3
  module Ensembl
4
4
  module Variation
5
- class Allele < Ensembl::ModelBase
5
+ class Connection < ActiveRecord::Base
6
+ self.extend TableNameOverrides
7
+
8
+ self.abstract_class = true
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
16
+
17
+ end
18
+
19
+ class ModelBase < Connection
20
+ self.extend PrimaryKeyOverrides
21
+
22
+ self.abstract_class = true
23
+ end
24
+
25
+ class Allele < ModelBase
6
26
  belongs_to :variation
7
27
  belongs_to :population
8
28
  belongs_to :subsnp_handle
@@ -10,78 +30,77 @@ module Ensembl
10
30
 
11
31
  end
12
32
 
13
- class AlleleCode < Ensembl::ModelBase
33
+ class AlleleCode < ModelBase
14
34
  has_many :genotype_codes
15
35
 
16
36
  end
17
37
 
18
- class AssociateStudy < Ensembl::Connection
38
+ class AssociateStudy < Connection
19
39
  belongs_to :study, foreign_key: 'study1_id', class_name: 'Study'
20
40
  belongs_to :associated_study, foreign_key: 'study2_id', class_name: 'Study'
21
41
 
22
42
  end
23
43
 
24
- class Attrib < Ensembl::ModelBase
44
+ class Attrib < ModelBase
25
45
  belongs_to :attrib_type
26
-
27
46
  end
28
47
 
29
- class AttribSet < Ensembl::ModelBase
48
+ class AttribSet < ModelBase
30
49
  belongs_to :attrib
31
50
 
32
51
  end
33
52
 
34
- class AttribType < Ensembl::ModelBase
53
+ class AttribType < ModelBase
35
54
  has_many :attribs, class_name: 'Attrib'
36
55
  has_many :pheotype_feature_attrib
37
56
  has_many :phenotype_features, through: :phenotype_feature_attrib
38
57
 
39
58
  end
40
59
 
41
- class CompressedGenotypeRegion < Ensembl::Connection
60
+ class CompressedGenotypeRegion < Connection
42
61
  belongs_to :individual
43
-
62
+ belongs_to :seq_region, class_name: 'Ensembl::Core::SeqRegion'
44
63
  end
45
64
 
46
- class CompressedGenotypeVar < Ensembl::Connection
65
+ class CompressedGenotypeVar < Connection
47
66
  belongs_to :variation
48
67
  belongs_to :subsnp_handle, foreign_key: 'subsnp_id'
49
68
 
50
69
  end
51
70
 
52
- class CoordSystem < Ensembl::ModelBase
71
+ class CoordSystem < ModelBase
53
72
  end
54
73
 
55
- class FailedAllele < Ensembl::ModelBase
74
+ class FailedAllele < ModelBase
56
75
  belongs_to :failed_description
57
76
  belongs_to :allele
58
77
 
59
78
  end
60
79
 
61
- class FailedDescription < Ensembl::ModelBase
80
+ class FailedDescription < ModelBase
62
81
  belongs_to :failed_variation
63
82
 
64
83
  end
65
84
 
66
- class FailedStructuralVariation < Ensembl::ModelBase
85
+ class FailedStructuralVariation < ModelBase
67
86
  belongs_to :structural_variation
68
87
  belongs_to :failed_description
69
88
 
70
89
  end
71
90
 
72
- class FailedVariation < Ensembl::ModelBase
91
+ class FailedVariation < ModelBase
73
92
  belongs_to :variation
74
93
  has_one :failed_description
75
94
 
76
95
  end
77
96
 
78
- class GenotypeCode < Ensembl::ModelBase
97
+ class GenotypeCode < ModelBase
79
98
  belongs_to :allele_code
80
99
  belongs_to :genotype_code
81
100
 
82
101
  end
83
102
 
84
- class Individual < Ensembl::ModelBase
103
+ class Individual < ModelBase
85
104
  belongs_to :individual_type
86
105
  belongs_to :father, foreign_key: 'father_individual_id', class_name: 'Individual'
87
106
  belongs_to :mother, foreign_key: 'mother_individual_id', class_name: 'Individual'
@@ -92,57 +111,59 @@ module Ensembl
92
111
  has_many :individual_synonyms, foreign_key: :synonym_id
93
112
  has_many :synonyms, through: :individual_synonyms
94
113
 
114
+ has_many :individual_genotype_multiple_bps
115
+
95
116
  scope :with_fathers, -> { where.not(father:nil) }
96
117
  scope :with_mothers, -> { where.not(mother:nil) }
97
118
 
98
119
  end
99
120
 
100
- class IndividualGenotypeMultipleBp < Ensembl::Connection
121
+ class IndividualGenotypeMultipleBp < Connection
101
122
  belongs_to :variation
102
123
  belongs_to :individual
103
124
  belongs_to :subsnp_handle, foreign_key: 'subsnp_id'
104
125
 
105
126
  end
106
127
 
107
- class IndividualPopulation < Ensembl::Connection
128
+ class IndividualPopulation < Connection
108
129
  belongs_to :individual
109
130
  belongs_to :population
110
-
111
131
  end
112
132
 
113
- class IndividualSynonym < Ensembl::Connection
133
+ class IndividualSynonym < Connection
114
134
  belongs_to :individual
115
135
  belongs_to :source
116
136
  belongs_to :synonym, class_name: 'Individual'
117
137
 
118
138
  end
119
139
 
120
- class IndividualType < Ensembl::ModelBase
140
+ class IndividualType < ModelBase
121
141
  has_many :individuals
122
142
  end
123
143
 
124
- class Meta < Ensembl::ModelBase
144
+ class Meta < ModelBase
125
145
  # TODO: Link with others
126
146
  end
127
147
 
128
- class MetaCoord < Ensembl::Connection
148
+ class MetaCoord < Connection
129
149
  end
130
150
 
131
- class MotifFreatureVariation < Ensembl::ModelBase
151
+ class MotifFreatureVariation < ModelBase
132
152
  belongs_to :variation_feature
133
153
  end
134
154
 
135
- class Phenotype < Ensembl::ModelBase
155
+ class Phenotype < ModelBase
136
156
  has_many :phenotype_features
137
157
  end
138
158
 
139
- class PhenotypeFeature < Ensembl::ModelBase
140
- # Hack because using type column in the database
159
+ class PhenotypeFeature < ModelBase
160
+ # FIXME: Hack because using type column in the database
141
161
  self.inheritance_column = ':_no_inheritance_column'
142
162
 
143
163
  belongs_to :phenotype
144
164
  belongs_to :source
145
165
  belongs_to :study
166
+ belongs_to :seq_region, class_name: 'Ensembl::Core::SeqRegion'
146
167
 
147
168
  has_many :phenotype_feature_attrib
148
169
  has_many :attrib_types, through: :phenotype_feature_attrib
@@ -153,15 +174,17 @@ module Ensembl
153
174
 
154
175
  end
155
176
 
156
- class PhenotypeFeatureAttrib < Ensembl::Connection
177
+ class PhenotypeFeatureAttrib < Connection
157
178
  belongs_to :attrib_type
158
179
  belongs_to :phenotype_feature
159
180
 
160
181
  end
161
182
 
162
- class Population < Ensembl::ModelBase
183
+ class Population < ModelBase
184
+ self.extend Ensembl::SearchByName
185
+
163
186
  has_many :population_synonyms
164
- has_many :synonyms, through: :population_synonyms, source: :synonym
187
+ #has_many :synonyms, through: :population_synonyms, source: :synonym
165
188
  has_many :alleles
166
189
 
167
190
  has_many :individual_populations
@@ -169,61 +192,82 @@ module Ensembl
169
192
 
170
193
  has_many :population_structures, foreign_key: 'super_population_id'
171
194
  has_many :sub_populations, through: :population_structures, source: :sub_population
195
+ has_many :parents, through: :population_structures, source: :super_populaton#, foreign_key: 'sub_population_id'
172
196
 
173
197
  has_many :population_genotypes
174
198
 
199
+ def parent
200
+ ps=PopulationStructure.find_by(sub_population: id)
201
+ ps.super_population unless ps.nil?
202
+ end
203
+
175
204
  def all_individual_populations
176
- IndividualPopulation.where(population_id: sub_populations.pluck(:population_id))
205
+ IndividualPopulation.where(population_id: sub_population_ids(self)<<id)
177
206
  end
178
207
 
179
208
  def all_individuals
180
209
  Individual.where individual_id: all_individual_populations.pluck(:individual_id)
181
210
  end
182
211
 
212
+ def all_population_genotypes
213
+ PopulationGenotype.where(population_id: sub_population_ids(self)<<id)
214
+ end
215
+
216
+ private
217
+ def sub_population_ids(population,array=[])
218
+ subs=population.sub_populations
219
+ subs.each do |p|
220
+ array<<p.id
221
+ sub_population_ids(p,array)
222
+ end
223
+ end
183
224
  end
184
225
 
185
- class PopulationSynonym < Ensembl::Connection
186
- belongs_to :synonym, foreign_key: 'synonym_id', class_name: 'Population'
226
+ class PopulationSynonym < Connection
227
+ #belongs_to :synonym, foreign_key: 'synonym_id', class_name: 'Population'
187
228
  belongs_to :population
188
229
  belongs_to :source
189
230
  end
190
231
 
191
- class PopulationGenotype < Ensembl::ModelBase
232
+ class PopulationGenotype < ModelBase
192
233
  belongs_to :variation
193
234
  belongs_to :population
194
235
  belongs_to :subsnp_handle, foreign_key: 'subsnp_id'
195
- belongs_to :genotype_code
196
236
 
237
+ belongs_to :genotype_code
238
+ has_one :allele_code, through: :genotype_code
197
239
  end
198
240
 
199
- class PopulationStructure < Ensembl::Connection
200
- belongs_to :population, foreign_key: 'super_population_id', class_name: 'Population'
241
+ class PopulationStructure < Connection
242
+ belongs_to :super_population, foreign_key: 'super_population_id', class_name: 'Population'
201
243
  belongs_to :sub_population, foreign_key: 'sub_population_id', class_name: 'Population'
202
-
203
244
  end
204
245
 
205
- class ProteinFunctionPredictions < Ensembl::Connection
206
- end
246
+ class ProteinFunctionPredictions < Connection
207
247
 
208
- class Publication < Ensembl::ModelBase
209
248
  end
210
249
 
211
- class RegulatoryFeatureVariation < Ensembl::ModelBase
212
- belongs_to :variation_feature
250
+ class Publication < ModelBase
213
251
 
214
252
  end
215
253
 
216
- class SeqRegion < Ensembl::ModelBase
217
- belongs_to :coord_system
218
-
254
+ class RegulatoryFeatureVariation < ModelBase
255
+ belongs_to :variation_feature
219
256
  end
220
257
 
221
- class StrainGtypePoly < Ensembl::Connection
258
+ # class SeqRegion < Ensembl::Core::SeqRegion
259
+ # belongs_to :coord_system
260
+ # has_many :compressed_genotype_regions
261
+ # has_many :phenotype_features
262
+ # has_many :structureal_variation_features
263
+ # end
264
+
265
+ class StrainGtypePoly < Connection
222
266
  belongs_to :variation
223
267
 
224
268
  end
225
269
 
226
- class StructuralVariation < Ensembl::ModelBase
270
+ class StructuralVariation < ModelBase
227
271
  belongs_to :source
228
272
  belongs_to :study
229
273
 
@@ -245,13 +289,13 @@ module Ensembl
245
289
 
246
290
  end
247
291
 
248
- class StructuralVariationAssociation < Ensembl::Connection
292
+ class StructuralVariationAssociation < Connection
249
293
  belongs_to :structural_variation
250
294
  belongs_to :supporting_structural_variation, foreign_key: 'supporting_structural_variation_id', class_name: 'StructuralVariation'
251
295
  end
252
296
 
253
- class StructuralVariationFeature < Ensembl::ModelBase
254
- belongs_to :seq_region
297
+ class StructuralVariationFeature < ModelBase
298
+ belongs_to :seq_region, class_name: 'Ensembl::Core::SeqRegion'
255
299
  belongs_to :structural_variation
256
300
  belongs_to :source
257
301
  belongs_to :study
@@ -262,67 +306,66 @@ module Ensembl
262
306
 
263
307
  end
264
308
 
265
- class StructuralVariationSample < Ensembl::ModelBase
309
+ class StructuralVariationSample < ModelBase
266
310
  belongs_to :structural_variation
267
311
  belongs_to :individual
268
312
  end
269
313
 
270
- class Study < Ensembl::ModelBase
271
- has_many :study_variations
272
- has_many :variations, through: :study_variations
314
+ class Source < ModelBase
273
315
 
274
316
  end
275
317
 
276
- class Source < Ensembl::ModelBase
277
-
278
- end
279
-
280
- class Study < Ensembl::ModelBase
318
+ class Study < ModelBase
281
319
  has_many :associate_studies, foreign_key: 'study1_id'
282
320
  has_many :associated_studies, through: :associate_studies, source: :associated_study
283
321
 
284
322
  # FIXME: No data in database
323
+ has_many :study_variations
285
324
  has_many :variations, through: :study_variations
286
325
  end
287
326
 
288
327
  # FIXME: No data in database
289
- class StudyVariation < Ensembl::Connection
328
+ class StudyVariation < Connection
290
329
  belongs_to :study
291
330
  belongs_to :variation
292
331
  end
293
332
 
294
- class SubmitterHandle < Ensembl::Connection
333
+ class SubmitterHandle < Connection
295
334
  self.primary_key = 'handle_id'
296
335
  end
297
336
 
298
- class SubsnpHandle < Ensembl::Connection
337
+ class SubsnpHandle < Connection
299
338
  self.primary_key = 'subsnp_id'
300
339
 
301
340
  has_many :subsnp_maps
302
341
  end
303
342
 
304
- class SubsnpMap < Ensembl::Connection
343
+ class SubsnpMap < Connection
305
344
  belongs_to :variation
306
345
  belongs_to :subsnp_handle, foreign_key: 'subsnp_id'
307
346
  end
308
347
 
309
- class TaggedVariationFeature < Ensembl::ModelBase
348
+ class TaggedVariationFeature < ModelBase
310
349
  belongs_to :variation_feature
311
350
  belongs_to :population
312
351
  end
313
352
 
314
- class TranscriptVariation < Ensembl::ModelBase
353
+ class TranscriptVariation < ModelBase
315
354
  belongs_to :variation_feature
316
355
 
317
356
  end
318
357
 
319
- class TranslationMd5 < Ensembl::ModelBase
358
+ class TranslationMd5 < ModelBase
320
359
 
321
360
  end
322
361
 
323
- class Variation < Ensembl::ModelBase
362
+ class Variation < ModelBase
363
+ self.extend Ensembl::SearchByName
364
+
324
365
  belongs_to :source
366
+
325
367
  has_many :variation_synonyms
368
+
326
369
  has_many :failed_variations
327
370
  has_many :alleles
328
371
  has_many :population_genotypes
@@ -334,71 +377,108 @@ module Ensembl
334
377
  has_many :variation_genenames
335
378
  has_many :variation_hgvs, class_name: 'VariationHgvs'
336
379
  has_many :variation_sets
380
+ has_many :variation_features
381
+
382
+ has_many :individual_genotype_multiple_bps
383
+ has_many :compressed_genotype_vars
337
384
 
338
385
  def phenotype_features
339
386
  PhenotypeFeature.where(object_id: name, type: 'Variation')
340
387
  end
341
388
 
389
+ def synonyms
390
+ variation_synonyms.map{ |vs| vs.name }
391
+ end
392
+
393
+
394
+ # Find Variation by also using VariationSynonyms
395
+ # @name: name of the variation
396
+ # @return: [Variation]
397
+ def self.find_by_name(name)
398
+ v = self.find_by(name: name)
399
+ vs = VariationSynonym.eager_load(:variation).find_by(name: name) if v.nil?
400
+ vs.variation unless vs.nil?
401
+ end
402
+
342
403
  def all_phenotype_features
343
404
  object_ids = variation_synonyms.pluck :name
344
405
  object_ids<<name
345
406
  PhenotypeFeature.where(object_id: object_ids, type: 'Variation')
346
407
  end
408
+
409
+ # def population_genotypes
410
+ # PopulationGenotype.where(variation_id: id)
411
+ # end
347
412
  end
348
413
 
349
- class VariationCitation < Ensembl::Connection
414
+ class VariationCitation < Connection
350
415
  self.table_name = 'variation_citation'
351
416
  belongs_to :variation
352
417
  belongs_to :publication
353
418
  end
354
419
 
355
- class VariationFeature < Ensembl::ModelBase
420
+ class VariationFeature < ModelBase
356
421
  belongs_to :variation
357
422
  belongs_to :source
423
+ belongs_to :seq_region, class_name: 'Ensembl::Core::SeqRegion'
424
+
358
425
  has_many :transcript_variations
359
426
  has_many :motif_freature_variations
360
427
  has_many :tagged_variation_features
361
428
 
429
+ def variation_sets
430
+ VariationSets.where[variation_set_id: [variation_set_id.split(',').map{|id| id.to_i }]] unless variation_set_id.nil?
431
+ end
432
+
433
+ def class_type
434
+ Attrib.find(class_attrib_id) unless class_attrib_id.nil?
435
+ end
362
436
  end
363
437
 
364
- class VariationGenename < Ensembl::Connection
438
+ class VariationGenename < Connection
365
439
  belongs_to :variation
366
440
  end
367
441
 
368
- class VariationHgvs < Ensembl::Connection
442
+ class VariationHgvs < Connection
369
443
  belongs_to :variation
370
444
  end
371
445
 
372
- class VariationSet < Ensembl::ModelBase
446
+ class VariationSet < ModelBase
447
+ self.extend Ensembl::SearchByName
448
+
373
449
  belongs_to :short_name, foreign_key: 'short_name_attrib_id', class_name: 'Attrib'
374
450
  has_many :structural_variations
375
451
 
376
- has_many :variation_set_structures
377
- has_many :sub_variation_sets, through: :variation_set_structures, source: :sub_variation_set
452
+ #has_many :variation_set_structures, foreign_key: 'variation_set_super'
453
+ has_many :sub_variation_set_structures, foreign_key: 'variation_set_super', class_name: 'VariationSetStructure'
454
+ has_many :sub_variation_sets, through: :sub_variation_set_structures , source: :sub_variation_set
455
+
456
+ has_many :super_variation_set_structures, foreign_key: 'variation_set_sub', class_name: 'VariationSetStructure'
457
+ has_many :super_variation_sets, through: :super_variation_set_structures , source: :super_variation_set
458
+
459
+ has_many :variation_set_variations
460
+ has_many :variations, through: :variation_set_variations
378
461
 
379
- has_many :variations
380
462
  end
381
463
 
382
- class VariationSetStructuralVariation < Ensembl::Connection
464
+ class VariationSetStructuralVariation < Connection
383
465
  belongs_to :structural_variation
384
466
  belongs_to :variation_set
385
467
  end
386
468
 
387
- class VariationSetStructure < Ensembl::Connection
388
- belongs_to :super_variation_set, foreign_key: 'super_variation_set_id', class_name: 'VariationSet'
389
- belongs_to :sub_variation_set, foreign_key: 'sub_variation_set_id', class_name: 'VariationSet'
469
+ class VariationSetStructure < Connection
470
+ belongs_to :super_variation_set, foreign_key: 'variation_set_super', class_name: 'VariationSet'
471
+ belongs_to :sub_variation_set, foreign_key: 'variation_set_sub', class_name: 'VariationSet'
390
472
  end
391
473
 
392
- class VariationSetVariation < Ensembl::Connection
474
+ class VariationSetVariation < Connection
393
475
  belongs_to :variation
394
476
  belongs_to :variation_set
395
477
  end
396
478
 
397
- class VariationSynonym < Ensembl::ModelBase
479
+ class VariationSynonym < ModelBase
398
480
  belongs_to :variation
399
481
  belongs_to :source
400
482
  end
401
-
402
-
403
483
  end
404
484
  end
@@ -1,3 +1,3 @@
1
1
  module Ensembl
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/ensembl.rb CHANGED
@@ -24,8 +24,16 @@ module Ensembl
24
24
  @password||=''
25
25
  end
26
26
 
27
- def database
28
- @database||='homo_sapiens_variation_75_37'
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'
29
37
  end
30
38
 
31
39
  end
@@ -42,24 +50,63 @@ module Ensembl
42
50
  end
43
51
  end
44
52
 
45
- class Connection < ActiveRecord::Base
46
- self.extend TableNameOverrides
47
-
48
- self.abstract_class = true
49
-
50
- self.establish_connection :adapter => "mysql2",
51
- :host => Ensembl.host,
52
- :username => Ensembl.username,
53
- :password => Ensembl.password,
54
- :database => Ensembl.database
55
-
53
+ module SearchByName
54
+ def search(name)
55
+ table=self.arel_table
56
+ self.where(table[:name].matches("%#{name}%"))
57
+ end
56
58
  end
57
59
 
58
- class ModelBase < Connection
59
- self.extend PrimaryKeyOverrides
60
+ # class BaseConnection < ActiveRecord::Base
61
+ # self.extend TableNameOverrides
62
+ # self.abstract_class = true
63
+ # end
64
+
65
+ # module Core
66
+ # class Connection < ActiveRecord::Base
67
+ # self.extend TableNameOverrides
68
+ #
69
+ # self.abstract_class = true
70
+ #
71
+ # self.establish_connection :adapter => "mysql2",
72
+ # :host => Ensembl.host,
73
+ # :username => Ensembl.username,
74
+ # :password => Ensembl.password,
75
+ # :database => Ensembl.species+'_core_'+Ensembl.version+'_'+Ensembl.hg_version,
76
+ # :reconnect => true
77
+ #
78
+ # end
79
+ #
80
+ # class ModelBase < Connection
81
+ # self.extend PrimaryKeyOverrides
82
+ #
83
+ # self.abstract_class = true
84
+ # end
85
+ # end
86
+ #
87
+ # module Variation
88
+ # class Connection < ActiveRecord::Base
89
+ # self.extend TableNameOverrides
90
+ #
91
+ # self.abstract_class = true
92
+ #
93
+ # self.establish_connection :adapter => "mysql2",
94
+ # :host => Ensembl.host,
95
+ # :username => Ensembl.username,
96
+ # :password => Ensembl.password,
97
+ # :database => Ensembl.species+'_variation_'+Ensembl.version+'_'+Ensembl.hg_version,
98
+ # :reconnect => true
99
+ #
100
+ # end
101
+ #
102
+ # class ModelBase < Connection
103
+ # self.extend PrimaryKeyOverrides
104
+ #
105
+ # self.abstract_class = true
106
+ # end
107
+ # end
60
108
 
61
- self.abstract_class = true
62
- end
63
109
  end
64
110
 
65
- require File.dirname(__FILE__) + '/ensembl/variation/activerecord.rb'
111
+ require File.dirname(__FILE__) + '/ensembl/core/activerecord.rb'
112
+ require File.dirname(__FILE__) + '/ensembl/variation/activerecord.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.3
4
+ version: 0.0.4
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-06-27 00:00:00.000000000 Z
11
+ date: 2014-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -66,7 +66,21 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.3'
69
- description: " ensembl provides an ruby API to connect to ensembl databases. "
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ description: " ensembl provides an ruby API to connect to Ensembl.org databases. "
70
84
  email:
71
85
  - kristjan.metsalu@ut.ee
72
86
  executables: []
@@ -80,6 +94,7 @@ files:
80
94
  - Rakefile
81
95
  - ensembl.gemspec
82
96
  - lib/ensembl.rb
97
+ - lib/ensembl/core/activerecord.rb
83
98
  - lib/ensembl/variation/activerecord.rb
84
99
  - lib/ensembl/version.rb
85
100
  homepage: https://github.com/kmetsalu/ensembl
@@ -107,3 +122,4 @@ signing_key:
107
122
  specification_version: 4
108
123
  summary: Gem to access Ensembl.org databases through API
109
124
  test_files: []
125
+ has_rdoc: