PageRenderTime 58ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/nmb/bioruby
Ruby | 1136 lines | 847 code | 242 blank | 47 comment | 2 complexity | c93c67786c3fadd1f89e866dddc2d1a7 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. #
  2. # test/unit/bio/appl/blast/test_report.rb - Unit test for Bio::Blast::Report
  3. #
  4. # Copyright:: Copyright (C) 2005, 2008
  5. # Mitsuteru Nakao <n@bioruby.org>,
  6. # Naohisa Goto <ng@bioruby.org>
  7. # License:: The Ruby License
  8. #
  9. # $Id:$
  10. #
  11. # loading helper routine for testing bioruby
  12. require 'pathname'
  13. load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4,
  14. 'bioruby_test_helper.rb')).cleanpath.to_s
  15. # libraries needed for the tests
  16. require 'test/unit'
  17. require 'bio/appl/blast/report'
  18. module Bio
  19. module TestBlastReportHelper
  20. TestDataBlast = Pathname.new(File.join(BioRubyTestDataPath, 'blast')).cleanpath.to_s
  21. private
  22. def get_input_data(basename = 'b0002.faa')
  23. File.open(File.join(TestDataBlast, basename)).read
  24. end
  25. def get_output_data(basename = 'b0002.faa', format = 7)
  26. fn = basename + ".m#{format.to_i}"
  27. # available filenames:
  28. # 'b0002.faa.m0'
  29. # 'b0002.faa.m7'
  30. # 'b0002.faa.m8'
  31. File.open(File.join(TestDataBlast, fn)).read
  32. end
  33. def create_report_object(basename = 'b0002.faa')
  34. case self.class.name.to_s
  35. when /XMLParser/i
  36. text = get_output_data(basename, 7)
  37. Bio::Blast::Report.new(text, :xmlparser)
  38. when /REXML/i
  39. text = get_output_data(basename, 7)
  40. Bio::Blast::Report.new(text, :rexml)
  41. when /Default/i
  42. text = get_output_data(basename, 0)
  43. Bio::Blast::Default::Report.new(text)
  44. when /Tab/i
  45. text = get_output_data(basename, 8)
  46. Bio::Blast::Report.new(text)
  47. else
  48. text = get_output_data(basename, 7)
  49. Bio::Blast::Report.new(text)
  50. end
  51. end
  52. end #module TestBlastReportHelper
  53. class TestBlastReport < Test::Unit::TestCase
  54. include TestBlastReportHelper
  55. def setup
  56. @report = create_report_object
  57. end
  58. def test_iterations
  59. assert(@report.iterations)
  60. end
  61. def test_parameters
  62. assert_equal('BLOSUM62', @report.parameters['matrix'])
  63. assert_equal(10, @report.parameters['expect'])
  64. assert_equal(11, @report.parameters['gap-open'])
  65. assert_equal(1, @report.parameters['gap-extend'])
  66. assert_equal('S', @report.parameters['filter'])
  67. end
  68. def test_program
  69. assert_equal('blastp', @report.program)
  70. end
  71. def test_version
  72. assert_equal('blastp 2.2.10 [Oct-19-2004]', @report.version)
  73. end
  74. def test_reference
  75. xml_quoted_str = "~Reference: Altschul, Stephen F., Thomas L. Madden, Alejandro A. Schaffer, ~Jinghui Zhang, Zheng Zhang, Webb Miller, and David J. Lipman (1997), ~&quot;Gapped BLAST and PSI-BLAST: a new generation of protein database search~programs&quot;, Nucleic Acids Res. 25:3389-3402."
  76. text_str = '~Reference: Altschul, Stephen F., Thomas L. Madden, Alejandro A. Schaffer, ~Jinghui Zhang, Zheng Zhang, Webb Miller, and David J. Lipman (1997), ~"Gapped BLAST and PSI-BLAST: a new generation of protein database search~programs", Nucleic Acids Res. 25:3389-3402.'
  77. # assert_equal(xml_quoted_str, @report.reference)
  78. assert_equal(text_str, @report.reference)
  79. end
  80. def test_db
  81. assert_equal('b0002.faa', @report.db)
  82. end
  83. def test_query_id
  84. assert_equal('lcl|QUERY', @report.query_id)
  85. end
  86. def test_query_def
  87. assert_equal('eco:b0002 thrA, Hs, thrD, thrA2, thrA1; bifunctional: aspartokinase I (N-terminal); homoserine dehydrogenase I (C-terminal) [EC:2.7.2.4 1.1.1.3]; K00003 homoserine dehydrogenase; K00928 aspartate kinase (A)', @report.query_def)
  88. end
  89. def test_query_len
  90. assert_equal(820, @report.query_len)
  91. end
  92. def test_matrix
  93. assert_equal('BLOSUM62', @report.matrix)
  94. end
  95. def test_expect
  96. assert_equal(10, @report.expect)
  97. end
  98. def test_inclusion
  99. assert_nothing_raised { @report.inclusion }
  100. end
  101. def test_sc_match
  102. assert_nothing_raised { @report.sc_match }
  103. end
  104. def test_sc_mismatch
  105. assert_nothing_raised { @report.sc_mismatch }
  106. end
  107. def test_gap_open
  108. assert_equal(11, @report.gap_open)
  109. end
  110. def test_gap_extend
  111. assert_equal(1, @report.gap_extend)
  112. end
  113. def test_filter
  114. assert_equal('S', @report.filter)
  115. end
  116. def test_pattern
  117. assert_equal(nil, @report.pattern)
  118. end
  119. def test_entrez_query
  120. assert_equal(nil, @report.entrez_query)
  121. end
  122. def test_each_iteration
  123. assert_nothing_raised {
  124. @report.each_iteration { |itr| }
  125. }
  126. end
  127. def test_each_hit
  128. assert_nothing_raised {
  129. @report.each_hit { |hit| }
  130. }
  131. end
  132. def test_hits
  133. assert(@report.hits)
  134. end
  135. def test_statistics
  136. assert_equal({"kappa"=>0.041, "db-num"=>1, "eff-space"=>605284.0, "hsp-len"=>42, "db-len"=>820, "lambda"=>0.267, "entropy"=>0.14}, @report.statistics)
  137. end
  138. def test_db_num
  139. assert_equal(1, @report.db_num)
  140. end
  141. def test_db_len
  142. assert_equal(820, @report.db_len)
  143. end
  144. def test_hsp_len
  145. assert_equal(42, @report.hsp_len)
  146. end
  147. def test_eff_space
  148. assert_equal(605284, @report.eff_space)
  149. end
  150. def test_kappa
  151. assert_equal(0.041, @report.kappa)
  152. end
  153. def test_lambda
  154. assert_equal(0.267, @report.lambda)
  155. end
  156. def test_entropy
  157. assert_equal(0.14, @report.entropy)
  158. end
  159. def test_message
  160. assert_equal(nil, @report.message)
  161. end
  162. end
  163. class TestBlastReportIteration < Test::Unit::TestCase
  164. include TestBlastReportHelper
  165. def setup
  166. report = create_report_object
  167. @itr = report.iterations.first
  168. end
  169. def test_hits
  170. assert(@itr.hits)
  171. end
  172. def test_statistics
  173. stat = {"kappa" => 0.041, "eff-space" => 605284, "db-num" => 1,
  174. "hsp-len" => 42, "db-len" => 820, "lambda" => 0.267,
  175. "entropy" => 0.14}
  176. assert_equal(stat, @itr.statistics)
  177. end
  178. def test_num
  179. assert_equal(1, @itr.num)
  180. end
  181. def test_message
  182. assert_equal(nil, @itr.message)
  183. end
  184. end
  185. class TestBlastReportHit < Test::Unit::TestCase
  186. include TestBlastReportHelper
  187. def setup
  188. report = create_report_object
  189. @hit = report.hits.first
  190. end
  191. def test_Hit_hsps
  192. assert(@hit.hsps)
  193. end
  194. def test_Hit_query_id
  195. assert_equal('lcl|QUERY', @hit.query_id)
  196. end
  197. def test_Hit_query_def
  198. assert_equal('eco:b0002 thrA, Hs, thrD, thrA2, thrA1; bifunctional: aspartokinase I (N-terminal); homoserine dehydrogenase I (C-terminal) [EC:2.7.2.4 1.1.1.3]; K00003 homoserine dehydrogenase; K00928 aspartate kinase (A)', @hit.query_def)
  199. end
  200. def test_Hit_query_len
  201. assert_equal(820, @hit.query_len)
  202. end
  203. def test_Hit_num
  204. assert(@hit.num)
  205. end
  206. def test_Hit_hit_id
  207. assert_equal('gnl|BL_ORD_ID|0', @hit.hit_id)
  208. end
  209. def test_Hit_len
  210. assert_equal(820, @hit.len)
  211. end
  212. def test_Hit_target_len
  213. assert_equal(820, @hit.target_len)
  214. end
  215. def test_Hit_definition
  216. assert(@hit.definition)
  217. end
  218. def test_Hit_taeget_def
  219. assert(@hit.target_def)
  220. end
  221. def test_Hit_accession
  222. assert(@hit.accession)
  223. end
  224. def test_Hit_target_id
  225. assert(@hit.target_id)
  226. end
  227. def test_Hit_evalue
  228. assert_equal(0, @hit.evalue)
  229. end
  230. def test_Hit_bit_score
  231. assert_equal(1567.75, @hit.bit_score)
  232. end
  233. def test_Hit_identity
  234. assert_equal(820, @hit.identity)
  235. end
  236. def test_Hit_overlap
  237. assert_equal(820, @hit.overlap)
  238. end
  239. def test_Hit_query_seq
  240. seq = 'MRVLKFGGTSVANAERFLRVADILESNARQGQVATVLSAPAKITNHLVAMIEKTISGQDALPNISDAERIFAELLTGLAAAQPGFPLAQLKTFVDQEFAQIKHVLHGISLLGQCPDSINAALICRGEKMSIAIMAGVLEARGHNVTVIDPVEKLLAVGHYLESTVDIAESTRRIAASRIPADHMVLMAGFTAGNEKGELVVLGRNGSDYSAAVLAACLRADCCEIWTDVDGVYTCDPRQVPDARLLKSMSYQEAMELSYFGAKVLHPRTITPIAQFQIPCLIKNTGNPQAPGTLIGASRDEDELPVKGISNLNNMAMFSVSGPGMKGMVGMAARVFAAMSRARISVVLITQSSSEYSISFCVPQSDCVRAERAMQEEFYLELKEGLLEPLAVTERLAIISVVGDGMRTLRGISAKFFAALARANINIVAIAQGSSERSISVVVNNDDATTGVRVTHQMLFNTDQVIEVFVIGVGGVGGALLEQLKRQQSWLKNKHIDLRVCGVANSKALLTNVHGLNLENWQEELAQAKEPFNLGRLIRLVKEYHLLNPVIVDCTSSQAVADQYADFLREGFHVVTPNKKANTSSMDYYHQLRYAAEKSRRKFLYDTNVGAGLPVIENLQNLLNAGDELMKFSGILSGSLSYIFGKLDEGMSFSEATTLAREMGYTEPDPRDDLSGMDVARKLLILARETGRELELADIEIEPVLPAEFNAEGDVAAFMANLSQLDDLFAARVAKARDEGKVLRYVGNIDEDGVCRVKIAEVDGNDPLFKVKNGENALAFYSHYYQPLPLVLRGYGAGNDVTAAGVFADLLRTLSWKLGV'
  241. assert_equal(seq, @hit.query_seq)
  242. end
  243. def test_Hit_target_seq
  244. seq = 'MRVLKFGGTSVANAERFLRVADILESNARQGQVATVLSAPAKITNHLVAMIEKTISGQDALPNISDAERIFAELLTGLAAAQPGFPLAQLKTFVDQEFAQIKHVLHGISLLGQCPDSINAALICRGEKMSIAIMAGVLEARGHNVTVIDPVEKLLAVGHYLESTVDIAESTRRIAASRIPADHMVLMAGFTAGNEKGELVVLGRNGSDYSAAVLAACLRADCCEIWTDVDGVYTCDPRQVPDARLLKSMSYQEAMELSYFGAKVLHPRTITPIAQFQIPCLIKNTGNPQAPGTLIGASRDEDELPVKGISNLNNMAMFSVSGPGMKGMVGMAARVFAAMSRARISVVLITQSSSEYSISFCVPQSDCVRAERAMQEEFYLELKEGLLEPLAVTERLAIISVVGDGMRTLRGISAKFFAALARANINIVAIAQGSSERSISVVVNNDDATTGVRVTHQMLFNTDQVIEVFVIGVGGVGGALLEQLKRQQSWLKNKHIDLRVCGVANSKALLTNVHGLNLENWQEELAQAKEPFNLGRLIRLVKEYHLLNPVIVDCTSSQAVADQYADFLREGFHVVTPNKKANTSSMDYYHQLRYAAEKSRRKFLYDTNVGAGLPVIENLQNLLNAGDELMKFSGILSGSLSYIFGKLDEGMSFSEATTLAREMGYTEPDPRDDLSGMDVARKLLILARETGRELELADIEIEPVLPAEFNAEGDVAAFMANLSQLDDLFAARVAKARDEGKVLRYVGNIDEDGVCRVKIAEVDGNDPLFKVKNGENALAFYSHYYQPLPLVLRGYGAGNDVTAAGVFADLLRTLSWKLGV'
  245. assert_equal(seq, @hit.target_seq)
  246. end
  247. def test_Hit_midline
  248. seq = 'MRVLKFGGTSVANAERFLRVADILESNARQGQVATVLSAPAKITNHLVAMIEKTISGQDALPNISDAERIFAELLTGLAAAQPGFPLAQLKTFVDQEFAQIKHVLHGISLLGQCPDSINAALICRGEKMSIAIMAGVLEARGHNVTVIDPVEKLLAVGHYLESTVDIAESTRRIAASRIPADHMVLMAGFTAGNEKGELVVLGRNGSDYSAAVLAACLRADCCEIWTDVDGVYTCDPRQVPDARLLKSMSYQEAMELSYFGAKVLHPRTITPIAQFQIPCLIKNTGNPQAPGTLIGASRDEDELPVKGISNLNNMAMFSVSGPGMKGMVGMAARVFAAMSRARISVVLITQSSSEYSISFCVPQSDCVRAERAMQEEFYLELKEGLLEPLAVTERLAIISVVGDGMRTLRGISAKFFAALARANINIVAIAQGSSERSISVVVNNDDATTGVRVTHQMLFNTDQVIEVFVIGVGGVGGALLEQLKRQQSWLKNKHIDLRVCGVANSKALLTNVHGLNLENWQEELAQAKEPFNLGRLIRLVKEYHLLNPVIVDCTSSQAVADQYADFLREGFHVVTPNKKANTSSMDYYHQLRYAAEKSRRKFLYDTNVGAGLPVIENLQNLLNAGDELMKFSGILSGSLSYIFGKLDEGMSFSEATTLAREMGYTEPDPRDDLSGMDVARKLLILARETGRELELADIEIEPVLPAEFNAEGDVAAFMANLSQLDDLFAARVAKARDEGKVLRYVGNIDEDGVCRVKIAEVDGNDPLFKVKNGENALAFYSHYYQPLPLVLRGYGAGNDVTAAGVFADLLRTLSWKLGV'
  249. assert_equal(seq, @hit.midline)
  250. end
  251. def test_Hit_query_start
  252. assert_equal(1, @hit.query_start)
  253. # assert_equal(1, @hit.query_from)
  254. end
  255. def test_Hit_query_end
  256. assert_equal(820, @hit.query_end)
  257. # assert_equal(820, @hit.query_to)
  258. end
  259. def test_Hit_target_start
  260. assert_equal(1, @hit.target_start)
  261. # assert_equal(1, @hit.hit_from)
  262. end
  263. def test_Hit_target_end
  264. assert_equal(820, @hit.target_end)
  265. # assert_equal(820, @hit.hit_to)
  266. end
  267. def test_Hit_lap_at
  268. assert_equal([1, 820, 1, 820], @hit.lap_at)
  269. end
  270. end
  271. class TestBlastReportHsp < Test::Unit::TestCase
  272. include TestBlastReportHelper
  273. def setup
  274. report = create_report_object
  275. @hsp = report.hits.first.hsps.first
  276. end
  277. def test_Hsp_num
  278. assert_equal(1, @hsp.num)
  279. end
  280. def test_Hsp_bit_score
  281. assert_equal(1567.75, @hsp.bit_score)
  282. end
  283. def test_Hsp_score
  284. assert_equal(4058, @hsp.score)
  285. end
  286. def test_Hsp_evalue
  287. assert_equal(0, @hsp.evalue)
  288. end
  289. def test_Hsp_identity
  290. assert_equal(820, @hsp.identity)
  291. end
  292. def test_Hsp_gaps
  293. assert_nothing_raised { @hsp.gaps }
  294. end
  295. def test_Hsp_positive
  296. assert_equal(820, @hsp.positive)
  297. end
  298. def test_Hsp_align_len
  299. assert_equal(820, @hsp.align_len)
  300. end
  301. def test_Hsp_density
  302. assert(@hsp.density)
  303. end
  304. def test_Hsp_query_frame
  305. assert_equal(1, @hsp.query_frame)
  306. end
  307. def test_Hsp_query_from
  308. assert_equal(1, @hsp.query_from)
  309. end
  310. def test_Hsp_query_to
  311. assert_equal(820, @hsp.query_to)
  312. end
  313. def test_Hsp_hit_frame
  314. assert_equal(1, @hsp.hit_frame)
  315. end
  316. def test_Hsp_hit_from
  317. assert_equal(1, @hsp.hit_from)
  318. end
  319. def test_Hsp_hit_to
  320. assert_equal(820, @hsp.hit_to)
  321. end
  322. def test_Hsp_pattern_from
  323. assert_nothing_raised { @hsp.pattern_from }
  324. end
  325. def test_Hsp_pattern_to
  326. assert_nothing_raised { @hsp.pattern_to }
  327. end
  328. def test_Hsp_qseq
  329. seq = 'MRVLKFGGTSVANAERFLRVADILESNARQGQVATVLSAPAKITNHLVAMIEKTISGQDALPNISDAERIFAELLTGLAAAQPGFPLAQLKTFVDQEFAQIKHVLHGISLLGQCPDSINAALICRGEKMSIAIMAGVLEARGHNVTVIDPVEKLLAVGHYLESTVDIAESTRRIAASRIPADHMVLMAGFTAGNEKGELVVLGRNGSDYSAAVLAACLRADCCEIWTDVDGVYTCDPRQVPDARLLKSMSYQEAMELSYFGAKVLHPRTITPIAQFQIPCLIKNTGNPQAPGTLIGASRDEDELPVKGISNLNNMAMFSVSGPGMKGMVGMAARVFAAMSRARISVVLITQSSSEYSISFCVPQSDCVRAERAMQEEFYLELKEGLLEPLAVTERLAIISVVGDGMRTLRGISAKFFAALARANINIVAIAQGSSERSISVVVNNDDATTGVRVTHQMLFNTDQVIEVFVIGVGGVGGALLEQLKRQQSWLKNKHIDLRVCGVANSKALLTNVHGLNLENWQEELAQAKEPFNLGRLIRLVKEYHLLNPVIVDCTSSQAVADQYADFLREGFHVVTPNKKANTSSMDYYHQLRYAAEKSRRKFLYDTNVGAGLPVIENLQNLLNAGDELMKFSGILSGSLSYIFGKLDEGMSFSEATTLAREMGYTEPDPRDDLSGMDVARKLLILARETGRELELADIEIEPVLPAEFNAEGDVAAFMANLSQLDDLFAARVAKARDEGKVLRYVGNIDEDGVCRVKIAEVDGNDPLFKVKNGENALAFYSHYYQPLPLVLRGYGAGNDVTAAGVFADLLRTLSWKLGV'
  330. assert_equal(seq, @hsp.qseq)
  331. end
  332. def test_Hsp_midline
  333. seq = 'MRVLKFGGTSVANAERFLRVADILESNARQGQVATVLSAPAKITNHLVAMIEKTISGQDALPNISDAERIFAELLTGLAAAQPGFPLAQLKTFVDQEFAQIKHVLHGISLLGQCPDSINAALICRGEKMSIAIMAGVLEARGHNVTVIDPVEKLLAVGHYLESTVDIAESTRRIAASRIPADHMVLMAGFTAGNEKGELVVLGRNGSDYSAAVLAACLRADCCEIWTDVDGVYTCDPRQVPDARLLKSMSYQEAMELSYFGAKVLHPRTITPIAQFQIPCLIKNTGNPQAPGTLIGASRDEDELPVKGISNLNNMAMFSVSGPGMKGMVGMAARVFAAMSRARISVVLITQSSSEYSISFCVPQSDCVRAERAMQEEFYLELKEGLLEPLAVTERLAIISVVGDGMRTLRGISAKFFAALARANINIVAIAQGSSERSISVVVNNDDATTGVRVTHQMLFNTDQVIEVFVIGVGGVGGALLEQLKRQQSWLKNKHIDLRVCGVANSKALLTNVHGLNLENWQEELAQAKEPFNLGRLIRLVKEYHLLNPVIVDCTSSQAVADQYADFLREGFHVVTPNKKANTSSMDYYHQLRYAAEKSRRKFLYDTNVGAGLPVIENLQNLLNAGDELMKFSGILSGSLSYIFGKLDEGMSFSEATTLAREMGYTEPDPRDDLSGMDVARKLLILARETGRELELADIEIEPVLPAEFNAEGDVAAFMANLSQLDDLFAARVAKARDEGKVLRYVGNIDEDGVCRVKIAEVDGNDPLFKVKNGENALAFYSHYYQPLPLVLRGYGAGNDVTAAGVFADLLRTLSWKLGV'
  334. assert_equal(seq, @hsp.midline)
  335. end
  336. def test_Hsp_hseq
  337. seq = 'MRVLKFGGTSVANAERFLRVADILESNARQGQVATVLSAPAKITNHLVAMIEKTISGQDALPNISDAERIFAELLTGLAAAQPGFPLAQLKTFVDQEFAQIKHVLHGISLLGQCPDSINAALICRGEKMSIAIMAGVLEARGHNVTVIDPVEKLLAVGHYLESTVDIAESTRRIAASRIPADHMVLMAGFTAGNEKGELVVLGRNGSDYSAAVLAACLRADCCEIWTDVDGVYTCDPRQVPDARLLKSMSYQEAMELSYFGAKVLHPRTITPIAQFQIPCLIKNTGNPQAPGTLIGASRDEDELPVKGISNLNNMAMFSVSGPGMKGMVGMAARVFAAMSRARISVVLITQSSSEYSISFCVPQSDCVRAERAMQEEFYLELKEGLLEPLAVTERLAIISVVGDGMRTLRGISAKFFAALARANINIVAIAQGSSERSISVVVNNDDATTGVRVTHQMLFNTDQVIEVFVIGVGGVGGALLEQLKRQQSWLKNKHIDLRVCGVANSKALLTNVHGLNLENWQEELAQAKEPFNLGRLIRLVKEYHLLNPVIVDCTSSQAVADQYADFLREGFHVVTPNKKANTSSMDYYHQLRYAAEKSRRKFLYDTNVGAGLPVIENLQNLLNAGDELMKFSGILSGSLSYIFGKLDEGMSFSEATTLAREMGYTEPDPRDDLSGMDVARKLLILARETGRELELADIEIEPVLPAEFNAEGDVAAFMANLSQLDDLFAARVAKARDEGKVLRYVGNIDEDGVCRVKIAEVDGNDPLFKVKNGENALAFYSHYYQPLPLVLRGYGAGNDVTAAGVFADLLRTLSWKLGV'
  338. assert_equal(seq, @hsp.hseq)
  339. end
  340. def test_Hsp_percent_identity
  341. assert_nothing_raised { @hsp.percent_identity }
  342. end
  343. def test_Hsp_mismatch_count
  344. assert_nothing_raised { @hsp.mismatch_count }
  345. end
  346. end
  347. class TestBlastReportREXML < TestBlastReport
  348. end
  349. class TestBlastReportIterationREXML < TestBlastReportIteration
  350. end
  351. class TestBlastReportHitREXML < TestBlastReportHit
  352. end
  353. class TestBlastReportHspREXML < TestBlastReportHsp
  354. end
  355. if defined? XMLParser then
  356. class TestBlastReportXMLParser < TestBlastReport
  357. end
  358. class TestBlastReportIterationXMLParser < TestBlastReportIteration
  359. end
  360. class TestBlastReportHitXMLParser < TestBlastReportHit
  361. end
  362. class TestBlastReportHspXMLParser < TestBlastReportHsp
  363. end
  364. end #if defined? XMLParser
  365. class TestBlastReportDefault < TestBlastReport
  366. undef test_entrez_query
  367. undef test_filter
  368. undef test_hsp_len
  369. undef test_inclusion
  370. undef test_parameters
  371. undef test_query_id
  372. undef test_statistics
  373. def test_program
  374. assert_equal('BLASTP', @report.program)
  375. end
  376. def test_reference
  377. text_str = 'Reference: Altschul, Stephen F., Thomas L. Madden, Alejandro A. Schaffer, Jinghui Zhang, Zheng Zhang, Webb Miller, and David J. Lipman (1997), "Gapped BLAST and PSI-BLAST: a new generation of protein database search programs", Nucleic Acids Res. 25:3389-3402.'
  378. assert_equal(text_str, @report.reference)
  379. end
  380. def test_version
  381. assert_equal('BLASTP 2.2.10 [Oct-19-2004]', @report.version)
  382. end
  383. def test_kappa
  384. assert_equal(0.134, @report.kappa)
  385. end
  386. def test_lambda
  387. assert_equal(0.319, @report.lambda)
  388. end
  389. def test_entropy
  390. assert_equal(0.383, @report.entropy)
  391. end
  392. def test_gapped_kappa
  393. assert_equal(0.0410, @report.gapped_kappa)
  394. end
  395. def test_gapped_lambda
  396. assert_equal(0.267, @report.gapped_lambda)
  397. end
  398. def test_gapped_entropy
  399. assert_equal(0.140, @report.gapped_entropy)
  400. end
  401. end
  402. class TestBlastReportIterationDefault < TestBlastReportIteration
  403. undef test_statistics
  404. end
  405. class TestBlastReportHitDefault < TestBlastReportHit
  406. undef test_Hit_accession
  407. undef test_Hit_hit_id
  408. undef test_Hit_num
  409. undef test_Hit_query_def
  410. undef test_Hit_query_id
  411. undef test_Hit_query_len
  412. def setup
  413. @filtered_query_sequence = 'MRVLKFGGTSVANAERFLRVADILESNARQGQVATVLSAPAKITNHLVAMIEKTISGQDALPNISDAERIFAELLTGLAAAQPGFPLAQLKTFVDQEFAQIKHVLHGISLLGQCPDSINAALICRGEKMSIAIMAGVLEARGHNVTVIDPVEKLLAVGHYLESTVDIAESTRRIAASRIPADHMVLMAGFTAGNEKGELVVLGRNGSDYSAAVLAACLRADCCEIWTDVDGVYTCDPRQVPDARLLKSMSYQEAMELSYFGAKVLHPRTITPIAQFQIPCLIKNTGNPQAPGTLIGASRDEDELPVKGISNLNNMAMFSVSGPGMKGMVGMAARVFAAMSRARISVVLITQSSSEYSISFCVPQSDCVRAERAMQEEFYLELKEGLLEPLAVTERLAIISVVGDGMRTLRGISAKFFAALARANINIVAIAQGSSERSISVVVNNDDATTGVRVTHQMLFNTDQxxxxxxxxxxxxxxALLEQLKRQQSWLKNKHIDLRVCGVANSKALLTNVHGLNLENWQEELAQAKEPFNLGRLIRLVKEYHLLNPVIVDCTSSQAVADQYADFLREGFHVVTPNKKANTSSMDYYHQLRYAAEKSRRKFLYDTNVGAGLPVIENLQNLLNAGDELMKFSGILSGSLSYIFGKLDEGMSFSEATTLAREMGYTEPDPRDDLSGMDVARKLLILARETGRELELADIEIEPVLPAEFNAEGDVAAFMANLSQLDDLFAARVAKARDEGKVLRYVGNIDEDGVCRVKIAEVDGNDPLFKVKNGENALAFYSHYYQPLPLVLRGYGAGNDVTAAGVFADLLRTLSWKLGV'
  414. super
  415. end
  416. def test_Hit_bit_score
  417. # differs from XML because of truncation in the default format
  418. assert_equal(1567.0, @hit.bit_score)
  419. end
  420. def test_Hit_identity
  421. # differs from XML because filtered residues are not counted in the
  422. # default format
  423. assert_equal(806, @hit.identity)
  424. end
  425. def test_Hit_midline
  426. # differs from XML because filtered residues are not specified in XML
  427. seq = @filtered_query_sequence.gsub(/x/, ' ')
  428. assert_equal(seq, @hit.midline)
  429. end
  430. def test_Hit_query_seq
  431. # differs from XML because filtered residues are not specified in XML
  432. seq = @filtered_query_sequence.gsub(/x/, 'X')
  433. assert_equal(seq, @hit.query_seq)
  434. end
  435. end
  436. class TestBlastReportHspDefault < TestBlastReportHsp
  437. undef test_Hsp_density
  438. undef test_Hsp_mismatch_count
  439. undef test_Hsp_num
  440. undef test_Hsp_pattern_from
  441. undef test_Hsp_pattern_to
  442. def setup
  443. @filtered_query_sequence = 'MRVLKFGGTSVANAERFLRVADILESNARQGQVATVLSAPAKITNHLVAMIEKTISGQDALPNISDAERIFAELLTGLAAAQPGFPLAQLKTFVDQEFAQIKHVLHGISLLGQCPDSINAALICRGEKMSIAIMAGVLEARGHNVTVIDPVEKLLAVGHYLESTVDIAESTRRIAASRIPADHMVLMAGFTAGNEKGELVVLGRNGSDYSAAVLAACLRADCCEIWTDVDGVYTCDPRQVPDARLLKSMSYQEAMELSYFGAKVLHPRTITPIAQFQIPCLIKNTGNPQAPGTLIGASRDEDELPVKGISNLNNMAMFSVSGPGMKGMVGMAARVFAAMSRARISVVLITQSSSEYSISFCVPQSDCVRAERAMQEEFYLELKEGLLEPLAVTERLAIISVVGDGMRTLRGISAKFFAALARANINIVAIAQGSSERSISVVVNNDDATTGVRVTHQMLFNTDQxxxxxxxxxxxxxxALLEQLKRQQSWLKNKHIDLRVCGVANSKALLTNVHGLNLENWQEELAQAKEPFNLGRLIRLVKEYHLLNPVIVDCTSSQAVADQYADFLREGFHVVTPNKKANTSSMDYYHQLRYAAEKSRRKFLYDTNVGAGLPVIENLQNLLNAGDELMKFSGILSGSLSYIFGKLDEGMSFSEATTLAREMGYTEPDPRDDLSGMDVARKLLILARETGRELELADIEIEPVLPAEFNAEGDVAAFMANLSQLDDLFAARVAKARDEGKVLRYVGNIDEDGVCRVKIAEVDGNDPLFKVKNGENALAFYSHYYQPLPLVLRGYGAGNDVTAAGVFADLLRTLSWKLGV'
  444. super
  445. end
  446. def test_Hsp_identity
  447. # differs from XML because filtered residues are not counted in the
  448. # default format
  449. assert_equal(806, @hsp.identity)
  450. end
  451. def test_Hsp_positive
  452. # differs from XML because filtered residues are not counted in the
  453. # default format
  454. assert_equal(806, @hsp.positive)
  455. end
  456. def test_Hsp_midline
  457. # differs from XML because filtered residues are not specified in XML
  458. seq = @filtered_query_sequence.gsub(/x/, ' ')
  459. assert_equal(seq, @hsp.midline)
  460. end
  461. def test_Hsp_qseq
  462. # differs from XML because filtered residues are not specified in XML
  463. seq = @filtered_query_sequence.gsub(/x/, 'X')
  464. assert_equal(seq, @hsp.qseq)
  465. end
  466. def test_Hsp_bit_score
  467. # differs from XML because of truncation in the default format
  468. assert_equal(1567.0, @hsp.bit_score)
  469. end
  470. def test_Hsp_hit_frame
  471. # differs from XML because not available in the default BLASTP format
  472. assert_equal(nil, @hsp.hit_frame)
  473. end
  474. def test_Hsp_query_frame
  475. # differs from XML because not available in the default BLASTP format
  476. assert_equal(nil, @hsp.query_frame)
  477. end
  478. end
  479. ########################################################################
  480. # Tests for new BLAST XML format (blastall 2.2.14 or later)
  481. # with the result of multiple query sequences
  482. ########################################################################
  483. class TestBlastReportMulti < Test::Unit::TestCase
  484. include TestBlastReportHelper
  485. def setup
  486. @report = create_report_object('blastp-multi')
  487. @overall = [ @report ] + @report.reports
  488. end
  489. def test_reports
  490. assert_equal(5, @report.reports.size)
  491. end
  492. def test_iterations
  493. assert_equal(1, @report.iterations.size)
  494. assert_equal([ 1, 1, 1, 1, 1],
  495. @report.reports.collect { |x| x.iterations.size })
  496. end
  497. def test_parameters
  498. @overall.each do |r|
  499. assert_equal('BLOSUM62', r.parameters['matrix'])
  500. assert_equal(0.001, r.parameters['expect'])
  501. assert_equal(11, r.parameters['gap-open'])
  502. assert_equal(1, r.parameters['gap-extend'])
  503. assert_equal('F', r.parameters['filter'])
  504. end
  505. end
  506. def test_program
  507. @overall.each do |r|
  508. assert_equal('blastp', r.program)
  509. end
  510. end
  511. def test_version
  512. @overall.each do |r|
  513. assert_equal('blastp 2.2.18 [Mar-02-2008]', r.version)
  514. end
  515. end
  516. def test_reference
  517. text_str = '~Reference: Altschul, Stephen F., Thomas L. Madden, Alejandro A. Schaffer, ~Jinghui Zhang, Zheng Zhang, Webb Miller, and David J. Lipman (1997), ~"Gapped BLAST and PSI-BLAST: a new generation of protein database search~programs", Nucleic Acids Res. 25:3389-3402.'
  518. @overall.each do |r|
  519. assert_equal(text_str, r.reference)
  520. end
  521. end
  522. def test_db
  523. @overall.each do |r|
  524. assert_equal('BA000007.faa', r.db)
  525. end
  526. end
  527. def test_query_id
  528. qids = [ 'lcl|1_0', 'lcl|2_0', 'lcl|3_0', nil, 'lcl|5_0' ]
  529. assert_equal(qids[0], @report.query_id)
  530. assert_equal(qids,
  531. @report.reports.collect { |r| r.query_id })
  532. end
  533. def test_query_def
  534. qdefs =
  535. [ 'gi|1790845|gb|AAC77338.1| predicted DNA-binding transcriptional regulator [Escherichia coli str. K-12 substr. MG1655]',
  536. 'gi|1790846|gb|AAC77339.1| lipoate-protein ligase A [Escherichia coli str. K-12',
  537. 'gi|1790847|gb|AAC77340.1| conserved protein [Escherichia coli str. K-12 substr. MG1655]',
  538. nil,
  539. 'gi|1790849|gb|AAC77341.1| 3-phosphoserine phosphatase [Escherichia coli str. K-12 substr. MG1655]'
  540. ]
  541. assert_equal(qdefs[0], @report.query_def)
  542. assert_equal(qdefs,
  543. @report.reports.collect { |r| r.query_def })
  544. end
  545. def test_query_len
  546. qlens = [ 443, 346, 214, nil, 322 ]
  547. assert_equal(qlens[0], @report.query_len)
  548. assert_equal(qlens,
  549. @report.reports.collect { |r| r.query_len })
  550. end
  551. def test_matrix
  552. @overall.each do |r|
  553. assert_equal('BLOSUM62', r.matrix)
  554. end
  555. end
  556. def test_expect
  557. @overall.each do |r|
  558. assert_equal(0.001, r.expect)
  559. end
  560. end
  561. def test_gap_open
  562. @overall.each do |r|
  563. assert_equal(11, r.gap_open)
  564. end
  565. end
  566. def test_gap_extend
  567. @overall.each do |r|
  568. assert_equal(1, r.gap_extend)
  569. end
  570. end
  571. def test_filter
  572. @overall.each do |r|
  573. assert_equal('F', r.filter)
  574. end
  575. end
  576. def test_pattern
  577. @overall.each do |r|
  578. assert_equal(nil, r.pattern)
  579. end
  580. end
  581. def test_each_iteration
  582. @overall.each do |r|
  583. count = 0
  584. assert_nothing_raised {
  585. r.each_iteration { |itr| count += 1 }
  586. }
  587. assert_equal(1, count)
  588. end
  589. end
  590. def test_each_hit
  591. @overall.each do |r|
  592. assert_nothing_raised {
  593. r.each_hit { |hit| }
  594. }
  595. end
  596. end
  597. def test_hits
  598. hsizes = [ 0, 1, 1, 0, 2 ]
  599. assert_equal(hsizes[0], @report.hits.size)
  600. assert_equal(hsizes,
  601. @report.reports.collect { |r| r.hits.size })
  602. end
  603. def test_statistics
  604. assert_equal({}, @report.statistics)
  605. stat = {
  606. "kappa" => 0.041, "eff-space" => 0, "db-num" => 5361,
  607. "hsp-len" => 0, "db-len" => 1609188, "lambda" => 0.267,
  608. "entropy" => 0.14
  609. }
  610. stats = [ {}, stat, stat, {}, stat ]
  611. @report.reports.each do |r|
  612. assert_equal(stats.shift, r.statistics)
  613. end
  614. end
  615. def test_db_num
  616. assert_equal(nil, @report.db_num)
  617. ary = [ nil, 5361, 5361, nil, 5361 ]
  618. @report.reports.each do |r|
  619. assert_equal(ary.shift, r.db_num)
  620. end
  621. end
  622. def test_db_len
  623. assert_equal(nil, @report.db_len)
  624. ary = [ nil, 1609188, 1609188, nil, 1609188 ]
  625. @report.reports.each do |r|
  626. assert_equal(ary.shift, r.db_len)
  627. end
  628. end
  629. def test_hsp_len
  630. assert_equal(nil, @report.hsp_len)
  631. ary = [ nil, 0, 0, nil, 0 ]
  632. @report.reports.each do |r|
  633. assert_equal(ary.shift, r.hsp_len)
  634. end
  635. end
  636. def test_eff_space
  637. assert_equal(nil, @report.eff_space)
  638. ary = [ nil, 0, 0, nil, 0 ]
  639. @report.reports.each do |r|
  640. assert_equal(ary.shift, r.eff_space)
  641. end
  642. end
  643. def test_kappa
  644. assert_equal(nil, @report.kappa)
  645. ary = [ nil, 0.041, 0.041, nil, 0.041 ]
  646. @report.reports.each do |r|
  647. assert_equal(ary.shift, r.kappa)
  648. end
  649. end
  650. def test_lambda
  651. assert_equal(nil, @report.lambda)
  652. ary = [ nil, 0.267, 0.267, nil, 0.267 ]
  653. @report.reports.each do |r|
  654. assert_equal(ary.shift, r.lambda)
  655. end
  656. end
  657. def test_entropy
  658. assert_equal(nil, @report.entropy)
  659. ary = [ nil, 0.14, 0.14, nil, 0.14 ]
  660. @report.reports.each do |r|
  661. assert_equal(ary.shift, r.entropy)
  662. end
  663. end
  664. def test_message
  665. @overall.each do |r|
  666. assert_equal(nil, r.message)
  667. end
  668. end
  669. end
  670. class TestBlastReportIterationMulti < Test::Unit::TestCase
  671. include TestBlastReportHelper
  672. def setup
  673. report = create_report_object('blastp-multi')
  674. @itr = report.reports[4].iterations[0]
  675. end
  676. def test_query_id
  677. assert_equal('lcl|5_0', @itr.query_id)
  678. end
  679. def test_query_def
  680. assert_equal('gi|1790849|gb|AAC77341.1| 3-phosphoserine phosphatase [Escherichia coli str. K-12 substr. MG1655]', @itr.query_def)
  681. end
  682. def test_query_len
  683. assert_equal(322, @itr.query_len)
  684. end
  685. def test_hits
  686. assert_equal(2, @itr.hits.size)
  687. end
  688. def test_each
  689. count = 0
  690. assert_nothing_raised {
  691. @itr.each { |hit| count += 1 }
  692. }
  693. assert_equal(2, count)
  694. end
  695. def test_statistics
  696. stat = {
  697. "kappa" => 0.041, "eff-space" => 0, "db-num" => 5361,
  698. "hsp-len" => 0, "db-len" => 1609188, "lambda" => 0.267,
  699. "entropy" => 0.14
  700. }
  701. assert_equal(stat, @itr.statistics)
  702. end
  703. def test_num
  704. assert_equal(5, @itr.num)
  705. end
  706. def test_message
  707. assert_equal(nil, @itr.message)
  708. end
  709. end
  710. class TestBlastReportHitMulti < Test::Unit::TestCase
  711. include TestBlastReportHelper
  712. def setup
  713. report = create_report_object('blastp-multi')
  714. @hit = report.reports[4].iterations[0].hits[1]
  715. end
  716. def test_Hit_hsps
  717. assert_equal(1, @hit.hsps.size)
  718. end
  719. def test_Hit_query_id
  720. assert_equal('lcl|5_0', @hit.query_id)
  721. end
  722. def test_Hit_query_def
  723. assert_equal('gi|1790849|gb|AAC77341.1| 3-phosphoserine phosphatase [Escherichia coli str. K-12 substr. MG1655]', @hit.query_def)
  724. end
  725. def test_Hit_query_len
  726. assert_equal(322, @hit.query_len)
  727. end
  728. def test_Hit_num
  729. assert_equal(2, @hit.num)
  730. end
  731. def test_Hit_hit_id
  732. assert_equal('gi|13363792|dbj|BAB37741.1|', @hit.hit_id)
  733. end
  734. def test_Hit_len
  735. assert_equal(732, @hit.len)
  736. end
  737. def test_Hit_target_len
  738. assert_equal(732, @hit.target_len)
  739. end
  740. def test_Hit_definition
  741. assert_equal('zinc-transporting ATPase [Escherichia coli O157:H7 str. Sakai]', @hit.definition)
  742. end
  743. def test_Hit_taeget_def
  744. assert_equal('zinc-transporting ATPase [Escherichia coli O157:H7 str. Sakai]', @hit.target_def)
  745. end
  746. def test_Hit_accession
  747. assert_equal('BAB37741', @hit.accession)
  748. end
  749. def test_Hit_target_id
  750. #assert_equal('gi|13363792|dbj|BAB37741.1|', @hit.target_id)
  751. assert_equal('BAB37741', @hit.target_id)
  752. end
  753. def test_Hit_evalue
  754. assert_equal(0.000899657, @hit.evalue)
  755. end
  756. def test_Hit_bit_score
  757. assert_equal(38.1206, @hit.bit_score)
  758. end
  759. def test_Hit_identity
  760. assert_equal(39, @hit.identity)
  761. end
  762. def test_Hit_overlap
  763. # alignment length
  764. assert_equal(123, @hit.overlap)
  765. end
  766. def test_Hit_query_seq
  767. seq = 'VLKLETLGWKVAIASGGFTFFAEYLRDKLRLTAVVANELEIMDGKFTGNVIGDIVDAQYKAKTLTRLAQEYEIPLAQTVAIGDGANDLPMIKAAGLGIAYHAKPKVN-EKAEVTIRHADLMGV'
  768. assert_equal(seq, @hit.query_seq)
  769. end
  770. def test_Hit_target_seq
  771. seq = 'ISELNALGVKGVILTG----------DNPRAAAAIAGELGL---EFKAGLL-----PEDKVKAVTELNQHA--PLAM---VGDGINDAPAMKAAAIGIAMGSGTDVALETADAALTHNHLRGL'
  772. assert_equal(seq, @hit.target_seq)
  773. end
  774. def test_Hit_midline
  775. seq = '+ +L LG K I +G D R A +A EL + +F ++ + K K +T L Q PLA +GDG ND P +KAA +GIA + V E A+ + H L G+'
  776. assert_equal(seq, @hit.midline)
  777. end
  778. def test_Hit_query_start
  779. assert_equal(190, @hit.query_start)
  780. # assert_equal(190, @hit.query_from)
  781. end
  782. def test_Hit_query_end
  783. assert_equal(311, @hit.query_end)
  784. # assert_equal(311, @hit.query_to)
  785. end
  786. def test_Hit_target_start
  787. assert_equal(569, @hit.target_start)
  788. # assert_equal(569, @hit.hit_from)
  789. end
  790. def test_Hit_target_end
  791. assert_equal(668, @hit.target_end)
  792. # assert_equal(668, @hit.hit_to)
  793. end
  794. def test_Hit_lap_at
  795. assert_equal([190, 311, 569, 668], @hit.lap_at)
  796. end
  797. end
  798. class TestBlastReportHspMulti < Test::Unit::TestCase
  799. include TestBlastReportHelper
  800. def setup
  801. report = create_report_object('blastp-multi')
  802. @hsp = report.reports[4].iterations[0].hits[1].hsps[0]
  803. end
  804. def test_Hsp_num
  805. assert_equal(1, @hsp.num)
  806. end
  807. def test_Hsp_bit_score
  808. assert_equal(38.1206, @hsp.bit_score)
  809. end
  810. def test_Hsp_score
  811. assert_equal(87, @hsp.score)
  812. end
  813. def test_Hsp_evalue
  814. assert_equal(0.000899657, @hsp.evalue)
  815. end
  816. def test_Hsp_identity
  817. assert_equal(39, @hsp.identity)
  818. end
  819. def test_Hsp_gaps
  820. assert_equal(24, @hsp.gaps)
  821. end
  822. def test_Hsp_positive
  823. assert_equal(56, @hsp.positive)
  824. end
  825. def test_Hsp_align_len
  826. assert_equal(123, @hsp.align_len)
  827. end
  828. def test_Hsp_density
  829. assert_nothing_raised { @hsp.density }
  830. end
  831. def test_Hsp_query_frame
  832. assert_equal(1, @hsp.query_frame)
  833. end
  834. def test_Hsp_query_from
  835. assert_equal(190, @hsp.query_from)
  836. end
  837. def test_Hsp_query_to
  838. assert_equal(311, @hsp.query_to)
  839. end
  840. def test_Hsp_hit_frame
  841. assert_equal(1, @hsp.hit_frame)
  842. end
  843. def test_Hsp_hit_from
  844. assert_equal(569, @hsp.hit_from)
  845. end
  846. def test_Hsp_hit_to
  847. assert_equal(668, @hsp.hit_to)
  848. end
  849. def test_Hsp_pattern_from
  850. assert_nothing_raised { @hsp.pattern_from }
  851. end
  852. def test_Hsp_pattern_to
  853. assert_nothing_raised { @hsp.pattern_to }
  854. end
  855. def test_Hsp_qseq
  856. seq = 'VLKLETLGWKVAIASGGFTFFAEYLRDKLRLTAVVANELEIMDGKFTGNVIGDIVDAQYKAKTLTRLAQEYEIPLAQTVAIGDGANDLPMIKAAGLGIAYHAKPKVN-EKAEVTIRHADLMGV'
  857. assert_equal(seq, @hsp.qseq)
  858. end
  859. def test_Hsp_midline
  860. seq = '+ +L LG K I +G D R A +A EL + +F ++ + K K +T L Q PLA +GDG ND P +KAA +GIA + V E A+ + H L G+'
  861. assert_equal(seq, @hsp.midline)
  862. end
  863. def test_Hsp_hseq
  864. seq = 'ISELNALGVKGVILTG----------DNPRAAAAIAGELGL---EFKAGLL-----PEDKVKAVTELNQHA--PLAM---VGDGINDAPAMKAAAIGIAMGSGTDVALETADAALTHNHLRGL'
  865. assert_equal(seq, @hsp.hseq)
  866. end
  867. def test_Hsp_percent_identity
  868. assert_nothing_raised { @hsp.percent_identity }
  869. end
  870. def test_Hsp_mismatch_count
  871. assert_nothing_raised { @hsp.mismatch_count }
  872. end
  873. end
  874. # Tests for REXML version
  875. class TestBlastReportMultiREXML < TestBlastReportMulti
  876. end
  877. class TestBlastReportIterationMultiREXML < TestBlastReportIterationMulti
  878. end
  879. class TestBlastReportHitMultiREXML < TestBlastReportHitMulti
  880. end
  881. class TestBlastReportHspMultiREXML < TestBlastReportHspMulti
  882. end
  883. # Tests for XMLParser version
  884. if defined? XMLParser then
  885. class TestBlastReportMultiXMLParser < TestBlastReportMulti
  886. end
  887. class TestBlastReportIterationMultiXMLParser < TestBlastReportIterationMulti
  888. end
  889. class TestBlastReportHitMultiXMLParser < TestBlastReportHitMulti
  890. end
  891. class TestBlastReportHspMultiXMLParser < TestBlastReportHspMulti
  892. end
  893. end #if defined? XMLParser
  894. end # module Bio