jandot-ruby-ensembl-api 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/TUTORIAL +623 -0
  2. data/bin/ensembl +39 -0
  3. data/lib/ensembl/core/activerecord.rb +1847 -0
  4. data/lib/ensembl/core/project.rb +248 -0
  5. data/lib/ensembl/core/slice.rb +627 -0
  6. data/lib/ensembl/core/transcript.rb +425 -0
  7. data/lib/ensembl/core/transform.rb +97 -0
  8. data/lib/ensembl/db_connection.rb +148 -0
  9. data/lib/ensembl/variation/activerecord.rb +308 -0
  10. data/lib/ensembl.rb +23 -0
  11. data/samples/examples_perl_tutorial.rb +120 -0
  12. data/samples/small_example_ruby_api.rb +34 -0
  13. data/test/unit/release_45/core/run_tests.rb +12 -0
  14. data/test/unit/release_45/core/test_project.rb +235 -0
  15. data/test/unit/release_45/core/test_project_human.rb +58 -0
  16. data/test/unit/release_45/core/test_relationships.rb +61 -0
  17. data/test/unit/release_45/core/test_sequence.rb +175 -0
  18. data/test/unit/release_45/core/test_slice.rb +56 -0
  19. data/test/unit/release_45/core/test_transcript.rb +94 -0
  20. data/test/unit/release_45/core/test_transform.rb +223 -0
  21. data/test/unit/release_45/variation/test_activerecord.rb +32 -0
  22. data/test/unit/release_50/core/run_tests.rb +12 -0
  23. data/test/unit/release_50/core/test_project.rb +215 -0
  24. data/test/unit/release_50/core/test_project_human.rb +58 -0
  25. data/test/unit/release_50/core/test_relationships.rb +66 -0
  26. data/test/unit/release_50/core/test_sequence.rb +175 -0
  27. data/test/unit/release_50/core/test_slice.rb +121 -0
  28. data/test/unit/release_50/core/test_transcript.rb +108 -0
  29. data/test/unit/release_50/core/test_transform.rb +223 -0
  30. data/test/unit/release_50/variation/test_activerecord.rb +136 -0
  31. data/test/unit/test_connection.rb +58 -0
  32. data/test/unit/test_releases.rb +40 -0
  33. metadata +243 -0
data/bin/ensembl ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/ruby
2
+ require 'irb'
3
+ require 'ensembl'
4
+
5
+ module IRB
6
+ def self.start_session(binding)
7
+ IRB.setup(nil)
8
+
9
+ workspace = WorkSpace.new(binding)
10
+
11
+ if @CONF[:SCRIPT]
12
+ irb = Irb.new(workspace, @CONF[:SCRIPT])
13
+ else
14
+ irb = Irb.new(workspace)
15
+ end
16
+
17
+ @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
18
+ @CONF[:MAIN_CONTEXT] = irb.context
19
+
20
+ trap("SIGINT") do
21
+ irb.signal_handle
22
+ end
23
+
24
+ catch(:IRB_EXIT) do
25
+ irb.eval_input
26
+ end
27
+ end
28
+ end
29
+
30
+ include Ensembl::Core
31
+ if ARGV.length == 2
32
+ species = ARGV.shift
33
+ release = ARGV.shift.to_i
34
+ DBConnection.connect(species,release)
35
+
36
+ IRB.start_session(Kernel.binding)
37
+ else
38
+ raise "ERROR: Please provide snake_case species and Ensembl release number"
39
+ end
@@ -0,0 +1,1847 @@
1
+ #
2
+ # = ensembl/core/activerecord.rb - ActiveRecord mappings to Ensembl core
3
+ #
4
+ # Copyright:: Copyright (C) 2007 Jan Aerts <http://jandot.myopenid.com>
5
+ # License:: The Ruby License
6
+ #
7
+
8
+ # = DESCRIPTION
9
+ # == What is it?
10
+ # The Ensembl module provides an API to the Ensembl databases
11
+ # stored at ensembldb.ensembl.org. This is the same information that is
12
+ # available from http://www.ensembl.org.
13
+ #
14
+ # The Ensembl::Core module mainly covers sequences and
15
+ # annotations.
16
+ # The Ensembl::Variation module covers variations (e.g. SNPs).
17
+ # The Ensembl::Compara module covers comparative mappings
18
+ # between species.
19
+ #
20
+ # == ActiveRecord
21
+ # The Ensembl API provides a ruby interface to the Ensembl mysql databases
22
+ # at ensembldb.ensembl.org. Most of the API is based on ActiveRecord to
23
+ # get data from that database. In general, each table is described by a
24
+ # class with the same name: the coord_system table is covered by the
25
+ # CoordSystem class, the seq_region table is covered by the SeqRegion class,
26
+ # etc. As a result, accessors are available for all columns in each table.
27
+ # For example, the seq_region table has the following columns: seq_region_id,
28
+ # name, coord_system_id and length. Through ActiveRecord, these column names
29
+ # become available as attributes of SeqRegion objects:
30
+ # puts my_seq_region.seq_region_id
31
+ # puts my_seq_region.name
32
+ # puts my_seq_region.coord_system_id
33
+ # puts my_seq_region.length.to_s
34
+ #
35
+ # ActiveRecord makes it easy to extract data from those tables using the
36
+ # collection of #find methods. There are three types of #find methods (e.g.
37
+ # for the CoordSystem class):
38
+ # a. find based on primary key in table:
39
+ # my_coord_system = CoordSystem.find(5)
40
+ # b. find_by_sql:
41
+ # my_coord_system = CoordSystem.find_by_sql('SELECT * FROM coord_system WHERE name = 'chromosome'")
42
+ # c. find_by_<insert_your_column_name_here>
43
+ # my_coord_system1 = CoordSystem.find_by_name('chromosome')
44
+ # my_coord_system2 = CoordSystem.find_by_rank(3)
45
+ # To find out which find_by_<column> methods are available, you can list the
46
+ # column names using the column_names class methods:
47
+ #
48
+ # puts Ensembl::Core::CoordSystem.column_names.join("\t")
49
+ #
50
+ # For more information on the find methods, see
51
+ # http://ar.rubyonrails.org/classes/ActiveRecord/Base.html#M000344
52
+ #
53
+ # The relationships between different tables are accessible through the
54
+ # classes as well. For example, to loop over all seq_regions belonging to
55
+ # a coord_system (a coord_system "has many" seq_regions):
56
+ # chr_coord_system = CoordSystem.find_by_name('chromosome')
57
+ # chr_coord_system.seq_regions.each do |seq_region|
58
+ # puts seq_region.name
59
+ # end
60
+ # Of course, you can go the other way as well (a seq_region "belongs to"
61
+ # a coord_system):
62
+ # chr4 = SeqRegion.find_by_name('4')
63
+ # puts chr4.coord_system.name #--> 'chromosome'
64
+ #
65
+ # To find out what relationships exist for a given class, you can use the
66
+ # #reflect_on_all_associations class methods:
67
+ # puts SeqRegion.reflect_on_all_associations(:has_many).collect{|a| a.name.to_s}.join("\n")
68
+ # puts SeqRegion.reflect_on_all_associations(:has_one).collect{|a| a.name.to_s}.join("\n")
69
+ # puts SeqRegion.reflect_on_all_associations(:belongs_to).collect{|a| a.name.to_s}.join("\n")
70
+ module Ensembl
71
+ # = DESCRIPTION
72
+ # The Ensembl::Core module covers the core databases from
73
+ # ensembldb.ensembl.org and covers mainly sequences and their annotations.
74
+ # For a full description of the database (and therefore the classes that
75
+ # are available), see http://www.ensembl.org/info/software/core/schema/index.html
76
+ # and http://www.ensembl.org/info/software/core/schema/schema_description.html
77
+ module Core
78
+ # = DESCRIPTION
79
+ # The Sliceable mixin holds the get_slice method and can be included
80
+ # in any class that lends itself to having a position on a SeqRegion.
81
+ module Sliceable
82
+ # = DESCRIPTION
83
+ # The Sliceable#slice method takes the coordinates on a reference
84
+ # and creates a Ensembl::Core::Slice object.
85
+ # ---
86
+ # *Arguments*:: none
87
+ # *Returns*:: Ensembl::Core::Slice object
88
+ def slice
89
+ start, stop, strand = nil, nil, nil
90
+
91
+ if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_start')
92
+ start = self.seq_region_start
93
+ end
94
+ if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_end')
95
+ stop = self.seq_region_end
96
+ end
97
+ if self.class == Ensembl::Core::Intron or self.class.column_names.include?('seq_region_strand')
98
+ strand = self.seq_region_strand
99
+ else #FIXME: we shouldn't do this, but can't #project if no strand given
100
+ strand = 1
101
+ end
102
+
103
+ return Ensembl::Core::Slice.new(self.seq_region, start, stop, strand)
104
+ end
105
+
106
+ # = DESCRIPTION
107
+ # The Sliceable#seq method takes the coordinates on a reference, transforms
108
+ # onto the seqlevel coordinate system if necessary, and retrieves the
109
+ # sequence.
110
+ # ---
111
+ # *Arguments*:: none
112
+ # *Returns*:: sequence
113
+ def seq
114
+ return self.slice.seq
115
+ end
116
+
117
+ # = DESCRIPTION
118
+ # The Sliceable#start method is a convenience method and returns
119
+ # self.seq_region_start.
120
+ # ---
121
+ # *Arguments*:: none
122
+ # *Returns*:: sequence
123
+ def start
124
+ return self.seq_region_start
125
+ end
126
+
127
+ # = DESCRIPTION
128
+ # The Sliceable#stop method is a convenience method and returns
129
+ # self.seq_region_end.
130
+ # ---
131
+ # *Arguments*:: none
132
+ # *Returns*:: sequence
133
+ def stop
134
+ return self.seq_region_end
135
+ end
136
+
137
+ # = DESCRIPTION
138
+ # The Sliceable#strand method is a convenience method and returns
139
+ # self.seq_region_strand.
140
+ # ---
141
+ # *Arguments*:: none
142
+ # *Returns*:: sequence
143
+ def strand
144
+ return self.seq_region_strand
145
+ end
146
+
147
+ # = DESCRIPTION
148
+ # The Sliceable#length method returns the length of the feature (based on
149
+ # seq_region_start and seq_region_end.
150
+ # ---
151
+ # *Arguments*:: none
152
+ # *Returns*:: sequence
153
+ def length
154
+ return self.stop - self.start + 1
155
+ end
156
+
157
+ # = DESCRIPTION
158
+ # The Sliceable#project method is used to transfer coordinates from one
159
+ # coordinate system to another. Suppose you have a feature on a
160
+ # contig in human (let's say on contig AC000031.6.1.38703) and you
161
+ # want to know the coordinates on the chromosome. This is a
162
+ # projection of coordinates from a higher ranked coordinate system to
163
+ # a lower ranked coordinate system. Projections can also be done
164
+ # from a chromosome to the contig level. However, it might be possible
165
+ # that more than one contig has to be included and that there exist
166
+ # gaps between the contigs. The output of this method therefore is
167
+ # an _array_ of Slice and Gap objects.
168
+ #
169
+ # At the moment, projections can only be done if the two coordinate
170
+ # systems are linked directly in the 'assembly' table.
171
+ #
172
+ # = USAGE
173
+ #
174
+ # # Get a contig slice in cow and project to scaffold level
175
+ # # (i.e. going from a high rank coord system to a lower rank coord
176
+ # # system)
177
+ # original_feature = Gene.find(85743)
178
+ # target_slices = original_feature.project('scaffold')
179
+ #
180
+ # ---
181
+ # *Arguments*:
182
+ # * coord_system_name:: name of coordinate system to project
183
+ # coordinates to
184
+ # *Returns*:: an array consisting of Slices and, if necessary, Gaps
185
+ def project(coord_system_name)
186
+ return self.slice.project(coord_system_name)
187
+ end
188
+
189
+ end
190
+
191
+
192
+ # = DESCRIPTION
193
+ # The CoordSystem class describes the coordinate system to which
194
+ # a given SeqRegion belongs. It is an interface to the coord_system
195
+ # table of the Ensembl mysql database.
196
+ #
197
+ # Two virtual coordinate systems exist for
198
+ # every species:
199
+ # * toplevel: the coordinate system with rank 1
200
+ # * seqlevel: the coordinate system that contains the seq_regions
201
+ # with the sequence
202
+ #
203
+ # This class uses ActiveRecord to access data in the Ensembl database.
204
+ # See the general documentation of the Ensembl module for
205
+ # more information on what this means and what methods are available.
206
+ #
207
+ # = USAGE
208
+ # coord_system = Ensembl::Core::CoordSystem.find_by_name('chromosome')
209
+ # if coord_system == CoordSystem.toplevel
210
+ # puts coord_system.name + " is the toplevel coordinate system."
211
+ # end
212
+ class CoordSystem < DBConnection
213
+ set_primary_key 'coord_system_id'
214
+
215
+ has_many :seq_regions
216
+
217
+ # = DESCRIPTION
218
+ # The CoordSystem#toplevel? method checks if this coordinate system is the
219
+ # toplevel coordinate system or not.
220
+ # ---
221
+ # *Arguments*:: none
222
+ # *Returns*:: TRUE or FALSE
223
+ def toplevel?
224
+ if self == CoordSystem.find_by_rank(1)
225
+ return true
226
+ else
227
+ return false
228
+ end
229
+ end
230
+
231
+ # = DESCRIPTION
232
+ # The CoordSystem#seqlevel? method checks if this coordinate system is the
233
+ # seqlevel coordinate system or not.
234
+ # ---
235
+ # *Arguments*:: none
236
+ # *Returns*:: TRUE or FALSE
237
+ def seqlevel?
238
+ if self == CoordSystem.find_by_sql("SELECT * FROM coord_system WHERE attrib LIKE '%sequence_level%'")[0]
239
+ return true
240
+ else
241
+ return false
242
+ end
243
+ end
244
+
245
+ # = DESCRIPTION
246
+ # The CoordSystem#find_toplevel class method returns the toplevel coordinate
247
+ # system.
248
+ # ---
249
+ # *Arguments*:: none
250
+ # *Returns*:: CoordSystem object
251
+ def self.find_toplevel
252
+ return CoordSystem.find_by_rank(1)
253
+ end
254
+
255
+ # = DESCRIPTION
256
+ # The CoordSystem#find_seqlevel class method returns the seqlevel coordinate
257
+ # system.
258
+ # ---
259
+ # *Arguments*:: none
260
+ # *Returns*:: CoordSystem object
261
+ def self.find_seqlevel
262
+ return CoordSystem.find_by_sql("SELECT * FROM coord_system WHERE attrib LIKE '%sequence_level%'")[0]
263
+ end
264
+
265
+ # = DESCRIPTION
266
+ # The CoordSystem#find_default_by_name class method returns the
267
+ # coordinate system by that name with the lowest rank. Normally, a lower
268
+ # rank means a 'bigger' coordinate system. The 'chromosome' typically has
269
+ # rank 1. However, there might be more than one coordinate system with the
270
+ # name chromosome but with different version (e.g. in human, there is one
271
+ # for the NCBI36 and one for the NCBI35 version). The older version of these
272
+ # is typically given a high number and the one with the new version is the
273
+ # 'default' system.
274
+ # ---
275
+ # *Arguments*:: none
276
+ # *Returns*:: CoordSystem object
277
+ def self.find_default_by_name(name)
278
+ all_coord_systems_with_name = Ensembl::Core::CoordSystem.find_all_by_name(name)
279
+ if all_coord_systems_with_name.length == 1
280
+ return all_coord_systems_with_name[0]
281
+ else
282
+ return all_coord_systems_with_name.select{|cs| cs.attrib =~ /default_version/}[0]
283
+ end
284
+ end
285
+
286
+ # = DESCRIPTION
287
+ # The CoordSystem#name_with_version returns a string containing the name
288
+ # and version of the coordinate system. If no version is available, then
289
+ # just the name is returned
290
+ # ---
291
+ # *Arguments*:: none
292
+ # *Returns*:: String object
293
+ def name_with_version
294
+ if self.version.nil?
295
+ return name
296
+ else
297
+ return [name, version].join(':')
298
+ end
299
+ end
300
+
301
+ ## Calculate the shortest path between a source coordinate system and a
302
+ ## target coordinate system. This can be done by looking for the
303
+ ## 'assembly.mapping' records in the meta_coord table.
304
+ ## At the moment, only direct mappings are possible. Later on, this method
305
+ ## should be changed to make longer paths possible.
306
+ ## Is used to get features for a slice object.
307
+ #def calculate_path(target_coord_system)
308
+ # MetaCoord.find_all_by_meta_key('assembly.mapping').each do |mapping|
309
+ # coord_system_names = mapping.meta_value.split(/[#|\|]/)
310
+ # if coord_system_names.sort.join(';') == [self.name_with_version, target_coord_system.name_with_version].sort.join(';')
311
+ # answer = Array.new
312
+ # answer.push(CoordSystem.find_by_name(coord_system_names[0]))
313
+ # answer.push(CoordSystem.find_by_name(coord_system_names[1]))
314
+ # return answer
315
+ # end
316
+ # end
317
+ # return nil
318
+ #
319
+ #end
320
+ end
321
+
322
+ # = DESCRIPTION
323
+ # The SeqRegion class describes a part of a coordinate systems. It is an
324
+ # interface to the seq_region table of the Ensembl mysql database.
325
+ #
326
+ # This class uses ActiveRecord to access data in the Ensembl database.
327
+ # See the general documentation of the Ensembl module for
328
+ # more information on what this means and what methods are available.
329
+ #
330
+ # = USAGE
331
+ # chr4 = SeqRegion.find_by_name('4')
332
+ # puts chr4.coord_system.name #--> 'chromosome'
333
+ # chr4.genes.each do |gene|
334
+ # puts gene.biotype
335
+ # end
336
+ class SeqRegion < DBConnection
337
+ set_primary_key 'seq_region_id'
338
+
339
+ belongs_to :coord_system
340
+ has_many :simple_features
341
+ has_many :marker_features
342
+ has_many :genes
343
+ has_many :exons
344
+ has_many :repeat_features
345
+ has_many :seq_region_attribs
346
+ has_many :attrib_types, :through => :seq_region_attrib
347
+ has_many :transcripts
348
+ has_one :dna
349
+ has_many :dna_align_features
350
+ has_many :misc_features
351
+ has_many :density_features
352
+ has_many :karyotypes
353
+ has_many :oligo_features
354
+ has_many :prediction_exons
355
+ has_many :prediction_transcripts
356
+ has_many :protein_align_features
357
+ has_many :regulatory_features
358
+ has_many :assembly_exceptions
359
+
360
+ # See http://blog.hasmanythrough.com/2006/4/21/self-referential-through
361
+ has_many :asm_links_as_asm, :foreign_key => 'asm_seq_region_id', :class_name => 'AssemblyLink'
362
+ has_many :asm_links_as_cmp, :foreign_key => 'cmp_seq_region_id', :class_name => 'AssemblyLink'
363
+ has_many :asm_seq_regions, :through => :asm_links_as_cmp
364
+ has_many :cmp_seq_regions, :through => :asm_links_as_asm
365
+
366
+ alias attribs seq_region_attribs
367
+
368
+ # = DESCRIPTION
369
+ # The SeqRegion#slice method returns a slice object that covers the whole
370
+ # of the seq_region.
371
+ # ---
372
+ # *Arguments*:: none
373
+ # *Returns*:: Ensembl::Core::Slice object
374
+ def slice
375
+ return Ensembl::Core::Slice.new(self)
376
+ end
377
+
378
+ # = DESCRIPTION
379
+ # The SeqRegion#assembled_seq_regions returns the sequence regions on which
380
+ # the current region is assembled. For example, calling this method on a
381
+ # contig sequence region, it might return the chromosome that that contig
382
+ # is part of. Optionally, this method takes a coordinate system name so
383
+ # that only regions of that coordinate system are returned.
384
+ # ---
385
+ # *Arguments*:: coord_system_name (optional)
386
+ # *Returns*:: array of SeqRegion objects
387
+ def assembled_seq_regions(coord_system_name = nil)
388
+ if coord_system_name.nil?
389
+ return self.asm_seq_regions
390
+ else
391
+ answer = Array.new
392
+ coord_system = CoordSystem.find_by_name(coord_system_name)
393
+ self.asm_seq_regions.each do |asr|
394
+ if asr.coord_system_id == coord_system.id
395
+ answer.push(asr)
396
+ end
397
+ end
398
+ return answer
399
+ end
400
+ end
401
+
402
+ # = DESCRIPTION
403
+ # The SeqRegion#component_seq_regions returns the sequence regions
404
+ # contained within the current region (in other words: the bits used to
405
+ # assemble the current region). For example, calling this method on a
406
+ # chromosome sequence region, it might return the contigs that were assembled
407
+ # into this chromosome. Optionally, this method takes a coordinate system
408
+ # name so that only regions of that coordinate system are returned.
409
+ # ---
410
+ # *Arguments*:: coord_system_name (optional)
411
+ # *Returns*:: array of SeqRegion objects
412
+ def component_seq_regions(coord_system_name = nil)
413
+ if coord_system_name.nil?
414
+ return self.cmp_seq_regions
415
+ else
416
+ answer = Array.new
417
+ coord_system = CoordSystem.find_by_name(coord_system_name)
418
+ self.cmp_seq_regions.each do |csr|
419
+ if csr.coord_system_id == coord_system.id
420
+ answer.push(csr)
421
+ end
422
+ end
423
+ return answer
424
+ end
425
+ end
426
+
427
+ # = DESCRIPTION
428
+ # This method queries the assembly table to find those rows (i.e.
429
+ # AssemblyLink objects) for which this seq_region is the assembly.
430
+ #
431
+ # = USAGE
432
+ #
433
+ # my_seq_region = SeqRegion.find('4')
434
+ # first_link = my_seq_region.assembly_links_as_assembly[0]
435
+ # puts first_link.asm_start.to_s + "\t" + first_link.asm_end.to_s
436
+ #
437
+ # ---
438
+ # *Arguments*:
439
+ # * coord_system_name: name of coordinate system that the components
440
+ # should belong to (default = nil)
441
+ # *Returns*:: array of AssemblyLink objects
442
+ def assembly_links_as_assembly(coord_system_name = nil)
443
+ if coord_system_name.nil?
444
+ return self.asm_links_as_asm
445
+ else
446
+ coord_system = CoordSystem.find_by_name(coord_system_name)
447
+ # return self.asm_links_as_asm.select{|alaa| alaa.cmp_seq_region.coord_system_id == coord_system.id}
448
+ return AssemblyLink.find_by_sql("SELECT * FROM assembly a WHERE a.asm_seq_region_id = " + self.id.to_s + " AND a.cmp_seq_region_id IN (SELECT sr.seq_region_id FROM seq_region sr WHERE coord_system_id = " + coord_system.id.to_s + ")")
449
+ end
450
+ end
451
+
452
+ # = DESCRIPTION
453
+ # This method queries the assembly table to find those rows (i.e.
454
+ # AssemblyLink objects) for which this seq_region is the component.
455
+ #
456
+ # = USAGE
457
+ #
458
+ # my_seq_region = SeqRegion.find('Chr4.003.1')
459
+ # first_link = my_seq_region.assembly_links_as_component[0]
460
+ # puts first_link.asm_start.to_s + "\t" + first_link.asm_end.to_s
461
+ #
462
+ # ---
463
+ # *Arguments*:
464
+ # * coord_system_name: name of coordinate system that the assembly
465
+ # should belong to (default = nil)
466
+ # *Returns*:: array of AssemblyLink objects
467
+ def assembly_links_as_component(coord_system_name = nil)
468
+ if coord_system_name.nil?
469
+ return self.asm_links_as_cmp
470
+ else
471
+ coord_system = CoordSystem.find_by_name(coord_system_name)
472
+ return self.asm_links_as_cmp.select{|alac| alac.asm_seq_region.coord_system_id == coord_system.id}
473
+ end
474
+ end
475
+
476
+ # = DESCRIPTION
477
+ # The SeqRegion#sequence method returns the sequence of this seq_region. At
478
+ # the moment, it will only return the sequence if the region belongs to the
479
+ # seqlevel coordinate system.
480
+ # ---
481
+ # *Arguments*:: none
482
+ # *Returns*:: DNA sequence as String
483
+ def sequence
484
+ return self.dna.sequence
485
+ end
486
+ alias seq sequence
487
+
488
+ # = DESCRIPTION
489
+ # The SeqRegion#subsequence method returns a subsequence of this seq_region. At
490
+ # the moment, it will only return the sequence if the region belongs to the
491
+ # seqlevel coordinate system.
492
+ # ---
493
+ # *Arguments*:: start and stop position
494
+ # *Returns*:: DNA sequence as String
495
+ def subsequence(start, stop)
496
+ return self.seq.slice(start - 1, (stop - start) + 1)
497
+ end
498
+ alias subseq subsequence
499
+
500
+ end
501
+
502
+ # = DESCRIPTION
503
+ # The AssemblyLink class describes the relationships between different
504
+ # seq_regions. For example, a chromosome might consist of a number of
505
+ # scaffolds, each of which in turn consists of a number of contigs. The
506
+ # AssemblyLink class
507
+ # This class is an interface to the assembly table of the Ensembl mysql
508
+ # database.
509
+ #
510
+ # This class uses ActiveRecord to access data in the Ensembl database.
511
+ # See the general documentation of the Ensembl module for
512
+ # more information on what this means and what methods are available.
513
+ #
514
+ # = USAGE
515
+ # chr4 = SeqRegion.find_by_name('4')
516
+ # puts chr4.coord_system.name #--> 'chromosome'
517
+ # chr4.genes.each do |gene|
518
+ # puts gene.biotype
519
+ # end
520
+ class AssemblyLink < DBConnection
521
+ set_table_name 'assembly'
522
+ set_primary_key nil
523
+
524
+ # See http://blog.hasmanythrough.com/2006/4/21/self-referential-through
525
+ belongs_to :asm_seq_region, :foreign_key => 'asm_seq_region_id', :class_name => 'SeqRegion'
526
+ belongs_to :cmp_seq_region, :foreign_key => 'cmp_seq_region_id', :class_name => 'SeqRegion'
527
+ end
528
+
529
+ # = DESCRIPTION
530
+ # The AssemblyException class describes the exceptions in to AssemblyLink. Most
531
+ # notably, this concerns the allosomes. In human, for example, only the
532
+ # part of the Y chromosome that is different from X is covered in the
533
+ # assembly table. Therefore, the sequence of the tip and end of the Y
534
+ # chromosome are not stored in the database, but fetched from the X
535
+ # chromosome. The assembly_exception table contain the information on
536
+ # which bits are the same.
537
+ #
538
+ # This class uses ActiveRecord to access data in the Ensembl database.
539
+ # See the general documentation of the Ensembl module for
540
+ # more information on what this means and what methods are available.
541
+ #
542
+ # This class should normally not be used directly by the user.
543
+ class AssemblyException < DBConnection
544
+ include Sliceable
545
+
546
+ set_primary_key 'assembly_exception_id'
547
+
548
+ belongs_to :seq_region
549
+ end
550
+
551
+ # = DESCRIPTION
552
+ # The MetaCoord class describes what coordinate systems are used to annotate
553
+ # features. It will for example tell you that marker_features are annotated
554
+ # either on the chromosome, supercontig and clone level.
555
+ #
556
+ # This class should normally not be used by the end user, but is used internally.
557
+ #
558
+ # This class uses ActiveRecord to access data in the Ensembl database.
559
+ # See the general documentation of the Ensembl module for
560
+ # more information on what this means and what methods are available.
561
+ class MetaCoord < DBConnection
562
+ set_primary_key nil
563
+ end
564
+
565
+ # = DESCRIPTION
566
+ # The Meta class describes meta data of the database. These include information
567
+ # on what coordinate system is mapping on another one and which patches
568
+ # are applied.
569
+ #
570
+ # This class should normally not be used by the end user, but is used internally.
571
+ #
572
+ # This class uses ActiveRecord to access data in the Ensembl database.
573
+ # See the general documentation of the Ensembl module for
574
+ # more information on what this means and what methods are available.
575
+ class Meta < DBConnection
576
+ set_primary_key nil
577
+ end
578
+
579
+ # = DESCRIPTION
580
+ # The Analysis class describes an analysis.
581
+ #
582
+ # This class uses ActiveRecord to access data in the Ensembl database.
583
+ # See the general documentation of the Ensembl module for
584
+ # more information on what this means and what methods are available.
585
+ #
586
+ # = USAGE
587
+ # repeat_masker_analysis = Analysis.find_by_logic_name('RepeatMask')
588
+ # puts repeat_masker_analysis.to_yaml
589
+ class Analysis < DBConnection
590
+ set_primary_key 'analysis_id'
591
+
592
+ has_many :dna_align_features
593
+ has_many :protein_align_features
594
+ has_one :analysis_description
595
+ has_many :density_types
596
+ has_many :oligo_features
597
+ has_many :protein_features
598
+ has_many :regulatory_features
599
+ has_many :simple_features
600
+ has_many :prediction_transcripts
601
+ end
602
+
603
+ # = DESCRIPTION
604
+ # The AnalysisDescription class belongs to an analysis.
605
+ #
606
+ # This class uses ActiveRecord to access data in the Ensembl database.
607
+ # See the general documentation of the Ensembl module for
608
+ # more information on what this means and what methods are available.
609
+ #
610
+ # = USAGE
611
+ # descr = AnalysisDescription.find(3)
612
+ # puts descr.to_yaml
613
+ class AnalysisDescription < DBConnection
614
+ set_primary_key nil
615
+
616
+ belongs_to :analysis
617
+ end
618
+
619
+ # = DESCRIPTION
620
+ # The Dna class contains the actual DNA sequence for the sequence regions
621
+ # that belong to the seq_level coordinate system.
622
+ #
623
+ # This class uses ActiveRecord to access data in the Ensembl database.
624
+ # See the general documentation of the Ensembl module for
625
+ # more information on what this means and what methods are available.
626
+ #
627
+ # = USAGE
628
+ # seq_region = SeqRegion.find(1)
629
+ # puts seq_region.dna.sequence
630
+ class Dna < DBConnection
631
+ set_primary_key nil
632
+
633
+ belongs_to :seq_region
634
+ end
635
+
636
+ # = DESCRIPTION
637
+ # The Exon class describes an exon.
638
+ #
639
+ # This class uses ActiveRecord to access data in the Ensembl database.
640
+ # See the general documentation of the Ensembl module for
641
+ # more information on what this means and what methods are available.
642
+ #
643
+ # This class includes the mixin Sliceable, which means that it is mapped
644
+ # to a SeqRegion object and a Slice can be created for objects of this
645
+ # class. See Sliceable and Slice for more information.
646
+ #
647
+ # = USAGE
648
+ # seq_region = SeqRegion.find(1)
649
+ # puts seq_region.exons.length
650
+ class Exon < DBConnection
651
+ include Sliceable
652
+
653
+ set_primary_key 'exon_id'
654
+
655
+ belongs_to :seq_region
656
+ has_many :exon_transcripts
657
+ has_many :transcripts, :through => :exon_transcripts
658
+
659
+ has_many :translations, :foreign_key => 'start_exon_id'
660
+ has_many :translations, :foreign_key => 'end_exon_id'
661
+
662
+ has_one :exon_stable_id
663
+
664
+ has_many :exon_supporting_features
665
+ has_many :dna_align_features, :through => :exon_supporting_features, :conditions => ["feature_type = 'dna_align_feature'"]
666
+ has_many :protein_align_features, :through => :exon_supporting_features, :conditions => ["feature_type = 'protein_align_feature'"]
667
+
668
+ def stable_id
669
+ return self.exon_stable_id.stable_id
670
+ end
671
+
672
+ # = DESCRIPTION
673
+ # The Exon#seq method returns the sequence of the exon.
674
+ def seq
675
+ slice = Ensembl::Core::Slice.new(self.seq_region, seq_region_start, seq_region_end, seq_region_strand)
676
+ return slice.seq
677
+ end
678
+ end
679
+
680
+ # = DESCRIPTION
681
+ # The ExonStableId class provides an interface to the exon_stable_id
682
+ # table. This table contains Ensembl stable IDs for exons.
683
+ #
684
+ # This class uses ActiveRecord to access data in the Ensembl database.
685
+ # See the general documentation of the Ensembl module for
686
+ # more information on what this means and what methods are available.
687
+ #
688
+ # = USAGE
689
+ # my_exon = ExonStableId.find_by_stable_id('ENSE00001494622').exon
690
+ class ExonStableId < DBConnection
691
+ set_primary_key 'stable_id'
692
+
693
+ belongs_to :exon
694
+ end
695
+
696
+ # = DESCRIPTION
697
+ # The ExonTranscript class provides the link between exons and transcripts.
698
+ #
699
+ # This class uses ActiveRecord to access data in the Ensembl database.
700
+ # See the general documentation of the Ensembl module for
701
+ # more information on what this means and what methods are available.
702
+ #
703
+ # = USAGE
704
+ # link = ExonTranscript.find(1)
705
+ # puts link.exon.to_yaml
706
+ # puts link.transcript.to_yaml
707
+ class ExonTranscript < DBConnection
708
+ set_primary_key nil
709
+
710
+ belongs_to :exon
711
+ belongs_to :transcript
712
+ end
713
+
714
+ class ExonSupportingFeature < DBConnection
715
+ set_table_name 'supporting_feature'
716
+ set_primary_key nil
717
+
718
+ belongs_to :exon
719
+ belongs_to :dna_align_feature, :class_name => "DnaAlignFeature", :foreign_key => 'feature_id'
720
+ belongs_to :protein_align_feature, :class_name => "ProteinAlignFeature", :foreign_key => 'feature_id'
721
+ end
722
+
723
+ class TranscriptSupportingFeature < DBConnection
724
+ set_primary_key nil
725
+
726
+ belongs_to :transcript
727
+ belongs_to :dna_align_feature, :class_name => "DnaAlignFeature", :foreign_key => 'feature_id'
728
+ belongs_to :protein_align_feature, :class_name => "ProteinAlignFeature", :foreign_key => 'feature_id'
729
+ end
730
+
731
+ # = DESCRIPTION
732
+ # The SimpleFeature class describes simple features that have positions
733
+ # on a SeqRegion.
734
+ #
735
+ # This class uses ActiveRecord to access data in the Ensembl database.
736
+ # See the general documentation of the Ensembl module for
737
+ # more information on what this means and what methods are available.
738
+ #
739
+ # This class includes the mixin Sliceable, which means that it is mapped
740
+ # to a SeqRegion object and a Slice can be created for objects of this
741
+ # class. See Sliceable and Slice for more information.
742
+ #
743
+ # = USAGE
744
+ # simple_feature = SimpleFeature.find(123)
745
+ # puts simple_feature.analysis.logic_name
746
+ class SimpleFeature < DBConnection
747
+ include Sliceable
748
+
749
+ set_primary_key 'simple_feature_id'
750
+
751
+ belongs_to :seq_region
752
+ belongs_to :analysis
753
+ end
754
+
755
+ # = DESCRIPTION
756
+ # The DensityFeature class provides an interface to the density_feature
757
+ # table.
758
+ #
759
+ # This class uses ActiveRecord to access data in the Ensembl database.
760
+ # See the general documentation of the Ensembl module for
761
+ # more information on what this means and what methods are available.
762
+ #
763
+ # This class includes the mixin Sliceable, which means that it is mapped
764
+ # to a SeqRegion object and a Slice can be created for objects of this
765
+ # class. See Sliceable and Slice for more information.
766
+ #
767
+ # = USAGE
768
+ # density_feature = DensityFeature.find(2716384)
769
+ # puts density_feature.to_yaml
770
+ class DensityFeature < DBConnection
771
+ set_primary_key 'density_feature_id'
772
+
773
+ belongs_to :density_type
774
+ belongs_to :seq_region
775
+ end
776
+
777
+ # = DESCRIPTION
778
+ # The DensityType class provides an interface to the density_type
779
+ # table.
780
+ #
781
+ # This class uses ActiveRecord to access data in the Ensembl database.
782
+ # See the general documentation of the Ensembl module for
783
+ # more information on what this means and what methods are available.
784
+ #
785
+ # This class includes the mixin Sliceable, which means that it is mapped
786
+ # to a SeqRegion object and a Slice can be created for objects of this
787
+ # class. See Sliceable and Slice for more information.
788
+ #
789
+ class DensityType < DBConnection
790
+ set_primary_key 'density_type_id'
791
+
792
+ has_many :density_features
793
+ belongs_to :analysis
794
+ end
795
+
796
+ # = DESCRIPTION
797
+ # The Marker class provides an interface to the marker
798
+ # table. This table contains primer sequences and PCR product lengths.
799
+ #
800
+ # This class uses ActiveRecord to access data in the Ensembl database.
801
+ # See the general documentation of the Ensembl module for
802
+ # more information on what this means and what methods are available.
803
+ #
804
+ # = USAGE
805
+ # marker = Marker.find(52194)
806
+ # puts marker.left_primer
807
+ # puts marker.right_primer
808
+ # puts marker.min_primer_dist.to_s
809
+ class Marker < DBConnection
810
+ set_primary_key 'marker_id'
811
+
812
+ has_many :marker_features
813
+ has_many :marker_synonyms
814
+ has_many :marker_map_locations
815
+
816
+ def self.inheritance_column
817
+ nil
818
+ end
819
+
820
+ # = DESCRIPTION
821
+ # The Marker#name method returns a comma-separated list of synonyms of
822
+ # this marker
823
+ #
824
+ # = USAGE
825
+ # marker = Marker.find(1)
826
+ # puts marker.name --> 58017,D29149
827
+ def name
828
+ self.marker_synonyms.collect{|ms| ms.name}.join(',')
829
+ end
830
+
831
+ # = DESCRIPTION
832
+ # The Marker#find_by_name class method returns one marker with this name.
833
+ #
834
+ # ---
835
+ # *Arguments*:: name
836
+ # *Returns*:: Marker object or nil
837
+ def self.find_by_name(name)
838
+ all_names = self.find_all_by_name(name)
839
+ if all_names.length == 0
840
+ return nil
841
+ else
842
+ return all_names[0]
843
+ end
844
+ end
845
+
846
+ # = DESCRIPTION
847
+ # The Marker#find_all_by_name class method returns all markers with this
848
+ # name. If no marker is found, it returns an empty array.
849
+ # ---
850
+ # *Arguments*:: name
851
+ # *Returns*:: empty array or array of Marker objects
852
+ def self.find_all_by_name(name)
853
+ marker_synonyms = Ensembl::Core::MarkerSynonym.find_all_by_name(name)
854
+ answers = Array.new
855
+ marker_synonyms.each do |ms|
856
+ answers.push(Ensembl::Core::Marker.find_all_by_marker_id(ms.marker_id))
857
+ end
858
+ answers.flatten!
859
+ return answers
860
+ end
861
+
862
+ #def to_mappings
863
+ # output = Array.new
864
+ # self.marker_features.each do |mf|
865
+ # output.push(mf.slice.display_name)
866
+ # end
867
+ # return output.join("\n")
868
+ #
869
+ #end
870
+
871
+ end
872
+
873
+ # = DESCRIPTION
874
+ # The MarkerSynonym class provides an interface to the marker_synonym
875
+ # table. This table contains names for markers (that are themselves
876
+ # stored in the marker table (so Marker class)).
877
+ #
878
+ # This class uses ActiveRecord to access data in the Ensembl database.
879
+ # See the general documentation of the Ensembl module for
880
+ # more information on what this means and what methods are available.
881
+ #
882
+ # = USAGE
883
+ # marker = Marker.find(52194)
884
+ # puts marker.marker_synonym.source
885
+ # puts marker.marker_synonym.name
886
+ class MarkerSynonym < DBConnection
887
+ set_primary_key 'marker_synonym_id'
888
+
889
+ belongs_to :marker
890
+ end
891
+
892
+ # = DESCRIPTION
893
+ # The MarkerFeature class provides an interface to the marker_feature
894
+ # table. This table contains mappings of markers to a SeqRegion.
895
+ #
896
+ # This class uses ActiveRecord to access data in the Ensembl database.
897
+ # See the general documentation of the Ensembl module for
898
+ # more information on what this means and what methods are available.
899
+ #
900
+ # This class includes the mixin Sliceable, which means that it is mapped
901
+ # to a SeqRegion object and a Slice can be created for objects of this
902
+ # class. See Sliceable and Slice for more information.
903
+ #
904
+ # = USAGE
905
+ # marker = Marker.find(52194)
906
+ # puts marker.marker_feature.seq_region_start.to_s
907
+ # puts marker.marker_feature.seq_region_end.to_s
908
+ class MarkerFeature < DBConnection
909
+ include Sliceable
910
+
911
+ set_primary_key 'marker_feature_id'
912
+
913
+ belongs_to :marker
914
+ belongs_to :seq_region
915
+ end
916
+
917
+ # = DESCRIPTION
918
+ # The MiscFeature class provides an interface to the misc_feature
919
+ # table. The actual type of feature is stored in the MiscSet class.
920
+ #
921
+ # This class uses ActiveRecord to access data in the Ensembl database.
922
+ # See the general documentation of the Ensembl module for
923
+ # more information on what this means and what methods are available.
924
+ #
925
+ # This class includes the mixin Sliceable, which means that it is mapped
926
+ # to a SeqRegion object and a Slice can be created for objects of this
927
+ # class. See Sliceable and Slice for more information.
928
+ #
929
+ # = USAGE
930
+ # #TODO
931
+ class MiscFeature < DBConnection
932
+ include Sliceable
933
+
934
+ set_primary_key 'misc_feature_id'
935
+
936
+ belongs_to :seq_region
937
+ has_one :misc_feature_misc_set
938
+ has_many :misc_sets, :through => :misc_feature_misc_set
939
+
940
+ has_many :misc_attribs
941
+
942
+ alias attribs misc_attribs
943
+
944
+ def self.find_by_attrib_type_value(code, value)
945
+ return self.find_all_by_attrib_type_value(code, value)[0]
946
+ end
947
+
948
+ def self.find_all_by_attrib_type_value(code, value)
949
+ code_id = AttribType.find_by_code(code)
950
+ misc_attribs = MiscAttrib.find_all_by_attrib_type_id_and_value(code_id, value)
951
+ answers = Array.new
952
+ misc_attribs.each do |ma|
953
+ answers.push(MiscFeature.find_all_by_misc_feature_id(ma.misc_feature_id))
954
+ end
955
+ answers.flatten!
956
+ return answers
957
+ end
958
+ end
959
+
960
+
961
+ # = DESCRIPTION
962
+ # The MiscAttrib class provides an interface to the misc_attrib
963
+ # table. It is the link between MiscFeature and AttribType.
964
+ #
965
+ # This class uses ActiveRecord to access data in the Ensembl database.
966
+ # See the general documentation of the Ensembl module for
967
+ # more information on what this means and what methods are available.
968
+ #
969
+ # = USAGE
970
+ # marker = Marker.find(52194)
971
+ # puts marker.marker_feature.seq_region_start.to_s
972
+ # puts marker.marker_feature.seq_region_end.to_s
973
+ class MiscAttrib < DBConnection
974
+ set_primary_key nil
975
+
976
+ belongs_to :misc_feature
977
+ belongs_to :attrib_type
978
+
979
+ def to_s
980
+ return self.attrib_type.code + ":" + self.value.to_s
981
+ end
982
+ end
983
+
984
+ # = DESCRIPTION
985
+ # The MiscSet class provides an interface to the misc_set
986
+ # table. This table contains the sets to which MiscFeature objects
987
+ # belong.
988
+ #
989
+ # This class uses ActiveRecord to access data in the Ensembl database.
990
+ # See the general documentation of the Ensembl module for
991
+ # more information on what this means and what methods are available.
992
+ #
993
+ # = USAGE
994
+ # feature_set = MiscFeature.find(1)
995
+ # puts feature_set.features.length.to_s
996
+ class MiscSet < DBConnection
997
+ set_primary_key 'misc_set_id'
998
+
999
+ has_many :misc_feature_misc_sets
1000
+ has_many :misc_features, :through => :misc_feature_misc_set
1001
+ end
1002
+
1003
+ # = DESCRIPTION
1004
+ # The MiscFeatureMiscSet class provides an interface to the
1005
+ # misc_feature_misc_set table. This table links MiscFeature objects to
1006
+ # their MiscSet.
1007
+ #
1008
+ # This class uses ActiveRecord to access data in the Ensembl database.
1009
+ # See the general documentation of the Ensembl module for
1010
+ # more information on what this means and what methods are available.
1011
+ #
1012
+ # = USAGE
1013
+ # # TODO
1014
+ class MiscFeatureMiscSet < DBConnection
1015
+ set_primary_key nil
1016
+
1017
+ belongs_to :misc_feature
1018
+ belongs_to :misc_set
1019
+ end
1020
+
1021
+ # = DESCRIPTION
1022
+ # The Gene class provides an interface to the gene
1023
+ # table. This table contains mappings of genes to a SeqRegion.
1024
+ #
1025
+ # This class uses ActiveRecord to access data in the Ensembl database.
1026
+ # See the general documentation of the Ensembl module for
1027
+ # more information on what this means and what methods are available.
1028
+ #
1029
+ # This class includes the mixin Sliceable, which means that it is mapped
1030
+ # to a SeqRegion object and a Slice can be created for objects of this
1031
+ # class. See Sliceable and Slice for more information.
1032
+ #
1033
+ # = USAGE
1034
+ # puts Gene.find_by_biotype('protein_coding').length
1035
+ class Gene < DBConnection
1036
+ include Sliceable
1037
+
1038
+ set_primary_key 'gene_id'
1039
+
1040
+ belongs_to :seq_region
1041
+ has_one :gene_stable_id
1042
+
1043
+ has_many :gene_attribs
1044
+ has_many :attrib_types, :through => :gene_attrib
1045
+
1046
+ has_many :transcripts
1047
+
1048
+ has_many :object_xrefs, :foreign_key => 'ensembl_id', :conditions => "ensembl_object_type = 'Gene'"
1049
+ has_many :xrefs, :through => :object_xrefs
1050
+
1051
+ alias attribs gene_attribs
1052
+
1053
+ # = DESCRIPTION
1054
+ # The Gene#stable_id method returns the stable_id of the gene (i.e. the
1055
+ # ENSG id).
1056
+ def stable_id
1057
+ return self.gene_stable_id.stable_id
1058
+
1059
+ end
1060
+
1061
+ # = DESCRIPTION
1062
+ # The Gene#display_label method returns the default name of the gene.
1063
+ def display_label
1064
+ return Xref.find(self.display_xref_id).display_label
1065
+ end
1066
+ alias :display_name :display_label
1067
+ alias :label :display_label
1068
+ alias :name :display_label
1069
+
1070
+ # = DESCRIPTION
1071
+ # The Gene#find_all_by_name class method searches the Xrefs for that name
1072
+ # and returns an array of the corresponding Gene objects. If the name is
1073
+ # not found, it returns an empty array.
1074
+ def self.find_all_by_name(name)
1075
+ answer = Array.new
1076
+ xrefs = Ensembl::Core::Xref.find_all_by_display_label(name)
1077
+ xrefs.each do |xref|
1078
+ answer.push(Ensembl::Core::Gene.find_by_display_xref_id(xref.xref_id))
1079
+ end
1080
+
1081
+ return answer
1082
+ end
1083
+
1084
+ # = DESCRIPTION
1085
+ # The Gene#find_by_name class method searches the Xrefs for that name
1086
+ # and returns one Gene objects (even if there should be more). If the name is
1087
+ # not found, it returns nil.
1088
+ def self.find_by_name(name)
1089
+ all_names = self.find_all_by_name(name)
1090
+ if all_names.length == 0
1091
+ return nil
1092
+ else
1093
+ return all_names[0]
1094
+ end
1095
+ end
1096
+
1097
+ # = DESCRIPTION
1098
+ # The Gene#find_by_stable_id class method fetches a Gene object based on
1099
+ # its stable ID (i.e. the "ENSG" accession number). If the name is
1100
+ # not found, it returns nil.
1101
+ def self.find_by_stable_id(stable_id)
1102
+ gene_stable_id = GeneStableId.find_by_stable_id(stable_id)
1103
+ if gene_stable_id.nil?
1104
+ return nil
1105
+ else
1106
+ return gene_stable_id.gene
1107
+ end
1108
+ end
1109
+
1110
+ # = DESCRIPTION
1111
+ # The Gene#all_xrefs method is a convenience method in that it combines
1112
+ # three methods into one. It collects all xrefs for the gene itself, plus
1113
+ # all xrefs for all transcripts for the gene, and all xrefs for all
1114
+ # translations for those transcripts.
1115
+ def all_xrefs
1116
+ answer = Array.new
1117
+ answer.push(self.xrefs)
1118
+ self.transcripts.each do |transcript|
1119
+ answer.push(transcript.xrefs)
1120
+ if ! transcript.translation.nil?
1121
+ answer.push(transcript.translation.xrefs)
1122
+ end
1123
+ end
1124
+ answer.flatten!
1125
+ return answer
1126
+ end
1127
+
1128
+ # = DESCRIPTION
1129
+ # The Gene#go_terms method returns all GO terms associated with a gene.
1130
+ def go_terms
1131
+ go_db_id = ExternalDb.find_by_db_name('GO').id
1132
+ return self.all_xrefs.select{|x| x.external_db_id == go_db_id}.collect{|x| x.dbprimary_acc}.uniq
1133
+ end
1134
+
1135
+ # = DESCRIPTION
1136
+ # The Gene#hgnc returns the HGNC symbol for the gene.
1137
+ def hgnc
1138
+ hgnc_db_id = ExternalDb.find_by_db_name('HGNC_curated_gene').id
1139
+ xref = self.all_xrefs.select{|x| x.external_db_id == hgnc_db_id}[0]
1140
+ return nil if xref.nil?
1141
+ return xref.display_label
1142
+ end
1143
+
1144
+ end
1145
+
1146
+ # = DESCRIPTION
1147
+ # The GeneStableId class provides an interface to the gene_stable_id
1148
+ # table. This table contains Ensembl stable IDs for genes.
1149
+ #
1150
+ # This class uses ActiveRecord to access data in the Ensembl database.
1151
+ # See the general documentation of the Ensembl module for
1152
+ # more information on what this means and what methods are available.
1153
+ #
1154
+ # = USAGE
1155
+ # my_gene = GeneStableId.find_by_stable_id('ENSBTAG00000011670').gene
1156
+ class GeneStableId < DBConnection
1157
+ set_primary_key 'stable_id'
1158
+
1159
+ belongs_to :gene
1160
+ end
1161
+
1162
+ # = DESCRIPTION
1163
+ # The MarkerMapLocation class provides an interface to the
1164
+ # marker_map_location table. This table contains mappings of
1165
+ # MarkerSynonym objects to a chromosome, and basically just stores
1166
+ # the genetic maps.
1167
+ #
1168
+ # This class uses ActiveRecord to access data in the Ensembl database.
1169
+ # See the general documentation of the Ensembl module for
1170
+ # more information on what this means and what methods are available.
1171
+ #
1172
+ # = USAGE
1173
+ # marker_synonym = MarkerSynonym.find_by_name('CYP19A1_(5)')
1174
+ # marker_synonym.marker_map_locations.each do |mapping|
1175
+ # puts mapping.chromosome_name + "\t" + mapping.position.to_s
1176
+ # end
1177
+ class MarkerMapLocation < DBConnection
1178
+ set_primary_key nil
1179
+
1180
+ belongs_to :map
1181
+ belongs_to :marker
1182
+
1183
+ end
1184
+
1185
+ # = DESCRIPTION
1186
+ # The Map class provides an interface to the map
1187
+ # table. This table contains genetic maps.
1188
+ #
1189
+ # This class uses ActiveRecord to access data in the Ensembl database.
1190
+ # See the general documentation of the Ensembl module for
1191
+ # more information on what this means and what methods are available.
1192
+ #
1193
+ # = USAGE
1194
+ # map = Map.find_by_name('MARC')
1195
+ # puts map.markers.length.to_s
1196
+ class Map < DBConnection
1197
+ set_primary_key 'map_id'
1198
+
1199
+ has_many :marker_map_locations
1200
+ has_many :markers, :through => :marker_map_locations
1201
+
1202
+ def name
1203
+ return self.map_name
1204
+ end
1205
+ end
1206
+
1207
+ # = DESCRIPTION
1208
+ # The RepeatConsensus class provides an interface to the repeat_consensus
1209
+ # table. This table contains consensus sequences for repeats.
1210
+ #
1211
+ # This class uses ActiveRecord to access data in the Ensembl database.
1212
+ # See the general documentation of the Ensembl module for
1213
+ # more information on what this means and what methods are available.
1214
+ #
1215
+ # = USAGE
1216
+ # repeat = RepeatFeature.find(29)
1217
+ # puts repeat.repeat_consensus.repeat_name + "\t" + repeat.repeat_consensus.repeat_consensus
1218
+ class RepeatConsensus < DBConnection
1219
+ set_primary_key 'repeat_consensus_id'
1220
+
1221
+ has_many :repeat_features
1222
+ end
1223
+
1224
+ # = DESCRIPTION
1225
+ # The RepeatFeature class provides an interface to the repeat_feature
1226
+ # table. This table contains mappings of repeats to a SeqRegion.
1227
+ #
1228
+ # This class uses ActiveRecord to access data in the Ensembl database.
1229
+ # See the general documentation of the Ensembl module for
1230
+ # more information on what this means and what methods are available.
1231
+ #
1232
+ # This class includes the mixin Sliceable, which means that it is mapped
1233
+ # to a SeqRegion object and a Slice can be created for objects of this
1234
+ # class. See Sliceable and Slice for more information.
1235
+ #
1236
+ # = USAGE
1237
+ # repeat_feature = RepeatFeature.find(29)
1238
+ # puts repeat_feature.seq_region_start.to_s
1239
+ class RepeatFeature < DBConnection
1240
+ include Sliceable
1241
+
1242
+ set_primary_key 'repeat_feature_id'
1243
+
1244
+ belongs_to :repeat_consensus
1245
+ belongs_to :seq_region
1246
+ end
1247
+
1248
+ # = DESCRIPTION
1249
+ # The SeqRegionAttrib class provides an interface to the seq_region_attrib
1250
+ # table. This table contains attribute values for SeqRegion objects
1251
+ #
1252
+ # This class uses ActiveRecord to access data in the Ensembl database.
1253
+ # See the general documentation of the Ensembl module for
1254
+ # more information on what this means and what methods are available.
1255
+ #
1256
+ # = USAGE
1257
+ # chr4 = SeqRegion.find_by_name('4')
1258
+ # chr4.seq_region_attribs.each do |attrib|
1259
+ # puts attrib.attrib_type.name + "\t" + attrib.value.to_s
1260
+ # end
1261
+ class SeqRegionAttrib < DBConnection
1262
+ set_primary_key nil
1263
+
1264
+ belongs_to :seq_region
1265
+ belongs_to :attrib_type
1266
+ end
1267
+
1268
+ # = DESCRIPTION
1269
+ # The GeneAttrib class provides an interface to the gene_attrib
1270
+ # table. This table contains attribute values for Gene objects
1271
+ #
1272
+ # This class uses ActiveRecord to access data in the Ensembl database.
1273
+ # See the general documentation of the Ensembl module for
1274
+ # more information on what this means and what methods are available.
1275
+ #
1276
+ # = USAGE
1277
+ # #TODO
1278
+ class GeneAttrib < DBConnection
1279
+ set_primary_key nil
1280
+
1281
+ belongs_to :gene
1282
+ belongs_to :attrib_type
1283
+ end
1284
+
1285
+ # = DESCRIPTION
1286
+ # The AttribType class provides an interface to the attrib_type
1287
+ # table. This table contains the types that attributes can belong to for
1288
+ # SeqRegion, Gene and Transcript.
1289
+ #
1290
+ # This class uses ActiveRecord to access data in the Ensembl database.
1291
+ # See the general documentation of the Ensembl module for
1292
+ # more information on what this means and what methods are available.
1293
+ #
1294
+ # = USAGE
1295
+ # #TODO
1296
+ class AttribType < DBConnection
1297
+ set_primary_key 'attrib_type_id'
1298
+
1299
+ has_many :seq_region_attribs
1300
+ has_many :seq_regions, :through => :seq_region_attrib
1301
+
1302
+ has_many :gene_attribs
1303
+ has_many :genes, :through => :gene_attrib
1304
+
1305
+ has_many :transcript_attribs
1306
+ has_many :transcripts, :through => :transcript_attrib
1307
+ end
1308
+
1309
+ # = DESCRIPTION
1310
+ # The Transcript class provides an interface to the transcript_stable_id
1311
+ # table. This table contains the Ensembl stable IDs for Transcript
1312
+ # objects.
1313
+ #
1314
+ # This class uses ActiveRecord to access data in the Ensembl database.
1315
+ # See the general documentation of the Ensembl module for
1316
+ # more information on what this means and what methods are available.
1317
+ #
1318
+ # = USAGE
1319
+ # transcript_stable_id = TranscriptStableId.find_by_stable_id('ENSBTAT00000015494')
1320
+ # puts transcript_stable_id.transcript.to_yaml
1321
+ class TranscriptStableId < DBConnection
1322
+ set_primary_key 'stable_id'
1323
+
1324
+ belongs_to :transcript
1325
+ end
1326
+
1327
+ # = DESCRIPTION
1328
+ # The TranscriptAttrib class provides an interface to the transcript_attrib
1329
+ # table. This table contains the attributes for Transcript objects.
1330
+ #
1331
+ # This class uses ActiveRecord to access data in the Ensembl database.
1332
+ # See the general documentation of the Ensembl module for
1333
+ # more information on what this means and what methods are available.
1334
+ #
1335
+ # = USAGE
1336
+ # transcript = Transcript.find(32495)
1337
+ # transcript.transcript_attribs.each do |attr|
1338
+ # puts attr.attrib_type.name + "\t" + attr.value
1339
+ # end
1340
+ class TranscriptAttrib < DBConnection
1341
+ set_primary_key nil
1342
+
1343
+ belongs_to :transcript
1344
+ belongs_to :attrib_type
1345
+ end
1346
+
1347
+ # = DESCRIPTION
1348
+ # The DnaAlignFeature class provides an interface to the
1349
+ # dna_align_feature table. This table contains sequence similarity
1350
+ # mappings against a SeqRegion.
1351
+ #
1352
+ # This class uses ActiveRecord to access data in the Ensembl database.
1353
+ # See the general documentation of the Ensembl module for
1354
+ # more information on what this means and what methods are available.
1355
+ #
1356
+ # This class includes the mixin Sliceable, which means that it is mapped
1357
+ # to a SeqRegion object and a Slice can be created for objects of this
1358
+ # class. See Sliceable and Slice for more information.
1359
+ #
1360
+ # = USAGE
1361
+ # unigene_scan = Analysis.find_by_logic_name('Unigene')
1362
+ # unigene_scan.dna_align_features.each do |hit|
1363
+ # puts hit.seq_region.name + "\t" + hit.hit_name + "\t" + hit.cigar_line
1364
+ # end
1365
+ class DnaAlignFeature < DBConnection
1366
+ include Sliceable
1367
+
1368
+ set_primary_key 'dna_align_feature_id'
1369
+
1370
+ belongs_to :seq_region
1371
+ belongs_to :analysis
1372
+
1373
+ has_many :exon_supporting_features
1374
+ has_many :protein_supporting_features
1375
+ end
1376
+
1377
+ # = DESCRIPTION
1378
+ # The Translation class provides an interface to the
1379
+ # translation table. This table contains the translation start and
1380
+ # stop positions and exons for a given Transcript
1381
+ #
1382
+ # This class uses ActiveRecord to access data in the Ensembl database.
1383
+ # See the general documentation of the Ensembl module for
1384
+ # more information on what this means and what methods are available.
1385
+ #
1386
+ # = USAGE
1387
+ # #TODO
1388
+ class Translation < DBConnection
1389
+ set_primary_key 'translation_id'
1390
+
1391
+ belongs_to :transcript
1392
+ has_many :translation_stable_ids
1393
+
1394
+ has_many :translation_attribs
1395
+ has_many :protein_features
1396
+
1397
+ has_one :translation_stable_id
1398
+
1399
+ has_many :object_xrefs, :foreign_key => 'ensembl_id', :conditions => "ensembl_object_type = 'Translation'"
1400
+ has_many :xrefs, :through => :object_xrefs
1401
+
1402
+ belongs_to :start_exon, :class_name => 'Exon', :foreign_key => 'start_exon_id'
1403
+ belongs_to :end_exon, :class_name => 'Exon', :foreign_key => 'end_exon_id'
1404
+
1405
+ alias attribs translation_attribs
1406
+
1407
+ # The Translation#stable_id method returns the stable ID of the translation.
1408
+ # ---
1409
+ # *Arguments*:: none
1410
+ # *Returns*:: String
1411
+ def stable_id
1412
+ return self.translation_stable_id.stable_id
1413
+ end
1414
+
1415
+ # = DESCRIPTION
1416
+ # The Translation#display_label method returns the default name of the translation.
1417
+ def display_label
1418
+ return Xref.find(self.display_xref_id).display_label
1419
+ end
1420
+ alias :display_name :display_label
1421
+ alias :label :display_label
1422
+ alias :name :display_label
1423
+
1424
+ # = DESCRIPTION
1425
+ # The Translation#find_by_stable_id class method fetches a Translation
1426
+ # object based on its stable ID (i.e. the "ENSP" accession number). If the
1427
+ # name is not found, it returns nil.
1428
+ def self.find_by_stable_id(stable_id)
1429
+ translation_stable_id = TranslationStableId.find_by_stable_id(stable_id)
1430
+ if translation_stable_id.nil?
1431
+ return nil
1432
+ else
1433
+ return translation_stable_id.translation
1434
+ end
1435
+ end
1436
+ end
1437
+
1438
+ # = DESCRIPTION
1439
+ # The TranslationStableId class provides an interface to the
1440
+ # translation_stable_id table. This table contains the Ensembl stable IDs
1441
+ # for a given Translation.
1442
+ #
1443
+ # This class uses ActiveRecord to access data in the Ensembl database.
1444
+ # See the general documentation of the Ensembl module for
1445
+ # more information on what this means and what methods are available.
1446
+ #
1447
+ # = USAGE
1448
+ # stable_id = TranslationStableId.find_by_name('ENSBTAP00000015494')
1449
+ # puts stable_id.to_yaml
1450
+ class TranslationStableId < DBConnection
1451
+ set_primary_key 'stable_id'
1452
+
1453
+ belongs_to :translation
1454
+ end
1455
+
1456
+ # = DESCRIPTION
1457
+ # The TranslationAttrib class provides an interface to the
1458
+ # translation_attrib table. This table contains attribute values for the
1459
+ # Translation class.
1460
+ #
1461
+ # This class uses ActiveRecord to access data in the Ensembl database.
1462
+ # See the general documentation of the Ensembl module for
1463
+ # more information on what this means and what methods are available.
1464
+ #
1465
+ # = USAGE
1466
+ # translation = Translation.find(9979)
1467
+ # translation.translation_attribs.each do |attr|
1468
+ # puts attr.attr_type.name + "\t" + attr.value
1469
+ # end
1470
+ class TranslationAttrib < DBConnection
1471
+ set_primary_key nil
1472
+
1473
+ belongs_to :translation
1474
+ belongs_to :attrib_type
1475
+ end
1476
+
1477
+ # = DESCRIPTION
1478
+ # The Xref class provides an interface to the
1479
+ # xref table. This table contains external references for objects in the
1480
+ # database.
1481
+ #
1482
+ # This class uses ActiveRecord to access data in the Ensembl database.
1483
+ # See the general documentation of the Ensembl module for
1484
+ # more information on what this means and what methods are available.
1485
+ #
1486
+ # = USAGE
1487
+ # gene = Gene.find(1)
1488
+ # gene.xrefs.each do |xref|
1489
+ # puts xref.display_label + "\t" + xref.description
1490
+ # end
1491
+ class Xref < DBConnection
1492
+ set_primary_key 'xref_id'
1493
+
1494
+ belongs_to :external_db
1495
+ has_many :external_synonyms
1496
+
1497
+ has_many :genes
1498
+
1499
+ def to_s
1500
+ return self.external_db.db_name.to_s + ":" + self.display_label
1501
+ end
1502
+ end
1503
+
1504
+ # = DESCRIPTION
1505
+ # The ObjectXref class provides the link between gene, transcript and
1506
+ # translation objects on the one hand and an xref on the other.
1507
+ #
1508
+ # This class uses ActiveRecord to access data in the Ensembl database.
1509
+ # See the general documentation of the Ensembl module for
1510
+ # more information on what this means and what methods are available.
1511
+ #
1512
+ # = USAGE
1513
+ # gene = Gene.find(1)
1514
+ # gene.object_xrefs.each do |ox|
1515
+ # puts ox.to_yaml
1516
+ # end
1517
+ class ObjectXref < DBConnection
1518
+ set_primary_key 'object_xref_id'
1519
+
1520
+ belongs_to :gene, :class_name => "Gene", :foreign_key => 'ensembl_id', :conditions => ["ensembl_object_type = 'Gene'"]
1521
+ belongs_to :transcript, :class_name => "Transcript", :foreign_key => 'ensembl_id', :conditions => ["ensembl_object_type = 'Transcript'"]
1522
+ belongs_to :translation, :class_name => "Translation", :foreign_key => 'ensembl_id', :conditions => ["ensembl_object_type = 'Translation'"]
1523
+ belongs_to :xref
1524
+ has_one :go_xref
1525
+ end
1526
+
1527
+ # = DESCRIPTION
1528
+ # The GoXref class provides an interface to the
1529
+ # go_xref table. This table contains the evidence codes for those object_refs
1530
+ # that are GO terms.
1531
+ #
1532
+ # This class uses ActiveRecord to access data in the Ensembl database.
1533
+ # See the general documentation of the Ensembl module for
1534
+ # more information on what this means and what methods are available.
1535
+ class GoXref < DBConnection
1536
+ set_primary_key nil
1537
+
1538
+ belongs_to :xref
1539
+ end
1540
+
1541
+ # = DESCRIPTION
1542
+ # The ExternalDb class provides an interface to the
1543
+ # external_db table. This table contains references to databases to which
1544
+ # xrefs can point to
1545
+ #
1546
+ # This class uses ActiveRecord to access data in the Ensembl database.
1547
+ # See the general documentation of the Ensembl module for
1548
+ # more information on what this means and what methods are available.
1549
+ #
1550
+ # = USAGE
1551
+ # embl_db = ExternalDb.find_by_db_name('EMBL')
1552
+ # puts embl_db.xrefs.length.to_s
1553
+ class ExternalDb < DBConnection
1554
+ set_primary_key 'external_db_id'
1555
+
1556
+ has_many :xrefs
1557
+
1558
+ def self.inheritance_column
1559
+ nil
1560
+ end
1561
+
1562
+ # = DESCRIPTION
1563
+ # The ExternalDb#find_all_by_display_label method returns all external
1564
+ # databases that have this label. There should normally be no more than
1565
+ # one. If no databases are found with this name, this method returns an
1566
+ # empty array.
1567
+ def self.find_all_by_display_label(label)
1568
+ answer = Array.new
1569
+ xrefs = Xref.find_all_by_display_label(label)
1570
+ xrefs.each do |xref|
1571
+ answer.push(self.class.find_by_xref_id(xref.xref_id))
1572
+ end
1573
+
1574
+ return answer
1575
+ end
1576
+
1577
+ # = DESCRIPTION
1578
+ # The ExternalDb#find_by_display_label method returns a
1579
+ # database that has this label. If no databases are found with this name,
1580
+ # this method returns nil.
1581
+ # empty array.
1582
+ def self.find_by_display_label(label)
1583
+ all_dbs = self.find_all_by_display_label(label)
1584
+ if all_dbs.length == 0
1585
+ return nil
1586
+ else
1587
+ return all_dbs[0]
1588
+ end
1589
+ end
1590
+
1591
+
1592
+ end
1593
+
1594
+ # = DESCRIPTION
1595
+ # The ExternalSynonym class provides an interface to the
1596
+ # external_synonym table. This table contains synonyms for Xref objects.
1597
+ #
1598
+ # This class uses ActiveRecord to access data in the Ensembl database.
1599
+ # See the general documentation of the Ensembl module for
1600
+ # more information on what this means and what methods are available.
1601
+ #
1602
+ # This class includes the mixin Sliceable, which means that it is mapped
1603
+ # to a SeqRegion object and a Slice can be created for objects of this
1604
+ # class. See Sliceable and Slice for more information.
1605
+ #
1606
+ # = USAGE
1607
+ # xref = Xref.find(185185)
1608
+ # puts xref.external_synonyms[0].synonyms
1609
+ class ExternalSynonym < DBConnection
1610
+ set_primary_key nil
1611
+
1612
+ belongs_to :xref
1613
+ end
1614
+
1615
+ # = DESCRIPTION
1616
+ # The Karyotype class provides an interface to the
1617
+ # karyotype table. This table contains <>.
1618
+ #
1619
+ # This class uses ActiveRecord to access data in the Ensembl database.
1620
+ # See the general documentation of the Ensembl module for
1621
+ # more information on what this means and what methods are available.
1622
+ #
1623
+ # This class includes the mixin Sliceable, which means that it is mapped
1624
+ # to a SeqRegion object and a Slice can be created for objects of this
1625
+ # class. See Sliceable and Slice for more information.
1626
+ #
1627
+ # = USAGE
1628
+ # band = Karyotype.find_by_band('p36.32')
1629
+ # puts band.to_yaml
1630
+ class Karyotype < DBConnection
1631
+ include Sliceable
1632
+
1633
+ set_primary_key 'karyotype_id'
1634
+
1635
+ belongs_to :seq_region
1636
+ end
1637
+
1638
+ # = DESCRIPTION
1639
+ # The OligoFeature class provides an interface to the
1640
+ # oligo_feature table. This table contains mappings of Oligo objects to
1641
+ # a SeqRegion.
1642
+ #
1643
+ # This class uses ActiveRecord to access data in the Ensembl database.
1644
+ # See the general documentation of the Ensembl module for
1645
+ # more information on what this means and what methods are available.
1646
+ #
1647
+ # This class includes the mixin Sliceable, which means that it is mapped
1648
+ # to a SeqRegion object and a Slice can be created for objects of this
1649
+ # class. See Sliceable and Slice for more information.
1650
+ #
1651
+ # = USAGE
1652
+ # seq_region = SeqRegion.find_by_name('4')
1653
+ # puts seq_region.oligo_features.length
1654
+ class OligoFeature < DBConnection
1655
+ include Sliceable
1656
+
1657
+ set_primary_key 'oligo_feature_id'
1658
+
1659
+ belongs_to :seq_region
1660
+ belongs_to :oligo_probe
1661
+ belongs_to :analysis
1662
+ end
1663
+
1664
+ # = DESCRIPTION
1665
+ # The OligoProbe class provides an interface to the
1666
+ # oligo_probe table.
1667
+ #
1668
+ # This class uses ActiveRecord to access data in the Ensembl database.
1669
+ # See the general documentation of the Ensembl module for
1670
+ # more information on what this means and what methods are available.
1671
+ #
1672
+ # = USAGE
1673
+ # probe = OligoProbe.find_by_name('373:434;')
1674
+ # puts probe.probeset + "\t" + probe.oligo_array.name
1675
+ class OligoProbe < DBConnection
1676
+ set_primary_key 'oligo_probe_id'
1677
+
1678
+ has_many :oligo_features
1679
+ belongs_to :oligo_array
1680
+ end
1681
+
1682
+ # = DESCRIPTION
1683
+ # The OligoArray class provides an interface to the
1684
+ # oligo_array table. This table contains data describing a microarray
1685
+ # slide.
1686
+ #
1687
+ # This class uses ActiveRecord to access data in the Ensembl database.
1688
+ # See the general documentation of the Ensembl module for
1689
+ # more information on what this means and what methods are available.
1690
+ #
1691
+ # = USAGE
1692
+ # array = OligoArray.find_by_name_and_type('Bovine','AFFY')
1693
+ # puts array.oligo_probes.length
1694
+ class OligoArray < DBConnection
1695
+ set_primary_key 'oligo_array_id'
1696
+
1697
+ has_many :oligo_probes
1698
+ end
1699
+
1700
+ # = DESCRIPTION
1701
+ # The PredictionExon class provides an interface to the
1702
+ # prediction_exon table. This table contains <>.
1703
+ #
1704
+ # This class uses ActiveRecord to access data in the Ensembl database.
1705
+ # See the general documentation of the Ensembl module for
1706
+ # more information on what this means and what methods are available.
1707
+ #
1708
+ # This class includes the mixin Sliceable, which means that it is mapped
1709
+ # to a SeqRegion object and a Slice can be created for objects of this
1710
+ # class. See Sliceable and Slice for more information.
1711
+ #
1712
+ # = USAGE
1713
+ # #TODO
1714
+ class PredictionExon < DBConnection
1715
+ include Sliceable
1716
+
1717
+ set_primary_key 'prediction_exon_id'
1718
+
1719
+ belongs_to :prediction_transcript
1720
+ belongs_to :seq_region
1721
+ end
1722
+
1723
+ # = DESCRIPTION
1724
+ # The PredictionTranscript class provides an interface to the
1725
+ # prediction_transcript table.
1726
+ #
1727
+ # This class uses ActiveRecord to access data in the Ensembl database.
1728
+ # See the general documentation of the Ensembl module for
1729
+ # more information on what this means and what methods are available.
1730
+ #
1731
+ # This class includes the mixin Sliceable, which means that it is mapped
1732
+ # to a SeqRegion object and a Slice can be created for objects of this
1733
+ # class. See Sliceable and Slice for more information.
1734
+ #
1735
+ # = USAGE
1736
+ # predicted_transcript = PredictionTranscript.find_by_display_label('GENSCAN00000000006')
1737
+ # puts predicted_transcript.prediction_exons.length
1738
+ class PredictionTranscript < DBConnection
1739
+ include Sliceable
1740
+
1741
+ set_primary_key 'prediction_transcript_id'
1742
+
1743
+ has_many :prediction_exons
1744
+ belongs_to :seq_region
1745
+ belongs_to :analysis
1746
+ end
1747
+
1748
+ # = DESCRIPTION
1749
+ # The ProteinFeature class provides an interface to the
1750
+ # protein_feature table. This table contains mappings of a Translation
1751
+ # onto a SeqRegion.
1752
+ #
1753
+ # This class uses ActiveRecord to access data in the Ensembl database.
1754
+ # See the general documentation of the Ensembl module for
1755
+ # more information on what this means and what methods are available.
1756
+ #
1757
+ # This class includes the mixin Sliceable, which means that it is mapped
1758
+ # to a SeqRegion object and a Slice can be created for objects of this
1759
+ # class. See Sliceable and Slice for more information.
1760
+ #
1761
+ # = USAGE
1762
+ # #TODO
1763
+ class ProteinFeature < DBConnection
1764
+ include Sliceable
1765
+
1766
+ set_primary_key 'protein_feature_id'
1767
+
1768
+ belongs_to :translation
1769
+ belongs_to :analysis
1770
+ end
1771
+
1772
+ # = DESCRIPTION
1773
+ # The ProteinAlignFeature class provides an interface to the
1774
+ # protein_align_feature table. This table contains sequence similarity
1775
+ # mappings against a SeqRegion.
1776
+ #
1777
+ # This class uses ActiveRecord to access data in the Ensembl database.
1778
+ # See the general documentation of the Ensembl module for
1779
+ # more information on what this means and what methods are available.
1780
+ #
1781
+ # This class includes the mixin Sliceable, which means that it is mapped
1782
+ # to a SeqRegion object and a Slice can be created for objects of this
1783
+ # class. See Sliceable and Slice for more information.
1784
+ #
1785
+ # = USAGE
1786
+ # uniprot_scan = Analysis.find_by_logic_name('Uniprot')
1787
+ # uniprot_scan.protein_align_features.each do |hit|
1788
+ # puts hit.seq_region.name + "\t" + hit.hit_name + "\t" + hit.cigar_line
1789
+ # end
1790
+ class ProteinAlignFeature < DBConnection
1791
+ include Sliceable
1792
+
1793
+ set_primary_key 'protein_align_feature_id'
1794
+
1795
+ belongs_to :seq_region
1796
+ belongs_to :analysis
1797
+
1798
+ has_many :exon_supporting_features
1799
+ has_many :transcript_supporting_features
1800
+ end
1801
+
1802
+ # = DESCRIPTION
1803
+ # The RegulatoryFactor class provides an interface to the
1804
+ # regulatory_factor table.
1805
+ #
1806
+ # This class uses ActiveRecord to access data in the Ensembl database.
1807
+ # See the general documentation of the Ensembl module for
1808
+ # more information on what this means and what methods are available.
1809
+ #
1810
+ # = USAGE
1811
+ # factor = RegulatoryFactor.find_by_name('crtHsap8070')
1812
+ # puts factor.to_yaml
1813
+ class RegulatoryFactor < DBConnection
1814
+ set_primary_key 'regulatory_factor_id'
1815
+
1816
+ has_many :regulatory_features
1817
+ end
1818
+
1819
+ # = DESCRIPTION
1820
+ # The RegulatoryFeature class provides an interface to the
1821
+ # regulatory_feature table. This table contains mappings of
1822
+ # RegulatoryFactor objects against a SeqRegion.
1823
+ #
1824
+ # This class uses ActiveRecord to access data in the Ensembl database.
1825
+ # See the general documentation of the Ensembl module for
1826
+ # more information on what this means and what methods are available.
1827
+ #
1828
+ # This class includes the mixin Sliceable, which means that it is mapped
1829
+ # to a SeqRegion object and a Slice can be created for objects of this
1830
+ # class. See Sliceable and Slice for more information.
1831
+ #
1832
+ # = USAGE
1833
+ # analysis = Analysis.find_by_logic_name('miRanda')
1834
+ # analysis.regulatory_features.each do |feature|
1835
+ # puts feature.name + "\t" + feature.regulatory_factor.name
1836
+ # end
1837
+ class RegulatoryFeature < DBConnection
1838
+ include Sliceable
1839
+
1840
+ set_primary_key 'regulatory_feature_id'
1841
+
1842
+ belongs_to :seq_region
1843
+ belongs_to :analysis
1844
+ belongs_to :regulatory_factor
1845
+ end
1846
+ end
1847
+ end