PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/nmb/bioruby
Ruby | 339 lines | 248 code | 76 blank | 15 comment | 5 complexity | b83fd5913ca3c4de5323672c49bdca46 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. #
  2. # test/unit/bio/appl/iprscan/test_report.rb - Unit test for Bio::InterProScan::Report
  3. #
  4. # Copyright (C) 2006 Mitsuteru Nakao <n@bioruby.org>
  5. #
  6. # $Id:$
  7. #
  8. # loading helper routine for testing bioruby
  9. require 'pathname'
  10. load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4,
  11. 'bioruby_test_helper.rb')).cleanpath.to_s
  12. # libraries needed for the tests
  13. require 'test/unit'
  14. require 'bio/appl/iprscan/report'
  15. module Bio
  16. class TestIprscanData
  17. TestDataIprscan = Pathname.new(File.join(BioRubyTestDataPath, "iprscan")).cleanpath.to_s
  18. def self.raw_format
  19. File.open(File.join(TestDataIprscan, "merged.raw"))
  20. end
  21. def self.txt_format
  22. File.open(File.join(TestDataIprscan, "merged.txt"))
  23. end
  24. end
  25. class TestIprscanPTxtReport < Test::Unit::TestCase
  26. def setup
  27. test_entry=<<-END
  28. slr0002\t860
  29. InterPro\tIPR001264\tGlycosyl transferase, family 51
  30. BlastProDom\tPD001895\tsp_Q55683_SYNY3_Q55683\t2e-37\t292-370
  31. HMMPfam\tPF00912\tTransglycosyl\t8e-104\t204-372
  32. InterPro\tIPR001460\tPenicillin-binding protein, transpeptidase domain
  33. HMMPfam\tPF00905\tTranspeptidase\t5.7e-30\t451-742
  34. InterPro\tNULL\tNULL
  35. ProfileScan\tPS50310\tALA_RICH\t10.224\t805-856
  36. //
  37. END
  38. @obj = Bio::Iprscan::Report.parse_ptxt_entry(test_entry)
  39. end
  40. def test_query_id
  41. assert_equal('slr0002', @obj.query_id)
  42. end
  43. def test_query_length
  44. assert_equal(860, @obj.query_length)
  45. end
  46. def test_matches_size
  47. assert_equal(4, @obj.matches.size)
  48. end
  49. def test_match_ipr_id
  50. assert_equal('IPR001264', @obj.matches.first.ipr_id)
  51. end
  52. def test_match_ipr_description
  53. assert_equal('Glycosyl transferase, family 51', @obj.matches.first.ipr_description)
  54. end
  55. def test_match_method
  56. assert_equal('BlastProDom', @obj.matches.first.method_name)
  57. end
  58. def test_match_accession
  59. assert_equal('PD001895', @obj.matches.first.accession)
  60. end
  61. def test_match_description
  62. assert_equal('sp_Q55683_SYNY3_Q55683', @obj.matches.first.description)
  63. end
  64. def test_match_evalue
  65. assert_equal('2e-37', @obj.matches.first.evalue)
  66. end
  67. def test_match_match_start
  68. assert_equal(292, @obj.matches.first.match_start)
  69. end
  70. def test_match_match_end
  71. assert_equal(370, @obj.matches.first.match_end)
  72. end
  73. end # TestIprscanPTxtReport
  74. class TestIprscanTxtEntry < Test::Unit::TestCase
  75. def setup
  76. test_txt = Bio::TestIprscanData.txt_format.read.split(/\n\nSequence/)[0]
  77. @obj = Bio::Iprscan::Report.parse_txt_entry(test_txt)
  78. end
  79. def test_iprscan_report_class
  80. assert_equal(Bio::Iprscan::Report, @obj.class)
  81. end
  82. def test_query_id
  83. assert_equal('Q9RHD9', @obj.query_id)
  84. end
  85. def test_query_length
  86. assert_equal(267, @obj.query_length)
  87. end
  88. def test_matches_size
  89. assert_equal(16, @obj.matches.size)
  90. end
  91. def test_match_ipr_id
  92. assert_equal('IPR000110', @obj.matches.first.ipr_id)
  93. end
  94. def test_match_ipr_description
  95. assert_equal('Ribosomal protein S1', @obj.matches.first.ipr_description)
  96. end
  97. def test_match_method
  98. assert_equal('FPrintScan', @obj.matches.first.method_name)
  99. end
  100. def test_match_accession
  101. assert_equal('PR00681', @obj.matches.first.accession)
  102. end
  103. def test_match_description
  104. assert_equal('RIBOSOMALS1', @obj.matches.first.description)
  105. end
  106. def test_match_evalue
  107. assert_equal('1.5e-17', @obj.matches.first.evalue)
  108. end
  109. def test_match_status
  110. assert_equal('T', @obj.matches.first.status)
  111. end
  112. def test_match_date
  113. assert_equal(nil, @obj.matches.first.date)
  114. end
  115. def test_match_match_start
  116. assert_equal(6, @obj.matches.first.match_start)
  117. end
  118. def test_match_match_end
  119. assert_equal(27, @obj.matches.first.match_end)
  120. end
  121. def test_match_go_terms
  122. ary = [["Molecular Function", "RNA binding", "GO:0003723"],
  123. ["Molecular Function", "structural constituent of ribosome", "GO:0003735"],
  124. ["Cellular Component", "ribosome", "GO:0005840"],
  125. ["Biological Process", "protein biosynthesis", "GO:0006412"]]
  126. assert_equal(ary, @obj.matches.first.go_terms)
  127. end
  128. end # TestIprscanTxtEntry
  129. class TestIprscanTxtEntryList < Test::Unit::TestCase
  130. def setup
  131. test_txt = Bio::TestIprscanData.txt_format.read.split(/\n\nSequence/)[0]
  132. @obj = Bio::Iprscan::Report.parse_txt_entry(test_txt)
  133. end
  134. def test_to_hash
  135. hsh = {"IPR008994" => [12, 13, 14].map {|x| @obj.matches[x] },
  136. "IPR000110" => [0, 1, 2].map {|x| @obj.matches[x] },
  137. "IPR003029" => [3, 4, 5, 6, 7, 8, 9, 10, 11].map {|x| @obj.matches[x] },
  138. "NULL" => [15].map {|x| @obj.matches[x] }}
  139. assert_equal(hsh.keys.sort, @obj.to_hash.keys.sort)
  140. assert_equal(hsh, @obj.to_hash)
  141. end
  142. def test_to_hash_match?
  143. @obj.to_hash.each do |ipr_id, matches|
  144. matches.each do |match|
  145. assert_equal(ipr_id, match.ipr_id)
  146. end
  147. end
  148. end
  149. end # TestIprscanTxtEntryList
  150. class TestIprscanTxtReport < Test::Unit::TestCase
  151. def setup
  152. @test_txt = Bio::TestIprscanData.txt_format
  153. end
  154. def test_parse_txt
  155. Bio::Iprscan::Report.parse_txt(@test_txt) do |report|
  156. assert_equal(Bio::Iprscan::Report, report.class)
  157. end
  158. end
  159. end # TestIprscanTxtReport
  160. class TestIprscanRawReport < Test::Unit::TestCase
  161. def setup
  162. test_raw = Bio::TestIprscanData.raw_format
  163. entry = ''
  164. @obj = []
  165. while line = test_raw.gets
  166. if entry.split("\t").first == line.split("\t").first
  167. entry << line
  168. elsif entry != '' and entry.split("\t").first != line.split("\t").first
  169. @obj << Bio::Iprscan::Report.parse_raw_entry(entry)
  170. entry = ''
  171. else
  172. entry << line
  173. end
  174. end
  175. @obj << Bio::Iprscan::Report.parse_raw_entry(entry)
  176. end
  177. def test_self_reports_in_raw
  178. io = File.open(File.join(Bio::TestIprscanData::TestDataIprscan,
  179. "merged.raw"))
  180. result = []
  181. Bio::Iprscan::Report.parse_raw(io) {|x| result << x }
  182. assert_equal(@obj.size, result.size)
  183. assert_equal(@obj.first.query_id, result.first.query_id)
  184. assert_equal(@obj.first.query_id, result.first.query_id)
  185. assert_equal(@obj[2].query_id, result[2].query_id)
  186. assert_equal(@obj.last.query_id, result.last.query_id)
  187. end
  188. def test_obj
  189. assert_equal(3, @obj.size)
  190. end
  191. def test_query_id
  192. assert_equal('Q9RHD9', @obj.first.query_id)
  193. end
  194. def test_entry_id
  195. assert_equal('Q9RHD9', @obj.first.entry_id)
  196. end
  197. def test_query_length
  198. assert_equal(267, @obj.first.query_length)
  199. end
  200. def test_match_query_id
  201. assert_equal('Q9RHD9', @obj.first.matches.first.query_id)
  202. end
  203. def test_match_crc64
  204. assert_equal('D44DAE8C544CB7C1', @obj.first.matches.first.crc64)
  205. end
  206. def test_match_query_length
  207. assert_equal(267, @obj.first.matches.first.query_length)
  208. end
  209. def test_match_method
  210. assert_equal('HMMPfam', @obj.first.matches.first.method_name)
  211. end
  212. def test_match_accession
  213. assert_equal('PF00575', @obj.first.matches.first.accession)
  214. end
  215. def test_match_description
  216. assert_equal('S1', @obj.first.matches.first.description)
  217. end
  218. def test_match_match_start
  219. assert_equal(1, @obj.first.matches.first.match_start)
  220. end
  221. def test_match_match_end
  222. assert_equal(55, @obj.first.matches.first.match_end)
  223. end
  224. def test_match_evalue
  225. assert_equal('3.3E-6', @obj.first.matches.first.evalue)
  226. end
  227. def test_match_status
  228. assert_equal('T', @obj.first.matches.first.status)
  229. end
  230. def test_match_date
  231. assert_equal('11-Nov-2005', @obj.first.matches.first.date)
  232. end
  233. def test_match_ipr_id
  234. assert_equal('IPR003029', @obj.first.matches.first.ipr_id)
  235. end
  236. def test_match_ipr_description
  237. assert_equal('RNA binding S1', @obj.first.matches.first.ipr_description)
  238. end
  239. def test_match_go_terms
  240. ary = ["Biological Process:phosphorylation (GO:0016310)",
  241. "Molecular Function:transferase activity, transferring phosphorus-containing groups (GO:0016772)"]
  242. assert_equal(ary,
  243. @obj.last.matches.last.go_terms)
  244. end
  245. end
  246. class TestIprscanReport < Test::Unit::TestCase
  247. def setup
  248. @test_txt = Bio::TestIprscanData.txt_format.read.split(/\n\nSequence/)[0]
  249. @obj = Bio::Iprscan::Report.parse_txt_entry(@test_txt)
  250. @test_raw = Bio::TestIprscanData.raw_format.read.split("RS16_ECOLI")[0]
  251. end
  252. def test_to_raw
  253. # assert_equal(@test_raw.split("\n").sort,
  254. # @obj.format_raw.split("\n").sort)
  255. end
  256. def test_output_raw
  257. # assert_equal(@test_raw.split("\n").sort,
  258. # @obj.output(:raw).split("\n").sort)
  259. # assert_equal(@test_raw.split("\n").sort,
  260. # @obj.output('raw').split("\n").sort)
  261. end
  262. end # TestIprscanReport
  263. end