Module: Ms::Mascot::Dat::Query::Utils
- Included in:
- Ms::Mascot::Dat::Query
- Defined in:
- lib/ms/mascot/dat/query.rb
Class Method Summary collapse
-
.parse_ions(str) ⇒ Object
Parses an ion string into a simple data array.
-
.scan_ions(str) ⇒ Object
Scans an ion string for values, yielding each number as a string and the a flag signaling whether or not the number marks the end of a datapoint (ie the number is the intensity).
Class Method Details
.parse_ions(str) ⇒ Object
Parses an ion string into a simple data array. Parse ions requires data points be separated with a comma and mz/intensity values with a semicolon, but is tolerant to integer and floats.
Query.parse_ions('1.23:4.56,7.8:9') # => [[1.23, 4.56], [7.8, 9]]
All ions are cast to floats; see scan_ions for scanning the string values.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ms/mascot/dat/query.rb', line 67 def parse_ions(str) ions = [] current = [] scan_ions(str) do |num, end_point| current << num.to_f if end_point ions << current current = [] end end ions end |
.scan_ions(str) ⇒ Object
Scans an ion string for values, yielding each number as a string and the a flag signaling whether or not the number marks the end of a datapoint (ie the number is the intensity).
str = "\nReformatted Ions\n"
Query.scan_ions('1.23:4.56,7.8:9') do |num, end_point|
str << num
str << (end_point ? "\n" : " ")
end
str
# => %q{
# Reformatted Ions
# 1.23 4.56
# 7.8 9
# }
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ms/mascot/dat/query.rb', line 47 def scan_ions(str) # :yields: num, end_point scanner = StringScanner.new(str) while num = scanner.scan(/[^:,]+/) if scanner.skip(/:/) yield(num, false) else scanner.skip(/,/) yield(num, true) end end end |