mspire 0.10.4 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3beb508a5e9e4b407d4d45083082b514a90383b8
4
- data.tar.gz: 72e98503c17aba6707379a5d9a2ffb12130861f7
3
+ metadata.gz: b4dcc320a2ee49559d1d64c2c42f1d647a33901c
4
+ data.tar.gz: 2562f3e4bcd33b71da96151cb6fc7cae172277a4
5
5
  SHA512:
6
- metadata.gz: 0eae06fd5de59f47cb7d2d3e2d99d1394a47863bbc887a1a1b85743ce98ad6b7e857f67494346fb8e2b6dd1d38c1e6f77efd65be6817f039c7497f3f5b6b4e29
7
- data.tar.gz: 758310dcd10c5d9815064943b05823765e2cb7503dcb0a393f7f23990d7e1dfdf945ec2081a8af9c6157217f46aa237dd8258dfcb7c81ca9031c944ddd477ccb
6
+ metadata.gz: 7f680070a1151cd563e2ade3b3ced3691f630ea42a67bbef4c866c6edfb163356f249ea519eefebd57149f0a2a4b23f8a16a964274d8df6a141edb6b79c4df29
7
+ data.tar.gz: eca1464a336117c98312e71c392761d7d3dd4b3e58528e8da05647319eb516f958bd248ba2a86db702d1010f896329ab5a8513b287da1ba5ef4d014cc0d6f90f
@@ -120,6 +120,25 @@ module Mspire
120
120
  self
121
121
  end
122
122
 
123
+ # the range begin value will also be excluded on an exact match if
124
+ # exclude_begin is true. (respects the ranges exclude_end? value for the
125
+ # end).
126
+ def select_indices(range, exclude_begin=false)
127
+ indices = []
128
+ _mzs = mzs
129
+ lo_i = _mzs.bsearch_lower_boundary {|v| v <=> range.begin }
130
+ return indices unless lo_i
131
+
132
+ hi_i = nil
133
+ (lo_i..._mzs.size).each do |i|
134
+ break unless range === _mzs[i]
135
+ indices << i
136
+ end
137
+
138
+ indices.shift if exclude_begin && range.begin == _mzs[indices.first]
139
+ indices
140
+ end
141
+
123
142
  # returns the m/z that is closest to the value, favoring the lower m/z in
124
143
  # the case of a tie. Uses a binary search.
125
144
  def find_nearest(val)
@@ -1,3 +1,3 @@
1
1
  module Mspire
2
- VERSION = "0.10.4"
2
+ VERSION = "0.10.5"
3
3
  end
@@ -43,5 +43,16 @@ describe Mspire::Spectrum do
43
43
  spec.mzs.should == subject.mzs
44
44
  spec.intensities.should == subject.intensities
45
45
  end
46
+
47
+ specify 'select_indices returns the indices whose m/z values lie within the given range' do
48
+ spec = Mspire::Spectrum.new [[10.1, 10.5, 10.7, 11.5, 11.6], [2, 1, 4, 3, 5]]
49
+ expect(spec.select_indices( 10.5...11.5 )).to eq([1,2])
50
+ expect(spec.select_indices( 10.5..11.5 )).to eq([1,2,3])
51
+ expect(spec.select_indices( 10.5...11.5, true )).to eq([2])
52
+
53
+ [10.6..10.65, 0..1, 12..13].each do |range|
54
+ expect(spec.select_indices(range)).to eq([])
55
+ end
56
+ end
46
57
  end
47
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mspire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - John T. Prince
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-08 00:00:00.000000000 Z
12
+ date: 2014-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri