require File.dirname(__FILE__) + '/load_lib_path' require 'test/unit' require 'spec/msrun' require 'spec/mzxml/parser' class MSRunTest < Test::Unit::TestCase def initialize(arg) super(arg) @tfiles = File.dirname(__FILE__) + '/tfiles/' @ti_file = @tfiles + "020a.mzXML.timeIndex" @mzxml_file = @tfiles + "opd1/twenty_scans.mzXML" end def test_basename_noext obj = Spec::MSRunIndex.new {'path/to/file.mzXML' => 'file', 'other/path/file1.mzXML.timeIndex' => 'file1', 'path2/path3/file2.timeIndex' => 'file2', 'other/path/file3.weird' => 'file3'}.each do |k,v| obj.basename_noext = k assert_equal(v, obj.basename_noext) end end def test_msrun_index_from_file guy = Spec::MSRunIndex.new(@ti_file) sbn = guy.scans_by_num s1 = sbn[1] s2 = sbn[2] sl = sbn[-1] assert [1, 1, 600.020000], [s1.num, s1.ms_level, s1.time] assert [2, 2, 601.280000], [s2.num, s2.ms_level, s2.time] assert [3496, 2, 4802.130000], [sl.num, sl.ms_level, sl.time] end def test_msrun_index_from_mzXML exp = [ "1 1 0.44", "2 2 1.9 391.045410 6986078.0", "2 3 2.75 446.009033 1531503.0", "2 4 3.64 1222.033203 1520220.0", "1 5 5.15", "2 6 6.5 390.947449 6191130.0", "2 7 7.47 1221.905518 2245001.0", "2 8 9.14 1322.036621 1946525.0", "1 9 10.69", "2 10 12.0 1322.000732 1475536.0", "2 11 13.66 1122.119141 1188303.0", "2 12 15.37 444.804504 716303.0", "1 13 16.4", "2 14 17.77 446.796082 1472386.0", "2 15 18.77 1122.041260 1411827.0", "2 16 20.65 1421.951416 1187501.0", "1 17 22.37", "2 18 23.74 358.676636 826186.0", "2 19 25.23 1460.548340 720317.0", "2 20 27.05 1422.277100 709884.0", ] %w(xmlparser rexml).each do |parser| scans = Spec::MzXML::Parser.new.scans_by_num(@mzxml_file, parser) obj = Spec::MSRunIndex.new obj.scans_by_num = scans assert_equal(Spec::MSRunIndex, obj.class) obj.scans_by_num.each_with_index do |scan,i| next if i == 0 assert_equal(Spec::Scan, scan.class) assert_equal_values(exp[i-1], scan.to_index_file_string) end end end # takes two space delimited strings # and asks if they are the same (as floats) def assert_equal_values(string1, string2) arr1 = string1.split(" ") arr2 = string2.split(" ") arr1.each_with_index do |val,i| assert_equal(val.to_f, arr2[i].to_f) end end end