Class: Mascot::MGF::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/mascot/mgf/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry = nil) ⇒ Query

Initializes a spectrum entry from a MGF formatted string or from an Array that is the newline split of MGF ‘BEGIN IONSn…nEND IONS’



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mascot/mgf/query.rb', line 9

def initialize(entry=nil)
  if entry.kind_of? String
    entry = entry.split(/\n/)
  end
  @title = 'id=1'
  @pepmass = []
  @atts = {}
  @ions = []
  @charge = nil
  parse(entry)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/mascot/mgf/query.rb', line 34

def method_missing(m)
  if @atts.has_key? m.to_sym
    return @atts[m.to_sym]
  else
    return nil
  end
end

Instance Attribute Details

#chargeObject

Returns the value of attribute charge.



5
6
7
# File 'lib/mascot/mgf/query.rb', line 5

def charge
  @charge
end

#entryObject

Returns the value of attribute entry.



5
6
7
# File 'lib/mascot/mgf/query.rb', line 5

def entry
  @entry
end

#ionsObject

Returns the value of attribute ions.



5
6
7
# File 'lib/mascot/mgf/query.rb', line 5

def ions
  @ions
end

#pepmassObject

Returns the value of attribute pepmass.



5
6
7
# File 'lib/mascot/mgf/query.rb', line 5

def pepmass
  @pepmass
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/mascot/mgf/query.rb', line 5

def title
  @title
end

Instance Method Details

#to_sObject

Returns the formatted MGF entry string



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mascot/mgf/query.rb', line 22

def to_s
  tmp = "BEGIN IONS\nTITLE=#{@title}\n"
  tmp += "PEPMASS=#{@pepmass.join(' ')}\n" if @pepmass.length > 0
  tmp += "CHARGE=#{@charge}+\n" if @charge
  @atts.each_pair do |k,v|
    tmp += "#{k.to_s.upcase}=#{v}\n"
  end
  tmp += @ions.collect { |i| i.join(" ")}.join("\n")
  tmp += "\nEND IONS\n"
  return tmp
end