mspire 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. data/INSTALL +1 -0
  2. data/README +25 -0
  3. data/Rakefile +129 -40
  4. data/bin/{find_aa_freq.rb → aafreqs.rb} +2 -2
  5. data/bin/bioworks_to_pepxml.rb +1 -0
  6. data/bin/fasta_shaker.rb +1 -96
  7. data/bin/filter_and_validate.rb +5 -0
  8. data/bin/{mzxml_to_lmat.rb → ms_to_lmat.rb} +8 -7
  9. data/bin/prob_validate.rb +6 -0
  10. data/bin/raw_to_mzXML.rb +2 -2
  11. data/bin/srf_group.rb +1 -0
  12. data/bin/srf_to_sqt.rb +40 -0
  13. data/changelog.txt +68 -0
  14. data/lib/align/chams.rb +6 -6
  15. data/lib/align.rb +4 -3
  16. data/lib/bsearch.rb +120 -0
  17. data/lib/fasta.rb +318 -86
  18. data/lib/group_by.rb +10 -0
  19. data/lib/index_by.rb +11 -0
  20. data/lib/merge_deep.rb +21 -0
  21. data/lib/{spec → ms/converter}/mzxml.rb +77 -109
  22. data/lib/ms/gradient_program.rb +171 -0
  23. data/lib/ms/msrun.rb +209 -0
  24. data/lib/{spec/msrun.rb → ms/msrun_index.rb} +7 -40
  25. data/lib/ms/parser/mzdata/axml.rb +12 -0
  26. data/lib/ms/parser/mzdata/dom.rb +160 -0
  27. data/lib/ms/parser/mzdata/libxml.rb +7 -0
  28. data/lib/ms/parser/mzdata.rb +25 -0
  29. data/lib/ms/parser/mzxml/axml.rb +11 -0
  30. data/lib/ms/parser/mzxml/dom.rb +159 -0
  31. data/lib/ms/parser/mzxml/hpricot.rb +253 -0
  32. data/lib/ms/parser/mzxml/libxml.rb +15 -0
  33. data/lib/ms/parser/mzxml/regexp.rb +122 -0
  34. data/lib/ms/parser/mzxml/rexml.rb +72 -0
  35. data/lib/ms/parser/mzxml/xmlparser.rb +248 -0
  36. data/lib/ms/parser/mzxml.rb +175 -0
  37. data/lib/ms/parser.rb +108 -0
  38. data/lib/ms/precursor.rb +10 -0
  39. data/lib/ms/scan.rb +81 -0
  40. data/lib/ms/spectrum.rb +193 -0
  41. data/lib/ms.rb +10 -0
  42. data/lib/mspire.rb +4 -0
  43. data/lib/roc.rb +61 -1
  44. data/lib/sample_enzyme.rb +31 -8
  45. data/lib/scan_i.rb +21 -0
  46. data/lib/spec_id/aa_freqs.rb +7 -3
  47. data/lib/spec_id/bioworks.rb +20 -14
  48. data/lib/spec_id/digestor.rb +139 -0
  49. data/lib/spec_id/mass.rb +116 -0
  50. data/lib/spec_id/parser/proph.rb +236 -0
  51. data/lib/spec_id/precision/filter/cmdline.rb +209 -0
  52. data/lib/spec_id/precision/filter/interactive.rb +134 -0
  53. data/lib/spec_id/precision/filter/output.rb +147 -0
  54. data/lib/spec_id/precision/filter.rb +623 -0
  55. data/lib/spec_id/precision/output.rb +60 -0
  56. data/lib/spec_id/precision/prob/cmdline.rb +139 -0
  57. data/lib/spec_id/precision/prob/output.rb +88 -0
  58. data/lib/spec_id/precision/prob.rb +171 -0
  59. data/lib/spec_id/proph/pep_summary.rb +92 -0
  60. data/lib/spec_id/proph/prot_summary.rb +484 -0
  61. data/lib/spec_id/proph.rb +2 -466
  62. data/lib/spec_id/protein_summary.rb +2 -2
  63. data/lib/spec_id/sequest/params.rb +316 -0
  64. data/lib/spec_id/sequest/pepxml.rb +1513 -0
  65. data/lib/spec_id/sequest.rb +2 -1672
  66. data/lib/spec_id/srf.rb +445 -177
  67. data/lib/spec_id.rb +183 -95
  68. data/lib/spec_id_xml.rb +8 -10
  69. data/lib/transmem/phobius.rb +147 -0
  70. data/lib/transmem/toppred.rb +368 -0
  71. data/lib/transmem.rb +157 -0
  72. data/lib/validator/aa.rb +135 -0
  73. data/lib/validator/background.rb +73 -0
  74. data/lib/validator/bias.rb +95 -0
  75. data/lib/validator/cmdline.rb +260 -0
  76. data/lib/validator/decoy.rb +94 -0
  77. data/lib/validator/digestion_based.rb +69 -0
  78. data/lib/validator/probability.rb +48 -0
  79. data/lib/validator/prot_from_pep.rb +234 -0
  80. data/lib/validator/transmem.rb +272 -0
  81. data/lib/validator/true_pos.rb +46 -0
  82. data/lib/validator.rb +214 -0
  83. data/lib/xml.rb +38 -0
  84. data/lib/xml_style_parser.rb +105 -0
  85. data/lib/xmlparser_wrapper.rb +19 -0
  86. data/script/compile_and_plot_smriti_final.rb +97 -0
  87. data/script/extract_gradient_programs.rb +56 -0
  88. data/script/get_apex_values_rexml.rb +44 -0
  89. data/script/mzXML2timeIndex.rb +1 -1
  90. data/script/smriti_final_analysis.rb +103 -0
  91. data/script/toppred_to_yaml.rb +47 -0
  92. data/script/tpp_installer.rb +1 -1
  93. data/{test/tc_align.rb → specs/align_spec.rb} +21 -27
  94. data/{test/tc_bioworks_to_pepxml.rb → specs/bin/bioworks_to_pepxml_spec.rb} +25 -41
  95. data/specs/bin/fasta_shaker_spec.rb +259 -0
  96. data/specs/bin/filter_and_validate__multiple_vals_helper.yaml +202 -0
  97. data/specs/bin/filter_and_validate_spec.rb +124 -0
  98. data/specs/bin/ms_to_lmat_spec.rb +34 -0
  99. data/specs/bin/prob_validate_spec.rb +62 -0
  100. data/specs/bin/protein_summary_spec.rb +10 -0
  101. data/{test/tc_fasta.rb → specs/fasta_spec.rb} +354 -310
  102. data/specs/gi_spec.rb +22 -0
  103. data/specs/load_bin_path.rb +7 -0
  104. data/specs/merge_deep_spec.rb +13 -0
  105. data/specs/ms/gradient_program_spec.rb +77 -0
  106. data/specs/ms/msrun_spec.rb +455 -0
  107. data/specs/ms/parser_spec.rb +92 -0
  108. data/specs/ms/spectrum_spec.rb +89 -0
  109. data/specs/roc_spec.rb +251 -0
  110. data/specs/rspec_autotest.rb +149 -0
  111. data/specs/sample_enzyme_spec.rb +41 -0
  112. data/specs/spec_helper.rb +133 -0
  113. data/specs/spec_id/aa_freqs_spec.rb +52 -0
  114. data/{test/tc_bioworks.rb → specs/spec_id/bioworks_spec.rb} +56 -71
  115. data/specs/spec_id/digestor_spec.rb +75 -0
  116. data/specs/spec_id/precision/filter/cmdline_spec.rb +20 -0
  117. data/specs/spec_id/precision/filter/output_spec.rb +31 -0
  118. data/specs/spec_id/precision/filter_spec.rb +243 -0
  119. data/specs/spec_id/precision/prob_spec.rb +111 -0
  120. data/specs/spec_id/precision/prob_spec_helper.rb +0 -0
  121. data/specs/spec_id/proph/pep_summary_spec.rb +143 -0
  122. data/{test/tc_proph.rb → specs/spec_id/proph/prot_summary_spec.rb} +52 -32
  123. data/{test/tc_protein_summary.rb → specs/spec_id/protein_summary_spec.rb} +85 -0
  124. data/specs/spec_id/sequest/params_spec.rb +68 -0
  125. data/specs/spec_id/sequest/pepxml_spec.rb +452 -0
  126. data/specs/spec_id/sqt_spec.rb +138 -0
  127. data/specs/spec_id/srf_spec.rb +209 -0
  128. data/specs/spec_id/srf_spec_helper.rb +302 -0
  129. data/specs/spec_id_helper.rb +33 -0
  130. data/specs/spec_id_spec.rb +361 -0
  131. data/specs/spec_id_xml_spec.rb +33 -0
  132. data/specs/transmem/phobius_spec.rb +423 -0
  133. data/specs/transmem/toppred_spec.rb +297 -0
  134. data/specs/transmem_spec.rb +60 -0
  135. data/specs/transmem_spec_shared.rb +64 -0
  136. data/specs/validator/aa_spec.rb +107 -0
  137. data/specs/validator/background_spec.rb +51 -0
  138. data/specs/validator/bias_spec.rb +146 -0
  139. data/specs/validator/decoy_spec.rb +51 -0
  140. data/specs/validator/fasta_helper.rb +26 -0
  141. data/specs/validator/prot_from_pep_spec.rb +141 -0
  142. data/specs/validator/transmem_spec.rb +145 -0
  143. data/specs/validator/true_pos_spec.rb +58 -0
  144. data/specs/validator_helper.rb +33 -0
  145. data/specs/xml_spec.rb +12 -0
  146. data/test_files/000_pepxml18_small.xml +206 -0
  147. data/test_files/020a.mzXML.timeIndex +4710 -0
  148. data/test_files/4-03-03_mzXML/000.mzXML.timeIndex +3973 -0
  149. data/test_files/4-03-03_mzXML/020.mzXML.timeIndex +3872 -0
  150. data/test_files/4-03-03_small-prot.xml +321 -0
  151. data/test_files/4-03-03_small.xml +3876 -0
  152. data/test_files/7MIX_STD_110802_1.sequest_params_fragment.srf +0 -0
  153. data/test_files/bioworks-3.3_10prots.xml +5999 -0
  154. data/test_files/bioworks31.params +77 -0
  155. data/test_files/bioworks32.params +62 -0
  156. data/test_files/bioworks33.params +63 -0
  157. data/test_files/bioworks_single_run_small.xml +7237 -0
  158. data/test_files/bioworks_small.fasta +212 -0
  159. data/test_files/bioworks_small.params +63 -0
  160. data/test_files/bioworks_small.phobius +109 -0
  161. data/test_files/bioworks_small.toppred.out +2847 -0
  162. data/test_files/bioworks_small.xml +5610 -0
  163. data/test_files/bioworks_with_INV_small.xml +3753 -0
  164. data/test_files/bioworks_with_SHUFF_small.xml +2503 -0
  165. data/test_files/corrupted_900.srf +0 -0
  166. data/test_files/head_of_7MIX.srf +0 -0
  167. data/test_files/interact-opd1_mods_small-prot.xml +304 -0
  168. data/test_files/messups.fasta +297 -0
  169. data/test_files/opd1/000.my_answer.100lines.xml +101 -0
  170. data/test_files/opd1/000.tpp_1.2.3.first10.xml +115 -0
  171. data/test_files/opd1/000.tpp_2.9.2.first10.xml +126 -0
  172. data/test_files/opd1/000.v2.1.mzXML.timeIndex +3748 -0
  173. data/test_files/opd1/000_020-prot.png +0 -0
  174. data/test_files/opd1/000_020_3prots-prot.mod_initprob.xml +62 -0
  175. data/test_files/opd1/000_020_3prots-prot.xml +62 -0
  176. data/test_files/opd1/opd1_cat_inv_small-prot.xml +139 -0
  177. data/test_files/opd1/sequest.3.1.params +77 -0
  178. data/test_files/opd1/sequest.3.2.params +62 -0
  179. data/test_files/opd1/twenty_scans.mzXML +418 -0
  180. data/test_files/opd1/twenty_scans.v2.1.mzXML +382 -0
  181. data/test_files/opd1/twenty_scans_answ.lmat +0 -0
  182. data/test_files/opd1/twenty_scans_answ.lmata +9 -0
  183. data/test_files/opd1_020_beginning.RAW +0 -0
  184. data/test_files/opd1_2runs_2mods/interact-opd1_mods__small.xml +753 -0
  185. data/test_files/orbitrap_mzData/000_cut.xml +1920 -0
  186. data/test_files/pepproph_small.xml +4691 -0
  187. data/test_files/phobius.small.noheader.txt +50 -0
  188. data/test_files/phobius.small.small.txt +53 -0
  189. data/test_files/s01_anC1_ld020mM.key.txt +25 -0
  190. data/test_files/s01_anC1_ld020mM.meth +0 -0
  191. data/test_files/small.fasta +297 -0
  192. data/test_files/smallraw.RAW +0 -0
  193. data/test_files/tf_bioworks2excel.bioXML +14340 -0
  194. data/test_files/tf_bioworks2excel.txt.actual +1035 -0
  195. data/test_files/toppred.small.out +416 -0
  196. data/test_files/toppred.xml.out +318 -0
  197. data/test_files/validator_hits_separate/bias_bioworks_small_HS.fasta +7 -0
  198. data/test_files/validator_hits_separate/bioworks_small_HS.xml +5651 -0
  199. data/test_files/yeast_gly_small-prot.xml +265 -0
  200. data/test_files/yeast_gly_small.1.0_1.0_1.0.parentTimes +6 -0
  201. data/test_files/yeast_gly_small.xml +3807 -0
  202. data/test_files/yeast_gly_small2.parentTimes +6 -0
  203. metadata +273 -57
  204. data/bin/filter.rb +0 -6
  205. data/bin/precision.rb +0 -5
  206. data/lib/spec/mzdata/parser.rb +0 -108
  207. data/lib/spec/mzdata.rb +0 -48
  208. data/lib/spec/mzxml/parser.rb +0 -449
  209. data/lib/spec/scan.rb +0 -55
  210. data/lib/spec_id/filter.rb +0 -797
  211. data/lib/spec_id/precision.rb +0 -421
  212. data/lib/toppred.rb +0 -18
  213. data/script/filter-peps.rb +0 -164
  214. data/test/tc_aa_freqs.rb +0 -59
  215. data/test/tc_fasta_shaker.rb +0 -149
  216. data/test/tc_filter.rb +0 -203
  217. data/test/tc_filter_peps.rb +0 -46
  218. data/test/tc_gi.rb +0 -17
  219. data/test/tc_id_class_anal.rb +0 -70
  220. data/test/tc_id_precision.rb +0 -89
  221. data/test/tc_msrun.rb +0 -88
  222. data/test/tc_mzxml.rb +0 -88
  223. data/test/tc_mzxml_to_lmat.rb +0 -36
  224. data/test/tc_peptide_parent_times.rb +0 -27
  225. data/test/tc_precision.rb +0 -60
  226. data/test/tc_roc.rb +0 -166
  227. data/test/tc_sample_enzyme.rb +0 -32
  228. data/test/tc_scan.rb +0 -26
  229. data/test/tc_sequest.rb +0 -336
  230. data/test/tc_spec.rb +0 -78
  231. data/test/tc_spec_id.rb +0 -201
  232. data/test/tc_spec_id_xml.rb +0 -36
  233. data/test/tc_srf.rb +0 -262
@@ -0,0 +1,89 @@
1
+
2
+ require File.expand_path( File.dirname(__FILE__) + '/../spec_helper' )
3
+ require 'ms/spectrum'
4
+
5
+ describe MS::Spectrum, 'equal_after_rounding?' do
6
+ before(:all) do
7
+ @spectrum = MS::Spectrum.new
8
+ end
9
+ it 'returns equal after rounding' do
10
+ [[123.32145, 123.32, true], [123.328, 123.32, false], [123, 124, false], [122.94532, 123, true], [123, 123, true], [6.233355, 6.2334, true], [1029.212890625, 1029.212891, true]].each do |ar|
11
+ (precise, less_precise, answ) = ar
12
+ @spectrum.equal_after_rounding?(precise.to_f, less_precise.to_f).should == answ
13
+ end
14
+ end
15
+
16
+
17
+ end
18
+ describe MS::Spectrum, 'with a few values' do
19
+ before(:each) do
20
+ @mz = [1.2, 4.23332, 5.345734, 6.233355, 7.889]
21
+ @spec = MS::Spectrum.new(@mz,Array.new(5,100))
22
+ end
23
+ it 'finds an index given an exact m/z' do
24
+ @mz.each_with_index do |x,i|
25
+ @spec.index(x).should == i
26
+ end
27
+ [1, 4.233, 5.346, 6.2334, 7.89].each_with_index do |x,i|
28
+ @spec.index(x).should == i
29
+ end
30
+ end
31
+
32
+ it 'index returns nil if the m/z does not exist' do
33
+ [0.9, 1.28, 0, -10, 100, 4.233322, 4.233310, 4.3, 8.001, 7.905].each_with_index do |x,i|
34
+ @spec.index(x).should == nil
35
+ end
36
+ end
37
+ it 'finds an index given a rounded m/z' do
38
+ [1, 4, 5, 6, 8].each_with_index do |x,i|
39
+ @spec.index(x).should == i
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ describe MS::Spectrum, 'of full values' do
46
+ before(:each) do
47
+ @spec = MS::Spectrum.new(Ref::MZ,Array.new(Ref::MZ.size,100))
48
+ end
49
+
50
+ it 'finds an index given an exact m/z' do
51
+ @spec.index(1121.91625976562).should == 665
52
+ @spec.index(1029.212890625).should == 597
53
+
54
+ #@spec.index(1029.212891).should == 665
55
+ end
56
+
57
+ it 'finds an index given approximate m/z' do
58
+ @spec.index(1121.91626).should == 665
59
+ @spec.index(1029.212891).should == 597
60
+ end
61
+
62
+
63
+
64
+ end
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+ class Ref
88
+ MZ = [300.801086425781, 301.70166015625, 302.771240234375, 303.972473144531, 304.845275878906, 305.704711914062, 306.92919921875, 307.755126953125, 309.0087890625, 309.868713378906, 310.956420898438, 312.174194335938, 312.815185546875, 314.045654296875, 315.086730957031, 316.046752929688, 317.3525390625, 318.233642578125, 319.613647460938, 321.082092285156, 322.192321777344, 322.95458984375, 323.894653320312, 325.020385742188, 325.743286132812, 326.779418945312, 327.823303222656, 328.613891601562, 329.550903320312, 330.544738769531, 331.53125, 332.574829101562, 334.576965332031, 335.536254882812, 336.649353027344, 337.825805664062, 339.057189941406, 340.065063476562, 340.720581054688, 341.499572753906, 342.942199707031, 343.76025390625, 344.600280761719, 345.855041503906, 346.655639648438, 347.846435546875, 348.9169921875, 349.891235351562, 350.635437011719, 351.70458984375, 352.663940429688, 353.673217773438, 354.972717285156, 355.828247070312, 356.828125, 357.716613769531, 358.844848632812, 360.2294921875, 360.850402832031, 361.569580078125, 362.565002441406, 363.612182617188, 365.454711914062, 366.121337890625, 366.760559082031, 367.6083984375, 368.523986816406, 369.439453125, 370.830444335938, 371.803466796875, 372.514587402344, 374.044555664062, 374.806091308594, 375.821472167969, 377.040344238281, 377.854248046875, 378.756591796875, 379.71533203125, 380.576477050781, 381.725463867188, 382.475708007812, 383.616394042969, 384.813537597656, 386.129638671875, 387.6005859375, 388.932556152344, 390.297546386719, 391.094055175781, 392.089965820312, 392.823608398438, 394.235961914062, 394.960632324219, 395.694702148438, 396.635864257812, 397.776733398438, 399.250183105469, 400.538269042969, 401.433288574219, 402.387023925781, 402.995971679688, 403.692077636719, 404.801391601562, 405.716735839844, 406.731872558594, 408.219970703125, 409.398498535156, 410.421936035156, 411.209594726562, 412.011962890625, 412.739013671875, 413.435119628906, 414.143432617188, 415.083251953125, 416.492919921875, 417.629638671875, 418.542541503906, 419.22216796875, 419.897338867188, 420.7880859375, 421.839172363281, 422.86328125, 424.165710449219, 425.020263671875, 425.712097167969, 427.219360351562, 427.953247070312, 429.039367675781, 429.842346191406, 430.9833984375, 431.811462402344, 432.787719726562, 434.198486328125, 434.911071777344, 435.6279296875, 437.321166992188, 438.197448730469, 441.392822265625, 442.794372558594, 443.688232421875, 444.597534179688, 445.466247558594, 446.227966308594, 446.914245605469, 447.546936035156, 448.173278808594, 449.515563964844, 450.155517578125, 451.076049804688, 451.80859375, 452.888122558594, 454.161865234375, 455.119873046875, 456.791748046875, 457.733276367188, 458.702209472656, 459.986145019531, 460.669982910156, 461.494323730469, 462.233276367188, 463.476440429688, 464.808959960938, 465.488830566406, 466.521667480469, 467.236267089844, 468.25927734375, 469.573364257812, 470.788391113281, 471.397033691406, 472.3251953125, 473.016174316406, 473.884033203125, 474.768127441406, 475.71484375, 476.4599609375, 477.563171386719, 478.803833007812, 479.960021972656, 480.684143066406, 482.565612792969, 483.507568359375, 484.445495605469, 485.277221679688, 485.967590332031, 486.720397949219, 487.870178222656, 488.918029785156, 489.744018554688, 491.068664550781, 491.833435058594, 492.650573730469, 493.965026855469, 495.259765625, 496.394714355469, 497.059448242188, 498.060180664062, 499.154357910156, 501.302062988281, 502.07275390625, 504.229919433594, 505.106811523438, 505.800537109375, 508.017761230469, 508.681884765625, 509.696044921875, 510.333312988281, 512.247802734375, 513.393798828125, 514.066650390625, 515.622314453125, 516.840087890625, 518.3681640625, 519.65673828125, 521.18798828125, 521.8134765625, 522.556640625, 525.173583984375, 526.93017578125, 527.8955078125, 528.546630859375, 530.037109375, 530.682250976562, 531.6689453125, 533.123291015625, 534.359375, 535.144409179688, 535.915893554688, 537.208251953125, 537.831787109375, 538.450927734375, 539.700805664062, 540.919921875, 541.69873046875, 542.658203125, 544.65087890625, 546.431884765625, 547.52587890625, 549.49169921875, 551.28564453125, 552.2568359375, 554.173461914062, 554.998901367188, 555.777709960938, 556.683837890625, 557.781616210938, 558.829345703125, 559.62548828125, 561.412719726562, 566.22509765625, 568.303344726562, 569.317138671875, 570.64501953125, 571.35302734375, 572.68603515625, 573.504028320312, 574.764892578125, 576.551025390625, 578.062744140625, 579.164184570312, 579.979125976562, 580.649169921875, 581.505859375, 582.594116210938, 583.317016601562, 583.935546875, 584.800659179688, 585.533325195312, 586.652099609375, 588.186767578125, 589.5595703125, 591.04345703125, 593.177368164062, 594.206787109375, 595.06591796875, 595.67822265625, 596.616333007812, 598.947021484375, 599.933471679688, 601.442138671875, 602.24853515625, 603.02880859375, 604.325927734375, 605.169189453125, 606.299560546875, 608.28369140625, 609.507202148438, 610.47900390625, 611.820556640625, 616.285278320312, 617.404052734375, 618.650390625, 619.768432617188, 621.320068359375, 622.8955078125, 624.17431640625, 625.194091796875, 625.898803710938, 627.26611328125, 628.497802734375, 630.142333984375, 630.95556640625, 631.862182617188, 632.593872070312, 634.557373046875, 635.619506835938, 636.28173828125, 638.259521484375, 639.084716796875, 641.210693359375, 642.184326171875, 642.822143554688, 643.704345703125, 644.605224609375, 645.71630859375, 646.426391601562, 648.9580078125, 650.461791992188, 651.25927734375, 652.406005859375, 653.15771484375, 654.167236328125, 655.859619140625, 656.52783203125, 657.96044921875, 658.822143554688, 659.909545898438, 660.773681640625, 661.7734375, 664.002197265625, 664.96533203125, 666.625610351562, 668.973022460938, 669.7646484375, 670.6513671875, 672.27294921875, 673.169555664062, 674.858642578125, 675.718994140625, 676.745361328125, 677.466552734375, 678.604736328125, 680.147705078125, 681.142578125, 681.933349609375, 683.229736328125, 684.41357421875, 686.447509765625, 687.880859375, 689.662719726562, 690.491821289062, 691.112060546875, 694.089599609375, 694.885620117188, 695.734619140625, 698.015625, 699.21630859375, 700.71533203125, 702.184936523438, 703.388549804688, 704.596923828125, 705.3076171875, 706.487548828125, 707.610107421875, 708.528564453125, 709.323608398438, 710.18505859375, 711.12939453125, 712.266967773438, 713.28564453125, 715.2998046875, 716.581298828125, 717.333251953125, 718.65185546875, 719.658813476562, 721.110717773438, 722.131591796875, 723.205322265625, 724.197265625, 725.251342773438, 726.477783203125, 727.608154296875, 728.540283203125, 729.320678710938, 730.3056640625, 731.65185546875, 733.397705078125, 734.366943359375, 735.504150390625, 736.795166015625, 738.273315429688, 740.48046875, 741.299072265625, 742.173461914062, 742.86669921875, 744.785888671875, 746.8779296875, 748.128784179688, 748.85986328125, 750.027709960938, 750.9765625, 751.95361328125, 753.22216796875, 754.343505859375, 755.197631835938, 756.30712890625, 756.968139648438, 757.953491210938, 759.24609375, 760.630615234375, 762.342041015625, 763.35302734375, 765.677978515625, 766.75634765625, 768.7939453125, 769.42138671875, 770.463500976562, 771.560180664062, 772.955078125, 775.075927734375, 775.7666015625, 776.741333007812, 777.477416992188, 779.6455078125, 780.4052734375, 781.199340820312, 782.47265625, 783.567260742188, 784.414794921875, 785.167358398438, 785.986083984375, 787.664794921875, 788.28759765625, 791.491821289062, 793.939086914062, 795.66455078125, 797.485595703125, 798.37841796875, 799.091796875, 800.07421875, 801.76806640625, 802.5009765625, 803.33642578125, 806.570556640625, 807.333251953125, 808.1796875, 809.757690429688, 810.576171875, 811.278564453125, 813.463623046875, 814.234252929688, 815.956665039062, 818.929931640625, 820.739624023438, 822.134033203125, 823.384643554688, 824.442260742188, 827.7109375, 829.531616210938, 830.426879882812, 832.463134765625, 833.255004882812, 834.453125, 835.244750976562, 836.306396484375, 837.582153320312, 838.958251953125, 840.4677734375, 841.878173828125, 843.275024414062, 844.0, 845.133544921875, 846.884399414062, 847.799926757812, 848.9990234375, 850.070434570312, 851.87646484375, 854.469604492188, 855.295166015625, 857.824829101562, 860.77685546875, 862.132202148438, 863.554321289062, 864.557250976562, 865.8017578125, 867.702270507812, 868.665649414062, 869.851806640625, 872.493774414062, 873.479125976562, 875.295043945312, 876.073608398438, 877.45458984375, 878.231567382812, 879.895141601562, 881.426513671875, 882.178955078125, 882.82421875, 884.2978515625, 885.93603515625, 887.682739257812, 888.5888671875, 889.888305664062, 891.596313476562, 892.661010742188, 893.334716796875, 894.553466796875, 897.082275390625, 899.702270507812, 901.876586914062, 903.037475585938, 904.111450195312, 906.00146484375, 906.629516601562, 908.138671875, 909.345825195312, 911.360107421875, 913.2080078125, 915.34326171875, 915.966552734375, 918.234741210938, 919.238403320312, 920.685913085938, 922.227783203125, 925.145385742188, 926.242797851562, 927.669921875, 928.302124023438, 929.865600585938, 931.137939453125, 931.89404296875, 932.522705078125, 933.502563476562, 934.323364257812, 936.171630859375, 936.822021484375, 938.020751953125, 940.005615234375, 941.223266601562, 942.777587890625, 943.456787109375, 945.176391601562, 946.310302734375, 947.45068359375, 950.406494140625, 951.199829101562, 952.004028320312, 952.9482421875, 954.328369140625, 955.021484375, 955.98681640625, 957.270385742188, 958.439697265625, 959.066650390625, 961.471313476562, 964.653442382812, 965.29296875, 966.430786132812, 967.450073242188, 969.279663085938, 970.070434570312, 972.778686523438, 975.616088867188, 976.281982421875, 977.298461914062, 980.384887695312, 982.016845703125, 983.19482421875, 985.753173828125, 986.75439453125, 987.38916015625, 988.11328125, 989.251220703125, 991.101318359375, 992.167358398438, 993.356567382812, 994.288818359375, 994.909545898438, 996.360107421875, 997.033203125, 999.596435546875, 1000.70825195312, 1001.82934570312, 1002.5859375, 1003.97521972656, 1006.16870117188, 1007.17919921875, 1008.37512207031, 1010.92126464844, 1011.68957519531, 1014.60095214844, 1015.32788085938, 1016.53491210938, 1019.423828125, 1021.97961425781, 1023.03479003906, 1024.06762695312, 1025.23022460938, 1028.0390625, 1029.212890625, 1030.20458984375, 1030.9814453125, 1031.58642578125, 1032.22314453125, 1033.47900390625, 1035.31103515625, 1036.27783203125, 1037.73461914062, 1040.73681640625, 1041.61083984375, 1042.40795898438, 1044.15625, 1047.22192382812, 1048.4150390625, 1049.326171875, 1050.52856445312, 1052.19677734375, 1052.86840820312, 1055.55029296875, 1056.19995117188, 1056.91650390625, 1059.255859375, 1060.0, 1060.95922851562, 1062.39501953125, 1063.42504882812, 1064.02978515625, 1066.18505859375, 1067.46337890625, 1068.771484375, 1070.34008789062, 1071.54541015625, 1072.4619140625, 1073.06665039062, 1074.25317382812, 1075.02587890625, 1075.91650390625, 1077.90380859375, 1078.623046875, 1079.625, 1081.20092773438, 1082.90673828125, 1084.12646484375, 1084.93627929688, 1086.10693359375, 1086.8212890625, 1089.87060546875, 1090.95751953125, 1091.58227539062, 1092.58056640625, 1093.18798828125, 1094.03076171875, 1094.85888671875, 1095.67578125, 1096.91772460938, 1097.76611328125, 1099.94018554688, 1104.1787109375, 1106.17016601562, 1109.21435546875, 1110.64526367188, 1111.39990234375, 1115.15551757812, 1118.62060546875, 1119.3232421875, 1120.49560546875, 1121.24438476562, 1121.91625976562, 1123.04467773438, 1124.11328125, 1125.00732421875, 1128.94750976562, 1132.93701171875, 1135.576171875, 1137.48706054688, 1140.6787109375, 1142.33544921875, 1144.44482421875, 1145.72021484375, 1146.33325195312, 1148.22900390625, 1151.29833984375, 1155.04272460938, 1155.8359375, 1157.00634765625, 1159.06323242188, 1160.17724609375, 1161.82397460938, 1164.59252929688, 1166.2470703125, 1169.43603515625, 1172.52734375, 1174.78784179688, 1175.90966796875, 1177.07763671875, 1178.1201171875, 1179.05493164062, 1180.10815429688, 1181.087890625, 1182.23583984375, 1183.14404296875, 1183.8203125, 1184.86596679688, 1185.9677734375, 1187.96240234375, 1192.14208984375, 1192.8876953125, 1194.31494140625, 1195.25439453125, 1197.404296875, 1198.44677734375, 1199.986328125, 1200.9560546875, 1202.10986328125, 1204.16528320312, 1204.92626953125, 1207.64697265625, 1209.29638671875, 1210.31469726562, 1211.55810546875, 1212.96728515625, 1213.66650390625, 1215.88720703125, 1216.65844726562, 1221.25219726562, 1222.03955078125, 1222.94189453125, 1223.84765625, 1224.94677734375, 1226.40893554688, 1227.57470703125, 1229.04736328125, 1229.91796875, 1233.10815429688, 1234.28564453125, 1235.01904296875, 1236.62036132812, 1238.3466796875, 1242.61328125, 1247.39184570312, 1248.78662109375, 1250.59375, 1253.32861328125, 1254.3173828125, 1256.03540039062, 1259.39404296875, 1261.6796875, 1263.22534179688, 1265.2001953125, 1267.65600585938, 1271.38818359375, 1272.033203125, 1272.81103515625, 1273.9462890625, 1275.4443359375, 1276.86669921875, 1277.63012695312, 1278.470703125, 1283.57397460938, 1285.2294921875, 1286.77807617188, 1287.529296875, 1289.22631835938, 1289.90405273438, 1290.55541992188, 1291.89868164062, 1293.01733398438, 1297.19946289062, 1298.38549804688, 1299.29638671875, 1300.2783203125, 1303.30151367188, 1304.17211914062, 1306.76318359375, 1307.55786132812, 1308.35620117188, 1310.16162109375, 1312.1787109375, 1313.92797851562, 1314.58325195312, 1315.9853515625, 1318.7001953125, 1320.08544921875, 1321.87451171875, 1322.6083984375, 1323.46728515625, 1324.13891601562, 1326.99365234375, 1329.58764648438, 1334.52392578125, 1335.72412109375, 1336.44018554688, 1340.24731445312, 1342.57275390625, 1345.16650390625, 1346.63305664062, 1348.08911132812, 1352.998046875, 1354.26928710938, 1354.98779296875, 1355.89990234375, 1360.693359375, 1361.45068359375, 1370.07788085938, 1373.84790039062, 1376.78540039062, 1378.5107421875, 1379.88793945312, 1382.77880859375, 1386.8427734375, 1389.30444335938, 1391.45263671875, 1392.22045898438, 1395.37744140625, 1396.14916992188, 1401.87231445312, 1408.41772460938, 1409.84790039062, 1411.30883789062, 1414.53955078125, 1415.2880859375, 1417.7275390625, 1418.34155273438, 1419.27978515625, 1420.90063476562, 1422.11083984375, 1423.06079101562, 1423.76318359375, 1424.69409179688, 1425.6943359375, 1426.994140625, 1438.1064453125, 1441.8935546875, 1445.77099609375, 1448.7431640625, 1455.90747070312, 1458.3203125, 1462.12548828125, 1463.53540039062, 1466.44091796875, 1469.74291992188, 1472.12841796875, 1473.33764648438, 1478.65185546875, 1479.49877929688, 1480.69287109375, 1487.7763671875, 1493.84423828125, 1497.70141601562]
89
+ end
data/specs/roc_spec.rb ADDED
@@ -0,0 +1,251 @@
1
+ require File.expand_path( File.dirname(__FILE__) + '/spec_helper'
2
  )
3
+ require 'roc'
4
+
5
+ describe 'an area under the curve calculator', :shared => true do
6
+
7
+ it 'calculates area under curve correctly' do
8
+ x_y_pairs = {
9
+ [[1,2,3],[2,3,4]] => 6,
10
+ [[1,2,3],[-2,-3,-4]] => -6,
11
+ [[1,2,3],[4,3,2]] => 6,
12
+ [[1,2,3],[-4,-3,-2]] => -6,
13
+ [[4,5,6],[2,1,2]] => 3,
14
+ [[4,5,6],[-2,-1,-2]] => -3,
15
+ }
16
+ x_y_pairs.each do |k,v|
17
+ calculate(*k).should == v
18
+ end
19
+ end
20
+
21
+ def calculate(x,y)
22
+ @method.call(x,y)
23
+ end
24
+ end
25
+
26
+ describe ROC do
27
+ before(:all) do
28
+ @method = proc {|x,y| ROC.new.area_under_curve(x,y) }
29
+ end
30
+ it_should_behave_like 'an area under the curve calculator'
31
+
32
+ it 'gives doublets_to_separate' do
33
+ t = true
34
+ f = false
35
+ x,y = ROC.new.doublets_to_separate([[0,f],[1,f],[2,f],[3,t],[3,f],[0,f],[4,f],[1,t],[2,t]])
36
+ x.should == [1,2,3]
37
+ y.should == [0,0,1,2,3,4]
38
+ end
39
+
40
+ it 'gives tps_and_ppv' do
41
+ tp = %w(1 2 3 4 5 6 6 6 7 8 9 10 10 10 10 11 12 ).collect {|c| c.to_f } # 17 total
42
+ fp = %w(3.5 4 5 5 5 6 6 6.5 7 8 9 9.5 10 15).collect {|c| c.to_f } # 14 total
43
+ xe = [1, 2, 3, 4, 5, 8, 9, 10, 11, 15, 16, 17]
44
+ # 1, 2, 3, 4 5, 6, 7, 8, 9
45
+ # 10 11 12
46
+ ye = [1, 1, 1, 4.0/6.0, 0.5, 8.0/(7.0+8.0), 9.0/(9.0+9.0), 0.5, 11.0/(11.0+ 11.0), 15.0/(15.0+13.0), 16.0/(16.0+13.0), 17.0/(17.0+13.0)]
47
+ _test_tps_and_ppv_method(tp,fp,xe,ye,"complex real-life-like scenario")
48
+
49
+ ## leading fp's
50
+ tp = [1,2,3]
51
+ fp = [0,0,1,2,3,4]
52
+ xe = [1,2,3]
53
+ ye = [1.0/(1+3), 2.0/(2+4), 3.0/(3+5)]
54
+ _test_tps_and_ppv_method(tp,fp,xe,ye, "leading fps")
55
+
56
+ ## leading tp's
57
+ tp = [-1,2,3]
58
+ fp = [0,4]
59
+ xe = [1,2,3]
60
+ ye = [1.0/(1+0), 2.0/(2+1), 3.0/(3+1)]
61
+ _test_tps_and_ppv_method(tp,fp,xe,ye, "leading tps")
62
+
63
+ ## equal tp's leading
64
+ tp = [0.0001,0.0001,0.0001,2]
65
+ fp = [0.01,4.0]
66
+ xe = [3,4]
67
+ ye = [3.0/(3+0), 4.0/(4+1)]
68
+ _test_tps_and_ppv_method(tp,fp,xe,ye, "equal tps leading")
69
+
70
+ ## equal arrays with some repeated values
71
+ tp = %w(1 2 3 3 4 5 6 ).collect {|x| x.to_f } # 17 total
72
+ fp = %w(1 2 3 3 4 5 6 ).collect {|x| x.to_f } # 17 total
73
+ xe = [1,2,4,5,6,7]
74
+ ye = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5]
75
+ _test_tps_and_ppv_method(tp,fp,xe,ye, "equal arrays with some repeated values")
76
+
77
+ end
78
+
79
+ it 'gives numhits_and_ppv' do
80
+ ## leading fp's
81
+ tp = [1,2,3]
82
+ fp = [0,0,1,2,3,4]
83
+ xe = [2,4,6,8,9]
84
+ ye = [0.0/2, 1.0/4, 2.0/6, 3.0/8, 3.0/9]
85
+ _test_numhits_and_ppv_method(tp,fp,xe,ye, "leading fps")
86
+
87
+ ## leading tp's
88
+ tp = [-1,2,3]
89
+ fp = [0,4]
90
+ xe = [1, 2, 3, 4, 5]
91
+ ye = [1.0/1, 1.0/2, 2.0/3, 3.0/4, 3.0/5]
92
+ _test_numhits_and_ppv_method(tp,fp,xe,ye, "leading tps")
93
+
94
+ ## equal tp's leading
95
+ tp = [0.0001,0.0001,0.0001,2]
96
+ fp = [0.01,4.0]
97
+ xe = [3, 4, 5, 6]
98
+ ye = [3.0/3, 3.0/4, 4.0/5, 4.0/6]
99
+ _test_numhits_and_ppv_method(tp,fp,xe,ye, "equal tps leading")
100
+
101
+ ## equal arrays with some repeated values
102
+ tp = %w(1 2 3 3 4 5 6 ).collect {|x| x.to_f } # 17 total
103
+ fp = %w(1 2 3 3 4 5 6 ).collect {|x| x.to_f } # 17 total
104
+ xe = [2, 4, 8, 10, 12, 14]
105
+ ye = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5]
106
+ _test_numhits_and_ppv_method(tp,fp,xe,ye, "equal arrays with some repeated values")
107
+
108
+ ## @TODO: NEED TO FILL THIS OUT!
109
+ =begin
110
+ tp = %w(1 2 3 4 5 6 6 6 7 8 9 10 10 10 10 11 12 ).collect {|c| c.to_f } # 17 total
111
+ fp = %w(3.5 4 5 5 5 6 6 6.5 7 8 9 9.5 10 15).collect {|c| c.to_f } # 14 total
112
+ xe = [1, 2, 3, 4, ]
113
+ # 1, 2, 3, 4 5, 6, 7, 8, 9
114
+ # 10 11 12
115
+ ye = [1, 1, 1, 4.0/6.0, 0.5, 8.0/(7.0+8.0), 9.0/(9.0+9.0), 0.5, 11.0/(11.0+ 11.0), 15.0/(15.0+13.0), 16.0/(16.0+13.0), 17.0/(17.0+13.0)]
116
+ _test_tps_and_ppv_method(tp,fp,xe,ye,"complex real-life-like scenario")
117
+ =end
118
+
119
+ end
120
+
121
+ def _test_numhits_and_ppv_method(tp,fp,xe,ye,message='')
122
+ roc = ROC.new
123
+ list = roc.separate_to_doublets(tp,fp)
124
+ (x,y) = roc.numhits_and_ppv(list)
125
+ y.size.should == x.size
126
+ x.should == xe
127
+ y.should == ye
128
+ end
129
+
130
+ def _test_tps_and_ppv_method(tp,fp,xe,ye,message='')
131
+ (x,y) = ROC.new.tps_and_ppv(tp,fp)
132
+ y.size.should == x.size
133
+ x.should == xe
134
+ y.should == ye
135
+ end
136
+
137
+ end
138
+
139
+ describe DecoyROC do
140
+
141
+ ###################################################################
142
+
143
+ it 'gives pred_and_ppv' do
144
+ hits = [1,2,3]
145
+ decoys = [0,0,1,2,3,4]
146
+ num_hits_e = [1,2,3]
147
+ num_fps = [3,4,5]
148
+ # expected = [-2.0/1, -2.0/2, -2.0/3]
149
+ _test_pred_and_ppv(hits, decoys, num_hits_e, num_fps)
150
+ end
151
+
152
+ it 'gives pred_tps_ppv__leading_tps' do
153
+ ## leading tp's
154
+ hits = [-1,2,3]
155
+ decoys = [0,4]
156
+ num_hits_e = [1,2,3]
157
+ num_fps = [0,1,1]
158
+ _test_pred_and_ppv(hits, decoys, num_hits_e, num_fps)
159
+ end
160
+
161
+ it 'gives pred_tps_ppv__equal_tps_leading' do
162
+ hits = [0.0001,0.0001,0.0001,2]
163
+ decoys = [0.01,4.0]
164
+ num_hits_e = [3,4]
165
+ num_fps = [0,1]
166
+ _test_pred_and_ppv(hits, decoys, num_hits_e, num_fps)
167
+ end
168
+
169
+ it 'gives pred_tps_ppv__equal_arrays_with_some_repeated_values' do
170
+ hits = %w(1 2 3 3 4 5 6 ).collect {|x| x.to_f } # 17 total
171
+ decoys = %w(1 2 3 3 4 5 6 ).collect {|x| x.to_f } # 17 total
172
+ num_hits_e = [1,2,4,5,6,7]
173
+ num_fps = [1,2,4,5,6,7]
174
+ _test_pred_and_ppv(hits, decoys, num_hits_e, num_fps)
175
+ end
176
+
177
+ ###################################################################
178
+
179
+ it 'gives pred_tps_ppv__leading_fps' do
180
+ ## leading fp's
181
+ hits = [1,2,3]
182
+ decoys = [0,0,1,2,3,4]
183
+ num_hits_e = [1,2,3]
184
+ num_fps = [3,4,5]
185
+ tps_e = make_tps_e(num_fps, num_hits_e)
186
+ ppv_e = make_ppv_e(tps_e, num_hits_e)
187
+ _test_pred_and_tps_and_ppv(hits, decoys, num_hits_e, tps_e, ppv_e)
188
+ end
189
+
190
+ it 'gives pred_tps_ppv__leading_tps' do
191
+ ## leading tp's
192
+ hits = [-1,2,3]
193
+ decoys = [0,4]
194
+ num_hits_e = [1,2,3]
195
+ num_fps = [0,1,1]
196
+ tps_e = make_tps_e(num_fps, num_hits_e)
197
+ ppv_e = make_ppv_e(tps_e, num_hits_e)
198
+ _test_pred_and_tps_and_ppv(hits, decoys, num_hits_e, tps_e, ppv_e)
199
+ end
200
+
201
+ it 'gives pred_tps_ppv__equal_tps_leading' do
202
+ hits = [0.0001,0.0001,0.0001,2]
203
+ decoys = [0.01,4.0]
204
+ num_hits_e = [3,4]
205
+ num_fps = [0,1]
206
+ tps_e = make_tps_e(num_fps, num_hits_e)
207
+ ppv_e = make_ppv_e(tps_e, num_hits_e)
208
+ _test_pred_and_tps_and_ppv(hits, decoys, num_hits_e, tps_e, ppv_e)
209
+ end
210
+
211
+ it 'gives pred_tps_ppv__equal_arrays_with_some_repeated_values' do
212
+ hits = %w(1 2 3 3 4 5 6 ).collect {|x| x.to_f } # 17 total
213
+ decoys = %w(1 2 3 3 4 5 6 ).collect {|x| x.to_f } # 17 total
214
+ num_hits_e = [1,2,4,5,6,7]
215
+ num_fps = [1,2,4,5,6,7]
216
+ tps_e = make_tps_e(num_fps, num_hits_e)
217
+ ppv_e = make_ppv_e(tps_e, num_hits_e)
218
+ _test_pred_and_tps_and_ppv(hits, decoys, num_hits_e, tps_e, ppv_e)
219
+ end
220
+
221
+ def _test_pred_and_ppv(hits, decoys, num_hits_e, num_fps)
222
+ answer = DecoyROC.new.pred_and_ppv(hits, decoys)
223
+ precision = num_hits_e.zip(num_fps).map do |h,f|
224
+ (h - f).to_f / h
225
+ end
226
+ answer.should == [num_hits_e, precision]
227
+ end
228
+
229
+ def _test_pred_and_tps_and_ppv(hits, decoys, num_hits_e, tps_e, ppv_e)
230
+ answer = DecoyROC.new.pred_and_tps_and_ppv(hits, decoys)
231
+ expected = [num_hits_e, tps_e, ppv_e]
232
+ %w(num_hits num_tps ppv).each_with_index do |cat, i|
233
+ answer[i].should == expected[i]
234
+ end
235
+ end
236
+
237
+ def make_tps_e(num_fps, num_hits_e)
238
+ tps_e = []
239
+ num_hits_e.each_with_index do |v,i|
240
+ tps_e[i] = v - num_fps[i]
241
+ end
242
+ tps_e
243
+ end
244
+
245
+ def make_ppv_e(tps_e, num_hits_e)
246
+ ppv_e = []
247
+ tps_e.each_with_index {|v,i| ppv_e[i] = v.to_f/num_hits_e[i] }
248
+ ppv_e
249
+ end
250
+
251
+ end
252
+
@@ -0,0 +1,149 @@
1
+ # (c) Copyright 2006-2007 Nick Sieger <nicksieger@gmail.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person
4
+ # obtaining a copy of this software and associated documentation files
5
+ # (the "Software"), to deal in the Software without restriction,
6
+ # including without limitation the rights to use, copy, modify, merge,
7
+ # publish, distribute, sublicense, and/or sell copies of the Software,
8
+ # and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'rubygems'
24
+ gem 'ZenTest'
25
+ require 'autotest'
26
+
27
+ class RspecAutotest < Autotest
28
+ attr_accessor :spec_command
29
+ def initialize # :nodoc:
30
+ @spec_command = "spec --diff unified"
31
+ super
32
+ @exceptions = %r%^\./(?:coverage|doc)%
33
+ end
34
+
35
+ def tests_for_file(filename)
36
+ case filename
37
+ when /^lib\/.*\.rb$/ then
38
+ impl = File.basename(filename).gsub('_', '_?').sub(/\.rb$/, '')
39
+ @files.keys.select do |k|
40
+ k =~ %r%^spec/.*#{impl}_spec\.rb$%
41
+ end
42
+ when %r%^spec/spec_helper.rb% then
43
+ @files.keys.select do |f|
44
+ f =~ %r%^spec/.*_spec\.rb$%
45
+ end
46
+ when /^spec\/.*_spec\.rb$/ then
47
+ [filename]
48
+ when /#{Regexp.quote(File.basename(__FILE__))}/
49
+ # Don't respond to changes to this file
50
+ []
51
+ else
52
+ @output.puts "Dunno! #{filename}" if $TESTING
53
+ []
54
+ end
55
+ end
56
+
57
+ def handle_results(results)
58
+ failed = results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
59
+ @files_to_test = consolidate_failures failed
60
+ unless @files_to_test.empty? then
61
+ hook :red
62
+ else
63
+ hook :green
64
+ end unless $TESTING
65
+ @tainted = true unless @files_to_test.empty?
66
+ end
67
+
68
+ def consolidate_failures(failed)
69
+ filters = Hash.new { |h,k| h[k] = [] }
70
+ failed.each do |spec, failed_trace|
71
+ @files.keys.select{|f| f =~ /spec\//}.each do |f|
72
+ if failed_trace =~ Regexp.new(f)
73
+ filters[f] << spec
74
+ break
75
+ end
76
+ end
77
+ end
78
+ return filters
79
+ end
80
+
81
+ def make_test_cmd(files_to_test)
82
+ cmds = []
83
+ full, partial = files_to_test.partition { |k,v| v.empty? }
84
+
85
+ unless full.empty? then
86
+ classes = full.map {|k,v| k}.flatten.join(' ')
87
+ cmds << "#{spec_command} #{classes}"
88
+ end
89
+
90
+ partial.each do |klass, methods|
91
+ methods.each { |meth| cmds << "#{spec_command} -s #{meth.inspect} #{klass}" }
92
+ end
93
+
94
+ return cmds.join('; ')
95
+ end
96
+ end
97
+
98
+ class RspecOnRailsAutotest < RspecAutotest
99
+ def initialize # :nodoc:
100
+ super
101
+ @exceptions = %r%^\./(?:coverage|db|doc|log|public|script|vendor)%
102
+ end
103
+
104
+ def tests_for_file(filename)
105
+ case filename
106
+ when %r%^spec/fixtures/(.*)s.yml% then
107
+ ["spec/models/#{$1}_spec.rb",
108
+ "spec/controllers/#{$1}_controller_spec.rb"]
109
+ when %r%^spec/models/.*rb$% then
110
+ [filename]
111
+ when %r%^spec/controllers/.*\.rb$% then
112
+ [filename]
113
+ when %r%^spec/views/.*\.rb$% then
114
+ [filename]
115
+ when %r%^spec/helpers/.*\.rb$% then
116
+ [filename]
117
+ when %r%^app/models/(.*)\.rb$% then
118
+ ["spec/models/#{$1}_spec.rb"]
119
+ when %r%^app/helpers/application_helper.rb% then
120
+ @files.keys.select { |f|
121
+ f =~ %r%^spec/controllers/.*_spec\.rb$%
122
+ }
123
+ when %r%^app/helpers/(.*)_helper.rb% then
124
+ ["spec/controllers/#{$1}_controller_spec.rb", "spec/helpers/#{$1}_spec.rb"]
125
+ when %r%^app/controllers/application.rb$% then
126
+ @files.keys.select { |f|
127
+ f =~ %r%^spec/controllers/.*_spec\.rb$%
128
+ }
129
+ when %r%^app/controllers/(.*)\.rb$% then
130
+ ["spec/controllers/#{$1}_spec.rb"]
131
+ when %r%^app/views/layouts/% then
132
+ []
133
+ when %r%^app/views/(.*)/% then
134
+ ["spec/controllers/#{$1}_controller_spec.rb", "spec/views/#{$1}_spec.rb"]
135
+ when %r%^config/routes.rb$% then
136
+ @files.keys.select do |f|
137
+ f =~ %r%^spec/controllers/.*_spec\.rb$%
138
+ end
139
+ when %r%^spec/spec_helper.rb%,
140
+ %r%^config/((boot|environment(s/test)?).rb|database.yml)% then
141
+ @files.keys.select do |f|
142
+ f =~ %r%^spec/(models|controllers)/.*_spec\.rb$%
143
+ end
144
+ else
145
+ @output.puts "Dunno! #{filename}" if $TESTING
146
+ []
147
+ end.uniq.select { |f| @files.has_key? f }
148
+ end
149
+ end
@@ -0,0 +1,41 @@
1
+
2
+ require File.expand_path( File.dirname(__FILE__) + '/spec_helper' )
3
+ require 'sample_enzyme'
4
+ require 'set'
5
+
6
+ describe SampleEnzyme, "digesting sequences" do
7
+ it 'can digest with no missed cleavages' do
8
+ st = "CRGATKKTAGRPMEK"
9
+ SampleEnzyme.tryptic(st).should == %w(CR GATK K TAGRPMEK)
10
+ st = "CATRP"
11
+ SampleEnzyme.tryptic(st).should == %w(CATRP)
12
+ st = "RCATRP"
13
+ SampleEnzyme.tryptic(st).should == %w(R CATRP)
14
+ st = ""
15
+ SampleEnzyme.tryptic(st).should == []
16
+ st = "R"
17
+ SampleEnzyme.tryptic(st).should == %w(R)
18
+ end
19
+
20
+ it 'can digest with missed cleavages' do
21
+ st = "CRGATKKTAGRPMEKLLLERTKY"
22
+ zero = %w(CR GATK K TAGRPMEK LLLER TK Y)
23
+ SampleEnzyme.tryptic(st,0).to_set.should == zero.to_set
24
+ one = %w(CRGATK GATKK KTAGRPMEK TAGRPMEKLLLER LLLERTK TKY)
25
+ SampleEnzyme.tryptic(st,1).to_set.should == (zero+one).to_set
26
+ two = %w(CRGATKK GATKKTAGRPMEK KTAGRPMEKLLLER TAGRPMEKLLLERTK LLLERTKY)
27
+ all = zero + one + two
28
+ SampleEnzyme.tryptic(st,2).to_set.should == all.to_set
29
+ end
30
+
31
+ it 'contains duplicates IF there are duplicate tryptic sequences' do
32
+ st = "AAAAKCCCCKDDDDKCCCCK"
33
+ peps = SampleEnzyme.new('trypsin').digest(st, 2)
34
+ peps.select {|aaseq| aaseq == 'CCCCK'}.size.should == 2
35
+ end
36
+
37
+
38
+ end
39
+
40
+
41
+
@@ -0,0 +1,133 @@
1
+ gem 'rspec'
2
+
3
+
4
+ # a global flag that lets me know what format we're dealing with for output
5
+ $specdoc = false
6
+ ObjectSpace.each_object do |obj|
7
+ case obj
8
+ when Spec::Runner::Formatter::SpecdocFormatter
9
+ $specdoc = true
10
+ end
11
+ end
12
+
13
+ # Set up some global testing variables:
14
+ #silent {
15
+ ROOT_DIR = File.dirname(__FILE__) + '/..'
16
+ SPEC_DIR = File.dirname(__FILE__)
17
+
18
+ Tfiles = File.dirname(__FILE__) + '/../test_files'
19
+ Tfiles_l = File.dirname(__FILE__) + '/../test_files_large'
20
+ Tfiles_large = Tfiles_l
21
+ #}
22
+
23
+ # this variable is for large files!
24
+ if ENV['SPEC_LARGE']
25
+ $spec_large = true
26
+ else
27
+ #[NOTE: NOT testing with large test files]"
28
+ # ** run with env var: SPEC_LARGE and ensure tfiles_large dir"
29
+ $spec_large = false
30
+ end
31
+
32
+ def spec_large(&block)
33
+ if $spec_large
34
+ block.call
35
+ else
36
+ # Requires SPEC_LARGE=true and tfiles_large dir for testing large test files
37
+ it 'SKIPPING (not testing large files)' do
38
+ end
39
+ end
40
+ end
41
+
42
+ # returns all output to stdout as a string
43
+ # will respond to is_a? File -> false is_a? IO true even though it is really a
44
+ # file
45
+ def capture_stdout(&block)
46
+ capture_file = Tfiles + '/capture_stdout.tmp'
47
+ def capture_file.is_a?(klass)
48
+ case klass.to_s
49
+ when 'IO'
50
+ true
51
+ when 'File'
52
+ false
53
+ else
54
+ false
55
+ end
56
+ end
57
+ $stdout = File.open(capture_file, 'w')
58
+ block.call
59
+ $stdout.close
60
+ $stdout = STDOUT
61
+ string = IO.read(capture_file)
62
+ File.unlink capture_file
63
+ string
64
+ end
65
+
66
+ require 'ostruct'
67
+ # class for using a ruby-ish initializer
68
+ class MyOpenStruct < OpenStruct
69
+ def initialize(*args)
70
+ super(*args)
71
+ if block_given?
72
+ yield(self)
73
+ end
74
+ end
75
+ end
76
+
77
+
78
+ def xdescribe(*args)
79
+ puts "describe: #{args.join(' ')}"
80
+ puts "**SKIPPING**"
81
+ end
82
+
83
+ def Xdescribe(*args)
84
+ xdescribe(*args)
85
+ end
86
+
87
+ def xit(*args)
88
+ puts "\n- SKIPPING: #{args.join(' ')}"
89
+ end
90
+
91
+ def it_should(*args)
92
+ string = "- WRITE TEST: #{args.join(' ')}"
93
+ if $specdoc
94
+ puts(string)
95
+ else
96
+ puts("\n" + string)
97
+ end
98
+ end
99
+
100
+ def silent(&block)
101
+ tmp = $VERBOSE ; $VERBOSE = nil
102
+ block.call
103
+ $VERBOSE = tmp
104
+ end
105
+
106
+
107
+ require SPEC_DIR + '/load_bin_path'
108
+
109
+ class String
110
+ #alias_method :exist?, exist_as_a_file?
111
+ #alias_method exist_as_a_file?, exist?
112
+ def exist?
113
+ File.exist? self
114
+ end
115
+ def exist_as_a_file?
116
+ File.exist? self
117
+ end
118
+ end
119
+
120
+ describe "a cmdline program", :shared => true do
121
+ before(:all) do
122
+ testdir = File.dirname(__FILE__)
123
+ libdir = testdir + '/../lib'
124
+ bindir = testdir + '/../bin'
125
+ @cmd = "ruby -I #{libdir} #{bindir}/#{@progname} "
126
+ end
127
+
128
+ it 'gives usage when called with no args' do
129
+ reply = `#{@cmd}`
130
+ reply.should =~ /usage/i
131
+ end
132
+
133
+ end