imzml 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7be2442cc6f7ce7a1503a2a7c5380c9509043b2
4
- data.tar.gz: f76e6a4ff83c1335b90389d6ea6348a2df7a3656
3
+ metadata.gz: 5591dbd65b301f6c008d56453b7cf9f3668b394b
4
+ data.tar.gz: d1cd802b1ff67f067d60007687fbaab164745b52
5
5
  SHA512:
6
- metadata.gz: b6fa51fac3db3e0ed575eca4152b184063ab248da7c91989d1726781919119cb6def12d31965d7cea8a1b424d72d66f93da5ee3077b17ef02cc7dd837bc73409
7
- data.tar.gz: d56ab3b35465d58974c80d3e7dd8f1037bd13be794261765ffcee13194510d893ea8e684cffd4a06a82614a954c5c74d7c3f79489b8447fde8ba123f9ea4f1b3
6
+ metadata.gz: bd611f99d401acc47fdab97c0ce6e1a40a61cb6a95f684374656fdc635f9b745adff17e29116ae691b64044df8d174aa1f5453e9038c2fb87fed0c1ac36e8a8e
7
+ data.tar.gz: 1470bd7d36bfe4e5233d27d799f0702423a58991bf31175aa7c4cc11bd3965f1ada94fa5d17bb19f6e8a0c0f2628960efb3560036b22e340f42e6252d48ad186
@@ -1,9 +1,9 @@
1
1
  module ImzML
2
-
2
+
3
3
  class Spectrum
4
-
4
+
5
5
  class BinaryData
6
-
6
+
7
7
  # Binary data types, always little endian
8
8
  BINARY_TYPE_8BIT_INTEGER = "IMS:1100000"
9
9
  BINARY_TYPE_16BIT_INTEGER = "IMS:1100001"
@@ -11,40 +11,40 @@ module ImzML
11
11
  BINARY_TYPE_64BIT_INTEGER = "MS:1000522"
12
12
  BINARY_TYPE_32BIT_FLOAT = "MS:1000521"
13
13
  BINARY_TYPE_64BIT_FLOAT = "MS:1000523"
14
-
14
+
15
15
  # A data array of m/z values
16
16
  MZ_ARRAY = "MS:1000514"
17
-
17
+
18
18
  # A data array of intensity values
19
19
  INTENSITY_ARRAY = "MS:1000515"
20
-
20
+
21
21
  # Describes how many fields an array contains
22
22
  attr_accessor :length
23
23
  EXTERNAL_ARRAY_LENGTH = "IMS:1000103"
24
-
24
+
25
25
  # The position where the data of an array of a mass spectrum begins
26
26
  attr_accessor :offset
27
27
  EXTERNAL_OFFSET = "IMS:1000102"
28
-
28
+
29
29
  # Describes the length of the written data
30
30
  attr_accessor :encoded_length
31
31
  EXTERNAL_ENCODED_LENGHT = "IMS:1000104"
32
-
32
+
33
33
  # Path to the external binary file
34
34
  attr_accessor :filepath
35
-
35
+
36
36
  # Binary values type [:int8, :int16, :int32, :int64, :float32, :float64]
37
37
  attr_accessor :type
38
-
38
+
39
39
  # grabs the actual binary data from disk
40
40
  def data(cached = true)
41
-
41
+
42
42
  # Return the data from the cache
43
43
  return @cached_data if cached && !@cached_data.nil?
44
-
44
+
45
45
  # Remove possible data from the cache
46
46
  @cached_data = nil
47
-
47
+
48
48
  # Switch binary pattern reading type
49
49
  pattern = case type
50
50
  when :int8
@@ -63,65 +63,66 @@ module ImzML
63
63
 
64
64
  # Read data based on metadata
65
65
  data = IO.binread(@filepath, @encoded_length.to_i, @offset.to_i).unpack("#{pattern}*")
66
-
66
+
67
67
  # Save data only if user want's to cache it, saving take some CPU
68
68
  @cached_data = data if cached
69
69
  end
70
-
70
+
71
71
  private
72
-
72
+
73
73
  attr_accessor :cached_data
74
-
74
+
75
75
  end
76
-
76
+
77
77
  # Attributes to describe the position of a spectrum in the image.
78
- #
78
+ #
79
79
  # represented as Point with position x, y
80
80
  attr_accessor :position
81
81
  POSITION_X = "IMS:1000050"
82
82
  POSITION_Y = "IMS:1000051"
83
-
83
+
84
84
  # Info about mz binary data
85
85
  #
86
86
  # Represented by class BinaryData
87
87
  attr_accessor :mz_binary
88
-
88
+
89
89
  # Info about intensity binary data
90
90
  #
91
91
  # Represented by class BinaryData
92
92
  attr_accessor :intensity_binary
93
-
93
+
94
94
  def intensity(at, interval)
95
-
95
+
96
96
  # read whole the binary data
97
97
  mz_array = mz_binary.data
98
98
  intensity_array = intensity_binary.data
99
-
99
+
100
100
  default_from, default_to = mz_array.first, mz_array.first
101
-
101
+
102
+ from = default_from
103
+ to = default_to
104
+
102
105
  # find designated intensity
103
- if !at
104
- from = default_from
105
- to = default_to
106
- else
106
+ if at
107
107
  from = at - interval
108
108
  from = default_from if from < 0
109
109
  to = at + interval
110
110
  to = default_to if to > mz_array.last
111
111
  end
112
-
112
+
113
113
  # find values in mz array
114
- low_value = mz_array.binary_search(from, false)
114
+ low_value = mz_array.bsearch { |x| x >= from }
115
115
  low_index = mz_array.index(low_value)
116
- high_value = mz_array.binary_search(to)
116
+ high_value = mz_array.bsearch { |x| x >= to }
117
117
  high_index = mz_array.index(high_value)
118
-
118
+
119
119
  # sum all values in subarray
120
- intensity_array[low_index..high_index].inject{|sum, x| sum + x}
121
-
120
+ sum = intensity_array[low_index..high_index].inject{|sum, x| sum + x}
121
+
122
+ sum
122
123
  end
123
124
 
124
-
125
+
125
126
  end
126
-
127
+
127
128
  end
@@ -1,11 +1,16 @@
1
1
  module ImzML
2
-
2
+
3
3
  class Image
4
-
4
+
5
+ # Point
5
6
  attr_accessor :max_pixel_count
7
+
8
+ # Point
6
9
  attr_accessor :max_dimension
10
+
11
+ # Point
7
12
  attr_accessor :pixel_size
8
-
13
+
9
14
  end
10
-
15
+
11
16
  end
data/lib/imzml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module ImzML
2
-
3
- VERSION = "0.1.0"
4
-
2
+
3
+ VERSION = "0.1.1"
4
+
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imzml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondra Beneš
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-27 00:00:00.000000000 Z
11
+ date: 2014-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -73,7 +73,6 @@ files:
73
73
  - data/imagingMS.obo
74
74
  - data/psi-ms.obo
75
75
  - data/unit.obo
76
- - lib/core_ext/array.rb
77
76
  - lib/core_ext/string.rb
78
77
  - lib/imzml.rb
79
78
  - lib/imzml/metadata.rb
@@ -1,23 +0,0 @@
1
- class Array
2
-
3
- def binary_search(value, first = true)
4
-
5
- if (self.size > 2)
6
- middle_index = self.size/2
7
- middle = self[middle_index]
8
-
9
- if (middle > value)
10
- self[0..middle_index].binary_search(value, first)
11
- else
12
- self[middle_index..self.size].binary_search(value, first)
13
- end
14
- else
15
- if first
16
- self.first
17
- else
18
- self.last
19
- end
20
- end
21
- end
22
-
23
- end