Sha256: ce5d0cbe5e0c80eb41f9c3c40a0bc11f932336720d94e545bf3492ecbb6b7c4a

Contents?: true

Size: 1.59 KB

Versions: 16

Compression:

Stored size: 1.59 KB

Contents

#!/usr/bin/env ruby

require 'mspire/mzml'
require 'optparse'


# returns '3+' for 3 or '2-' for -2
def mascot_charge(val)
  "#{val}#{val > 0 ? '+' : '-'}"
end


opt = {
  filter_zero_intensity: true,
  retention_times: true,
}
opts = OptionParser.new do |op|
  op.banner = "usage: #{File.basename($0)} <file>.mzML ..."
  op.separator "outputs: <file>.mgf"
  op.on("--no-filter-zeros", "won't remove values with zero intensity") {|v| opt[:filter_zero_intensity] = false }
  # the default is set in ms/msrun/search.rb -> set_opts
  op.on("--no-retention-times", "won't include RT even if available") {|v| opt[:retention_times] = false }
end

opts.parse!

if ARGV.size == 0
  puts opts
  exit
end

filter_zeros = opt[:filter_zero_intensity]

ARGV.each do |file|
  basename = file.chomp(File.extname(file))
  outfile = basename + ".mgf"

  File.open(outfile, 'w') do |out|
    Mspire::Mzml.foreach(file).with_index do |spectrum,i|
      next unless spectrum.ms_level > 1
      out.puts "BEGIN IONS"
      # id, spectrumid, 
      rt = spectrum.retention_time
      title_ar = [i, "id_#{spectrum.id}"]
      title_ar.push("rt_#{rt.round}") if opt[:retention_times]
      title = title_ar.join('.')
      out.puts "TITLE=#{title}"
      out.puts "RTINSECONDS=#{rt}" if opt[:retention_times]
      out.puts "PEPMASS=#{spectrum.precursor_mz}"
      if z=spectrum.precursor_charge
        out.puts "CHARGE=#{mascot_charge(z)}"
      end

      spectrum.each do |mz,int|
        unless filter_zeros && (int==0.0)
          out.puts([mz, int].join(" ")) 
        end
      end
      out.puts "END IONS"
      out.puts ""
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mspire-0.10.7.2 script/mzml_to_mgf.rb
mspire-0.10.7.1 script/mzml_to_mgf.rb
mspire-0.10.7 script/mzml_to_mgf.rb
mspire-0.10.6 script/mzml_to_mgf.rb
mspire-0.10.5 script/mzml_to_mgf.rb
mspire-0.10.4 script/mzml_to_mgf.rb
mspire-0.10.3 script/mzml_to_mgf.rb
mspire-0.10.2 script/mzml_to_mgf.rb
mspire-0.10.1 script/mzml_to_mgf.rb
mspire-0.10.0 script/mzml_to_mgf.rb
mspire-0.9.2 script/mzml_to_mgf.rb
mspire-0.9.1 script/mzml_to_mgf.rb
mspire-0.9.0 script/mzml_to_mgf.rb
mspire-0.8.7 script/mzml_to_mgf.rb
mspire-0.8.6.2 script/mzml_to_mgf.rb
mspire-0.8.6.1 script/mzml_to_mgf.rb