Module: Ms::Spectrum::Filter
- Included in:
- Ms::Spectrum
- Defined in:
- lib/ms/spectrum/filter.rb
Instance Method Summary collapse
- #filter(by = :bins, opts = {}) ⇒ Object
-
#filter_by_bins(opts = {}) ⇒ Object
filters by binning the mz field bin_width is in m/z units num_peaks is the top peaks to include per bin.
Instance Method Details
#filter(by = :bins, opts = {}) ⇒ Object
7 8 9 |
# File 'lib/ms/spectrum/filter.rb', line 7 def filter(by=:bins, opts={}) send("filter_by_#{by}".to_sym, opts) end |
#filter_by_bins(opts = {}) ⇒ Object
filters by binning the mz field bin_width is in m/z units num_peaks is the top peaks to include per bin
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ms/spectrum/filter.rb', line 14 def filter_by_bins(opts={}) (bw, np) = {:bin_width => 100, :num_peaks => 7 }.merge(opts).values_at(:bin_width, :num_peaks) stop = bw track = [] track_all = [track] ints = self.intensities self.each do |mz,int| if mz > stop stop += bw track = [] track_all << track end track << [int, mz] end include = [] track_all.each do |track| track.sort! start = (track.size < np) ? track.size : np include.push( *( track[-start,np]) ) end ret_ints = [] ret_mzs = include.map {|int, mz| [mz, int] }.sort.map {|mz,int| ret_ints << int ; mz } return Spectrum.new([ret_mzs, ret_ints]) end |