require File.expand_path( File.dirname(__FILE__) + '/../../spec_helper' ) require 'spec_id/proph/pep_summary' ToCheck = { :spectrum_query => {:first => {:spectrum => "020.42.42.3", :start_scan=>42, :end_scan=>42, :precursor_neutral_mass=>1015.77285654469, :assumed_charge=>3, :index=>1 }, :last => {:spectrum=>"020.344.344.3", :start_scan=>344, :end_scan=>344, :precursor_neutral_mass=>1447.6040333025, :assumed_charge=>3, :index=>18 }, }, :search_hit => {:first => {:hit_rank=>1, :peptide=>"GTGVSVTR", :peptide_prev_aa=>"R", :peptide_next_aa=>"S", :protein=>"gi|49176370|ref|YP_026228.1|", :num_tot_proteins=>1, :num_matched_ions=>10, :tot_num_ions=>70, :calc_neutral_pep_mass=>1015.79382542, :massdiff=>-0.0209688753124055, :num_tol_term=>2, :num_missed_cleavages=>0, :is_rejected=>0, :xcorr=>1.06543827056885, :deltacn => 0.192325830459595, :deltacnstar=>0, :spscore=>77.8397979736328, :sprank=>3, :probability=>0.07881571, :fval=>0.1592, :ntt=>2, :nmc=> 0, :massd=>-0.021}, :last => { :hit_rank=>1, :peptide=>"VAALRVPGGASLTR", :peptide_prev_aa=>"R", :peptide_next_aa=>"K", :protein=>"gi|16129819|ref|NP_416380.1|", :num_tot_proteins=>1, :num_matched_ions=>16, :tot_num_ions=>78, :calc_neutral_pep_mass=>1447.58289842, :massdiff=> 0.0211348825000641, :num_tol_term=>2, :num_missed_cleavages=>1, :is_rejected=>0, :xcorr=>1.3090912103653, :deltacn => 0.259967535734177, :deltacnstar => 0, :spscore => 118.513412475586, :sprank => 4, :probability=>0.27738378, :fval=>1.3810, :ntt=>2, :nmc=>1, :massd=>0.021 }, } } describe Proph::PepSummary, "reading a .xml file" do before(:each) do file = Tfiles + '/opd1_2runs_2mods/interact-opd1_mods__small.xml' @obj = Proph::PepSummary.new(file) end it 'should raise an error if not a peptide prophet file' do lambda { Proph::PepSummary.new(Tfiles + '/opd1/000.tpp_2.9.2.first10.xml')}.should raise_error(ArgumentError) end it 'has spectrum queries' do @obj.spectrum_queries.size.should == 18 [:first, :last].each do |mth| ToCheck[:spectrum_query][mth].each do |k,v| @obj.spectrum_queries.send(mth).send(k).should == v end ToCheck[:search_hit][mth].each do |k,v| @obj.spectrum_queries.send(mth).search_results.first.search_hits.first.send(k).should == v end end end it 'has pephits (which are descended from SearchHit)' do @obj.peps.size.should == 18 [:hit_rank, :probability, :fval, :ntt, :nmc, :massd].each do |guy| @obj.peps.first.should respond_to(guy) end [:first, :last].each do |mth| ToCheck[:search_hit][mth].each do |k,v| @obj.peps.send(mth).send(k).should == v end end end end #################################################### # OTHER TESTS NOT IMPLEMENTED (do we need these??) #################################################### =begin require 'test/unit' require 'spec_id' require 'ms/scan' class ProphTest < Test::Unit::TestCase def initialize(arg) super(arg) @tfiles = File.dirname(__FILE__) + '/tfiles/' @pepproph_xml = @tfiles + 'pepproph_small.xml' end def Xtest_filter_by_min_pep_prob obj = Proph::Pep::Parser.new new_file = "tfiles/tmp.xml" assert_match(/peptideprophet_result probability="0.[0-5]/, IO.read(@pepproph_xml)) obj.filter_by_min_pep_prob(@pepproph_xml, new_file, 0.50) assert_no_match(/peptideprophet_result probability="0.[0-5]/, IO.read(new_file)) assert_match(/]*probability="0.[6-9][^>]*>/, IO.read(new_file)) File.unlink new_file end def Xtest_uniq_by_seqcharge cls = Proph::Pep p1 = cls.new({ :charge => '2', :sequence => 'PEPTIDE' }) p2 = cls.new({ :charge => '3', :sequence => 'PEPTIDE' }) p3 = cls.new({ :charge => '2', :sequence => 'PEPTIDE' }) p4 = cls.new({ :charge => '2', :sequence => 'APEPTIDE' }) p5 = cls.new({ :charge => '2', :sequence => 'APEPTIDE' }) un_peps = cls.uniq_by_seqcharge([p1,p2,p3,p4,p5]) ## WHY ISn't that working? below! ##assert_equal([p1,p2,p4].to_set, un_peps.to_set) assert(equal_sets([p1,p2,p4], un_peps)) end def Xequal_sets(arr1, arr2) c1 = arr1.dup c2 = arr2.dup arr1.each do |c| arr2.each do |d| if c == d c1.delete c c2.delete d end end end if (c1.size == c2.size) && (c1.size == 0) true else false end end def Xtest_arithmetic_avg_scan_by_parent_time i1 = 100015.0 i2 = 30000.0 i3 = 100.0 t1 = 0.13 t2 = 0.23 t3 = 0.33 p1 = MS::Scan.new(1,1, t1) p2 = MS::Scan.new(2,1, t2) p3 = MS::Scan.new(3,1, t3) s1 = MS::Scan.new(1,2,0.10, 300.2, i1, p1) s2 = MS::Scan.new(2,2,0.20, 301.1, i2, p2) s3 = MS::Scan.new(3,2,0.30, 302.0, i3, p3) scan = Proph::Pep.new({:scans => [s1,s2,s3]}).arithmetic_avg_scan_by_parent_time tot_inten = i1 + i2 + i3 tm = ( t1 * (i1/tot_inten) + t2 * (i2/tot_inten) + t3 * (i3/tot_inten) ) {:ms_level => 2, :prec_inten => 130115.0/3, :num => nil, :prec_mz => 301.1.to_f, :time => tm }.each do |k,v| if k == :prec_mz # not sure why this is bugging out, but.. assert_equal(v.to_s, scan.send(k).to_s) else assert_equal(v, scan.send(k)) end end end end =end