Sha256: 6805b5b51c8f3a3f6a13a06dd1c4769fc5b5f4d3000fb4b28763a3e802542996

Contents?: true

Size: 1.83 KB

Versions: 10

Compression:

Stored size: 1.83 KB

Contents

require 'mspire/mzml/list'
require 'mspire/mzml/selected_ion'
require 'mspire/mzml/isolation_window'
require 'mspire/mzml/activation'

module Mspire
  class Mzml
    # The method of precursor ion selection and activation
    class Precursor
      # (optional) the Mspire::Mzml::Spectrum object from which the precursor is
      # derived
      attr_accessor :spectrum

      # (optional)
      attr_accessor :isolation_window 

      # (optional) An array of ions that were selected.
      attr_accessor :selected_ions

      # (required) The type and energy level used for activation.
      attr_accessor :activation

      # a boolean indicating the spectrum is from an external source file
      attr_accessor :from_external_source_file

      def initialize(spectrum_derived_from=nil)
        @spectrum=spectrum_derived_from
      end

      def self.from_xml(xml)
        obj = self.new
        %w(isolationWindow activation).each do |el|
          sub_node = xml.xpath("./#{el}").first
          el[0] = el[0].capitalize
          Mspire::Mzml.const_get(el).from_xml(sub_node) if sub_node
        end
        obj.selected_ions = xml.xpath('./selectedIonList/selectedIon').map do |si_n|
          Mspire::Mzml::SelectedIon.from_xml(si_n)
        end
        obj
      end

      def to_xml(builder)
        atts = {}
        if @from_external_source_file
          atts[:sourceFileRef] = @spectrum.source_file.id
          atts[:externalSpectrumRef] = @spectrum.id
        else
          atts[:spectrumRef] = @spectrum.id if @spectrum
        end
        builder.precursor(atts) do |prec_n|
          @isolation_window.to_xml(prec_n) if @isolation_window
          Mspire::Mzml::SelectedIon.list_xml(@selected_ions, prec_n) if @selected_ions
          @activation.to_xml(prec_n) if @activation
        end
      end

      extend(Mspire::Mzml::List)

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mspire-0.7.18 lib/mspire/mzml/precursor.rb
mspire-0.7.17 lib/mspire/mzml/precursor.rb
mspire-0.7.13 lib/mspire/mzml/precursor.rb
mspire-0.7.12 lib/mspire/mzml/precursor.rb
mspire-0.7.11 lib/mspire/mzml/precursor.rb
mspire-0.7.10 lib/mspire/mzml/precursor.rb
mspire-0.7.9 lib/mspire/mzml/precursor.rb
mspire-0.7.8 lib/mspire/mzml/precursor.rb
mspire-0.7.7 lib/mspire/mzml/precursor.rb
mspire-0.7.6 lib/mspire/mzml/precursor.rb