Class: Mspire::Mzml::Index

Inherits:
Array
  • Object
show all
Defined in:
lib/mspire/mzml/index.rb

Overview

the array holds start bytes

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#in_groups

Instance Attribute Details

#idsObject

a parallel array of ids (idRef’s)



11
12
13
# File 'lib/mspire/mzml/index.rb', line 11

def ids
  @ids
end

#nameObject

the name of the index (as a symbol)



8
9
10
# File 'lib/mspire/mzml/index.rb', line 8

def name
  @name
end

Instance Method Details

#create_scan_to_indexObject

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.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mspire/mzml/index.rb', line 28

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
    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.

Parameters:

  • an (Object)

    Integer (the index number) or String (an id string)

Returns:

  • (Integer)

    the start byte of the spectrum



15
16
17
18
19
20
21
22
23
# File 'lib/mspire/mzml/index.rb', line 15

def start_byte(arg)
  case arg
  when Integer
    self[arg]
  when String
    @id_index ||= create_id_index
    @id_index[arg]
  end
end