require 'test/unit' require 'spec_id' class SpecIDTest < Test::Unit::TestCase def initialize(arg) super(arg) @tfiles = File.dirname(__FILE__) + '/tfiles/' @bw = @tfiles + "bioworks_small.xml" end def test_spec_id_creation sp = SpecID.new sp = SpecID.new(@bw) assert_equal(106, sp.prots.size) end def test_classify_by_prefix file = @tfiles + "bioworks_with_INV_small.xml" sp = SpecID.new(file) assert_equal(19, sp.prots.size) (tp, fp) = sp.classify_by_prefix(:prots, "INV_") assert_equal(4, fp.size, "num false pos") assert_equal(15, tp.size, "num true pos") end def test_precision require 'roc' file = @tfiles + "bioworks_with_INV_small.xml" # 4 INV and 15 non-inv for 19 total prots answ = %w( t t t t t t t t t t F t t t t F t F F ) index = 0 answ.collect! do |bool| bo = false if bool == 't'; bo = true end index += 1 write_index = index ## in the bioworks_with_INV_small.xml, protein 8 and 9 have the same ## probability as protein 7 if write_index == 8 || write_index == 9 write_index = 7 end [write_index, bo] end tp, fp = ROC.new.prep_list(answ) (exp_tp, exp_fp) = ROC.new.by_tps(:fpr2, tp, fp) sp = SpecID.new(file) assert_equal(19, sp.prots.size) tp, fp = sp.rank_and_classify(:prots, proc {|prt| prt.probability }, proc {|prt| if prt.reference =~ /^INV_/ ; false; else; true; end }) tps, ys = sp.by_tps(:fpr2, tp, fp) assert_equal(exp_tp, tps) assert_equal(exp_fp, ys) tps, prec, fpr = sp.tps_and_precision_and_fpr2_times2_for_prob("INV_") # @TODO: assert these guys for consistencies sake: assert_in_delta_arrays([1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 15], tps, 0.0000001) assert_in_delta_arrays([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.916666666666667, 0.923076923076923, 0.928571428571429, 0.933333333333333, 0.882352941176471], prec, 0.0000001) assert_in_delta_arrays([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.166666666666667, 0.153846153846154, 0.142857142857143, 0.133333333333333, 0.235294117647059], fpr, 0.0000001) end def assert_in_delta_arrays(one, two, delta, message=nil) one.each_with_index do |v,i| assert_in_delta(v, two[i], delta, message) end end end