Class: Xcalibur::Convert::RawToDta

Inherits:
Tap::FileTask
  • Object
show all
Defined in:
lib/xcalibur/convert/raw_to_dta.rb

Overview

:startdoc::manifest convert RAW files to dta format Converts a .RAW file to dta files using extract_msn.exe

extract_msn.exe is an Xcalibur/BioWorks tool that extracts spectra from .RAW files into .dta (Sequest) format and must be installed for RawToDta to work. RawToDta was developed against extract_msn version 4.0. You can check if extract_msn is installed at the default location, as well as determine the

version of your executable using:

% tap run -- xcalibur/convert/raw_to_dta  --extract_msn_help

Constant Summary collapse

CONFIG_MAP =
[
  [:first_scan, 'F'],
  [:last_scan, 'L'],
  [:lower_MW, 'B'],
  [:upper_MW, 'T'],
  [:precursor_mass_tol, 'M'],
  [:num_allowed_intermediate_scans_for_grouping, 'S'],
  [:charge_state, 'C'],
  [:num_required_group_scans, 'G'],
  [:num_ions_required, 'I'],
  [:output_path, 'D'],
  [:intensity_threshold, 'E'],
  [:use_unified_search_file, 'U'],
  [:subsequence, 'Y'],
  [:write_zta_files, 'Z'],
  [:perform_charge_calculations, 'K'],
  [:template_file, 'O'],
  [:options_string, 'A'],
  [:minimum_signal_to_noise, 'R'],
  [:minimum_number_of_peaks, 'r']
]

Instance Method Summary collapse

Instance Method Details

#cmd(input_file, output_dir = nil) ⇒ Object

Formats the extract_msn.exe command using the specified input_file, and the current configuration. A default output directory can be specified using output_dir; it will not override a configured output directory.

Note that output_dir should be an EXISTING filepath or relative filepath. execute_msn.exe will not generate .dta files if the

output_dir doesn’t exist.



107
108
109
110
111
112
113
114
# File 'lib/xcalibur/convert/raw_to_dta.rb', line 107

def cmd(input_file, output_dir=nil)
  args = []
  args << "\"#{normalize extract_msn}\""
  args << cmd_options(output_dir)
  args << "\"#{normalize input_file}\""
  
  args.join(' ')
end

#cmd_options(output_dir = nil) ⇒ Object

Formats command options for extract_msn.exe using the current configuration. Configurations are mapped to their single-letter keys using CONFIG_MAP.

A default output_dir can be specified for when config is not specified.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/xcalibur/convert/raw_to_dta.rb', line 75

def cmd_options(output_dir=nil)
  options = CONFIG_MAP.collect do |key, flag|
    value = (flag == "D" ? output_dir : config[key])
    next unless value
    
    # formatting consists of stringifying the value argument, or
    # in escaping the value if the arguement is a path
    formatted_value = case key
    when :use_unified_search_file, :perform_charge_calculations, :write_zta_files
      "" # no argument
    when :output_path, :template_file 
      # path argument, escape
      "\"#{normalize value}\""  
    else 
      # number or string, simply stringify
      value.to_s
    end

    "-#{flag}#{formatted_value}"
  end

  options.compact.join(" ")
end

#normalize(path) ⇒ Object

Expands the input path and converts all forward slashes (/) to backslashes () to make it into a Windows-style path.



66
67
68
# File 'lib/xcalibur/convert/raw_to_dta.rb', line 66

def normalize(path)
  File.expand_path(path).gsub(/\//, "\\")
end

#process(input_file, output_dir = nil) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/xcalibur/convert/raw_to_dta.rb', line 116

def process(input_file, output_dir=nil)
  extname = File.extname(input_file)
  raise "Expected .RAW file: #{input_file}" unless  extname =~ /\.RAW$/i

  # Target the output to a directory with the same basename 
  # as the raw file, unless otherwise specified.
  output_dir = input_file.chomp(File.extname(input_file)) if output_dir == nil
  
  mkdir(output_dir)
  command = cmd(input_file, output_dir)
  
  log :sh, command
  if app.quiet
    capture_sh(command, true)
  else
    sh(command)
    puts ""  # add extra line to make logging nice
  end
  
  # This may select additional .dta files that existed before raw_to_dta
  # TODO - maybe read lcq_dta for files? 
  Dir.glob( File.expand_path(File.join(output_dir, "*.dta")) ) 
end