Module: Spec::MzXML

Included in:
XMLParser::TimesAndSpectra
Defined in:
lib/spec/mzxml.rb

Defined Under Namespace

Modules: PrecMzByNum, REXMLStreamListener, XMLParser Classes: Parser, Regexp

Constant Summary collapse

Potential_mzxml_converters =
%w(readw.exe readw t2x)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_to_mzxml(file) ⇒ Object

if .mzXML returns the filename if .raw or .RAW converts the file to .mZXML and returns mzXML filename if no recognized extension, looks for .mzXML file, then .RAW file (and converts) aborts if file was not able to be converted returns nil if a file that can be converted or used was not found



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
# File 'lib/spec/mzxml.rb', line 21

def self.file_to_mzxml(file)
  file.gsub!("\\",'/')
  old_file = file.dup
  if file =~ /\.mzXML$/
    return file
  elsif file =~ /\.RAW$/i
    old_file = file.dup
    ## t2x outputs in cwd (so go to the directory of the file!)
    dir = File.dirname(file)
    basename = File.basename(file)
    converter = Spec::MzXML.find_mzxml_converter
    Dir.chdir(dir) do 
      if converter =~ /readw/
        cmd = "#{converter} #{basename} c #{basename.sub(/\.RAW$/i, '.mzXML')}"
      else
        cmd = "#{converter} #{basename}"
      end
      #puts cmd
      #puts `#{cmd}`
      reply = `#{cmd}`
      puts reply if $VERBOSE
    end
    file.sub!(/\.RAW$/i, '.mzXML')
    unless File.exist? file
      abort "Couldn't convert #{old_file} to #{file}"
    end
    return file
  else 
    if File.exist?( file + '.mzXML' )
      return file_to_mzxml(file + '.mzXML')
    elsif File.exist?( file + '.RAW' )
      return file_to_mzxml(file + '.RAW')
    elsif File.exist?( file + '.raw' )
      return file_to_mzxml(file + '.raw')
    else
      return nil
    end
  end
    
end

.find_mzxml_converterObject

Searchs each path element and returns the first one it finds returns nil if none found



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/spec/mzxml.rb', line 95

def self.find_mzxml_converter
  ENV['PATH'].split(/[:;]/).each do |path|
    Dir.chdir(path) do
      Potential_mzxml_converters.each do |pc|
        if File.exist? pc
          return File.join(path, pc)
        end
      end
    end
  end
  nil
end

Instance Method Details

#base64_peaks_to_array(string, precision = 32) ⇒ Object

takes a base64 peaks string and returns an array of alternating m/z and intensity mzXML as network ordered



83
84
85
86
87
88
89
90
91
# File 'lib/spec/mzxml.rb', line 83

def base64_peaks_to_array(string, precision=32)
  b64d = Base64.decode64(string) 
  if precision == 32
    unpack_code = "g*"
  elsif precision == 64
    unpack_code = "G*"
  end
  b64d.unpack(unpack_code)
end

#base64_peaks_to_pairs(string, precision = 32) ⇒ Object

takes a base64 peaks string and returns an array of [m/z,intens] doublets mzXML as network ordered



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/spec/mzxml.rb', line 66

def base64_peaks_to_pairs(string, precision=32)
  data = base64_peaks_to_array(string, precision)
  ndata = []
  data.each_with_index do |dat,ind|
    if (ind % 2) == 0  # even
      arr = Array.new(2)
      arr[0] = dat
      ndata.push( arr )
    else
      ndata.last[1] = dat 
    end
  end
  ndata
end

#strip_time(time) ⇒ Object

takes PT2.7500000S and returns it as 2.700000 (no PT or S)



10
11
12
# File 'lib/spec/mzxml.rb', line 10

def strip_time(time)
  return time[2...-1]
end