Class: Mspire::Mzml::Index
Overview
the array holds start bytes
Instance Attribute Summary collapse
-
#by_scans ⇒ Object
an index indexed by scan number.
-
#ids ⇒ Object
a parallel array of ids (idRef’s).
-
#name ⇒ Object
the name of the index (as a symbol).
Class Method Summary collapse
-
.index_offset(io, tag = 'indexListOffset', bytes_backwards = 200) ⇒ Object
returns an Integer or nil if not found does a single jump backwards from the tail of the file looking for an xml element based on tag.
Instance Method Summary collapse
-
#create_id_index ⇒ Object
returns hash of id to start_byte.
-
#create_scan_to_index ⇒ Object
generates a scan to index hash that points from scan number to the spectrum index number.
-
#start_byte(arg) ⇒ Integer
The start byte of the spectrum.
- #start_byte_and_id(int) ⇒ Object
Methods inherited from Array
Instance Attribute Details
#by_scans ⇒ Object
an index indexed by scan number
41 42 43 |
# File 'lib/mspire/mzml/index_list.rb', line 41 def by_scans @by_scans end |
#ids ⇒ Object
a parallel array of ids (idRef’s)
47 48 49 |
# File 'lib/mspire/mzml/index_list.rb', line 47 def ids @ids end |
#name ⇒ Object
the name of the index (as a symbol)
44 45 46 |
# File 'lib/mspire/mzml/index_list.rb', line 44 def name @name end |
Class Method Details
.index_offset(io, tag = 'indexListOffset', bytes_backwards = 200) ⇒ Object
returns an Integer or nil if not found does a single jump backwards from the tail of the file looking for an xml element based on tag. If it is not found, returns nil
32 33 34 35 36 37 |
# File 'lib/mspire/mzml/index_list.rb', line 32 def index_offset(io, tag='indexListOffset', bytes_backwards=200) tag_re = %r{<#{tag}>([\-\d]+)</#{tag}>} io.pos = (io.size - 1) - bytes_backwards md = io.readlines("\n").map {|line| line.match(tag_re) }.compact.shift md[1].to_i if md end |
Instance Method Details
#create_id_index ⇒ Object
returns hash of id to start_byte
54 55 56 |
# File 'lib/mspire/mzml/index_list.rb', line 54 def create_id_index Hash[self.ids.zip(self)] end |
#create_scan_to_index ⇒ Object
generates a scan to index hash that points from scan number to the spectrum index number. returns the index, nil if the scan ids are not present and spectra are, or false if they are not unique.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mspire/mzml/index_list.rb', line 73 def create_scan_to_index scan_re = /scan=(\d+)/ scan_to_index = {} ids.each_with_index do |id, index| md = id.match(scan_re) scan_num = md[1].to_i if md if scan_num if scan_to_index.key?(scan_num) return false else scan_to_index[scan_num] = index end end end if scan_to_index.size > 0 by_scans = scan_to_index elsif ids.size > 0 nil # there are scans, but we did not find scan numbers else scan_to_index end end |
#start_byte(arg) ⇒ Integer
Returns the start byte of the spectrum.
60 61 62 63 64 65 66 67 68 |
# File 'lib/mspire/mzml/index_list.rb', line 60 def start_byte(arg) case arg when Integer self[arg] when String @id_index ||= create_id_index @id_index[arg] end end |
#start_byte_and_id(int) ⇒ Object
49 50 51 |
# File 'lib/mspire/mzml/index_list.rb', line 49 def start_byte_and_id(int) [self[int], ids[int]] end |