Class: Combiner
- Inherits:
-
Object
- Object
- Combiner
- Defined in:
- lib/spectral_summing.rb
Constant Summary collapse
- Defaults =
{:bin_window => 0.1, :window_size => 4, :precursor_mass_tolerance_in_ppm => 10, :tolerant => false}
Instance Attribute Summary collapse
-
#output_spectra ⇒ Object
Returns the value of attribute output_spectra.
Instance Method Summary collapse
- #calculate_daltons_from_ppm(mass, ppm) ⇒ Object
- #combine(spectrum1, spectrum2) ⇒ Object
- #combine_for_more_combining(spectrum1, spectrum2) ⇒ Object
-
#combine_to_mgf(spectrum1, spectrum2, filename) ⇒ Object
Thanks JOHN!!! Ms-Msrun 0.3.6.
-
#initialize(spectra = nil, opts = {}) ⇒ Combiner
constructor
A new instance of Combiner.
-
#summer(x1, y1, x2, y2) ⇒ Object
What should this return?.
- #to_mgf(spectrum, filename) ⇒ Object
Constructor Details
Instance Attribute Details
#output_spectra ⇒ Object
Returns the value of attribute output_spectra.
34 35 36 |
# File 'lib/spectral_summing.rb', line 34 def output_spectra @output_spectra end |
Instance Method Details
#calculate_daltons_from_ppm(mass, ppm) ⇒ Object
93 94 95 96 |
# File 'lib/spectral_summing.rb', line 93 def calculate_daltons_from_ppm(mass, ppm) diff = ppm*mass/1e6 (mass-diff)..(mass+diff) end |
#combine(spectrum1, spectrum2) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/spectral_summing.rb', line 39 def combine(spectrum1, spectrum2) tolerance = calculate_daltons_from_ppm(spectrum1.precursor_mass, @opts[:precursor_mass_tolerance_in_ppm] ) if tolerance.include?(spectrum2.precursor_mass) or @opts[:tolerant] data_arr = summer(spectrum1.mz_values, spectrum1.intensities, spectrum2.mz_values, spectrum2.intensities) end data_arr end |
#combine_for_more_combining(spectrum1, spectrum2) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/spectral_summing.rb', line 84 def combine_for_more_combining(spectrum1, spectrum2) arr = combine(spectrum1, spectrum2) joined_spectrum = Spectrum.new() joined_spectrum.precursor_mass = (spectrum1.precursor_mass + spectrum2.precursor_mass)/2.0 joined_spectrum.mz_values = arr.first joined_spectrum.intensities = arr.last # Spectrum = Struct.new(:spectrum, :scan_num, :scan_time, :scan_range, :precursor_mass, :charge_states, :intensities, :mz_values) joined_spectrum end |
#combine_to_mgf(spectrum1, spectrum2, filename) ⇒ Object
Thanks JOHN!!! Ms-Msrun 0.3.6
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/spectral_summing.rb', line 110 def combine_to_mgf(spectrum1, spectrum2, filename) # Thanks JOHN!!! Ms-Msrun 0.3.6 results = combine(spectrum1, spectrum2) File.open(filename, 'w') do |out| out.puts "BEGIN IONS" out.puts "TITLE=Spec1:#{spectrum1.precursor_mass}_Spec2:#{spectrum2.precursor_mass}.#{spectrum1.scan_num}_#{spectrum2.scan_num}_#{spectrum1.charge_states.first}" out.puts "CHARGE=#{spectrum1.charge_states.to_s}+" # our current mzML parser doesn't have scan.time implemented... results.first.each_with_index do |mz, i| intensity = results.last[i] out.puts "#{"%.5f" % mz}/t#{"%.5f" % intensity}" unless intensity == 0 end out.puts "END IONS" end end |
#summer(x1, y1, x2, y2) ⇒ Object
What should this return?
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/spectral_summing.rb', line 46 def summer(x1,y1,x2,y2) # What should this return? endpoints = (x1+x2).each.minmax bin_width = @opts[:bin_window] num_bins = ((endpoints.last - endpoints.first)/bin_width).ceil data_x = [endpoints.first+bin_width/2.0] data_y = Array.new(num_bins, 0) j, k = 0,0 one = [x1,y1]; two = [x2,y2] if x1.first == endpoints.first data_x[0] = x1.first data_y[0] += y1.first y1[0] = 0 elsif x2.first == endpoints.first data_x[0] = x2.first data_y[0] += y2.first y2[0] = 0 end (1..num_bins-1).each do |i| data_x[i] = data_x[i-1] + bin_width check = data_x[i] + bin_width/2.0 #puts "check= #{check}" if one.first[j] while one.first[j] < check data_y[i] += one.last[j] j += 1 break if one.first[j].nil? end end if two.first[k] while two.first[k] < check data_y[i] += two.last[k] k += 1 break if two.first[k].nil? end end end [data_x, data_y] end |
#to_mgf(spectrum, filename) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/spectral_summing.rb', line 97 def to_mgf(spectrum, filename) File.open(filename,'w') do |out| out.puts "BEGIN IONS" out.puts "TITLE=Spec1:#{spectrum.precursor_mass}_#{spectrum.charge_states.first}" out.puts "CHARGE=#{spectrum.charge_states.to_s}+" # our current mzML parser doesn't have scan.time implemented... spectrum.mz_values.each_with_index do |mz, i| intensity = spectrum.intensities[i] out.puts "#{"%.5f" % mz}/t#{"%.5f" % intensity}" unless intensity == 0 end out.puts "END IONS" end end |