require 'strscan' module MS::Parser::MzXML ; end class MS::Parser::MzXML::Regexp @@first_scan_regexp = //mo def self.precursor_mz_and_intensity_by_scan(file) prec_re = /msLevel="2".*?([\d\.]+)<\/precursorMz>/mo self.by_scan_num(file, prec_re) {|match_obj| match_obj.captures.reverse} end # (array will likely start at 1!) def self.by_scan_num(file, regex) arr = [] File.open(file) do |fh| string = fh.read matches = string.scan(@@scan_re) matches.each do |matched| if inner_match = regex.match(matched[1]) index = matched[0].to_i arr[index] = yield(inner_match) end end end arr end # Returns array where array[scan_num] = precursorMz # Parent scans armme not arrayed # Values are strings. Array index likely starts at 1! # @TODO: replace the use of a yield block def self.precursor_mz_by_scan(file) prec_re = /msLevel="2".*?([\d\.]+)<\/precursorMz>/mo self.by_scan_num(file, prec_re) {|match_obj| match_obj.captures[0]} end end class MS::Parser::MzXML::Regexp::MsRun @@scan_count_regexp = /scanCount="(\d+)"/o @@start_time_regexp = /startTime="PT([\d\.]+)S"/o @@end_time_regexp = /endTime="PT([\d\.]+)S"/o @@first_scan_regexp = /