require 'test/unit' require 'spec/mzxml/parser' require 'benchmark' $SPEED_TEST = false class SpecTest < Test::Unit::TestCase def initialize(arg) super(arg) @tfiles = File.dirname(__FILE__) + '/tfiles/' @tfiles_l = File.dirname(__FILE__) + '/tfiles_large/' @tscans = @tfiles + "opd1/twenty_scans.mzXML" @tf_mzxml_path = @tfiles_l + "yeast_gly_mzXML" #@big_file = "/work/john/ISB_Proteomics_18Set/mzXML/sergei_digest_A_full_01.mzXML" @big_file = "../bioworks2prophet/xml/opd00001_test_set/opd00001_prophprepped/000.mzXML" end def test_mzxml_path_precursor_mz_by_scan if File.exist? @tfiles_l hash = Spec::MzXML::Parser.new.precursor_mz_by_scan_for_path(@tf_mzxml_path, "*.mzXML") assert_equal(%w(000 020), hash.keys.sort) assert(hash["000"].size > 0) assert(hash["020"].size > 0) else assert_nil( puts("--SKIPPING TEST-- (missing dir: #{@tfiles_l})") ) end end def test_mzxml_precursor_mz_by_scan answ = {11=>"1122.119141", 6=>"390.947449", 12=>"444.804504", 7=>"1221.905518", 8=>"1322.036621", 14=>"446.796082", 15=>"1122.041260", 16=>"1421.951416", 18=>"358.676636", 2=>"391.045410", 20=>"1422.277100", 19=>"1460.548340", 3=>"446.009033", 10=>"1322.000732", 4=>"1222.033203"} loaded_xmlparser = false $".each do |lib| if lib =~ /xmlparser/ then loaded_xmlparser = true end end types = %w(regex rexml) if loaded_xmlparser types.push("xmlparser") else puts "'xmlparser' not loaded: SKIPPING 'xmlparser' testing'" end types.unshift(nil) types.each do |ty| arr = Spec::MzXML::Parser.new.precursor_mz_by_scan(@tscans, ty) assert_hash_equal_arr(answ, arr) # On my linux box these are the speed comparisons: # REXMLStreamParser ~ 28.5 sec # REGEX ~ 3.7 sec # REGEX without procs?? # XMLParser ~0.85 sec # Speed test if $SPEED_TEST puts "PARSETYPE = #{ty ? ty : "DEFAULT"}: " puts Benchmark.measure { arr = Spec::MzXML::Parser.new.precursor_mz_by_scan(@big_file, ty ? ty : nil) } end end end def Xtest_mzxml_precursor_mz_and_inten_by_scan arr = Spec::MzXML.precursor_mz_and_inten_by_scan(@tscans) answ = {11=>["1122.119141", "1188303.000000"], 6=>["390.947449", "6191130.000000"], 12=>["444.804504", "716303.000000"], 7=>["1221.905518", "2245001.000000"], 8=>["1322.036621", "1946525.000000"], 14=>["446.796082", "1472386.000000"], 15=>["1122.041260", "1411827.000000"], 16=>["1421.951416", "1187501.000000"] , 18=>["358.676636", "826186.000000"], 2=>["391.045410", "6986078.000000"], 20=>["1422.277100", "709884.000000"], 19=>["1460.548340", "720317.000000"], 3=>["446.009033", "1531503.000000"], 10=>["1322.000732", "1475536.000000"], 4=>["1222.033203", "1520220.000000"]} assert_hash_equal_arr(answ, arr) end def assert_hash_equal_arr(hash,arr) hash.each do |k,v| assert_equal(hash[k], arr[k]) end end end