Class: MSAbundanceSim::Commandline

Inherits:
Object
  • Object
show all
Defined in:
lib/ms_abundance_sim.rb

Class Method Summary collapse

Class Method Details

.create_parserObject



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/ms_abundance_sim.rb', line 202

def create_parser
  defaults = MSAbundanceSim::DEFAULTS
  opts = MSAbundanceSim::DEFAULTS
  parser = OptionParser.new do |op|
    op.banner = "usage: #{File.basename(__FILE__)} [options] <file>.fasta ..."
    op.separator "generates files, each of this form: <file>_<n>_<case|control>"
    op.separator "  where the specified percentage of proteins have altered abundance (for cases)."
    op.separator ""
    op.separator "output: (yaml indicating all the related derivative files)"
    op.separator "  for 2 cases and 1 control the output for file.fasta would be: "
    op.separator "    file.fasta:"
    op.separator "      case:"
    op.separator "      - file_0_case"
    op.separator "      - file_1_case"
    op.separator "      control:"
    op.separator "      - file_2_control"
    op.separator ""
    op.separator "The file must have one or more abundances per protein entry (the protein"
    op.separator "sequence following the header line is optional)."
    op.separator "The abundance is placed at the end of the line following a ' #',"
    op.separator "with multiple abundances separated with a ','.  Here are two examples:"
    op.separator ""
    op.separator "> SWISSAB|23B The anchor protein #23.2"
    op.separator "> SWISSSPECIAL|24B A green protein #23.2,29.4"
    op.separator ""
    op.separator "notes: Protein sequences are optional and files need not end in '.fasta'"
    op.separator ""
    op.separator "options (<default>):"

    op.on(
      "--num-control <#{defaults[:num_control]}>",
      Integer,
      "Number of *control* samples to generate."
    ) {|v| opts[:num_control] = v }

    op.on(
      "--num-case <#{defaults[:num_case]}>",
      Integer,
      "Number of *case* samples to generate."
    ) {|v| opts[:num_case] = v }

    op.on(
      "--pct-diff-express <#{defaults[:pct_diff_express]}>",
      Float,
      "Percentage of proteins to differentially ",
      "  express between case and control."
    ) {|v| opts[:pct_diff_express] = v }

    op.on(
      "--control-variance <#{defaults[:control_variance]}>",
      Integer,
      "Variance for control samples (max lambda for",
      "  Poisson distribution). The higher the value, ",
      "  the more fold change will occur among healthy ",
      "  populations. Used only when multiple ",
      "  abundances are not provided in master fasta. ",
      "  Not recommended to modify this parameter."
    ) {|v| opts[:control_variance] = v }

    op.on(
      "--case-variance <#{defaults[:case_variance]}>",
      Integer,
      "Variance increase for case samples (max lambda ",
      "  for Poisson distribution). The higher the ",
      "  value the more fold change will occur."
    ) {|v| opts[:case_variance] = v }

    op.on(
      "--downshift-min-threshold<#{defaults[:downshift_min_threshold]}>",
      Float,
      "Min threshold for downshifting some fold changes."
    ) {|v| opts[:downshift_min_threshold] = v }

    op.on(
      "--downshift-probability-threshold<#{defaults[:downshift_probability_threshold]}>",
      Float,
      "Min probability threshold for downshifting",
      "some fold changes."
    ) {|v| opts[:downshift_probability_threshold] = v }

    op.on("--verbose", "talk about it") {|v| $VERBOSE = 3 }
  end
  [parser, opts]
end

.format_and_emit_output(output) ⇒ Object



195
196
197
198
199
200
# File 'lib/ms_abundance_sim.rb', line 195

def format_and_emit_output(output)
  # the type keys are symbols--make them strings
  output_string_types = output.map {|key, value| [key, value.map {|k, v| [k.to_s, v] }.to_h] }.to_h
  # emit yaml without leading "---"
  puts output_string_types.to_yaml.gsub(/\A---\n/, '')
end

.run(argv) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/ms_abundance_sim.rb', line 181

def run(argv)
  parser, opts = create_parser
  parser.parse!(argv)

  filenames = argv.to_a

  if filenames.size == 0
    puts parser
  else
    output = MSAbundanceSim.process_files(filenames, opts)
    format_and_emit_output(output)
  end
end