Class: ImzML::Spectrum::BinaryData
- Inherits:
-
Object
- Object
- ImzML::Spectrum::BinaryData
- Defined in:
- lib/imzml/metadata/run/spectrum.rb
Constant Summary collapse
- BINARY_TYPE_8BIT_INTEGER =
Binary data types, always little endian
"IMS:1100000"
- BINARY_TYPE_16BIT_INTEGER =
"IMS:1100001"
- BINARY_TYPE_32BIT_INTEGER =
"MS:1000519"
- BINARY_TYPE_64BIT_INTEGER =
"MS:1000522"
- BINARY_TYPE_32BIT_FLOAT =
"MS:1000521"
- BINARY_TYPE_64BIT_FLOAT =
"MS:1000523"
- MZ_ARRAY =
A data array of m/z values
"MS:1000514"
- INTENSITY_ARRAY =
A data array of intensity values
"MS:1000515"
- EXTERNAL_ARRAY_LENGTH =
"IMS:1000103"
- EXTERNAL_OFFSET =
"IMS:1000102"
- EXTERNAL_ENCODED_LENGHT =
"IMS:1000104"
Instance Attribute Summary collapse
-
#encoded_length ⇒ Object
Describes the length of the written data.
-
#filepath ⇒ Object
Path to the external binary file.
-
#length ⇒ Object
Describes how many fields an array contains.
-
#offset ⇒ Object
The position where the data of an array of a mass spectrum begins.
-
#type ⇒ Object
Binary values type [:int8, :int16, :int32, :int64, :float32, :float64].
Instance Method Summary collapse
-
#data(cached = false) ⇒ Object
Grabs the actual binary data from disk.
Instance Attribute Details
#encoded_length ⇒ Object
Describes the length of the written data
30 31 32 |
# File 'lib/imzml/metadata/run/spectrum.rb', line 30 def encoded_length @encoded_length end |
#filepath ⇒ Object
Path to the external binary file
34 35 36 |
# File 'lib/imzml/metadata/run/spectrum.rb', line 34 def filepath @filepath end |
#length ⇒ Object
Describes how many fields an array contains
22 23 24 |
# File 'lib/imzml/metadata/run/spectrum.rb', line 22 def length @length end |
#offset ⇒ Object
The position where the data of an array of a mass spectrum begins
26 27 28 |
# File 'lib/imzml/metadata/run/spectrum.rb', line 26 def offset @offset end |
#type ⇒ Object
Binary values type [:int8, :int16, :int32, :int64, :float32, :float64]
37 38 39 |
# File 'lib/imzml/metadata/run/spectrum.rb', line 37 def type @type end |
Instance Method Details
#data(cached = false) ⇒ Object
Grabs the actual binary data from disk
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/imzml/metadata/run/spectrum.rb', line 40 def data(cached = false) # Return the data from the cache return @cached_data if cached && !@cached_data.nil? # Remove possible data from the cache @cached_data = nil # Switch binary pattern reading type pattern = case type when :int8 "C" when :int16 "S" when :int32 "L" when :int64 "Q" when :float32 "e" when :float64 "E" end # Read data based on metadata data = IO.binread(@filepath, @encoded_length.to_i, @offset.to_i).unpack("#{pattern}*") # Save data only if user want's to cache it, saving take some CPU if cached @cached_data = data else data end end |