bio 1.4.0 → 1.4.1

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 (82) hide show
  1. data/ChangeLog +1712 -0
  2. data/KNOWN_ISSUES.rdoc +11 -1
  3. data/README.rdoc +3 -2
  4. data/RELEASE_NOTES.rdoc +65 -127
  5. data/bioruby.gemspec +38 -2
  6. data/doc/RELEASE_NOTES-1.4.0.rdoc +167 -0
  7. data/doc/Tutorial.rd +74 -16
  8. data/doc/Tutorial.rd.html +68 -16
  9. data/lib/bio.rb +2 -0
  10. data/lib/bio/appl/clustalw/report.rb +18 -0
  11. data/lib/bio/appl/paml/codeml/report.rb +579 -21
  12. data/lib/bio/command.rb +149 -21
  13. data/lib/bio/db/aaindex.rb +11 -1
  14. data/lib/bio/db/embl/sptr.rb +1 -1
  15. data/lib/bio/db/fasta/defline.rb +7 -2
  16. data/lib/bio/db/fasta/qual.rb +24 -0
  17. data/lib/bio/db/fasta/qual_to_biosequence.rb +29 -0
  18. data/lib/bio/db/fastq.rb +15 -0
  19. data/lib/bio/db/go.rb +2 -2
  20. data/lib/bio/db/kegg/common.rb +109 -5
  21. data/lib/bio/db/kegg/genes.rb +61 -15
  22. data/lib/bio/db/kegg/genome.rb +43 -38
  23. data/lib/bio/db/kegg/module.rb +158 -0
  24. data/lib/bio/db/kegg/orthology.rb +40 -1
  25. data/lib/bio/db/kegg/pathway.rb +254 -0
  26. data/lib/bio/db/medline.rb +6 -2
  27. data/lib/bio/io/flatfile/autodetection.rb +6 -0
  28. data/lib/bio/location.rb +39 -0
  29. data/lib/bio/reference.rb +24 -0
  30. data/lib/bio/sequence.rb +2 -0
  31. data/lib/bio/sequence/adapter.rb +1 -0
  32. data/lib/bio/sequence/format.rb +14 -0
  33. data/lib/bio/sequence/sequence_masker.rb +95 -0
  34. data/lib/bio/tree.rb +4 -4
  35. data/lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb +5 -0
  36. data/lib/bio/version.rb +1 -1
  37. data/setup.rb +5 -0
  38. data/test/data/KEGG/K02338.orthology +180 -52
  39. data/test/data/KEGG/M00118.module +44 -0
  40. data/test/data/KEGG/T00005.genome +140 -0
  41. data/test/data/KEGG/T00070.genome +34 -0
  42. data/test/data/KEGG/b0529.gene +47 -0
  43. data/test/data/KEGG/ec00072.pathway +23 -0
  44. data/test/data/KEGG/hsa00790.pathway +59 -0
  45. data/test/data/KEGG/ko00312.pathway +16 -0
  46. data/test/data/KEGG/map00030.pathway +37 -0
  47. data/test/data/KEGG/map00052.pathway +13 -0
  48. data/test/data/KEGG/rn00250.pathway +114 -0
  49. data/test/data/clustalw/example1.aln +58 -0
  50. data/test/data/go/selected_component.ontology +12 -0
  51. data/test/data/go/selected_gene_association.sgd +31 -0
  52. data/test/data/go/selected_wikipedia2go +13 -0
  53. data/test/data/medline/20146148_modified.medline +54 -0
  54. data/test/data/paml/codeml/models/aa.aln +26 -0
  55. data/test/data/paml/codeml/models/aa.dnd +13 -0
  56. data/test/data/paml/codeml/models/aa.ph +13 -0
  57. data/test/data/paml/codeml/models/alignment.phy +49 -0
  58. data/test/data/paml/codeml/models/results0-3.txt +312 -0
  59. data/test/data/paml/codeml/models/results7-8.txt +340 -0
  60. data/test/functional/bio/io/test_togows.rb +8 -8
  61. data/test/functional/bio/test_command.rb +7 -6
  62. data/test/unit/bio/appl/clustalw/test_report.rb +80 -0
  63. data/test/unit/bio/appl/paml/codeml/test_rates.rb +6 -6
  64. data/test/unit/bio/appl/paml/codeml/test_report.rb +231 -24
  65. data/test/unit/bio/appl/paml/codeml/test_report_single.rb +46 -0
  66. data/test/unit/bio/db/embl/test_sptr.rb +1 -1
  67. data/test/unit/bio/db/fasta/test_defline.rb +160 -0
  68. data/test/unit/bio/db/fasta/test_defline_misc.rb +490 -0
  69. data/test/unit/bio/db/kegg/test_genes.rb +281 -1
  70. data/test/unit/bio/db/kegg/test_genome.rb +408 -0
  71. data/test/unit/bio/db/kegg/test_module.rb +246 -0
  72. data/test/unit/bio/db/kegg/test_orthology.rb +95 -0
  73. data/test/unit/bio/db/kegg/test_pathway.rb +1250 -0
  74. data/test/unit/bio/db/test_aaindex.rb +8 -7
  75. data/test/unit/bio/db/test_fastq.rb +36 -0
  76. data/test/unit/bio/db/test_go.rb +171 -0
  77. data/test/unit/bio/db/test_medline.rb +148 -0
  78. data/test/unit/bio/db/test_qual.rb +9 -2
  79. data/test/unit/bio/sequence/test_sequence_masker.rb +169 -0
  80. data/test/unit/bio/test_tree.rb +260 -1
  81. data/test/unit/bio/util/test_contingency_table.rb +7 -7
  82. metadata +53 -6
@@ -162,11 +162,11 @@ module Bio
162
162
  end
163
163
 
164
164
  def test_matrix_1_2
165
- assert_equal(nil, @obj.matrix[1, 2])
165
+ assert_equal(0.0, @obj.matrix[1, 2])
166
166
  end
167
167
 
168
168
  def test_access_A_R
169
- assert_equal(nil, @obj['A', 'R'])
169
+ assert_equal(-2.0, @obj['A', 'R'])
170
170
  end
171
171
 
172
172
  def test_access_R_A
@@ -174,7 +174,7 @@ module Bio
174
174
  end
175
175
 
176
176
  def test_matrix_A_R
177
- assert_equal(nil, @obj.matrix('A', 'R'))
177
+ assert_equal(-2.0, @obj.matrix('A', 'R'))
178
178
  end
179
179
 
180
180
  def test_matrix_R_A
@@ -182,16 +182,17 @@ module Bio
182
182
  end
183
183
 
184
184
  def test_matrix_determinant
185
- assert_equal(0, @obj.matrix.determinant)
185
+ assert_in_delta(27926521998.0, @obj.matrix.determinant, 1e-3)
186
186
  end
187
187
 
188
188
  def test_matrix_rank
189
- assert_equal(1, @obj.matrix.rank)
189
+ assert_equal(20, @obj.matrix.rank)
190
190
  end
191
191
 
192
192
  def test_matrix_transpose
193
- ary = Matrix[[2.0, -2.0, 0.0, 0.0, -2.0, 0.0, 0.0, 1.0, -1.0, -1.0, -2.0, -1.0, -1.0, -4.0, 1.0, 1.0, 1.0, -6.0, -3.0, 0.0]]
194
- assert_equal(ary, @obj.matrix.transpose)
193
+ assert_equal(@obj.matrix, @obj.matrix.transpose)
194
+ ary = Matrix.row_vector([2.0, -2.0, 0.0, 0.0, -2.0, 0.0, 0.0, 1.0, -1.0, -1.0, -2.0, -1.0, -1.0, -4.0, 1.0, 1.0, 1.0, -6.0, -3.0, 0.0]).row(0)
195
+ assert_equal(ary, @obj.matrix.transpose.row(0))
195
196
  end
196
197
  end
197
198
  end
@@ -823,6 +823,42 @@ _9_
823
823
  ERRORS = [ Bio::Fastq::Error::No_qual.new ]
824
824
  end #class TestFastq_error_trunc_at_seq
825
825
 
826
+ # Unit tests for Bio::Fastq#mask.
827
+ class TestFastq_mask < Test::Unit::TestCase
828
+ def setup
829
+ fn = File.join(TestFastqDataDir, 'wrapping_original_sanger.fastq')
830
+ Bio::FlatFile.open(Bio::Fastq, fn) do |ff|
831
+ @entry = ff.next_entry
832
+ end
833
+ @entry.format = :fastq_sanger
834
+ end
835
+
836
+ def test_mask_60
837
+ expected = 'n' * 135
838
+ assert_equal(expected, @entry.mask(60).seq)
839
+ end
840
+
841
+ def test_mask_20
842
+ expected = "GAAnTTnCAGGnCCACCTTTnnnnnGATAGAATAATGGAGAAnnTTAAAnGCTGTACATATACCAATGAACAATAAnTCAATACATAAAnnnGGAGAAGTnGGAACCGAAnGGnTTnGAnTTCAAnCCnTTnCGn"
843
+ assert_equal(expected, @entry.mask(20).seq)
844
+ end
845
+
846
+ def test_mask_20_with_x
847
+ expected = "GAAxTTxCAGGxCCACCTTTxxxxxGATAGAATAATGGAGAAxxTTAAAxGCTGTACATATACCAATGAACAATAAxTCAATACATAAAxxxGGAGAAGTxGGAACCGAAxGGxTTxGAxTTCAAxCCxTTxCGx"
848
+ assert_equal(expected, @entry.mask(20, 'x').seq)
849
+ end
850
+
851
+ def test_mask_20_with_empty_string
852
+ expected = "GAATTCAGGCCACCTTTGATAGAATAATGGAGAATTAAAGCTGTACATATACCAATGAACAATAATCAATACATAAAGGAGAAGTGGAACCGAAGGTTGATTCAACCTTCG"
853
+ assert_equal(expected, @entry.mask(20, '').seq)
854
+ end
855
+
856
+ def test_mask_20_with_longer_string
857
+ expected = "GAA-*-TT-*-CAGG-*-CCACCTTT-*--*--*--*--*-GATAGAATAATGGAGAA-*--*-TTAAA-*-GCTGTACATATACCAATGAACAATAA-*-TCAATACATAAA-*--*--*-GGAGAAGT-*-GGAACCGAA-*-GG-*-TT-*-GA-*-TTCAA-*-CC-*-TT-*-CG-*-"
858
+ assert_equal(expected, @entry.mask(20, '-*-').seq)
859
+ end
860
+
861
+ end #class TestFastq_mask
826
862
 
827
863
  end #module TestFastq
828
864
  end #module Bio
@@ -0,0 +1,171 @@
1
+ #
2
+ # test/unit/bio/db/test_go.rb - Unit test for Bio::GO
3
+ #
4
+ # Copyright:: Copyright (C) 2010 Kazuhiro Hayashi <k.hayashi.info@gmail.com>
5
+ # License:: The Ruby License
6
+ #
7
+
8
+ # loading helper routine for testing bioruby
9
+ require 'pathname'
10
+ load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3,
11
+ 'bioruby_test_helper.rb')).cleanpath.to_s
12
+
13
+ # libraries needed for the tests
14
+ require 'test/unit'
15
+ require 'bio/db/go'
16
+
17
+ module Bio
18
+ class TestBioGOOntology < Test::Unit::TestCase
19
+
20
+ TestDataFileName = File.join(BioRubyTestDataPath,
21
+ 'go', 'selected_component.ontology')
22
+
23
+ def setup
24
+ @obj = Bio::GO::Ontology.new(File.read(TestDataFileName))
25
+ end
26
+
27
+ def test_dag_edit_format_parser
28
+ obj = Bio::GO::Ontology.new(File.read(TestDataFileName))
29
+ assert_equal(Bio::GO::Ontology,obj.class)
30
+ end
31
+ def test_goid2term
32
+ assert_equal('cellular_component', @obj.goid2term('0005575'))
33
+ assert_equal('cellular_component', @obj.goid2term('0008372'))
34
+ end
35
+
36
+ def test_parse_goids
37
+ actual = Bio::GO::Ontology.parse_goids("<cellular_component ; GO:0005575, GO:0008372 ; synonym:cellular component ; synonym:cellular component unknown")
38
+ assert_equal(["0005575", "0008372"], actual)
39
+ end
40
+ end
41
+
42
+ class TestGeneAssociation < Test::Unit::TestCase
43
+
44
+ TestDataFileName = File.join(BioRubyTestDataPath,
45
+ 'go', "selected_gene_association.sgd")
46
+
47
+ def setup
48
+ @ga = Bio::GO::GeneAssociation.new("SGD\tS000007287\t15S_RRNA\t\tGO:0005763\tSGD_REF:S000073642|PMID:6261980\tISS\t\tC\tRibosomal RNA of the small mitochondrial ribosomal subunit\t15S_rRNA|15S_RRNA_2\tgene\ttaxon:4932\t20040202\tSGD\t\t")
49
+ end
50
+
51
+ def test_parser
52
+ file = File.read(TestDataFileName)
53
+ gas = Bio::GO::GeneAssociation.parser(file)
54
+ gas.map{ |ga| assert_equal(Bio::GO::GeneAssociation, ga.class) }
55
+ Bio::GO::GeneAssociation.parser(file) {|ga| assert_equal(Bio::GO::GeneAssociation, ga.class) }
56
+ end
57
+
58
+ def test_goid
59
+ assert_equal("0005763", @ga.goid)
60
+ assert_equal("GO:0005763", @ga.goid(true))
61
+ end
62
+ def test_to_str
63
+ #Bio::GO::GeneAssociation#to_str probably has an error.
64
+ #
65
+ assert_equal("SGD\tS000007287\t15S_RRNA\t\tGO:0005763\tSGD_REF:S000073642|PMID:6261980\tISS\t\tC\tRibosomal RNA of the small mitochondrial ribosomal subunit\t15S_rRNA|15S_RRNA_2\tgene\ttaxon:4932\t20040202\tSGD",@ga.to_str)
66
+ end
67
+ def test_db
68
+ assert_equal("SGD",@ga.db)
69
+ end
70
+ def test_db_object_id
71
+ assert_equal("S000007287",@ga.db_object_id)
72
+ end
73
+ def test_db_object_symbol
74
+ assert_equal("15S_RRNA",@ga.db_object_symbol)
75
+ end
76
+ def test_qualifier
77
+ assert_equal("",@ga.qualifier)
78
+ end
79
+ def test_db_reference
80
+ assert_equal(["SGD_REF:S000073642", "PMID:6261980"],@ga.db_reference)
81
+ end
82
+ def test_evidence
83
+ assert_equal("ISS",@ga.evidence)
84
+ end
85
+ def test_with
86
+ assert_equal([],@ga.with)
87
+ end
88
+ def test_aspect
89
+ assert_equal("C",@ga.aspect)
90
+ end
91
+ def test_db_object_name
92
+ assert_equal("Ribosomal RNA of the small mitochondrial ribosomal subunit",@ga.db_object_name)
93
+ end
94
+ def test_db_object_synonym
95
+ assert_equal(["15S_rRNA", "15S_RRNA_2"],@ga.db_object_synonym)
96
+ end
97
+ def test_db_object_type
98
+ assert_equal("gene",@ga.db_object_type)
99
+ end
100
+ def test_taxon
101
+ assert_equal("taxon:4932",@ga.taxon)
102
+ end
103
+ def test_date
104
+ assert_equal("20040202",@ga.date)
105
+ end
106
+ def test_assigned_by
107
+ assert_equal("SGD",@ga.assigned_by)
108
+ end
109
+
110
+ end
111
+
112
+ class External2go < Test::Unit::TestCase
113
+
114
+ TestDataFileName = File.join(BioRubyTestDataPath,
115
+ 'go', "selected_wikipedia2go")
116
+
117
+ def setup
118
+ file = File.read(TestDataFileName)
119
+ @e2g = Bio::GO::External2go.parser(file)
120
+ end
121
+ def test_parser
122
+ expected = [{:go_id=>"GO:0003845",
123
+ :db=>"Wikipedia",
124
+ :db_id=>"11beta-hydroxysteroid_dehydrogenase",
125
+ :go_term=>"11-beta-hydroxysteroid dehydrogenase activity"},
126
+ {:go_id=>"GO:0047414",
127
+ :db=>"Wikipedia",
128
+ :db_id=>
129
+ "2-(hydroxymethyl)-3-(acetamidomethylene)succinate_amidohydrolase_(deaminating\\,_decarboxylating)",
130
+ :go_term=>
131
+ "2-(hydroxymethyl)-3-(acetamidomethylene)succinate hydrolase activity"},
132
+ {:go_id=>"GO:0043718",
133
+ :db=>"Wikipedia",
134
+ :db_id=>"2-hydroxymethylglutarate_dehydrogenase",
135
+ :go_term=>"2-hydroxymethylglutarate dehydrogenase activity"}]
136
+ file = File.read(TestDataFileName)
137
+ e2g = Bio::GO::External2go.parser(file)
138
+ assert_equal(expected, e2g)
139
+ assert_raise(RuntimeError){ Bio::GO::External2go.parser("probably this occurs error")}
140
+ end
141
+ def test_set_date
142
+ e2g = Bio::GO::External2go.new
143
+ e2g.set_date("$Date: 2010/06/11 01:01:37 $")
144
+ assert_equal("$Date: 2010/06/11 01:01:37 $",e2g.header[:date])
145
+ end
146
+ def test_set_desc
147
+ e2g = Bio::GO::External2go.new
148
+ e2g.set_desc([" Mapping of Gene Ontology terms to Wikipedia entries."," Wikipedia: http://en.wikipedia.org"])
149
+ assert_equal([" Mapping of Gene Ontology terms to Wikipedia entries."," Wikipedia: http://en.wikipedia.org"],e2g.header[:desc])
150
+ end
151
+ def test_to_str
152
+ assert_equal("!date: \n! version: $Revision: 1.17 $\n! date: $Date: 2010/06/11 01:01:37 $\n!\n! Generated from file ontology/editors/gene_ontology_write.obo,\n! CVS revision: 1.1296; date: 10:06:2010 16:16\n!\n! Mapping of Gene Ontology terms to Wikipedia entries.\n! Wikipedia: http://en.wikipedia.org\n! Last update at Thu Jun 10 17:21:44 2010 by the script /users/cjm/cvs/go-moose/bin/daily_from_obo.pl\n!\nWikipedia:11beta-hydroxysteroid_dehydrogenase > GO:11-beta-hydroxysteroid dehydrogenase activity ; GO:0003845\nWikipedia:2-(hydroxymethyl)-3-(acetamidomethylene)succinate_amidohydrolase_(deaminating\\,_decarboxylating) > GO:2-(hydroxymethyl)-3-(acetamidomethylene)succinate hydrolase activity ; GO:0047414\nWikipedia:2-hydroxymethylglutarate_dehydrogenase > GO:2-hydroxymethylglutarate dehydrogenase activity ; GO:0043718", @e2g.to_str)
153
+ end
154
+ def test_dbs
155
+ assert_equal(["Wikipedia"], @e2g.dbs)
156
+ end
157
+ def test_db_ids
158
+ assert_equal(["11beta-hydroxysteroid_dehydrogenase",
159
+ "2-(hydroxymethyl)-3-(acetamidomethylene)succinate_amidohydrolase_(deaminating\\,_decarboxylating)",
160
+ "2-hydroxymethylglutarate_dehydrogenase"], @e2g.db_ids)
161
+ end
162
+ def test_go_terms
163
+ assert_equal(["11-beta-hydroxysteroid dehydrogenase activity",
164
+ "2-(hydroxymethyl)-3-(acetamidomethylene)succinate hydrolase activity",
165
+ "2-hydroxymethylglutarate dehydrogenase activity"], @e2g.go_terms)
166
+ end
167
+ def test_go_ids
168
+ assert_equal(["GO:0003845", "GO:0047414", "GO:0043718"], @e2g.go_ids)
169
+ end
170
+ end
171
+ end
@@ -12,9 +12,157 @@ load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3,
12
12
 
13
13
  # libraries needed for the tests
14
14
  require 'test/unit'
15
+ require 'bio/reference'
15
16
  require 'bio/db/medline'
16
17
 
17
18
  module Bio
19
+ class TestMEDLINE_20146148 < Test::Unit::TestCase
20
+
21
+ def setup
22
+ filename = File.join(BioRubyTestDataPath, 'medline',
23
+ '20146148_modified.medline')
24
+ @obj = Bio::MEDLINE.new(File.read(filename))
25
+ end
26
+
27
+ def test_self_new
28
+ assert_instance_of(Bio::MEDLINE, @obj)
29
+ end
30
+
31
+ def test_reference
32
+ h = {
33
+ 'authors' => ["Mattsson, M.", "Summala, H."],
34
+ 'affiliations' =>
35
+ [ "Traffic Research Unit, Department of Psychology, University of Helsinki, Finland. markus.mattsson@helsinki.fi" ],
36
+ 'journal' => "Traffic Inj Prev",
37
+ 'title' =>
38
+ "With power comes responsibility: motorcycle engine power and power-to-weight ratio in relation to accident risk.",
39
+ 'pages' => '87-95',
40
+ 'issue' => "1",
41
+ 'volume' => "11",
42
+ 'year' => "2010",
43
+ 'pubmed' => "20146148",
44
+ 'mesh' =>
45
+ [ "Accidents, Traffic/mortality/*statistics & numerical data",
46
+ "Adult",
47
+ "Age Distribution",
48
+ "Body Weight",
49
+ "Female",
50
+ "Finland/epidemiology",
51
+ "Humans",
52
+ "Linear Models",
53
+ "Male",
54
+ "Motorcycles/classification/legislation & jurisprudence/*statistics & numerical data",
55
+ "Questionnaires",
56
+ "Risk",
57
+ "Social Responsibility",
58
+ "Young Adult" ],
59
+ 'abstract' =>
60
+ "(The abstract is omitted to avoid copyright issues. Please find the abstract at http://www.ncbi.nlm.nih.gov/pubmed/20146148. We believe that other information in this entry is within public domain, according to \"Copyright and Disclaimers\" in http://www.ncbi.nlm.nih.gov/About/disclaimer.html.)"
61
+ }
62
+ expected = Bio::Reference.new(h)
63
+ assert_equal(expected, @obj.reference)
64
+ end
65
+
66
+ def test_pmid
67
+ assert_equal("20146148", @obj.pmid)
68
+ end
69
+
70
+ def test_ui
71
+ assert_equal("", @obj.ui)
72
+ end
73
+
74
+ def test_ta
75
+ assert_equal("Traffic Inj Prev", @obj.ta)
76
+ end
77
+
78
+ def test_vi
79
+ assert_equal("11", @obj.vi)
80
+ end
81
+
82
+ def test_ip
83
+ assert_equal("1", @obj.ip)
84
+ end
85
+
86
+ def test_pg
87
+ assert_equal("87-95", @obj.pg)
88
+ end
89
+
90
+ def test_pages
91
+ assert_equal("87-95", @obj.pages)
92
+ end
93
+
94
+ def test_dp
95
+ assert_equal("2010 Feb", @obj.dp)
96
+ end
97
+
98
+ def test_year
99
+ assert_equal("2010", @obj.year)
100
+ end
101
+
102
+ def test_ti
103
+ expected = "With power comes responsibility: motorcycle engine power and power-to-weight ratio in relation to accident risk."
104
+ assert_equal(expected, @obj.ti)
105
+ end
106
+
107
+ def test_ab
108
+ expected = "(The abstract is omitted to avoid copyright issues. Please find the abstract at http://www.ncbi.nlm.nih.gov/pubmed/20146148. We believe that other information in this entry is within public domain, according to \"Copyright and Disclaimers\" in http://www.ncbi.nlm.nih.gov/About/disclaimer.html.)"
109
+ assert_equal(expected, @obj.ab)
110
+ end
111
+
112
+ def test_au
113
+ expected = "Mattsson M\nSummala H"
114
+ assert_equal(expected, @obj.au)
115
+ end
116
+
117
+ def test_authors
118
+ expected = ["Mattsson, M.", "Summala, H."]
119
+ assert_equal(expected, @obj.authors)
120
+ end
121
+
122
+ def test_so
123
+ expected = "Traffic Inj Prev. 2010 Feb;11(1):87-95."
124
+ assert_equal(expected, @obj.so)
125
+ end
126
+
127
+ def test_mh
128
+ expected =
129
+ [ "Accidents, Traffic/mortality/*statistics & numerical data",
130
+ "Adult",
131
+ "Age Distribution",
132
+ "Body Weight",
133
+ "Female",
134
+ "Finland/epidemiology",
135
+ "Humans",
136
+ "Linear Models",
137
+ "Male",
138
+ "Motorcycles/classification/legislation & jurisprudence/*statistics & numerical data",
139
+ "Questionnaires",
140
+ "Risk",
141
+ "Social Responsibility",
142
+ "Young Adult"
143
+ ]
144
+ assert_equal(expected, @obj.mh)
145
+ end
146
+
147
+ def test_ad
148
+ expected = [ "Traffic Research Unit, Department of Psychology, University of Helsinki, Finland. markus.mattsson@helsinki.fi" ]
149
+ assert_equal(expected, @obj.ad)
150
+ end
151
+
152
+ def test_doi
153
+ assert_equal("10.1080/15389580903471126", @obj.doi)
154
+ end
155
+
156
+ def test_pii
157
+ assert_equal("919158438", @obj.pii)
158
+ end
159
+
160
+ def test_pt
161
+ expected = [ "Journal Article", "Research Support, Non-U.S. Gov't" ]
162
+ assert_equal(expected, @obj.pt)
163
+ end
164
+ end #class TestMEDLINE_20146148
165
+
18
166
  class TestMEDLINE < Test::Unit::TestCase
19
167
  def test_authors
20
168
  assert_equal(["Kane, D. W.",
@@ -19,6 +19,8 @@ require 'bio/db/fasta/qual'
19
19
  module Bio
20
20
  class TestFastaNumericFormat < Test::Unit::TestCase
21
21
 
22
+ DATA = [24, 15, 23, 29, 20, 13, 20, 21, 21, 23, 22, 25, 13, 22, 17, 15, 25, 27, 32, 26, 32, 29, 29, 25].freeze
23
+
22
24
  def setup
23
25
  text =<<END
24
26
  >CRA3575282.F
@@ -41,8 +43,7 @@ END
41
43
  end
42
44
 
43
45
  def test_data
44
- data = [24, 15, 23, 29, 20, 13, 20, 21, 21, 23, 22, 25, 13, 22, 17, 15, 25, 27, 32, 26, 32, 29, 29, 25]
45
- assert_equal(data, @obj.data)
46
+ assert_equal(DATA, @obj.data)
46
47
  end
47
48
 
48
49
  def test_length
@@ -58,6 +59,12 @@ END
58
59
  assert(@obj[-1], '')
59
60
  end
60
61
 
62
+ def test_to_biosequence
63
+ assert_instance_of(Bio::Sequence, s = @obj.to_biosequence)
64
+ assert_equal(Bio::Sequence::Generic.new(''), s.seq)
65
+ assert_equal(DATA, s.quality_scores)
66
+ assert_equal(nil, s.quality_score_type)
67
+ end
61
68
 
62
69
  end #class TestFastaNumericFormat
63
70
  end #module Bio
@@ -0,0 +1,169 @@
1
+ #
2
+ # = test/unit/bio/sequence/test_sequence_masker.rb - Unit test for Bio::Sequence::SequenceMasker
3
+ #
4
+ # Copyright:: Copyright (C) 2010
5
+ # Naohisa Goto <ng@bioruby.org>
6
+ # License:: The Ruby License
7
+ #
8
+
9
+ # loading helper routine for testing bioruby
10
+ require 'pathname'
11
+ load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3,
12
+ 'bioruby_test_helper.rb')).cleanpath.to_s
13
+
14
+ # libraries needed for the tests
15
+ require 'test/unit'
16
+ require 'bio/sequence'
17
+ require 'bio/sequence/sequence_masker'
18
+
19
+ module Bio
20
+
21
+ class TestSequenceMasker < Test::Unit::TestCase
22
+
23
+ def setup
24
+ s = "aaacgcattagcaccaccattaccaccacc"
25
+ @raw = s.dup.freeze
26
+ @seq = Bio::Sequence.new(s)
27
+ @seq.quality_scores =
28
+ (0...30).collect { |i| i * 3 }
29
+ @seq.error_probabilities =
30
+ (0...30).collect { |i| 10 ** -(i * 3 / 10.0) }
31
+ end
32
+
33
+ # Very simple enumerator for testing.
34
+ class SimpleEnum
35
+ include Enumerable
36
+
37
+ def initialize(ary)
38
+ @ary = ary
39
+ end
40
+
41
+ def each(&block)
42
+ @ary.each(&block)
43
+ end
44
+ end #class SimpleEnum
45
+
46
+ def test_mask_with_enumerator
47
+ enum = SimpleEnum.new((0..29).to_a)
48
+ newseq = @seq.mask_with_enumerator(enum, 'n') do |item|
49
+ i = item % 10
50
+ i == 9 || i == 0
51
+ end
52
+ expected = "naacgcattnncaccaccannaccaccacn"
53
+ assert_equal(expected, newseq.seq)
54
+ # not breaking original sequence
55
+ assert_equal(@raw, @seq.seq)
56
+ end
57
+
58
+ def test_mask_with_enumerator_longer_mask_char
59
+ enum = SimpleEnum.new((0..29).to_a)
60
+ newseq = @seq.mask_with_enumerator(enum, '-*-') do |item|
61
+ i = item % 10
62
+ i == 9 || i == 0
63
+ end
64
+ expected = "-*-aacgcatt-*--*-caccacca-*--*-accaccac-*-"
65
+ assert_equal(expected, newseq.seq)
66
+ # not breaking original sequence
67
+ assert_equal(@raw, @seq.seq)
68
+ end
69
+
70
+ def test_mask_with_enumerator_empty_mask_char
71
+ enum = SimpleEnum.new((0..29).to_a)
72
+ newseq = @seq.mask_with_enumerator(enum, '') do |item|
73
+ i = item % 10
74
+ i == 9 || i == 0
75
+ end
76
+ expected = "aacgcattcaccaccaaccaccac"
77
+ assert_equal(expected, newseq.seq)
78
+ # not breaking original sequence
79
+ assert_equal(@raw, @seq.seq)
80
+ end
81
+
82
+ def test_mask_with_enumerator_shorter
83
+ enum = SimpleEnum.new((0..10).to_a.freeze)
84
+ enum.freeze
85
+ # normal mask char
86
+ newseq = @seq.mask_with_enumerator(enum, 'n') do |item|
87
+ item > 5
88
+ end
89
+ expected = "aaacgcnnnnncaccaccattaccaccacc"
90
+ assert_equal(expected, newseq.seq)
91
+ # not breaking original sequence
92
+ assert_equal(@raw, @seq.seq)
93
+ # empty mask char
94
+ newseq = @seq.mask_with_enumerator(enum, '') do |item|
95
+ item > 5
96
+ end
97
+ expected = "aaacgccaccaccattaccaccacc"
98
+ assert_equal(expected, newseq.seq)
99
+ # not breaking original sequence
100
+ assert_equal(@raw, @seq.seq)
101
+ # longer mask char
102
+ newseq = @seq.mask_with_enumerator(enum, '-*-') do |item|
103
+ item > 5
104
+ end
105
+ expected = "aaacgc-*--*--*--*--*-caccaccattaccaccacc"
106
+ assert_equal(expected, newseq.seq)
107
+ # not breaking original sequence
108
+ assert_equal(@raw, @seq.seq)
109
+ end
110
+
111
+ def test_mask_with_enumerator_excess
112
+ enum = SimpleEnum.new((0..200).to_a.freeze)
113
+ enum.freeze
114
+ # normal mask char
115
+ newseq = @seq.mask_with_enumerator(enum, 'n') do |item|
116
+ i = item % 10
117
+ i == 9 || i == 0
118
+ end
119
+ expected = "naacgcattnncaccaccannaccaccacn"
120
+ assert_equal(expected, newseq.seq)
121
+ # not breaking original sequence
122
+ assert_equal(@raw, @seq.seq)
123
+ # empty mask char
124
+ newseq = @seq.mask_with_enumerator(enum, '') do |item|
125
+ i = item % 10
126
+ i == 9 || i == 0
127
+ end
128
+ expected = "aacgcattcaccaccaaccaccac"
129
+ assert_equal(expected, newseq.seq)
130
+ # not breaking original sequence
131
+ assert_equal(@raw, @seq.seq)
132
+ # longer mask char
133
+ newseq = @seq.mask_with_enumerator(enum, '-*-') do |item|
134
+ i = item % 10
135
+ i == 9 || i == 0
136
+ end
137
+ expected = "-*-aacgcatt-*--*-caccacca-*--*-accaccac-*-"
138
+ assert_equal(expected, newseq.seq)
139
+ # not breaking original sequence
140
+ assert_equal(@raw, @seq.seq)
141
+ end
142
+
143
+ def test_mask_with_quality_score
144
+ newseq = @seq.mask_with_quality_score(30, 'n')
145
+ expected = "nnnnnnnnnngcaccaccattaccaccacc"
146
+ assert_equal(expected, newseq.seq)
147
+ # not breaking original sequence
148
+ assert_equal(@raw, @seq.seq)
149
+ end
150
+
151
+ def test_mask
152
+ newseq = @seq.mask_with_quality_score(30, 'n')
153
+ expected = "nnnnnnnnnngcaccaccattaccaccacc"
154
+ assert_equal(expected, newseq.seq)
155
+ # not breaking original sequence
156
+ assert_equal(@raw, @seq.seq)
157
+ end
158
+
159
+ def test_mask_with_error_probability
160
+ newseq = @seq.mask_with_error_probability(0.001, 'n')
161
+ expected = "nnnnnnnnnngcaccaccattaccaccacc"
162
+ assert_equal(expected, newseq.seq)
163
+ # not breaking original sequence
164
+ assert_equal(@raw, @seq.seq)
165
+ end
166
+
167
+ end #class TestSequenceMasker
168
+
169
+ end #module Bio