ruby-ensembl-api 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/TUTORIAL.rdoc +623 -0
  2. data/bin/ensembl +40 -0
  3. data/lib/ensembl.rb +64 -0
  4. data/lib/ensembl/core/activerecord.rb +1914 -0
  5. data/lib/ensembl/core/collection.rb +60 -0
  6. data/lib/ensembl/core/project.rb +264 -0
  7. data/lib/ensembl/core/slice.rb +693 -0
  8. data/lib/ensembl/core/transcript.rb +425 -0
  9. data/lib/ensembl/core/transform.rb +97 -0
  10. data/lib/ensembl/db_connection.rb +216 -0
  11. data/lib/ensembl/variation/activerecord.rb +253 -0
  12. data/lib/ensembl/variation/variation.rb +163 -0
  13. data/test/unit/data/seq_c6qbl.fa +10 -0
  14. data/test/unit/data/seq_cso19_coding.fa +16 -0
  15. data/test/unit/data/seq_cso19_transcript.fa +28 -0
  16. data/test/unit/data/seq_drd3_gene.fa +838 -0
  17. data/test/unit/data/seq_drd3_transcript.fa +22 -0
  18. data/test/unit/data/seq_drd4_transcript.fa +24 -0
  19. data/test/unit/data/seq_forward_composite.fa +1669 -0
  20. data/test/unit/data/seq_par_boundary.fa +169 -0
  21. data/test/unit/data/seq_rnd3_transcript.fa +47 -0
  22. data/test/unit/data/seq_ub2r1_coding.fa +13 -0
  23. data/test/unit/data/seq_ub2r1_gene.fa +174 -0
  24. data/test/unit/data/seq_ub2r1_transcript.fa +26 -0
  25. data/test/unit/data/seq_y.fa +2 -0
  26. data/test/unit/ensembl_genomes/test_collection.rb +51 -0
  27. data/test/unit/ensembl_genomes/test_gene.rb +52 -0
  28. data/test/unit/ensembl_genomes/test_slice.rb +71 -0
  29. data/test/unit/ensembl_genomes/test_variation.rb +17 -0
  30. data/test/unit/release_50/core/test_project.rb +215 -0
  31. data/test/unit/release_50/core/test_project_human.rb +58 -0
  32. data/test/unit/release_50/core/test_relationships.rb +66 -0
  33. data/test/unit/release_50/core/test_sequence.rb +175 -0
  34. data/test/unit/release_50/core/test_slice.rb +121 -0
  35. data/test/unit/release_50/core/test_transcript.rb +108 -0
  36. data/test/unit/release_50/core/test_transform.rb +223 -0
  37. data/test/unit/release_50/variation/test_activerecord.rb +143 -0
  38. data/test/unit/release_50/variation/test_variation.rb +84 -0
  39. data/test/unit/release_53/core/test_gene.rb +66 -0
  40. data/test/unit/release_53/core/test_project.rb +96 -0
  41. data/test/unit/release_53/core/test_project_human.rb +65 -0
  42. data/test/unit/release_53/core/test_slice.rb +47 -0
  43. data/test/unit/release_53/core/test_transform.rb +63 -0
  44. data/test/unit/release_53/variation/test_activerecord.rb +145 -0
  45. data/test/unit/release_53/variation/test_variation.rb +71 -0
  46. data/test/unit/release_56/core/test_gene.rb +66 -0
  47. data/test/unit/release_56/core/test_project.rb +96 -0
  48. data/test/unit/release_56/core/test_slice.rb +54 -0
  49. data/test/unit/release_56/core/test_transform.rb +63 -0
  50. data/test/unit/release_56/variation/test_activerecord.rb +142 -0
  51. data/test/unit/release_56/variation/test_variation.rb +68 -0
  52. data/test/unit/test_connection.rb +66 -0
  53. data/test/unit/test_releases.rb +136 -0
  54. metadata +128 -0
@@ -0,0 +1,175 @@
1
+ #
2
+ # = test/unit/test_seq.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 'yaml'
15
+ require 'lib/ensembl'
16
+
17
+ include Ensembl::Core
18
+
19
+ DBConnection.connect('homo_sapiens', 50)
20
+
21
+ #class SequenceForSlice < Test::Unit::TestCase
22
+ # def test_forward_strand_seqlevel
23
+ # slice = Slice.new(SeqRegion.find(170931),5,15)
24
+ # seq = 'gcagtggtgtg'
25
+ # assert_equal(seq, slice.seq)
26
+ # end
27
+ #
28
+ # def test_reverse_strand_seqlevel
29
+ # slice = Slice.new(SeqRegion.find(170931),5,15, -1)
30
+ # seq = 'cacaccactgc'
31
+ # assert_equal(seq, slice.seq)
32
+ # end
33
+ #
34
+ # def test_forward_strand_not_seqlevel_single_target
35
+ # slice = Slice.new(SeqRegion.find(226044),69437100,69437110)
36
+ # seq = 'gtctatttaca'
37
+ # assert_equal(seq, slice.seq)
38
+ # end
39
+ #
40
+ # def test_reverse_strand_not_seqlevel_single_target
41
+ # slice = Slice.new(SeqRegion.find(226044),69437100,69437110,-1)
42
+ # seq = 'tgtaaatagac'
43
+ # assert_equal(seq, slice.seq)
44
+ # end
45
+ #
46
+ # def test_forward_strand_not_seqlevel_composite_target
47
+ # seq = ''
48
+ # File.open('../../data/seq_forward_composite.fa').reject{|l| l=~/^>/}.each do |line|
49
+ # line.chomp!
50
+ # seq += line
51
+ # end
52
+ # seq.downcase!
53
+ # slice = Slice.new(SeqRegion.find(226044),69387650,69487649)
54
+ # assert_equal(seq, slice.seq)
55
+ # end
56
+ #
57
+ # def test_reverse_strand_not_seqlevel_composite_target
58
+ # slice = Slice.new(SeqRegion.find(226044),69437061,69437160,-1)
59
+ # assert_equal('nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnatgtaaatagacaactaacaagatagctgagattgtttccttatccagaca', slice.seq)
60
+ # end
61
+ #
62
+ #end
63
+ #
64
+ #class SequenceForUnsplicedFeature < Test::Unit::TestCase
65
+ # def test_forward_strand_seqlevel
66
+ # marker_feature = MarkerFeature.find(1323757)
67
+ # marker_seq = 'ggcttacttggaaaggtctcttccaacccaatattattcaaatactttcaattttcttctaatgtttttagtgtgtgtgtgtgtgtgtgtgtgtgtgtgtgtgtgtgtgtggttttgttttatttcttttaattctctgatacatttagaatttcttttattattttattttattttattatttatttatttatttttgagacagagttttgctc'
68
+ # assert_equal(marker_seq, marker_feature.seq)
69
+ # end
70
+ #
71
+ # def test_reverse_strand_seqlevel
72
+ # gene = Gene.find_by_name('ANKRD56')
73
+ #
74
+ # ankrd56_seq = 'atggcccgagagctgagccaggaggcactactggactttctgtgccaggctgggggccgcgtgaccaacgctgccttgctgagccacttcaagagctttctccgagaccccgacgcgtcccccagccagcaccagcaccgccgcgagctcttcaagggcttcgtcaactcggtcgccgcagtgcgccaggaccccgacggcaccaagtacgtggtgctcaagaggagatacagggaccttttgggggaggaggggctgcagcgaccccgcgagccgcccgcggccgcccccagtgcagggggagctgcgccctgctccccgcgaggcgcgcgccggggggagccgccccagcagcagcccaggcggcggcggcgcgagaaggagccggaggaggagccagcaggtgcagcagccagagccgccgacgcagcttgcaatggactcccgggcagcgactcccgtagggcgcccgggaagggcggcggatcgaagggcagtcccggacagaggccgccggtgcccgcagctgcagcggcaggggcccaggcgagagcgagctgcgcggcggcgaagacgcagggccgctgctgctgggaatgcctccagaacaacctggctgtactgccgggagagctcggcgcactcccgcactcggccaccgcggaggagaagccggcacgggctctgcctgcccaggatgaccgcggggcttccagggagcgggaagaaggcgcgctagctgagccggcgcctgtgcctgcagtggctcactcgcctcccgccaccgtcgaggctgcgacaagcagggcttccccgcctgctctcctgcccggccccgctccccgcggagaccggccggagctgctgacccccagctccctgcattattcgaccctgcagcagcagcagcagcgcactcgagagtgggtggccaggcacccgcaggtgcccgaggcccgtgatcagggccctatccgcgcctggtcggtgctgccagacaacttcctccagctgcccttggaacccggctccacggagcctaattcagagccgccagacccctgtctttcctcgcactctctctttcctgttgttccggatgagtcctgggaatcctgggcggggaacccttcattgactgtctttcgcagcattcgttgtcagctgtccctccaagatctggatgactttgtggaccaggagagtgatggcagtgaggagagcagcagtgggcccaaagactccccgggggcttctgaagaggggctgcaggttgtcttgggaaccccagatagggggaagctcaggaatccagctgggggcctttctgtatctcggaaggagggcagccccagccggagccctcagggtctcagaaacagaggggatggtcacatctctcagcaggtccctgcaggggctaatggccttgcaggccaccccctgaagcctttgccttggccagttcctaagttaaggaggtccctcaggaggagctctctggcagggagagccaaattgtcctcctctgatgaggagtacctcgatgagggcttgctgaaaagaagtcggcgcccacctcgatccaggaagccctccaaggcaggaacggcacccagcccaagggttgatgcaggtttatcactaaaacttgcagaggttaaggctgttgtggccgagcggggttggcgacacagcctgtgggtccccagtggggaggggtctgcagccttggccccccacagaacttctgagcacaaatcatccctggttccactagatgccagggagcatgagtggattgtgaagcttgccagtggctcctggattcaggtgtggactttgttctgggaggaccctcaactggccttgcacaaagactttttgactgggtacactgcgttgcactggatagccaaacatggtgacctcagggcccttcaggacttggtgtctggagcaaagaaggcagggattgtccttgatgtaaacgtgaggtccagttgtggatataccccgctgcaccttgcagccattcacggccaccagggggtcatcaaattgctagtgcaaaggttggcttctcgggtaaatgtcagggacagcagtgggaagaagccatggcagtatctaaccagtaatacctctggggaaatatggcagctgttgggagctcctcggggcaagcccattttccctgtctatcccttagttggaagttcttcccctaccagaaaggccaagagcaaggaaatatctagaagtgtcacccgaaaaacttccttcgctgcactactcaaaagtcagcacaacaagtggaaactggccaaccagtatgagaaattccacagtccaagggaaagagaagagtatagtgactga'
75
+ # assert_equal(ankrd56_seq, gene.seq)
76
+ # end
77
+ #
78
+ # def test_reverse_strand_not_seqlevel
79
+ # gene = Gene.find_by_name('DRD3')
80
+ # drd3_gene_seq = ''
81
+ # File.open('../../data/seq_drd3_gene.fa').reject{|l| l=~/^>/}.each do |line|
82
+ # line.chomp!
83
+ # drd3_gene_seq += line
84
+ # end
85
+ # drd3_gene_seq.downcase!
86
+ # assert_equal(drd3_gene_seq, gene.seq)
87
+ #
88
+ # end
89
+ #
90
+ # def test_exon
91
+ # exon = Exon.find(719588)
92
+ # assert_equal('atggcatctctgagccagctgagtggccacctgaactacacctgtggggcagagaactccacaggtgccagccaggcccgcccacatgcctactatgccctctcctactgcgcgctcatcctggccatcgtcttcggcaatggcctggtgtgcatggctgtgctgaaggagcgggccctgcagactaccaccaactacttagtagtgagcctggctgtggcagacttgctggtggccaccttggtgatgccctgggtggtatacctggag', exon.seq)
93
+ # end
94
+ #
95
+ #end
96
+
97
+ class SequenceForSlicedFeature < Test::Unit::TestCase
98
+ def test_transcript_foward
99
+ transcript = Transcript.find(73491) # UB2R1 = CDC34
100
+ ub2r1_transcript_seq = ''
101
+ File.open('test/unit/data/seq_ub2r1_transcript.fa').reject{|l| l=~/^>/}.each do |line|
102
+ line.chomp!
103
+ ub2r1_transcript_seq += line
104
+ end
105
+ ub2r1_transcript_seq.downcase!
106
+ assert_equal(ub2r1_transcript_seq, transcript.seq)
107
+
108
+ end
109
+
110
+ def test_transcript_reverse
111
+ transcript = Transcript.find(107548)
112
+ rnd3_transcript_seq = ''
113
+ File.open('test/unit/data/seq_rnd3_transcript.fa').reject{|l| l=~/^>/}.each do |line|
114
+ line.chomp!
115
+ rnd3_transcript_seq += line
116
+ end
117
+ rnd3_transcript_seq.downcase!
118
+ assert_equal(rnd3_transcript_seq, transcript.seq)
119
+ end
120
+
121
+ end
122
+
123
+ class SequenceForCDS < Test::Unit::TestCase
124
+ def setup
125
+ # Transcript tr_fw is ENST00000215574
126
+ @tr_fw = Transcript.find(73491)
127
+ # Transcript tr_rev is ENST00000315489
128
+ @tr_rev = Transcript.find(73411)
129
+ end
130
+
131
+ def test_cds_fw
132
+ ub2r1_coding_seq = ''
133
+ File.open('test/unit/data/seq_ub2r1_coding.fa').reject{|l| l=~/^>/}.each do |line|
134
+ line.chomp!
135
+ ub2r1_coding_seq += line
136
+ end
137
+ ub2r1_coding_seq.downcase!
138
+ assert_equal(ub2r1_coding_seq, @tr_fw.cds_seq)
139
+ end
140
+
141
+ def test_cds_rev
142
+ cso19_coding_seq = ''
143
+ File.open('test/unit/data/seq_cso19_coding.fa').reject{|l| l=~/^>/}.each do |line|
144
+ line.chomp!
145
+ cso19_coding_seq += line
146
+ end
147
+ cso19_coding_seq.downcase!
148
+ assert_equal(cso19_coding_seq, @tr_rev.cds_seq)
149
+ end
150
+
151
+ def test_five_prime_utr_fw
152
+ assert_equal('GGCAAGCGCCGGTGGGGCGGCGGCGCCAGAGCTGCTGGAGCGCTCGGGGTCCCCGGGCGGCGGCGGCGGCGCAGAGGAGGAGGCAGGCGGCGGCCCCGGTGGCTCCCCCCCGGACGGTGCGCGGCCCGGCCCGTCTCGCGAACTCGCGGTGGTCGCGCGGCCCCGCGCTGCTCCGACCCCGGGCCCCTCCGCCGCCGCC'.downcase, @tr_fw.five_prime_utr_seq)
153
+ end
154
+
155
+ def test_five_primer_utr_rev
156
+ assert_equal('ACTCGATCCCGGCCCCACTTCCAGGCCAGTGTCCGGCCGACCAGCCTGCCTTGGGCCAGGGCCCCACGACTCCCTGCTGCGGGACAAGAGGCCGTCTGTGCGGCTGTGGTCGTGGGAGGGTGTGGTGAGGCCGTGAAGGTGGGGACGGTGCCTGGGCCTGTGGCCGCCAGAGCTGCTGCGGCTCAGAAGGTAGCACCAGGCCCCGTGGGTGCTGTGGGGGCCATCGCCTGCCCACC'.downcase, @tr_rev.five_prime_utr_seq)
157
+ end
158
+
159
+ def test_three_prime_utr_fw
160
+ assert_equal('CACCACCAGAATAAACTTGCCGAGTTTACCTCACTAGGGCCGGACCCGTGGCTCCTTAGACGACAGACTACCTCACGGAGGTTTTGTGCTGGTCCCCGTCTCCTCTGGTTGTTTCGTTTTGGCTTTTTCTCCCTCCCCATGTCTGTTCTGGGTTTTCACGTGCTTCAGAGAAGAGGGGCTGCCCCACCGCCACTCACGTCACTCGGGGCTCGGTGGACGGGCCCAGGGTGGGAGCGGCCGGCCCACCTGTCCCCTCGGGAGGGGAGCTGAGCCCGACTTCTACCGGGGTCCCCCAGCTTCCGGACTGGCCGCACCCCGGAGGAGCCACGGGGGCGCTGCTGGGAACGTGGGCGGGGGGCCGTTTCCTGACACTACCAGCCTGGGAGGCCCAGGTGTAGCGGTCCGAGGGGCCCGGTCCTGCCTGTCAGCTCCAGGTCCTGGAGCCACGTCCAGCACAGAGTGGACGGATTCACCGTGGCCGACTCTTTTCCCTGCTTTGGTTTGTTTGAAATCTAAATAAAACTACTTTATG'.downcase, @tr_fw.three_prime_utr_seq)
161
+ end
162
+
163
+ def test_three_prime_utr_rev
164
+ assert_equal('GCCAGGCCTGTTTCCCACACAGTGAACGGGGGGCTGGCGGGCCTCTCCTGGGGCCTGGCTTTGGCTGGAGGGGCTAGAAGGCGAGAGGGGCTGGGAAAGGAGTCTTCCCTCCCCTTTCCTGAACTGTCCAGGTCCTTCTAGGACACCTGATCCTTCCAGTCCCTGGGGGCTGTGACCCATGGCCCTGTGCAGGGTGCAGGGTGAGTCTCCTTCCAGTGCCCCAGTTTCTTCCAGGTCACGCCAGGCCAGGCCAGGCCAGGTGGGGAAAGGGACACCTTCCGGCCCTCCCCAGTAGCTGGCTGGAGATGGAGCTTCCTGTGTCCCAGAACTCGGCGTCCAGCTCCACTAGGGCCTGGATCCCCATCACAGCTTGGGTTAGCCCCGGTCCCAGCCCAAACTCAGGCTGGAGGCAGCCCCGAGGCCTGTGCCTTTCCCACTCCACCTTCTACAGTTGCTTAGCCAATAAACCTTTCCTGGGCTGGAG'.downcase, @tr_rev.three_prime_utr_seq)
165
+ end
166
+
167
+ def test_protein_fw
168
+ assert_equal('MARPLVPSSQKALLLELKGLQEEPVEGFRVTLVDEGDLYNWEVAIFGPPNTYYEGGYFKARLKFPIDYPYSPPAFRFLTKMWHPNIYETGDVCISILHPPVDDPQSGELPSERWNPTQNVRTILLSVISLLNEPNTFSPANVDASVMYRKWKESKGKDREYTDIIRKQVLGTKVDAERDGVKVPTTLAEYCVKTKAPAPDEGSDLFYDDYYEDGEVEEEADSCFGDDEDDSGTEES*', @tr_fw.protein_seq)
169
+ end
170
+
171
+ def test_protein_rev
172
+ assert_equal('MGTLSCDSTPRLATAPLGRRVTEGQIPETGLRKSCGTATLENGSGPGLYVLPSTVGFINHDCTRVASPAYSLVRRPSEAPPQDTSPGPIYFLDPKVTRFGRSCTPAYSMQGRAKSRGPEVTPGPGAYSPEKVPPVRHRTPPAFTLGCRLPLKPLDTSAPAPNAYTMPPLWGSQIFTKPSSPSYTVVGRTPPARPPQDPAEIPGPGQYDSPDANTYRQRLPAFTMLGRPRAPRPLEETPGPGAHCPEQVTVNKARAPAFSMGIRHSKRASTMAATTPSRPAGHRLPGRCC*', @tr_rev.protein_seq)
173
+ end
174
+ end
175
+
@@ -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 'lib/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 'lib/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 'lib/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