require File.expand_path( File.dirname(__FILE__) + '/../spec_helper' ) require File.expand_path( File.dirname(__FILE__) + '/../validator_helper' ) require 'validator/aa' require 'spec_id' require 'spec_id/digestor' klass = Validator::AA class MyAA < Validator::AA ; def initialize ; end ; end describe klass, "using frequency estimates" do before(:each) do @small_fasta = Tfiles + '/small.fasta' @sequest_params = Tfiles + '/bioworks32.params' # C/D C/D J (7) @seqs = %w(ABCDEFGC CCDCCC JJJJJ XYZ WXXXYZ TXXXXXYZ ZZXIIPTYZ ZZXTYZZ ZZZZ YYYYYTL) @peps = @seqs.map {|n| v = SpecID::GenericPep.new; v.aaseq = n ; v } val = klass.new('C') val.frequency = 0.11 @validator = val end #C: 0.0157714433456144 #D: 0.0526145691939758 it_should_behave_like 'a validator' it 'calculates precision from actual and expected correctly' do MyAA.new.pephit_precision_from_actual_and_expected(5, 10, 100).should == 0.5 (0..10).each do |actual| precision = MyAA.new.pephit_precision_from_actual_and_expected(actual, 10, 100) answer = 1.0 - (actual.to_f/10.0) precision.should be_close(answer, 0.00000001) #0 -> 1 #1 -> 0.9 #2 -> 0.8 end end it 'calculates precision (with background) reasonably and consistently' do (0..10).each do |bkg| precision = MyAA.new.pephit_precision_from_actual_and_expected(5, 10, 100, bkg.to_f/100) answer = 0.5 + bkg.to_f/10 answer = 1.0 if answer > 1.0 precision.should == answer end end it 'calculates at_least_one correctly' do aa = 'C' freq = 0.0157714433456144 ## from @small_fasta (actual, expected) = MyAA.new.at_least_one(aa, freq, @seqs) actual.should == 2 expected.should be_close(0.949318337979434, 0.0001) # freeze for consistency end it 'gives consistent precision of peptides given fastafile and aa (even negative)' do aa = 'C' val = klass.new(aa).set_frequency(Fasta.new(@small_fasta)) # I checked this answer out by hand and it is correct val.pephit_precision(@peps).should be_close(-1.10677, 0.001) end end describe klass, "using empirical digestion data" do before(:each) do @small_fasta = Tfiles + '/small.fasta' @sequest_params = Tfiles + '/bioworks32.params' # C/D C/D J (7) @seqs = %w(ABCDEFGC CCDCCC JJJJJ XYZ WXXXYZ TXXXXXYZ ZZXIIPTYZ ZZXTYZZ ZZZZ YYYYYTL) @peps = @seqs.map {|n| v = SpecID::GenericPep.new; v.aaseq = n ; v } val = klass.new('C') val.false_to_total_ratio = 0.22 # arbitrary @validator = val end it_should_behave_like 'a validator' it 'gives correct false to total ratio' do aa = 'C' val = klass.new(aa) peptides = Digestor.digest( Fasta.new(@small_fasta), Sequest::Params.new(@sequest_params)) val.set_false_to_total_ratio( peptides ) # frozen (but I checked the peptides by hand to make sure they were # correct) val.false_to_total_ratio.should be_close(0.177629264861062, 0.0000000000001) end it 'can validate with theoretical digestion or frequency estimate' do aa = 'C' val = klass.new(aa) val.false_to_total_ratio = 0.177629264861062 answ = val.pephit_precision(@peps) # frozen answ.should be_close(-0.125940594059407, 0.0000000001) val.frequency = 0.0157714433456144 ## from @small_fasta val.false_to_total_ratio = nil answ = val.pephit_precision(@peps) answ.should be_close(-1.10677485094924, 0.0000000001) end end