lib/imzml/metadata/run/spectrum.rb in imzml-0.1.1 vs lib/imzml/metadata/run/spectrum.rb in imzml-0.1.4
- old
+ new
@@ -34,12 +34,12 @@
attr_accessor :filepath
# Binary values type [:int8, :int16, :int32, :int64, :float32, :float64]
attr_accessor :type
- # grabs the actual binary data from disk
- def data(cached = true)
+ # Grabs the actual binary data from disk
+ def data(cached = false)
# Return the data from the cache
return @cached_data if cached && !@cached_data.nil?
# Remove possible data from the cache
@@ -63,11 +63,15 @@
# 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
- @cached_data = data if cached
+ if cached
+ @cached_data = data
+ else
+ data
+ end
end
private
attr_accessor :cached_data
@@ -88,41 +92,9 @@
# Info about intensity binary data
#
# Represented by class BinaryData
attr_accessor :intensity_binary
-
- def intensity(at, interval)
-
- # read whole the binary data
- mz_array = mz_binary.data
- intensity_array = intensity_binary.data
-
- default_from, default_to = mz_array.first, mz_array.first
-
- from = default_from
- to = default_to
-
- # find designated intensity
- if at
- from = at - interval
- from = default_from if from < 0
- to = at + interval
- to = default_to if to > mz_array.last
- end
-
- # find values in mz array
- low_value = mz_array.bsearch { |x| x >= from }
- low_index = mz_array.index(low_value)
- high_value = mz_array.bsearch { |x| x >= to }
- high_index = mz_array.index(high_value)
-
- # sum all values in subarray
- sum = intensity_array[low_index..high_index].inject{|sum, x| sum + x}
-
- sum
- end
-
end
end
\ No newline at end of file