PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/test/unit/bio/appl/hmmer/test_report.rb

https://github.com/nmb/bioruby
Ruby | 343 lines | 260 code | 73 blank | 10 comment | 0 complexity | f183654213c75c4a80b9f1748f90b20e MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. #
  2. # test/unit/bio/appl/hmmer/test_report.rb - Unit test for Bio::HMMER::Report
  3. #
  4. # Copyright:: Copyright (C) 2006 Mitsuteru Nakao <n@bioruby.org>
  5. # License:: The Ruby License
  6. #
  7. # $Id:$
  8. #
  9. # loading helper routine for testing bioruby
  10. require 'pathname'
  11. load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4,
  12. 'bioruby_test_helper.rb')).cleanpath.to_s
  13. # libraries needed for the tests
  14. require 'test/unit'
  15. require 'bio/appl/hmmer/report'
  16. module Bio
  17. class TestHMMERReportData
  18. TestDataHMMER = Pathname.new(File.join(BioRubyTestDataPath, 'HMMER')).cleanpath.to_s
  19. def self.hmmpfam
  20. File.open(File.join(TestDataHMMER, 'hmmpfam.out')).read
  21. end
  22. def self.output
  23. self.hmmpfam
  24. end
  25. def self.hmmsearch
  26. File.open(File.join(TestDataHMMER, 'hmmsearch.out')).read
  27. end
  28. end
  29. class TestHMMERReportClassMethods < Test::Unit::TestCase
  30. def test_reports_ary
  31. ary = Bio::HMMER.reports(Bio::TestHMMERReportData.output)
  32. assert_equal(Array, ary.class)
  33. end
  34. def test_reports_ary_contents
  35. Bio::HMMER.reports(Bio::TestHMMERReportData.output).each do |report|
  36. assert_equal(Bio::HMMER::Report, report.class)
  37. end
  38. end
  39. end
  40. class TestHMMERReportConstants < Test::Unit::TestCase
  41. def test_rs
  42. assert_equal("\n//\n", Bio::HMMER::Report::RS)
  43. assert_equal("\n//\n", Bio::HMMER::Report::DELIMITER)
  44. end
  45. end
  46. class TestHMMERReportHmmpfam < Test::Unit::TestCase
  47. def setup
  48. @obj = Bio::HMMER::Report.new(Bio::TestHMMERReportData.hmmpfam)
  49. end
  50. def test_program
  51. assert_equal(Hash, @obj.program.class)
  52. assert_equal("hmmpfam - search one or more sequences against HMM database", @obj.program['name'])
  53. assert_equal("HMMER 2.3.2 (Oct 2003)", @obj.program['version'])
  54. assert_equal("Copyright (C) 1992-2003 HHMI/Washington University School of Medicine", @obj.program['copyright'])
  55. assert_equal("Freely distributed under the GNU General Public License (GPL)", @obj.program['license'])
  56. end
  57. def test_parameter
  58. assert_equal(Hash, @obj.parameter.class)
  59. assert_equal("/Users/nakao/Sites/iprscan/tmp/20050517/iprscan-20050517-16244071/chunk_1/iprscan-20050517-16244071.nocrc", @obj.parameter["Sequence file"])
  60. assert_equal("/Users/nakao/Sites/iprscan/data/Pfam", @obj.parameter['HMM file'])
  61. end
  62. def test_query_info
  63. assert_equal(Hash, @obj.query_info.class)
  64. assert_equal("104K_THEPA", @obj.query_info["Query sequence"])
  65. assert_equal("[none]", @obj.query_info["Accession"])
  66. assert_equal("[none]", @obj.query_info["Description"])
  67. end
  68. def test_hits
  69. assert_equal(Bio::HMMER::Report::Hit, @obj.hits.first.class)
  70. end
  71. def test_hsps
  72. assert_equal(Bio::HMMER::Report::Hsp, @obj.hsps.first.class)
  73. end
  74. def test_histogram
  75. assert_equal(nil, @obj.histogram)
  76. end
  77. def test_statistical_detail
  78. assert_equal(nil, @obj.statistical_detail)
  79. end
  80. def test_total_seq_searched
  81. assert_equal(nil, @obj.total_seq_searched)
  82. end
  83. def test_whole_seq_top_hits
  84. assert_equal(nil, @obj.whole_seq_top_hits)
  85. end
  86. def test_domain_top_hits
  87. assert_equal(nil, @obj.domain_top_hits)
  88. end
  89. def test_each
  90. @obj.each do |hit|
  91. assert_equal(Bio::HMMER::Report::Hit, hit.class)
  92. end
  93. end
  94. def test_each_hit
  95. @obj.each_hit do |hit|
  96. assert_equal(Bio::HMMER::Report::Hit, hit.class)
  97. end
  98. end
  99. end
  100. class TestHMMERReportHit < Test::Unit::TestCase
  101. def setup
  102. @obj = Bio::HMMER::Report.new(Bio::TestHMMERReportData.output).hits.first
  103. end
  104. def test_hit
  105. assert_equal(Bio::HMMER::Report::Hit, @obj.class)
  106. end
  107. def test_hsps
  108. assert_equal(Bio::HMMER::Report::Hsp, @obj.hsps.first.class)
  109. end
  110. def test_accession
  111. assert_equal("PF04385.4", @obj.accession)
  112. end
  113. def test_target_id
  114. assert_equal("PF04385.4", @obj.target_id)
  115. end
  116. def test_hit_id
  117. assert_equal("PF04385.4", @obj.hit_id)
  118. end
  119. def test_entry_id
  120. assert_equal("PF04385.4", @obj.entry_id)
  121. end
  122. def test_description
  123. assert_equal("Domain of unknown function, DUF529", @obj.description)
  124. end
  125. def test_definition
  126. assert_equal("Domain of unknown function, DUF529", @obj.definition)
  127. end
  128. def test_score
  129. assert_equal(259.3, @obj.score)
  130. end
  131. def test_bit_score
  132. assert_equal(259.3, @obj.bit_score)
  133. end
  134. def test_evalue
  135. assert_equal(6.6e-75, @obj.evalue)
  136. end
  137. def test_num
  138. assert_equal(4, @obj.num)
  139. end
  140. def test_each
  141. @obj.each do |hsp|
  142. assert_equal(Bio::HMMER::Report::Hsp, hsp.class)
  143. end
  144. end
  145. def test_each_hsp
  146. @obj.each_hsp do |hsp|
  147. assert_equal(Bio::HMMER::Report::Hsp, hsp.class)
  148. end
  149. end
  150. def test_target_def
  151. assert_equal("<4> Domain of unknown function, DUF529", @obj.target_def)
  152. end
  153. def test_append_hsp
  154. hsp = @obj.hsps.first
  155. assert_equal(5, @obj.append_hsp(hsp).size)
  156. end
  157. end
  158. class TestHMMERReportHsp < Test::Unit::TestCase
  159. def setup
  160. @obj = Bio::HMMER::Report.new(Bio::TestHMMERReportData.output).hits.first.hsps.first
  161. end
  162. def test_hsp
  163. assert_equal(Bio::HMMER::Report::Hsp, @obj.class)
  164. end
  165. def test_accession
  166. assert_equal("PF04385.4", @obj.accession)
  167. end
  168. def test_domain
  169. assert_equal("1/4", @obj.domain)
  170. end
  171. def test_seq_f
  172. assert_equal(36, @obj.seq_f)
  173. end
  174. def test_seq_t
  175. assert_equal(111, @obj.seq_t)
  176. end
  177. def test_seq_ft
  178. assert_equal("..", @obj.seq_ft)
  179. end
  180. def test_hmm_f
  181. assert_equal(1, @obj.hmm_f)
  182. end
  183. def test_hmm_t
  184. assert_equal(80, @obj.hmm_t)
  185. end
  186. def test_score
  187. assert_equal(65.0, @obj.score)
  188. end
  189. def test_bit_score
  190. assert_equal(65.0, @obj.bit_score)
  191. end
  192. def test_evalue
  193. assert_equal(2.0e-16, @obj.evalue)
  194. end
  195. def test_midline
  196. assert_equal("t+D+n++++ f +v+++g+++ + ++ ++v+++++++Gn+v+We++ + +l++ ++++++++++++++++ +++", @obj.midline)
  197. end
  198. def test_hmmseq
  199. assert_equal("tLDlndtgstlkqfdykvalngdivvtytpkpGvkftkitdGnevvWeseddpefglivtlsfyldsnkfLvlllintak", @obj.hmmseq)
  200. end
  201. def test_flatseq
  202. assert_equal("TFDINSNQTG-PAFLTAVEMAGVKYLQVQHGSNVNIHRLVEGNVVIWENA---STPLYTGAIVTNNDGPYMAYVEVLGDP", @obj.flatseq)
  203. end
  204. def test_query_frame
  205. assert_equal(1, @obj.query_frame)
  206. end
  207. def test_target_frame
  208. assert_equal(1, @obj.target_frame)
  209. end
  210. def test_csline
  211. assert_equal(nil, @obj.csline)
  212. end
  213. def test_rfline
  214. assert_equal(nil, @obj.rfline)
  215. end
  216. def test_set_alignment
  217. end
  218. def test_query_seq
  219. assert_equal("TFDINSNQTG-PAFLTAVEMAGVKYLQVQHGSNVNIHRLVEGNVVIWENA---STPLYTGAIVTNNDGPYMAYVEVLGDP", @obj.query_seq)
  220. end
  221. def test_target_seq
  222. assert_equal("tLDlndtgstlkqfdykvalngdivvtytpkpGvkftkitdGnevvWeseddpefglivtlsfyldsnkfLvlllintak", @obj.target_seq)
  223. end
  224. def test_target_from
  225. assert_equal(1, @obj.target_from)
  226. end
  227. def test_targat_to
  228. assert_equal(80, @obj.target_to)
  229. end
  230. def test_query_from
  231. assert_equal(36, @obj.query_from)
  232. end
  233. def test_query_to
  234. assert_equal(111, @obj.query_to)
  235. end
  236. end
  237. class TestHMMERReportHmmsearch < Test::Unit::TestCase
  238. def setup
  239. @obj = Bio::HMMER::Report.new(Bio::TestHMMERReportData.hmmsearch)
  240. end
  241. def test_histogram
  242. hist = "score obs exp (one = represents 1 sequences)\n----- --- ---\n 377 1 0|="
  243. assert_equal(hist, @obj.histogram)
  244. end
  245. def test_statistical_detail
  246. hash = {"P(chi-square)" => 0.0, "chi-sq statistic" => 0.0, "lambda" => 0.7676, "mu" => -10.6639}
  247. assert_equal(hash, @obj.statistical_detail)
  248. hash.keys.each do |key|
  249. assert_equal(hash[key], @obj.statistical_detail[key])
  250. end
  251. end
  252. def test_total_seq_searched
  253. assert_equal(1, @obj.total_seq_searched)
  254. end
  255. def test_whole_seq_top_hit
  256. hash = {"Total memory" => "16K", "Satisfying E cutoff" => 1, "Total hits" => 1}
  257. assert_equal(hash, @obj.whole_seq_top_hits)
  258. hash.keys.each do |key|
  259. assert_equal(hash[key], @obj.whole_seq_top_hits[key])
  260. end
  261. end
  262. def test_domain_top_hits
  263. hash = {"Total memory" => "17K", "Satisfying E cutoff" => 1, "Total hits" => 1}
  264. assert_equal(hash, @obj.domain_top_hits)
  265. hash.keys.each do |key|
  266. assert_equal(hash[key], @obj.domain_top_hits[key])
  267. end
  268. end
  269. end
  270. end # module Bio