Module: Mspire::Imzml::Writer::Commandline

Defined in:
lib/mspire/imzml/writer/commandline.rb

Class Method Summary collapse

Class Method Details

.parserObject

generates the Trollop parser



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
84
# File 'lib/mspire/imzml/writer/commandline.rb', line 17

def self.parser
  return @parser if @parser

  default_config = "config.yaml"
  scan_patterns = %w(flyback meandering random)
  scan_types = %w(horizontal vertical)
  scan_direction = %w(left-right right-left bottom-up top-down none)
  scan_sequence = %w(top-down bottom-up left-right right-left)
  default_dims = '800x600'
  default_pixel_size = '1x1'
  matrix_application_types = %w(sprayed precoated printed drieddroplet)

  @parser = Trollop::Parser.new do
    banner "usage: mspire to_imzml [OPTIONS] <file>.mzML ...\"\noutput: <file>.imzML and <file>.ibd\n\n* imzML docs: \n  http://www.maldi-msi.org/index.php?option=com_content&view=article&id=187&Itemid=67\n* explanation of vocabulary (followed here): \n  http://www.maldi-msi.org/index.php?option=com_content&view=article&id=193&Itemid=66\n* github repository:\n  https://github.com/princelab/mzml_to_imzml\n    EOS\n    text \"\\ngeneral:\"\n    opt :config, \"read a config file for default values. Command line options overide those from the config file \", :type => :string\n    opt :print_config, \"print current options to \#{default_config} and exit\"\n    opt :omit_zeros, \"remove zero values\"\n    opt :combine, \"combine all files and set the base name of resulting imzML and ibd files\", :type => String\n    opt :outfile, \"use a specific basename for the resulting file. Acts like --combine for multiple files\", :type => String\n\n    text \"\\nediting:\"\n    opt :trim_files, \"determines the least number of spectra in a file and shortens all spectra to be the same length\"\n\n    text \"\\nimaging:\"\n    opt :continuous, \"assumes m/z values are the same for every scan. The 'processed' storage format is used unless this flag is given.\"\n    opt :scan_pattern, scan_patterns.join('|'), :default => scan_patterns.first\n    opt :scan_type, scan_types.join('|'), :default => scan_types.first\n    opt :linescan_direction, scan_direction.join('|'), :default => scan_direction.first\n    opt :linescan_sequence, scan_sequence.join('|'), :default => scan_sequence.first\n    opt :max_dimensions_pixels, \"maximum X by Y pixels (e.g. 300x100)\", :default => default_dims\n    opt :shots_per_position, \"number of spectra per position\", :default => 1\n    opt :pixel_size, \"X by Y of a single pixel in microns (\u03BCm)\", :default => default_pixel_size \n    opt :max_dimensions_microns, \"maximum X by Y in microns (e.g. 25x20)\", :default => default_dims\n\n    text \"\\ncontact: \"\n    opt :name, \"name of the person or organization\", :type => :string\n    opt :address, \"address of the person or organization\", :type => :string\n    opt :url, \"url of person or organization\", :type => :string\n    opt :email, \"email of person or organization\", :type => :string\n    opt :organization, \"home institution of contact\", :type => :string\n\n    text \"\\nDESI: \"\n    opt :solvent, \"the solvent used\", :type => :string\n    opt :solvent_flowrate, \"flowrate of the solvent (ml/min)\", :type => :float\n    opt :spray_voltage, \"spray voltage in kV\", :type => :float\n    opt :target_material, \"the material the target is made of\", :type => :string\n\n    text \"\\nMALDI: \"\n    opt :matrix_application_types, \"\#{matrix_application_types.join('|')} (comma separated)\", :type => :string\n    opt :matrix_solution_concentration, \"in grams per liter\", :type => :float\n    opt :matrix_solution, \"the chemical solution used as matrix (e.g., DHB)\", :type => :string\n\n    # things to add: data types for m/z and intensity\n    # filters (cutoff / max # peaks, etc.)\n    # ms_level, etc.\n  end\nend\n"

.run(argv, globalopts = []) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/mspire/imzml/writer/commandline.rb', line 86

def self.run(argv, globalopts=[])
  begin
    opts = parser.parse(argv)
  rescue Trollop::HelpNeeded
    return parser.educate
  end

  opts = Hash[YAML.load_file(opts[:config]).map {|k,v| [k.to_sym, v]}].merge(opts) if opts[:config]

  opts[:combine] ||= opts.delete(:outfile)

  if opts.delete(:print_config)
    puts "writing defaults to: #{default_config}"
    string_opts = Hash[ opts.map {|k,v| [k.to_s, v] } ]
    %w(help).each {|key| string_opts.delete key }
    string_opts.delete_if {|k,v| k =~ /_given$/ }
    File.write(default_config, string_opts.to_yaml) 
    exit
  end

  if argv.size == 0
    return parser.educate
  end

  opts[:data_structure] = (opts.delete(:continuous) ? :continuous : :processed)
  opts[:matrix_application_types] = opts[:matrix_application_types].split(',') if opts[:matrix_application_types]

  # prep args a little
  writer = Mspire::Imzml::Writer.new
  writer.write(argv, opts)

end