class Mspire::Sequest::Srf::Dta

Constants

Unpack_32

original Unpack = “EeIvvvv”

Unpack_35

Public Class Methods

from_io(fh, unpack_35) click to toggle source
# File lib/mspire/sequest/srf.rb, line 483
def self.from_io(fh, unpack_35)
  (unpack, read_header, read_spacer) = 
    if unpack_35
      [Unpack_35, 34, 22]
    else
      [Unpack_32, 24, 24]
    end

  # get the bulk of the data in single unpack
  # sets the first 7 attributes
  dta = self.new(*fh.read(read_header).unpack(unpack))

  # Scan numbers are given at the end in an index!
  fh.read(read_spacer) # throwaway the spacer

  dta[7] = fh.read(dta.num_peaks * 8)  # (num_peaks * 8) is the number of bytes to read
  dta
end

Public Instance Methods

inspect() click to toggle source
# File lib/mspire/sequest/srf.rb, line 477
def inspect
  peaks_st = 'nil'
  if self[7] ; peaks_st = "[#{self[7].size} bytes]" end
  "<Mspire::Sequest::Srf::Dta @mh=#{mh} @dta_tic=#{dta_tic} @num_peaks=#{num_peaks} @charge=#{charge} @ms_level=#{ms_level} @total_num_possible_charge_states=#{total_num_possible_charge_states} @peaks=#{peaks_st} >"
end
round(float, decimal_places) click to toggle source

returns a string where the float has been rounded to the specified number of decimal places

# File lib/mspire/sequest/srf.rb, line 520
def round(float, decimal_places)
  sprintf("%.#{decimal_places}f", float)
end
to_dta_file_data() click to toggle source
# File lib/mspire/sequest/srf.rb, line 502
def to_dta_file_data
  string = "#{round(mh, 6)} #{charge}\r\n"
  peak_ar = peaks.unpack('e*')
  (0...(peak_ar.size)).step(2) do |i|
    # %d is equivalent to floor, so we round by adding 0.5!
    string << "#{round(peak_ar[i], 4)} #{(peak_ar[i+1] + 0.5).floor}\r\n"
    #string << peak_ar[i,2].join(' ') << "\r\n"
  end
  string
end
write_dta_file(io) click to toggle source

write a class dta file to the io object

# File lib/mspire/sequest/srf.rb, line 514
def write_dta_file(io)
  io.print to_dta_file_data
end