Class: MS::Sequest::Srf::Dta

Inherits:
Object
  • Object
show all
Defined in:
lib/ms/sequest/srf.rb

Constant Summary collapse

Unpack_32 =

original Unpack = “EeIvvvv”

"EeIvvvv"
Unpack_35 =
"Ex8eVx2vvvv"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_io(fh, unpack_35) ⇒ Object



483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/ms/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

Instance Method Details

#inspectObject



477
478
479
480
481
# File 'lib/ms/sequest/srf.rb', line 477

def inspect
  peaks_st = 'nil'
  if self[7] ; peaks_st = "[#{self[7].size} bytes]" end
  "<MS::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) ⇒ Object

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



520
521
522
# File 'lib/ms/sequest/srf.rb', line 520

def round(float, decimal_places)
  sprintf("%.#{decimal_places}f", float)
end

#to_dta_file_dataObject



502
503
504
505
506
507
508
509
510
511
# File 'lib/ms/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) ⇒ Object

write a class dta file to the io object



514
515
516
# File 'lib/ms/sequest/srf.rb', line 514

def write_dta_file(io)
  io.print to_dta_file_data
end