require File.dirname(__FILE__) + '/load_lib_path' require 'test/unit' require 'spec_id' require 'spec/scan' class ProphTest < Test::Unit::TestCase def initialize(arg) super(arg) @tfiles = File.dirname(__FILE__) + '/tfiles/' @pepproph_xml = @tfiles + 'pepproph_small.xml' end def test_parse_protxml_file file = @tfiles + 'opd1/000_020_3prots-prot.xml' #obj = SpecID::Proph::ProtSummary.new obj = SpecID::Proph::ProtSummary.new(file) assert_equal(3, obj.prot_groups.size) assert_equal("1.00", obj.prot_groups.first.probability) assert_equal("0.98", obj.prot_groups[2].probability) assert_equal_xml_atts_to_obj('protein_name="gi|16132019|ref|NP_418618.1|" n_indistinguishable_proteins="1" probability="1.00" percent_coverage="13.0" unique_stripped_peptides="FRDGLK+AIQFAQDVGIRVIQLAGYDVYYQEANNETRR" group_sibling_id="a" total_number_peptides="2" pct_spectrum_ids="0.41"', obj.prot_groups[1].prots.first) end def assert_equal_xml_atts_to_obj(string, obj, msg=nil) parts = string.split(/\s+/) parts.each do |part| pi = part.split('=') value = pi[1].sub(/^"/,'').sub(/"$/,'') if pi[0] == "probability" value = value.to_f end assert_equal(value, obj.send(pi[0].to_sym)) end end def Xtest_filter_by_min_pep_prob obj = SpecID::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 = SpecID::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 = Spec::Scan.new(1,1, t1) p2 = Spec::Scan.new(2,1, t2) p3 = Spec::Scan.new(3,1, t3) s1 = Spec::Scan.new(1,2,0.10, 300.2, i1, p1) s2 = Spec::Scan.new(2,2,0.20, 301.1, i2, p2) s3 = Spec::Scan.new(3,2,0.30, 302.0, i3, p3) scan = SpecID::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