jandot-ruby-ensembl-api 0.9.2

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.
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
@@ -0,0 +1,121 @@
1
+ #
2
+ # = test/unit/test_project.rb - Unit test for Ensembl::Core
3
+ #
4
+ # Copyright:: Copyright (C) 2007
5
+ # Jan Aerts <http://jandot.myopenid.com>
6
+ # License:: Ruby's
7
+ #
8
+ # $Id:
9
+ require 'pathname'
10
+ libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
11
+ $:.unshift(libpath) unless $:.include?(libpath)
12
+
13
+ require 'test/unit'
14
+ require 'ensembl'
15
+
16
+ include Ensembl::Core
17
+ DBConnection.connect('bos_taurus', 50)
18
+
19
+ class GetFeatures < Test::Unit::TestCase
20
+ # Chr4.003.122 has no simple features in itself, but the corresponding region
21
+ # covered by the chromosome has 37. In addition, contigs within the scaffold
22
+ # have 85. Total should therefore be 122.
23
+ def test_simple_features
24
+ contig = SeqRegion.find_by_name('AAFC03055312')
25
+ assert_equal(19, contig.simple_features.length)
26
+ assert_equal(19, contig.slice.simple_features.length)
27
+ slice = Slice.fetch_by_region('contig','AAFC03055312')
28
+ assert_equal(19, slice.simple_features.length)
29
+ end
30
+ end
31
+
32
+ class SliceMethodMissing < Test::Unit::TestCase
33
+ def setup
34
+ @slice = Slice.fetch_by_region('chromosome','4',10000,10000000)
35
+ end
36
+
37
+ # There is not NotExistingTable class
38
+ def test_non_existing_tables
39
+ assert_raise(NoMethodError) { @slice.not_existing_tables }
40
+ end
41
+
42
+ # A slice can get its exons
43
+ def test_exons
44
+ assert_equal(291, @slice.exons.length)
45
+ assert_equal(Exon, @slice.exons[0].class)
46
+ end
47
+
48
+ # A slice can _not_ get its markers; it has marker_features instead.
49
+ def test_markers
50
+ assert_raise(NoMethodError) { @slice.markers }
51
+ end
52
+
53
+ def test_transcripts
54
+ assert_equal(36, @slice.transcripts.length)
55
+ end
56
+ end
57
+
58
+ class GetOverlappingObjects < Test::Unit::TestCase
59
+ def setup
60
+ @small_slice = Slice.fetch_by_region('chromosome','Un.004.10515',850,900)
61
+ @genes_inclusive = @small_slice.genes(true)
62
+ @genes_exclusive = @small_slice.genes
63
+
64
+ @large_slice = Slice.fetch_by_region('contig','AAFC03055312',1,18210)
65
+ @repeats_inclusive = @large_slice.repeat_features(true).select{|r| r.analysis_id == 6}
66
+ end
67
+
68
+ def test_get_gene
69
+ assert_equal(1, @genes_inclusive.length)
70
+ assert_equal('ENSBTAG00000039669', @genes_inclusive[0].stable_id)
71
+ assert_equal(0, @genes_exclusive.length)
72
+ end
73
+
74
+ def test_get_repeat_features
75
+ assert_equal(2, @repeats_inclusive.length)
76
+ end
77
+ end
78
+
79
+ class ExcisingSlice < Test::Unit::TestCase
80
+ def setup
81
+ @original_slice = Slice.fetch_by_region('chromosome','1',1,1000)
82
+ end
83
+
84
+ def test_excise_one_range
85
+ output = @original_slice.excise([20..50])
86
+ assert_equal(2, output.length)
87
+ assert_equal('chromosome:Btau_4.0:1:1:19:1', output[0].to_s)
88
+ assert_equal('chromosome:Btau_4.0:1:51:1000:1', output[1].to_s)
89
+ end
90
+
91
+ def test_excise_two_nonoverlapping_ranges
92
+ output = @original_slice.excise([20..50,100..200])
93
+ assert_equal(3, output.length)
94
+ assert_equal('chromosome:Btau_4.0:1:1:19:1', output[0].to_s)
95
+ assert_equal('chromosome:Btau_4.0:1:51:99:1', output[1].to_s)
96
+ assert_equal('chromosome:Btau_4.0:1:201:1000:1', output[2].to_s)
97
+ end
98
+
99
+ def test_excise_two_overlapping_ranges
100
+ output = @original_slice.excise([20..150,100..200])
101
+ assert_equal(2, output.length)
102
+ assert_equal('chromosome:Btau_4.0:1:1:19:1', output[0].to_s)
103
+ assert_equal('chromosome:Btau_4.0:1:201:1000:1', output[1].to_s)
104
+ end
105
+
106
+ def test_excise_two_adjacent_ranges
107
+ output = @original_slice.excise([20..99,100..200])
108
+ assert_equal(2, output.length)
109
+ assert_equal('chromosome:Btau_4.0:1:1:19:1', output[0].to_s)
110
+ assert_equal('chromosome:Btau_4.0:1:201:1000:1', output[1].to_s)
111
+ end
112
+
113
+ def test_excise_internal_ranges
114
+ output = @original_slice.excise([20..300,100..200])
115
+ assert_equal(2, output.length)
116
+ assert_equal('chromosome:Btau_4.0:1:1:19:1', output[0].to_s)
117
+ assert_equal('chromosome:Btau_4.0:1:201:1000:1', output[1].to_s)
118
+ end
119
+
120
+
121
+ end
@@ -0,0 +1,108 @@
1
+ #
2
+ # = test/unit/test_transcript.rb - Unit test for Ensembl::Core
3
+ #
4
+ # Copyright:: Copyright (C) 2007
5
+ # Jan Aerts <http://jandot.myopenid.com>
6
+ # License:: Ruby's
7
+ #
8
+ # $Id:
9
+ require 'pathname'
10
+ libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
11
+ $:.unshift(libpath) unless $:.include?(libpath)
12
+
13
+ require 'test/unit'
14
+
15
+ require 'ensembl'
16
+
17
+ include Ensembl::Core
18
+
19
+ DBConnection.connect('homo_sapiens', 50)
20
+
21
+ class CodingPositions < Test::Unit::TestCase
22
+ def setup
23
+ # Transcript tr_fw is ENST00000215574
24
+ @tr_fw = Transcript.find(73491)
25
+ # Transcript tr_rev is ENST00000358041
26
+ @tr_rev = Transcript.find(73774)
27
+ end
28
+
29
+ def test_transcript_coords
30
+ assert_equal(482733, @tr_fw.seq_region_start)
31
+ assert_equal(493084, @tr_fw.seq_region_end)
32
+ assert_equal(595371, @tr_rev.seq_region_start)
33
+ assert_equal(598309, @tr_rev.seq_region_end)
34
+ end
35
+
36
+ def test_coding_regions_genomic_coords_of_fw
37
+ assert_equal(482932, @tr_fw.coding_region_genomic_start)
38
+ assert_equal(492552, @tr_fw.coding_region_genomic_end)
39
+ end
40
+
41
+ def test_coding_regions_genomic_coords_of_rev
42
+ assert_equal(597652, @tr_rev.coding_region_genomic_start)
43
+ assert_equal(598047, @tr_rev.coding_region_genomic_end)
44
+ end
45
+
46
+ def test_coding_regions_cdna_coords_of_fw
47
+ assert_equal(200, @tr_fw.coding_region_cdna_start)
48
+ assert_equal(910, @tr_fw.coding_region_cdna_end)
49
+ end
50
+
51
+ def test_coding_regions_cdna_coords_of_rev
52
+ assert_equal(263, @tr_rev.coding_region_cdna_start)
53
+ assert_equal(658, @tr_rev.coding_region_cdna_end)
54
+ end
55
+
56
+ end
57
+
58
+ class GenomicVsCDna < Test::Unit::TestCase
59
+ def setup
60
+ # Transcript tr_fw is ENST00000215574
61
+ @tr_fw = Transcript.find(73491)
62
+ # Transcript tr_rev is ENST00000315489
63
+ @tr_rev = Transcript.find(73411)
64
+ end
65
+
66
+ def test_identify_exon
67
+ assert_equal(Exon.find(374767), @tr_fw.exon_for_cdna_position(601))
68
+ assert_equal(Exon.find(374767), @tr_fw.exon_for_genomic_position(488053))
69
+ assert_equal(Exon.find(374458), @tr_rev.exon_for_cdna_position(541))
70
+ assert_equal(Exon.find(374458), @tr_rev.exon_for_genomic_position(418719))
71
+ end
72
+
73
+ def test_cdna2genomic
74
+ assert_equal(488053, @tr_fw.cdna2genomic(601))
75
+ assert_equal(418719, @tr_rev.cdna2genomic(541))
76
+ end
77
+
78
+ def test_cds2genomic
79
+ assert_equal(488053, @tr_fw.cds2genomic(401))
80
+ assert_equal(418719, @tr_rev.cds2genomic(304))
81
+ end
82
+
83
+ def test_genomic2cdna
84
+ assert_equal(601, @tr_fw.genomic2cdna(488053))
85
+ assert_equal(541, @tr_rev.genomic2cdna(418719))
86
+ end
87
+
88
+ def test_genomic2cds
89
+ assert_equal(401, @tr_fw.genomic2cds(488053))
90
+ assert_equal(304, @tr_rev.genomic2cds(418719))
91
+ end
92
+ end
93
+
94
+ class TestIntron < Test::Unit::TestCase
95
+ def setup
96
+ @transcript = Transcript.find(58973)
97
+ @introns = @transcript.introns
98
+ end
99
+
100
+ def test_get_introns
101
+ assert_equal(2, @introns.length)
102
+ end
103
+
104
+ def test_intron_slices
105
+ assert_equal('chromosome:NCBI36:8:159418:172128:-1', @introns[0].slice.to_s)
106
+ end
107
+ end
108
+
@@ -0,0 +1,223 @@
1
+ #
2
+ # = test/unit/test_transform.rb - Unit test for Ensembl::Core
3
+ #
4
+ # Copyright:: Copyright (C) 2007
5
+ # Jan Aerts <http://jandot.myopenid.com>
6
+ # License:: Ruby's
7
+ #
8
+ # $Id:
9
+ require 'pathname'
10
+ libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
11
+ $:.unshift(libpath) unless $:.include?(libpath)
12
+
13
+ require 'test/unit'
14
+
15
+ require 'ensembl'
16
+
17
+ include Ensembl::Core
18
+ DBConnection.connect('bos_taurus', 50)
19
+
20
+ # For all tests, the source (i.e. the seq_region that the feature is annotated
21
+ # on initially) remains forward.
22
+ #
23
+ # Same coordinate system: test names refer to direction of gene vs chromosome
24
+ class TransformOntoSameCoordinateSystem < Test::Unit::TestCase
25
+ # |-------|========>-------------------------> chromosome
26
+ # ^ ^
27
+ # | |
28
+ # |-------|========>-------------------------> chromosome
29
+ # This should return itself.
30
+ def test_fw
31
+ source_gene = Gene.find(6043)
32
+ target_gene = source_gene.transform('chromosome')
33
+
34
+ assert_equal('4', source_gene.seq_region.name)
35
+ assert_equal(4595538, source_gene.seq_region_start)
36
+ assert_equal(4827723, source_gene.seq_region_end)
37
+ assert_equal(1, source_gene.seq_region_strand)
38
+ assert_equal('4', target_gene.seq_region.name)
39
+ assert_equal(4595538, target_gene.seq_region_start)
40
+ assert_equal(4827723, target_gene.seq_region_end)
41
+ assert_equal(1, target_gene.seq_region_strand)
42
+ end
43
+
44
+ # |-------<========|-------------------------> chromosome
45
+ # ^ ^
46
+ # | |
47
+ # |-------<========|-------------------------> chromosome
48
+ # This should return itself.
49
+ def test_rev
50
+ source_gene = Gene.find(6053)
51
+ target_gene = source_gene.transform('chromosome')
52
+
53
+ assert_equal('4', source_gene.seq_region.name)
54
+ assert_equal(5199677, source_gene.seq_region_start)
55
+ assert_equal(5201728, source_gene.seq_region_end)
56
+ assert_equal(-1, source_gene.seq_region_strand)
57
+ assert_equal('4', target_gene.seq_region.name)
58
+ assert_equal(5199677, target_gene.seq_region_start)
59
+ assert_equal(5201728, target_gene.seq_region_end)
60
+ assert_equal(-1, target_gene.seq_region_strand)
61
+ end
62
+ end
63
+
64
+ ## Test names refer to:
65
+ ## (1) direction of gene vs chromosome
66
+ ## (2) direction of component (scaffold) vs assembly (chromosome)
67
+ #class TransformFromComponentToAssembly < Test::Unit::TestCase
68
+ # def test_fw_fw
69
+ # assert true
70
+ # end
71
+ #
72
+ # def test_fw_rev
73
+ # assert true
74
+ # end
75
+ #
76
+ # def test_rev_fw
77
+ # assert true
78
+ # end
79
+ #
80
+ # def test_rev_rev
81
+ # assert true
82
+ # end
83
+ #end
84
+ #
85
+ ## Test names refer to:
86
+ ## (1) direction of gene vs chromosome
87
+ ## (2) direction of component (scaffold) vs assembly (chromosome)
88
+ ## We have to test for features that are covered by a scaffold, and those
89
+ ## overlapping more than 1 scaffold.
90
+ #class TransformFromAssemblyToComponent < Test::Unit::TestCase
91
+ # # |-----------------> scaffold
92
+ # # ^ ^
93
+ # # | |
94
+ # # |---------|=====>-----------------------------> chromosome
95
+ # def test_fw_fw_full_overlap
96
+ # source_gene = Gene.find(2995)
97
+ # target_gene = source_gene.transform('scaffold')
98
+ #
99
+ # assert_equal('4', source_gene.seq_region.name)
100
+ # assert_equal(10333321, source_gene.seq_region_start)
101
+ # assert_equal(10510842, source_gene.seq_region_end)
102
+ # assert_equal(1, source_gene.seq_region_strand)
103
+ # assert_equal('Chr4.003.12', target_gene.seq_region.name)
104
+ # assert_equal(43842, target_gene.seq_region_start)
105
+ # assert_equal(221363, target_gene.seq_region_end)
106
+ # assert_equal(1, target_gene.seq_region_strand)
107
+ # end
108
+ #
109
+ # # |-----------------> scaffold
110
+ # # |
111
+ # # |
112
+ # # |---|===>-------------------------------> chromosome
113
+ # def test_fw_fw_partial_overlap
114
+ # source_feature = PredictionTranscript.find(52425)
115
+ # target_feature = source_feature.transform('scaffold')
116
+ #
117
+ # assert_equal('4', source_feature.seq_region.name)
118
+ # assert_equal(1443280, source_feature.seq_region_start)
119
+ # assert_equal(1482777, source_feature.seq_region_end)
120
+ # assert_equal(1, source_feature.seq_region_strand)
121
+ # assert_equal(nil, target_feature)
122
+ # end
123
+ #
124
+ # # <-----------------| scaffold
125
+ # # ^ ^
126
+ # # | |
127
+ # # |----------|=====>-----------------------------> chromosome
128
+ # def test_fw_rev_full_overlap
129
+ # source_gene = Gene.find(2708)
130
+ # target_gene = source_gene.transform('scaffold')
131
+ #
132
+ # assert_equal('4', source_gene.seq_region.name)
133
+ # assert_equal(8312492, source_gene.seq_region_start)
134
+ # assert_equal(8312812, source_gene.seq_region_end)
135
+ # assert_equal(1, source_gene.seq_region_strand)
136
+ # assert_equal('Chr4.003.10', target_gene.seq_region.name)
137
+ # assert_equal(1774466, target_gene.seq_region_start)
138
+ # assert_equal(1774786, target_gene.seq_region_end)
139
+ # assert_equal(-1, target_gene.seq_region_strand)
140
+ # end
141
+ #
142
+ # # <-----------------| scaffold
143
+ # # |
144
+ # # |
145
+ # # |---------------------|===>------------------> chromosome
146
+ # def test_fw_rev_partial_overlap
147
+ # source_feature = PredictionTranscript.find(23305)
148
+ # target_feature = source_feature.transform('scaffold')
149
+ #
150
+ # assert_equal('4', source_feature.seq_region.name)
151
+ # assert_equal(10008188, source_feature.seq_region_start)
152
+ # assert_equal(10156104, source_feature.seq_region_end)
153
+ # assert_equal(1, source_feature.seq_region_strand)
154
+ # assert_equal(nil, target_feature)
155
+ # end
156
+ #
157
+ # # |-----------------> scaffold
158
+ # # | ^ ^
159
+ # # | | |
160
+ # # |---<===|--<=====|-----------------------------> chromosome
161
+ # def test_rev_fw_full_overlap
162
+ # source_gene = Gene.find(3124)
163
+ # target_gene = source_gene.transform('scaffold')
164
+ #
165
+ # assert_equal('4', source_gene.seq_region.name)
166
+ # assert_equal(10353230, source_gene.seq_region_start)
167
+ # assert_equal(10371155, source_gene.seq_region_end)
168
+ # assert_equal(-1, source_gene.seq_region_strand)
169
+ # assert_equal('Chr4.003.12', target_gene.seq_region.name)
170
+ # assert_equal(63751, target_gene.seq_region_start)
171
+ # assert_equal(81676, target_gene.seq_region_end)
172
+ # assert_equal(-1, target_gene.seq_region_strand)
173
+ # end
174
+ #
175
+ # # |-----------------> scaffold
176
+ # # |
177
+ # # |
178
+ # # |---------------------<===|------------------> chromosome
179
+ # def test_rev_fw_partial_overlap
180
+ # source_feature = PredictionTranscript.find(24185)
181
+ # target_feature = source_feature.transform('scaffold')
182
+ #
183
+ # assert_equal('4', source_feature.seq_region.name)
184
+ # assert_equal(11389212, source_feature.seq_region_start)
185
+ # assert_equal(11471635, source_feature.seq_region_end)
186
+ # assert_equal(-1, source_feature.seq_region_strand)
187
+ # assert_equal(nil, target_feature)
188
+ # end
189
+ #
190
+ # # <-----------------| scaffold
191
+ # # | ^ ^
192
+ # # | | |
193
+ # # |---<===|--<=====|-----------------------------> chromosome
194
+ # def test_rev_rev_full_overlap
195
+ # source_gene = Gene.find(2408)
196
+ # target_gene = source_gene.transform('scaffold')
197
+ #
198
+ # assert_equal('4', source_gene.seq_region.name)
199
+ # assert_equal(8104409, source_gene.seq_region_start)
200
+ # assert_equal(8496477, source_gene.seq_region_end)
201
+ # assert_equal(-1, source_gene.seq_region_strand)
202
+ # assert_equal('Chr4.003.10', target_gene.seq_region.name)
203
+ # assert_equal(1590801, target_gene.seq_region_start)
204
+ # assert_equal(1982869, target_gene.seq_region_end)
205
+ # assert_equal(1, target_gene.seq_region_strand)
206
+ # end
207
+ #
208
+ # # <-----------------| scaffold
209
+ # # |
210
+ # # |
211
+ # # |---<===|-----------------------------> chromosome
212
+ # def test_rev_rev_partial_overlap
213
+ # source_feature = Transcript.find(14723)
214
+ # target_feature = source_feature.transform('scaffold')
215
+ #
216
+ # assert_equal('4', source_feature.seq_region.name)
217
+ # assert_equal(55713316, source_feature.seq_region_start)
218
+ # assert_equal(55792273, source_feature.seq_region_end)
219
+ # assert_equal(-1, source_feature.seq_region_strand)
220
+ # assert_equal(nil, target_feature)
221
+ # end
222
+ #
223
+ #end