require File.expand_path( File.dirname(__FILE__) + '/../spec_helper' ) require 'ms/msrun' require 'ostruct' parsers = %w(AXML LibXML XMLParser Regexp REXML) XMLStyleParser::Parser_precedence.replace( %w(AXML) ) describe "an msrun with basic, non-spectral information", :shared => true do it 'knows the type and version of file' do @run.filetype.should == @info.filetype @run.version.should == @info.version end it 'knows basic run information' do @run.scan_count.should == @info.scan_count @run.start_time.should == @info.start_time @run.end_time.should == @info.end_time end it 'has all scans' do @run.scans.size.should == @info.scan_count @run.scans.each_with_index do |sc,i| sc.class.should == MS::Scan end end it 'can determine scan counts for any mslevel' do @run.scan_counts.class.should == Array @run.scan_count(0).should == @info.scan_count0 @run.scan_count(1).should == @info.scan_count1 @run.scan_count(2).should == @info.scan_count2 end it 'has correct first two scans and last scan' do [0,1,-1].each do |i| @info.scans[i].each do |k,v| if k == :precursors v.zip( @run.scans[i].send(k) ) do |exp, act| act.mz.should be_close(exp.mz, 0.000001) #if act.intensity # intensity not guaranteed to exist! # act.intensity.should == exp.intensity #end end else @run.scans[i].send(k).should == v end end end end end describe "an msrun with spectrum", :shared => true do it 'has all scans with spectrum data' do @run.scans.size.should == @info.scan_count @run.scans.each_with_index do |sc,i| sc.class.should == MS::Scan sc.spectrum.should have_mz_data sc.spectrum.should have_intensity_data end end it 'can determine start_and_end_mz' do @run.start_and_end_mz(1).should == @info.start_and_end_mz1 @run.start_and_end_mz(2).should == @info.start_and_end_mz2 end it "has correct prec inten for first two scans and last scan" do [0,1,-1].each do |i| if i == 0 # currently we do diff't things for ms_level 1 scans! is it nil or [] #@run.scans[i].precursors.should == [] #@run.scans[i].precursors.should be_nil next end expected = @info.scans[i][:precursors] @run.scans[i].precursors.zip(expected) do |act,exp| act.mz.should be_close(exp.mz, 0.000001) act.intensity.should == exp.intensity end end end it_should_behave_like "an msrun with basic, non-spectral information" end describe 'a basic scan info generator', :shared => true do def check_table(table, answer) answer.each do |k,v| if v == nil table[k].should be_nil else table[k].should be_close(v, 0.000001) end end end it 'generates precursor_mz_by_scan_num lookup table' do ar = @run.precursor_mz_by_scan_num check_table(ar, @info.num_to_prec_mz_hash) end it 'class method -> precursor_mz_by_scan_num (with file)' do ar = @info.klass.precursor_mz_by_scan_num(@info.file) check_table(ar, @info.num_to_prec_mz_hash) end end MzXML_version_1_info = MyOpenStruct.new do |info| info.file = Tfiles_l + '/yeast_gly_mzXML/000.mzXML' info.klass = MS::MSRun info.filetype = :mzxml info.version = '1.0' info.scan_count = 3748 #info.scan_counts = [3748, 937, nil] ## need to get ms2 info.start_time = 0.44 info.end_time = 5102.55 info.num_to_prec_mz_hash = { 0 => nil, 1 => nil, 2 => 391.045410, 3 => 446.009033, 4 => 1222.033203, 5 => nil, 6 => 390.947449, 3744 => 338.779114, 3745 => nil, 3746 => 304.136597, 3748 => 433.564941, } info.scans = {} info.scans[0] = { :num => 1, :ms_level => 1, :time => 0.440, } info.scans[1] = { :num => 2, :ms_level => 2, :time => 1.90, :precursors => [MS::Precursor.new(:mz => 391.045410, :intensity => 6986078.0)] } info.scans[-1] = { :num => 3748, :ms_level => 2, :time => 5102.55, :precursors => [MS::Precursor.new(:mz => 433.564941, :intensity => 481800.0)] } info.scan_count0 = info.scan_count info.scan_count1 = 937 info.scan_count2 = 2811 info.start_and_end_mz1 = [300.0, 1500.0] info.start_and_end_mz2 = [0.0, 2000.0] end describe MS::MSRun, "on mzXML version 1 files (w/o spectra)" do spec_large do before(:all) do @info = MzXML_version_1_info start = Time.now @run = @info.klass.new(@info.file, :spectra => false) puts "- read #{File.basename(@info.file)} in #{Time.now - start} seconds" if $specdoc end it_should_behave_like "an msrun with basic, non-spectral information" it_should_behave_like 'a basic scan info generator' end end describe MS::MSRun, "on mzXML version 1 files (w/spectra)" do spec_large do before(:all) do @info = MzXML_version_1_info start = Time.now @run = @info.klass.new(@info.file) puts "- read #{File.basename(@info.file)} in #{Time.now - start} seconds" if $specdoc end it_should_behave_like "an msrun with spectrum" it_should_behave_like 'a basic scan info generator' end end MzXML_version_20_info = MyOpenStruct.new do |info| info.file = Tfiles_l + '/opd1_2runs_2mods/data/020.readw.mzXML' info.klass = MS::MSRun info.filetype = :mzxml info.version = '2.0' info.scan_count = 3620 #info.scan_counts = ?? info.start_time = 0.13 info.end_time = 5099.69 info.num_to_prec_mz_hash = { 0 => nil, 1 => nil, 2 => 390.9291992, 3 => 1121.944824, 4 => 1321.913574, 3617 => nil, 3618 => 828.2867432, 3619 => 424.8538208, 3620 => 357.0411987, } info.scans = {} info.scans[0]= { :num => 1, :ms_level => 1, :time => 0.13, } info.scans[1] = { :num => 2, :ms_level => 2, :time => 1.49, :precursors => [MS::Precursor.new(:mz => 390.9291992, :intensity => 8.14409e+006)] } info.scans[-1] = { :num => 3620, :ms_level => 2, :time => 5099.69, :precursors => [MS::Precursor.new(:mz => 357.0411987, :intensity => 643017.0)] } info.scan_count0 = info.scan_count info.scan_count1 = 905 info.scan_count2 = 2715 info.start_and_end_mz1 = [300.0, 1500.0] # that first number on start_and_end_mz2 is a arbitrary as to accuracy... # I'm not sure the correct answer info.start_and_end_mz2 = [110.0, 2000.0] end describe MS::MSRun, "on mzXML version 2.0 files (w/o spectra)" do spec_large do before(:all) do @info = MzXML_version_20_info start = Time.now @run = @info.klass.new(@info.file, :spectra => false) puts "- read #{File.basename(@info.file)} in #{Time.now - start} seconds" if $specdoc end it_should_behave_like "an msrun with basic, non-spectral information" it_should_behave_like 'a basic scan info generator' end end describe MS::MSRun, "on mzXML version 2.0 files (w/spectra)" do spec_large do before(:all) do @info = MzXML_version_20_info start = Time.now @run = @info.klass.new(@info.file) puts "- read #{File.basename(@info.file)} in #{Time.now - start} seconds" if $specdoc end it_should_behave_like "an msrun with spectrum" it_should_behave_like 'a basic scan info generator' end end Mzdata_105_info = MyOpenStruct.new do |info| info.file = Tfiles_l + '/opd1_2runs_2mods/data/020.mzData.xml' info.klass = MS::MSRun info.filetype = :mzdata info.version = '1.05' info.scan_count = 3619 # this should be 3620, they drop the last scan info.start_time = 0.13002 # minutes == 0.00216667 # This is the correct one!, but Thermo drops last scan # info.end_time = 5099.688 #84.9948 info.end_time = 84.968500*60 # 5098.11 info.num_to_prec_mz_hash = { 0 => nil, 1 => nil, 2 => 390.9291992, 3 => 1121.944824, 4 => 1321.913574, 3617 => nil, 3618 => 828.2867432, 3619 => 424.8538208, # 3620 => 357.0411987, Bioworks 3.3 is broken } info.scans = {} info.scans[0] = { :num => 1, :ms_level => 1, :time => 0.13002, # a little rounding error coming from minutes } info.scans[1] = { :num => 2, :ms_level => 2, :time => 0.024833 * 60, # 1.48998 :precursors => [MS::Precursor.new( :mz => 390.9291992, :intensity => 8.144094e+006) ], } info.scans[-1] = { :num => 3619, :ms_level => 2, #:time => 5099.69, :time => 84.968500 * 60, # 5098.11 :precursors => [MS::Precursor.new( :mz => 424.853821, :intensity => 738590.0 )] # wrong } info.scan_count0 = info.scan_count info.scan_count1 = 905 info.scan_count2 = 2714 # should be 2715, they dropped the last scan! info.start_and_end_mz1 = [300.0, 1500.0] # This is the Correct one!!!, but Thermo drops last scan #info.start_and_end_mz2 = [112.0, 2000.0] info.start_and_end_mz2 = [95.0, 2000.0] end describe MS::MSRun, "on mzData version 1.05 files (Bioworks3.3) (w/o spectra)" do spec_large do before(:all) do @info = Mzdata_105_info start = Time.now @run = @info.klass.new(@info.file, :spectra => false) puts "- read #{File.basename(@info.file)} in #{Time.now - start} seconds" if $specdoc puts "- [NOTE] mzData files from Thermo are missing their last scan!" if $specdoc end it_should_behave_like "an msrun with basic, non-spectral information" it_should_behave_like 'a basic scan info generator' end end describe MS::MSRun, "on mzData version 1.05 files (Bioworks3.3) (w/spectra)" do spec_large do before(:all) do @info = Mzdata_105_info start = Time.now @run = @info.klass.new(@info.file) puts "- read #{File.basename(@info.file)} in #{Time.now - start} seconds" if $specdoc puts "- [NOTE] mzData files from Thermo are missing their last scan!" if $specdoc end it_should_behave_like "an msrun with spectrum" it_should_behave_like 'a basic scan info generator' it 'gets correct precursor intensities for all scans' do check_file = Tfiles_l + '/opd1_2runs_2mods/data/020.readw.mzXML' prec_inten_mzs = IO.readlines(check_file).grep(/precursorMz/).map do |line| if line =~ /Intensity="([\d\.e\+\-]+)">([\d\.e\+\-]+)[20, 5, 15], :start_time=>0.44, :end_time=>27.05, :start_mz=>300.0, :end_mz=>1500.0, :ms_level=>1}, hash, "basic info the same") end end =end