Sha256: b32d37bb5831512ee018bd5178add4de081194ba233e52293083bc160be8873e

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require 'base64'

module Spec; end

module Spec::MzXML

  MZXML_CONVERTER = 't2x'

  # takes PT2.7500000S and returns it as 2.700000 (no PT or S)
  def strip_time(time)
    return time[2...-1]
  end


  # takes a base64 peaks string and returns an array of [m/z,intens] doublets
  # mzXML as network ordered
  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

  # takes a base64 peaks string and returns an array of alternating m/z and
  # intensity mzXML as network ordered
  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

 
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mspire-0.1.3 lib/spec/mzxml.rb
mspire-0.1.5 lib/spec/mzxml.rb
mspire-0.1.7 lib/spec/mzxml.rb