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
@@ -0,0 +1,61 @@
1
+ #
2
+ # = test/unit/test_transfers.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')
20
+
21
+ # Let's see if we can 'find' things
22
+ class SimpleRecordsTest < Test::Unit::TestCase
23
+ def setup
24
+ @sry_gene = Gene.find(85743)
25
+ @sry_transcript = Transcript.find(271533)
26
+ end
27
+
28
+ def test_coord_system
29
+ coord_system = CoordSystem.find(17)
30
+ assert_equal('chromosome', coord_system.name)
31
+ end
32
+
33
+ def test_coord_system_toplevel
34
+ coord_system = CoordSystem.find_toplevel
35
+ assert_equal('chromosome', coord_system.name)
36
+ end
37
+
38
+ def test_coord_system_seqlevel
39
+ coord_system = CoordSystem.find_seqlevel
40
+ assert_equal('contig', coord_system.name)
41
+ end
42
+
43
+ def test_display_label
44
+ assert_equal('SRY', @sry_gene.display_label)
45
+ assert_equal('SRY', @sry_gene.display_name)
46
+ assert_equal('SRY', @sry_gene.label)
47
+ assert_equal('SRY', @sry_gene.name)
48
+
49
+ assert_equal('SRY_HUMAN', @sry_transcript.display_label)
50
+ assert_equal('SRY_HUMAN', @sry_transcript.display_name)
51
+ assert_equal('SRY_HUMAN', @sry_transcript.label)
52
+ assert_equal('SRY_HUMAN', @sry_transcript.name)
53
+ end
54
+ end
55
+
56
+ class RelationshipsTest < Test::Unit::TestCase
57
+ def test_go_terms
58
+ gene = Gene.find(91283)
59
+ assert_equal(['GO:0000166','GO:0000287','GO:0003779','GO:0004674','GO:0005515','GO:0005524','GO:0005737','GO:0006468','GO:0007243','GO:0015629','GO:0016740','GO:0051128'], gene.go_terms.sort)
60
+ end
61
+ end
@@ -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__), ['..'] * 3, 'lib')).cleanpath.to_s
11
+ $:.unshift(libpath) unless $:.include?(libpath)
12
+
13
+ require 'test/unit'
14
+ require 'yaml'
15
+ require 'ensembl'
16
+
17
+ include Ensembl::Core
18
+
19
+ DBConnection.connect('homo_sapiens')
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(276333)
100
+ ub2r1_transcript_seq = ''
101
+ File.open('../../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(276225)
112
+ cso19_transcript_seq = ''
113
+ File.open('../../data/seq_cso19_transcript.fa').reject{|l| l=~/^>/}.each do |line|
114
+ line.chomp!
115
+ cso19_transcript_seq += line
116
+ end
117
+ cso19_transcript_seq.downcase!
118
+ assert_equal(cso19_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(276333)
127
+ # Transcript tr_rev is ENST00000315489
128
+ @tr_rev = Transcript.find(276225)
129
+ end
130
+
131
+ def test_cds_fw
132
+ ub2r1_coding_seq = ''
133
+ File.open('../../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('../../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,56 @@
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')
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
+ scaffold = SeqRegion.find_by_name('Chr4.003.122')
25
+ assert_equal(0, scaffold.simple_features.length)
26
+ assert_equal(122, scaffold.slice.simple_features.length)
27
+ slice = Slice.fetch_by_region('scaffold','Chr4.003.122')
28
+ assert_equal(122, slice.simple_features.length)
29
+ end
30
+ end
31
+
32
+ class SliceMethodMissing < Test::Unit::TestCase
33
+ def setup
34
+ @slice = Slice.new(SeqRegion.find_by_name('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(256, @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(34, @slice.transcripts.length)
55
+ end
56
+ end
@@ -0,0 +1,94 @@
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')
20
+
21
+ class CodingPositions < Test::Unit::TestCase
22
+ def setup
23
+ # Transcript tr_fw is ENST00000215574
24
+ @tr_fw = Transcript.find(276333)
25
+ # Transcript tr_rev is ENST00000358041
26
+ @tr_rev = Transcript.find(276403)
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(276333)
62
+ # Transcript tr_rev is ENST00000315489
63
+ @tr_rev = Transcript.find(276225)
64
+ end
65
+
66
+ def test_identify_exon
67
+ assert_equal(Exon.find(621287), @tr_fw.exon_for_cdna_position(601))
68
+ assert_equal(Exon.find(621287), @tr_fw.exon_for_genomic_position(488053))
69
+ assert_equal(Exon.find(620486), @tr_rev.exon_for_cdna_position(541))
70
+ assert_equal(Exon.find(620486), @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
+
@@ -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')
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(2115)
32
+ target_gene = source_gene.transform('chromosome')
33
+
34
+ assert_equal('4', source_gene.seq_region.name)
35
+ assert_equal(1454668, source_gene.seq_region_start)
36
+ assert_equal(1483537, 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(1454668, target_gene.seq_region_start)
40
+ assert_equal(1483537, 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(2408)
51
+ target_gene = source_gene.transform('chromosome')
52
+
53
+ assert_equal('4', source_gene.seq_region.name)
54
+ assert_equal(8104409, source_gene.seq_region_start)
55
+ assert_equal(8496477, 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(8104409, target_gene.seq_region_start)
59
+ assert_equal(8496477, 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