bio 0.7.1 → 1.0.0

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 (142) hide show
  1. data/bin/bioruby +71 -27
  2. data/bin/br_biofetch.rb +5 -17
  3. data/bin/br_bioflat.rb +14 -26
  4. data/bin/br_biogetseq.rb +6 -18
  5. data/bin/br_pmfetch.rb +6 -16
  6. data/doc/Changes-0.7.rd +35 -0
  7. data/doc/KEGG_API.rd +287 -172
  8. data/doc/KEGG_API.rd.ja +273 -160
  9. data/doc/Tutorial.rd +18 -9
  10. data/doc/Tutorial.rd.ja +656 -138
  11. data/lib/bio.rb +6 -24
  12. data/lib/bio/alignment.rb +5 -5
  13. data/lib/bio/appl/blast.rb +132 -98
  14. data/lib/bio/appl/blast/format0.rb +9 -19
  15. data/lib/bio/appl/blast/wublast.rb +5 -18
  16. data/lib/bio/appl/emboss.rb +40 -47
  17. data/lib/bio/appl/hmmer.rb +116 -82
  18. data/lib/bio/appl/hmmer/report.rb +509 -364
  19. data/lib/bio/appl/spidey/report.rb +7 -18
  20. data/lib/bio/data/na.rb +3 -21
  21. data/lib/bio/db.rb +3 -21
  22. data/lib/bio/db/aaindex.rb +147 -52
  23. data/lib/bio/db/embl/common.rb +27 -6
  24. data/lib/bio/db/embl/embl.rb +18 -10
  25. data/lib/bio/db/embl/sptr.rb +87 -67
  26. data/lib/bio/db/embl/swissprot.rb +32 -3
  27. data/lib/bio/db/embl/trembl.rb +32 -3
  28. data/lib/bio/db/embl/uniprot.rb +32 -3
  29. data/lib/bio/db/fasta.rb +327 -289
  30. data/lib/bio/db/medline.rb +25 -4
  31. data/lib/bio/db/nbrf.rb +12 -20
  32. data/lib/bio/db/pdb.rb +4 -1
  33. data/lib/bio/db/pdb/chemicalcomponent.rb +240 -0
  34. data/lib/bio/db/pdb/pdb.rb +13 -8
  35. data/lib/bio/db/rebase.rb +93 -97
  36. data/lib/bio/feature.rb +2 -31
  37. data/lib/bio/io/ddbjxml.rb +167 -139
  38. data/lib/bio/io/fastacmd.rb +89 -56
  39. data/lib/bio/io/flatfile.rb +994 -278
  40. data/lib/bio/io/flatfile/index.rb +257 -194
  41. data/lib/bio/io/flatfile/indexer.rb +37 -29
  42. data/lib/bio/reference.rb +147 -64
  43. data/lib/bio/sequence.rb +57 -417
  44. data/lib/bio/sequence/aa.rb +64 -0
  45. data/lib/bio/sequence/common.rb +175 -0
  46. data/lib/bio/sequence/compat.rb +68 -0
  47. data/lib/bio/sequence/format.rb +134 -0
  48. data/lib/bio/sequence/generic.rb +24 -0
  49. data/lib/bio/sequence/na.rb +189 -0
  50. data/lib/bio/shell.rb +9 -23
  51. data/lib/bio/shell/core.rb +130 -125
  52. data/lib/bio/shell/demo.rb +143 -0
  53. data/lib/bio/shell/{session.rb → interface.rb} +42 -40
  54. data/lib/bio/shell/object.rb +52 -0
  55. data/lib/bio/shell/plugin/codon.rb +4 -22
  56. data/lib/bio/shell/plugin/emboss.rb +23 -0
  57. data/lib/bio/shell/plugin/entry.rb +34 -25
  58. data/lib/bio/shell/plugin/flatfile.rb +5 -23
  59. data/lib/bio/shell/plugin/keggapi.rb +11 -24
  60. data/lib/bio/shell/plugin/midi.rb +5 -23
  61. data/lib/bio/shell/plugin/obda.rb +4 -22
  62. data/lib/bio/shell/plugin/seq.rb +6 -24
  63. data/lib/bio/shell/rails/Rakefile +10 -0
  64. data/lib/bio/shell/rails/app/controllers/application.rb +4 -0
  65. data/lib/bio/shell/rails/app/controllers/shell_controller.rb +94 -0
  66. data/lib/bio/shell/rails/app/helpers/application_helper.rb +3 -0
  67. data/lib/bio/shell/rails/app/models/shell_connection.rb +30 -0
  68. data/lib/bio/shell/rails/app/views/layouts/shell.rhtml +37 -0
  69. data/lib/bio/shell/rails/app/views/shell/history.rhtml +5 -0
  70. data/lib/bio/shell/rails/app/views/shell/index.rhtml +2 -0
  71. data/lib/bio/shell/rails/app/views/shell/show.rhtml +13 -0
  72. data/lib/bio/shell/rails/config/boot.rb +19 -0
  73. data/lib/bio/shell/rails/config/database.yml +85 -0
  74. data/lib/bio/shell/rails/config/environment.rb +53 -0
  75. data/lib/bio/shell/rails/config/environments/development.rb +19 -0
  76. data/lib/bio/shell/rails/config/environments/production.rb +19 -0
  77. data/lib/bio/shell/rails/config/environments/test.rb +19 -0
  78. data/lib/bio/shell/rails/config/routes.rb +19 -0
  79. data/lib/bio/shell/rails/doc/README_FOR_APP +2 -0
  80. data/lib/bio/shell/rails/public/404.html +8 -0
  81. data/lib/bio/shell/rails/public/500.html +8 -0
  82. data/lib/bio/shell/rails/public/dispatch.cgi +10 -0
  83. data/lib/bio/shell/rails/public/dispatch.fcgi +24 -0
  84. data/lib/bio/shell/rails/public/dispatch.rb +10 -0
  85. data/lib/bio/shell/rails/public/favicon.ico +0 -0
  86. data/lib/bio/shell/rails/public/images/icon.png +0 -0
  87. data/lib/bio/shell/rails/public/images/rails.png +0 -0
  88. data/lib/bio/shell/rails/public/index.html +277 -0
  89. data/lib/bio/shell/rails/public/javascripts/controls.js +750 -0
  90. data/lib/bio/shell/rails/public/javascripts/dragdrop.js +584 -0
  91. data/lib/bio/shell/rails/public/javascripts/effects.js +854 -0
  92. data/lib/bio/shell/rails/public/javascripts/prototype.js +1785 -0
  93. data/lib/bio/shell/rails/public/robots.txt +1 -0
  94. data/lib/bio/shell/rails/public/stylesheets/main.css +187 -0
  95. data/lib/bio/shell/rails/script/about +3 -0
  96. data/lib/bio/shell/rails/script/breakpointer +3 -0
  97. data/lib/bio/shell/rails/script/console +3 -0
  98. data/lib/bio/shell/rails/script/destroy +3 -0
  99. data/lib/bio/shell/rails/script/generate +3 -0
  100. data/lib/bio/shell/rails/script/performance/benchmarker +3 -0
  101. data/lib/bio/shell/rails/script/performance/profiler +3 -0
  102. data/lib/bio/shell/rails/script/plugin +3 -0
  103. data/lib/bio/shell/rails/script/process/reaper +3 -0
  104. data/lib/bio/shell/rails/script/process/spawner +3 -0
  105. data/lib/bio/shell/rails/script/process/spinner +3 -0
  106. data/lib/bio/shell/rails/script/runner +3 -0
  107. data/lib/bio/shell/rails/script/server +42 -0
  108. data/lib/bio/shell/rails/test/test_helper.rb +28 -0
  109. data/lib/bio/shell/web.rb +90 -0
  110. data/lib/bio/util/contingency_table.rb +231 -225
  111. data/sample/any2fasta.rb +59 -0
  112. data/test/data/HMMER/hmmpfam.out +64 -0
  113. data/test/data/HMMER/hmmsearch.out +88 -0
  114. data/test/data/aaindex/DAYM780301 +30 -0
  115. data/test/data/aaindex/PRAM900102 +20 -0
  116. data/test/data/bl2seq/cd8a_cd8b_blastp.bl2seq +53 -0
  117. data/test/data/bl2seq/cd8a_p53_e-5blastp.bl2seq +37 -0
  118. data/test/data/blast/{eco:b0002.faa → b0002.faa} +0 -0
  119. data/test/data/blast/{eco:b0002.faa.m0 → b0002.faa.m0} +2 -2
  120. data/test/data/blast/{eco:b0002.faa.m7 → b0002.faa.m7} +1 -1
  121. data/test/data/blast/{eco:b0002.faa.m8 → b0002.faa.m8} +0 -0
  122. data/test/unit/bio/appl/bl2seq/test_report.rb +134 -0
  123. data/test/unit/bio/appl/blast/test_report.rb +15 -12
  124. data/test/unit/bio/appl/blast/test_xmlparser.rb +4 -4
  125. data/test/unit/bio/appl/hmmer/test_report.rb +355 -0
  126. data/test/unit/bio/appl/test_blast.rb +5 -5
  127. data/test/unit/bio/data/test_na.rb +9 -18
  128. data/test/unit/bio/db/pdb/test_pdb.rb +169 -0
  129. data/test/unit/bio/db/test_aaindex.rb +197 -0
  130. data/test/unit/bio/io/test_fastacmd.rb +55 -0
  131. data/test/unit/bio/sequence/test_aa.rb +102 -0
  132. data/test/unit/bio/sequence/test_common.rb +178 -0
  133. data/test/unit/bio/sequence/test_compat.rb +82 -0
  134. data/test/unit/bio/sequence/test_na.rb +242 -0
  135. data/test/unit/bio/shell/plugin/test_seq.rb +29 -19
  136. data/test/unit/bio/test_alignment.rb +15 -7
  137. data/test/unit/bio/test_reference.rb +198 -0
  138. data/test/unit/bio/test_sequence.rb +4 -49
  139. data/test/unit/bio/test_shell.rb +2 -2
  140. metadata +118 -15
  141. data/lib/bio/io/brdb.rb +0 -103
  142. data/lib/bioruby.rb +0 -34
@@ -0,0 +1,102 @@
1
+ #
2
+ # = test/unit/bio/sequence/test_aa.rb - Unit test for Bio::Sequencce::AA
3
+ #
4
+ # Copyright:: Copyright (C) 2006
5
+ # Mitsuteru C. Nakao <n@bioruby.org>
6
+ # Lisence:: Ruby's
7
+ #
8
+ # $Id: test_aa.rb,v 1.1 2006/02/08 07:20:24 nakao Exp $
9
+ #
10
+
11
+ require 'pathname'
12
+ libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
13
+ $:.unshift(libpath) unless $:.include?(libpath)
14
+
15
+ require 'test/unit'
16
+ require 'bio/sequence'
17
+ require 'bio/sequence/aa'
18
+
19
+
20
+ module Bio
21
+
22
+
23
+ class TestSequenceAANew < Test::Unit::TestCase
24
+ def test_new
25
+ str = "RRLEHTFVFL RNFSLMLLRY"
26
+ assert(Bio::Sequence::AA.new(str))
27
+ end
28
+
29
+ def test_new_t
30
+ str = "RRLEHTFVFLRNFSLMLLRY"
31
+ str_t = "RRLEHTFVFL\tRNFSLMLLRY"
32
+ assert_equal(str, Bio::Sequence::AA.new(str_t))
33
+ end
34
+
35
+ def test_new_n
36
+ str = "RRLEHTFVFLRNFSLMLLRY"
37
+ str_n = "RRLEHTFVFL\nRNFSLMLLRY"
38
+ assert_equal(str, Bio::Sequence::AA.new(str_n))
39
+ end
40
+
41
+ def test_new_r
42
+ str = "RRLEHTFVFLRNFSLMLLRY"
43
+ str_r = "RRLEHTFVFL\n\rRNFSLMLLRY"
44
+ assert_equal(str, Bio::Sequence::AA.new(str_r))
45
+ end
46
+
47
+ end
48
+
49
+
50
+ class TestSequenceAA < Test::Unit::TestCase
51
+
52
+ def setup
53
+ str = "RRLEHTFVFLRNFSLMLLRY"
54
+ @obj = Bio::Sequence::AA.new(str)
55
+ end
56
+
57
+ def test_to_s
58
+ str = "RRLEHTFVFLRNFSLMLLRY"
59
+ assert_equal(str, @obj.to_s)
60
+ end
61
+
62
+ def test_molecular_weight
63
+ assert_in_delta(2612.105, @obj.molecular_weight, 1e-4)
64
+ end
65
+
66
+ def test_to_re
67
+ re = /RRLEHTFVFLRNFSLMLLRY/
68
+ assert_equal(re, @obj.to_re)
69
+ @obj[1, 1] = 'B'
70
+ re = /R[DN]LEHTFVFLRNFSLMLLRY/
71
+ assert_equal(re, @obj.to_re)
72
+ end
73
+
74
+ def test_codes
75
+ ary = ["Arg", "Arg", "Leu", "Glu", "His", "Thr", "Phe", "Val",
76
+ "Phe", "Leu", "Arg", "Asn", "Phe", "Ser", "Leu", "Met",
77
+ "Leu", "Leu", "Arg", "Tyr"]
78
+ assert_equal(ary, @obj.codes)
79
+ end
80
+
81
+ def test_names
82
+ ary = ["arginine", "arginine", "leucine", "glutamic acid",
83
+ "histidine", "threonine", "phenylalanine", "valine",
84
+ "phenylalanine", "leucine", "arginine", "asparagine",
85
+ "phenylalanine", "serine", "leucine", "methionine",
86
+ "leucine", "leucine", "arginine", "tyrosine"]
87
+ assert_equal(ary, @obj.names)
88
+ end
89
+ end
90
+
91
+
92
+
93
+ require 'bio/sequence/aa'
94
+
95
+ class TestSequenceAACompat < Test::Unit::TestCase
96
+ def test_aa_self_randomize
97
+ composition = Bio::Sequence::AA.new("WWDTGAK").composition
98
+ assert(Bio::Sequence::AA.randomize(composition))
99
+ end
100
+ end
101
+
102
+ end
@@ -0,0 +1,178 @@
1
+ #
2
+ # test/unit/bio/sequence/test_common.rb - Unit test for Bio::Sequencce::Common
3
+ #
4
+ # Copyright (C) 2006 Mitsuteru C. Nakao <n@bioruby.org>
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # $Id: test_common.rb,v 1.2 2006/02/07 16:53:08 nakao Exp $
21
+ #
22
+
23
+ require 'pathname'
24
+ libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
25
+ $:.unshift(libpath) unless $:.include?(libpath)
26
+
27
+ require 'test/unit'
28
+ require 'bio/sequence'
29
+ require 'bio/sequence/common'
30
+
31
+ module Bio
32
+
33
+ class TSequence < String
34
+ include Bio::Sequence::Common
35
+ end
36
+
37
+ class TestSequenceCommon < Test::Unit::TestCase
38
+
39
+ def setup
40
+ @obj = TSequence.new('atgcatgcatgcatgcaaaa')
41
+ end
42
+
43
+ def test_to_s
44
+ assert_equal('atgcatgcatgcatgcaaaa', @obj.to_s)
45
+ end
46
+
47
+ def test_seq
48
+ str = "atgcatgcatgcatgcaaaa"
49
+ assert_equal(str, @obj.seq)
50
+ end
51
+
52
+
53
+ # <<(*arg)
54
+ def test_push
55
+ str = "atgcatgcatgcatgcaaaaA"
56
+ assert_equal(str, @obj << "A")
57
+ end
58
+
59
+ # +(*arg)
60
+ def test_sum
61
+ str = "atgcatgcatgcatgcaaaaatgcatgcatgcatgcaaaa"
62
+ assert_equal(str, @obj + @obj)
63
+ end
64
+
65
+ # window_search(window_size, step_size = 1)
66
+ def test_window_search
67
+ @obj.window_search(4) do |subseq|
68
+ assert_equal(20, @obj.size)
69
+ end
70
+ end
71
+
72
+ #total(hash)
73
+ def test_total
74
+ hash = {'a' => 1, 'c' => 2, 'g' => 4, 't' => 3}
75
+ assert_equal(44.0, @obj.total(hash))
76
+ end
77
+
78
+ def test_composition
79
+ composition = {"a"=>8, "c"=>4, "g"=>4, "t"=>4}
80
+ assert_equal(composition, @obj.composition)
81
+ end
82
+
83
+ def test_splicing
84
+ #(position)
85
+ assert_equal("atgcatgc", @obj.splicing("join(1..4, 13..16)"))
86
+ end
87
+ end
88
+
89
+
90
+ class TestSequenceCommonNormalize < Test::Unit::TestCase
91
+ def test_no_normalize
92
+ str = "atgcatgcatgcatgcaaaA"
93
+ obj = Bio::TSequence.new(str)
94
+ assert_equal("atgcatgcatgcatgcaaaA", obj)
95
+ end
96
+
97
+ def test_normalize_A
98
+ str = "atgcatgcatgcatgcaaaA"
99
+ seq = Bio::TSequence.new(str)
100
+ assert_equal("atgcatgcatgcatgcaaaA", seq)
101
+ obj = seq.normalize!
102
+ assert_equal("atgcatgcatgcatgcaaaA", obj)
103
+ end
104
+
105
+ def test_normalize_a
106
+ str = "atgcatgcatgcatgcaaa"
107
+ seq = Bio::TSequence.new(str)
108
+ assert_equal("atgcatgcatgcatgcaaa", seq)
109
+ obj = seq.normalize!
110
+ assert_equal("atgcatgcatgcatgcaaa", obj)
111
+ end
112
+ end
113
+
114
+
115
+ class TestSequenceCommonRansomize < Test::Unit::TestCase
116
+
117
+ def test_self_randomize
118
+ # self.randomize(*arg, &block)
119
+ end
120
+
121
+ def test_randomize
122
+ #randomize(hash = nil)
123
+ end
124
+
125
+ end
126
+
127
+
128
+ class TestSequenceCommonSubseq < Test::Unit::TestCase
129
+ #def subseq(s = 1, e = self.length)
130
+
131
+ def test_to_s_returns_self_as_string
132
+ s = "abcefghijklmnop"
133
+ sequence = TSequence.new(s)
134
+ assert_equal(s, sequence.to_s, "wrong value")
135
+ assert_instance_of(String, sequence.to_s, "not a String")
136
+ end
137
+
138
+ def test_subseq_returns_RuntimeError_blank_sequence_default_end
139
+ sequence = TSequence.new("")
140
+ assert_raise(RuntimeError) { sequence.subseq(5) }
141
+ end
142
+
143
+ def test_subseq_returns_RuntimeError_start_less_than_one
144
+ sequence = TSequence.new("blahblah")
145
+ assert_raise(RuntimeError) { sequence.subseq(0) }
146
+ end
147
+
148
+ def test_subseq_returns_subsequence
149
+ sequence = TSequence.new("hahasubhehe")
150
+ assert_equal("sub", sequence.subseq(5,7))
151
+ end
152
+
153
+ end
154
+
155
+
156
+ # Test Sequence#window_wearch
157
+ class TestSequenceCommonWindowSearch < Test::Unit::TestCase
158
+
159
+ def test_window_search_with_width_3_default_step_no_residual
160
+ sequence = TSequence.new("agtca")
161
+ windows = []
162
+ returned_value = sequence.window_search(3) { |window| windows << window }
163
+ assert_equal(["agt", "gtc", "tca"], windows, "windows wrong")
164
+ assert_equal("", returned_value, "returned value wrong")
165
+ end
166
+
167
+ # added
168
+ def test_window_search_with_width_3_step_two_with_residual
169
+ sequence = TSequence.new("agtcat")
170
+ windows = []
171
+ returned_value = sequence.window_search(3, 2) { |window| windows << window }
172
+ assert_equal(["agt", "tca"], windows, "windows wrong")
173
+ assert_equal("t", returned_value, "returned value wrong")
174
+ end
175
+
176
+ end
177
+
178
+ end
@@ -0,0 +1,82 @@
1
+ #
2
+ # test/unit/bio/sequence/test_compat.rb - Unit test for Bio::Sequencce::Compat
3
+ #
4
+ # Copyright (C) 2006 Mitsuteru C. Nakao <n@bioruby.org>
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # $Id: test_compat.rb,v 1.1 2006/02/05 17:39:27 nakao Exp $
21
+ #
22
+
23
+ require 'pathname'
24
+ libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
25
+ $:.unshift(libpath) unless $:.include?(libpath)
26
+
27
+ require 'test/unit'
28
+ require 'bio/sequence'
29
+ require 'bio/sequence/compat'
30
+
31
+ module Bio
32
+
33
+ class TSequence < String
34
+ include Bio::Sequence::Common
35
+ end
36
+
37
+
38
+ class TestSequenceCompat < Test::Unit::TestCase
39
+
40
+ def setup
41
+ @obj = TSequence.new('atgcatgcatgcatgcaaaa')
42
+ end
43
+
44
+ def test_to_s
45
+ str = 'atgcatgcatgcatgcaaaa'
46
+ assert_equal(str, @obj.to_s)
47
+ end
48
+ end
49
+
50
+
51
+ class TestSequenceCommonCompat < Test::Unit::TestCase
52
+
53
+ # Test Sequence#to_fasta
54
+ def test_to_fasta
55
+ sequence = TSequence.new("agtc" * 10)
56
+ header = "the header"
57
+ str = ">the header\n" + ("agtc" * 5) + "\n" + ("agtc" * 5) + "\n"
58
+ assert_equal(str, sequence.to_fasta(header, 20))
59
+ end
60
+
61
+ end
62
+
63
+
64
+ require 'bio/sequence/na'
65
+
66
+ class TestSequenceNACompat < Test::Unit::TestCase
67
+ def test_na_self_randomize
68
+ composition = Bio::Sequence::NA.new("acgtacgt").composition
69
+ assert(Bio::Sequence::NA.randomize(composition))
70
+ end
71
+ end
72
+
73
+ require 'bio/sequence/aa'
74
+
75
+ class TestSequenceNACompat < Test::Unit::TestCase
76
+ def test_aa_self_randomize
77
+ composition = Bio::Sequence::AA.new("WWDTGAK").composition
78
+ assert(Bio::Sequence::AA.randomize(composition))
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,242 @@
1
+ #
2
+ # = test/unit/bio/sequence/test_na.rb - Unit test for Bio::Sequencce::NA
3
+ #
4
+ # Copyright:: Copyright (C) 2006
5
+ # Mitsuteru C. Nakao <n@bioruby.org>
6
+ # Lisence:: Ruby's
7
+ #
8
+ # $Id: test_na.rb,v 1.1 2006/02/08 07:08:22 nakao Exp $
9
+ #
10
+
11
+ require 'pathname'
12
+ libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
13
+ $:.unshift(libpath) unless $:.include?(libpath)
14
+
15
+ require 'test/unit'
16
+ require 'bio/sequence'
17
+ require 'bio/sequence/na'
18
+
19
+ module Bio
20
+
21
+ class TestSequenceNANew < Test::Unit::TestCase
22
+ def test_new
23
+ str = 'atgcatgcatgcatgcaaaa'
24
+ assert(Bio::Sequence::NA.new(str))
25
+ end
26
+
27
+ def test_new_t
28
+ str = "atgcatgcatgcatgcaaaa"
29
+ str_t = "atgcatgcat\tgca\ttgcaaaa"
30
+ assert_equal(str, Bio::Sequence::NA.new(str_t))
31
+ end
32
+
33
+ def test_new_n
34
+ str = "atgcatgcatgcatgcaaaa"
35
+ str_n = "atgcatgcat\ngca\ntgcaaaa"
36
+ assert_equal(str, Bio::Sequence::NA.new(str_n))
37
+ end
38
+
39
+ def test_new_r
40
+ str = "atgcatgcatgcatgcaaaa"
41
+ str_r = "atgcatgcat\n\rgca\n\rtgcaaaa"
42
+ assert_equal(str, Bio::Sequence::NA.new(str_r))
43
+ end
44
+
45
+ end
46
+
47
+ class TestSequenceNA < Test::Unit::TestCase
48
+
49
+ def setup
50
+ @obj = Bio::Sequence::NA.new('atgcatgcatgcatgcaaaa')
51
+ end
52
+
53
+ def test_splicing
54
+ # 'atgcatgcatgcatgcaaaa'
55
+ # 12345678901234567890
56
+ str = 'atgca catgcatg'.gsub(' ','')
57
+ assert_equal(str, @obj.splicing("join(1..5,8..15)"))
58
+ end
59
+
60
+ def test_forward_complement
61
+ str = 'atgcatgcatgcatgcaaaa'
62
+ str_fcomp = 'tacgtacgtacgtacgtttt'
63
+ fcomp = @obj.forward_complement
64
+ assert_equal(str_fcomp, @obj.forward_complement)
65
+ assert_equal(str, @obj)
66
+ assert_equal(str_fcomp, @obj.forward_complement!)
67
+ assert_equal(str_fcomp, @obj)
68
+ end
69
+
70
+ def test_reverse_complement
71
+ str = 'atgcatgcatgcatgcaaaa'
72
+ str_rcomp = 'tacgtacgtacgtacgtttt'.reverse
73
+ rcomp = @obj.forward_complement
74
+ assert_equal(str_rcomp, @obj.reverse_complement)
75
+ assert_equal(str, @obj)
76
+ assert_equal(str_rcomp, @obj.reverse_complement!)
77
+ assert_equal(str_rcomp, @obj)
78
+ end
79
+
80
+ def test_complement
81
+ assert(@obj.complement)
82
+ assert(@obj.complement!)
83
+ end
84
+
85
+ def test_to_s
86
+ str = 'atgcatgcatgcatgcaaaa'
87
+ assert_equal(str, @obj.to_s)
88
+ end
89
+
90
+ def test_codon_usage
91
+ usage = {"cat"=>1, "caa"=>1, "tgc"=>1, "gca"=>1, "atg"=>2}
92
+ assert_equal(usage, @obj.codon_usage)
93
+ end
94
+
95
+ def test_gc_percent
96
+ assert_equal(40, @obj.gc_percent)
97
+ @obj[0, 1] = 'g'
98
+ assert_equal(45, @obj.gc_percent)
99
+ end
100
+
101
+ def test_iliegal_bases
102
+ @obj[0, 1] = 'n'
103
+ @obj[1, 1] = 'y'
104
+ assert_equal(['n', 'y'], @obj.illegal_bases)
105
+ end
106
+
107
+ def test_molecular_weight
108
+ assert_in_delta(6174.3974, @obj.molecular_weight, 1e-4)
109
+ end
110
+
111
+ def test_to_re
112
+ assert_equal(/atgcatgcatgcatgcaaaa/, @obj.to_re)
113
+ @obj[1,1] = 'n'
114
+ @obj[2,1] = 'r'
115
+ @obj[3,1] = 's'
116
+ @obj[4,1] = 'y'
117
+ @obj[5,1] = 'w'
118
+ assert_equal(/a[atgc][ag][gc][tc][at]gcatgcatgcaaaa/, @obj.to_re)
119
+ end
120
+
121
+ def test_names
122
+ ary = ["Adenine", "Thymine", "Guanine"]
123
+ assert_equal(ary , @obj.splice("1..3").names)
124
+ end
125
+
126
+ def test_dna
127
+ @obj[0,1] = 'u'
128
+ assert_equal('utgcatgcatgcatgcaaaa', @obj)
129
+ assert_equal('ttgcatgcatgcatgcaaaa', @obj.dna)
130
+ end
131
+
132
+ def test_dna!
133
+ @obj[0,1] = 'u'
134
+ assert_equal('utgcatgcatgcatgcaaaa', @obj)
135
+ @obj.dna!
136
+ assert_equal('ttgcatgcatgcatgcaaaa', @obj)
137
+ end
138
+
139
+ def test_rna
140
+ assert_equal('atgcatgcatgcatgcaaaa', @obj)
141
+ assert_equal('augcaugcaugcaugcaaaa', @obj.rna)
142
+ end
143
+
144
+ def test_rna!
145
+ assert_equal('atgcatgcatgcatgcaaaa', @obj)
146
+ @obj.rna!
147
+ assert_equal('augcaugcaugcaugcaaaa', @obj)
148
+ end
149
+
150
+ end
151
+
152
+ class TestSequenceNATranslation < Test::Unit::TestCase
153
+ def setup
154
+
155
+ str = "aaacccgggttttaa"
156
+ # K>>P>>G>>F>>*>>
157
+ # N>>P>>G>>F>>
158
+ # T>>R>>V>>L>>
159
+ # P>>G>>F>>*>>
160
+ # "tttgggcccaaaatt"
161
+ # <<F<<G<<P<<K<<L
162
+ # <<G<<P<<N<<*
163
+ # <<V<<R<<T<<K
164
+ @obj = Bio::Sequence::NA.new(str)
165
+ end
166
+
167
+ def test_translate
168
+ assert_equal("KPGF*", @obj.translate)
169
+ end
170
+
171
+ def test_translate_1
172
+ assert_equal("KPGF*", @obj.translate(1))
173
+ end
174
+
175
+ def test_translate_2
176
+ assert_equal("NPGF", @obj.translate(2))
177
+ end
178
+
179
+ def test_translate_3
180
+ assert_equal("TRVL", @obj.translate(3))
181
+ end
182
+
183
+ def test_translate_4
184
+ assert_equal("LKPGF", @obj.translate(4))
185
+ end
186
+
187
+ def test_translate_5
188
+ assert_equal("*NPG", @obj.translate(5))
189
+ end
190
+
191
+ def test_translate_6
192
+ assert_equal("KTRV", @obj.translate(6))
193
+ end
194
+
195
+ def test_translate_7
196
+ assert_equal("KPGF*", @obj.translate(7))
197
+ assert_equal(@obj.translate, @obj.translate(7))
198
+ end
199
+
200
+ def test_translate_n1
201
+ assert_equal("LKPGF", @obj.translate(-1))
202
+ assert_equal(@obj.translate(4), @obj.translate(-1))
203
+ end
204
+
205
+ def test_translate_n2
206
+ assert_equal("*NPG", @obj.translate(-2))
207
+ assert_equal(@obj.translate(5), @obj.translate(-2))
208
+ end
209
+
210
+ def test_translate_n3
211
+ assert_equal("KTRV", @obj.translate(-3))
212
+ assert_equal(@obj.translate(6), @obj.translate(-3))
213
+ end
214
+
215
+ def test_translate_0
216
+ assert_equal("KPGF*", @obj.translate(0))
217
+ assert_equal(@obj.translate, @obj.translate(0))
218
+ assert_equal(@obj.translate(7), @obj.translate(0))
219
+ end
220
+
221
+ def test_translate_unknown_x
222
+ @obj[3, 1] = 'N'
223
+ assert_equal("KXGF*", @obj.translate)
224
+ end
225
+
226
+ def test_translate_unknown_o
227
+ @obj[3, 1] = 'N'
228
+ assert_equal("KOGF*", @obj.translate(1, 1, 'O'))
229
+ end
230
+
231
+ def test_translate_given_codon_table
232
+ @obj[0, 1] = 't'
233
+ @obj[1, 1] = 'g'
234
+ @obj[2, 1] = 'a'
235
+ seleno_ct = Bio::CodonTable.copy(1)
236
+ seleno_ct['tga'] = 'U'
237
+ assert_equal("UPGF*", @obj.translate(1, seleno_ct))
238
+ end
239
+
240
+ end
241
+
242
+ end