Sha256: 4ac757086693deacbb1545800dd8fb0600e5577afc61a42b792050e38888e82b

Contents?: true

Size: 1.54 KB

Versions: 11

Compression:

Stored size: 1.54 KB

Contents

require 'ms/precursor'

module Ms ; end

#              0      1          2      3         4        5           6     7           8 
MsScanAtts =  [:num, :ms_level, :time, :start_mz, :end_mz, :num_peaks, :tic, :precursor, :spectrum]

Ms::Scan = Struct.new(*MsScanAtts) do

# time in seconds
# everything else in float/int

 
  def to_s
    "<Scan num=#{num} ms_level=#{ms_level} time=#{time}>"
  end

  undef_method :inspect
  def inspect
    atts = %w(num ms_level time start_mz end_mz) 
    display = atts.map do |att|
      if val = send(att.to_sym)
        "#{att}=#{val}"
      else
        nil
      end
    end
    display.compact!
    spec_display = 
      if spectrum
        spectrum.mzs.size
      else
        'nil'
      end
    "<Ms::Scan:#{__id__} " + display.join(", ") + " precursor=#{precursor.inspect}" + " spectrum(size)=#{spec_display}" + " >"
  end

  # if > cutoff is below the precusure, then it is considered a +1 charge,
  # otherwise > 1
  # Algorithm from the MzXML2Search code by Jimmy Eng
  def plus1?(cutoff=0.95)
    prec_mz = precursor.mz 
    mzs, intens = spectrum.mzs_and_intensities
    tic = 0.0
    below = 0.0
    mzs.zip(intens) do |mz, int|
      if mz < prec_mz
        below += int
      end
      tic += int
    end
    tic == 0.0 || below/tic > cutoff
  end


  # returns the string (space delimited): "ms_level num time [prec_mz prec_inten]"
  def to_index_file_string
    arr = [ms_level, num, time]
    if precursor then arr << precursor.mz end
    if x = precursor.intensity then arr << x end
    arr.join(" ")
  end

end


Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ms-msrun-0.3.6 lib/ms/scan.rb
ms-msrun-0.3.5 lib/ms/scan.rb
ms-msrun-0.3.4 lib/ms/scan.rb
ms-msrun-0.3.3 lib/ms/scan.rb
ms-msrun-0.3.2 lib/ms/scan.rb
ms-msrun-0.3.1 lib/ms/scan.rb
ms-msrun-0.3.0 lib/ms/scan.rb
ms-msrun-0.2.4 lib/ms/scan.rb
ms-msrun-0.2.1 lib/ms/scan.rb
ms-msrun-0.2.0 lib/ms/scan.rb
ms-msrun-0.1.0 lib/ms/scan.rb