Class: MS::Lipid::Search::Bin
- Inherits:
-
Bin
- Object
- Bin
- MS::Lipid::Search::Bin
- Defined in:
- lib/ms/lipid/search/bin.rb
Overview
A Search::Bin is a range that contains the entire query spectrum (not just the portion covered by the range). the query spectrum, and a ProbabilityDistribution – the probability that a peak’s delta to nearest peak is that small by chance.
Instance Attribute Summary collapse
-
#db_spectrum ⇒ Object
the intensity value of the query spectrum should be a query.
-
#probability_distribution ⇒ Object
Returns the value of attribute probability_distribution.
Instance Method Summary collapse
- #<<(query) ⇒ Object
-
#best_hits(query, num_hits) ⇒ Object
returns a HitGroup object.
-
#initialize(range_obj, db_spectrum) ⇒ Bin
constructor
A new instance of Bin.
- #inspect ⇒ Object
-
#queries_to_hit_groups!(num_hits = 1) ⇒ Object
returns the nearest num_hits MS::Lipid::Search::Hits sorted by delta [with tie going to the lower m/z] searches all queries and removes them from the data queue.
- #to_range ⇒ Object
Constructor Details
#initialize(range_obj, db_spectrum) ⇒ Bin
Returns a new instance of Bin.
16 17 18 19 |
# File 'lib/ms/lipid/search/bin.rb', line 16 def initialize(range_obj, db_spectrum) super(range_obj.begin, range_obj.end, range_obj.exclude_end?) @db_spectrum = db_spectrum end |
Instance Attribute Details
#db_spectrum ⇒ Object
the intensity value of the query spectrum should be a query
13 14 15 |
# File 'lib/ms/lipid/search/bin.rb', line 13 def db_spectrum @db_spectrum end |
#probability_distribution ⇒ Object
Returns the value of attribute probability_distribution.
14 15 16 |
# File 'lib/ms/lipid/search/bin.rb', line 14 def probability_distribution @probability_distribution end |
Instance Method Details
#<<(query) ⇒ Object
21 22 23 |
# File 'lib/ms/lipid/search/bin.rb', line 21 def <<(query) @data << query end |
#best_hits(query, num_hits) ⇒ Object
returns a HitGroup object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ms/lipid/search/bin.rb', line 48 def best_hits(query, num_hits) query_mz = query.mz #puts "MZ: #{query_mz}" db_mzs = @db_spectrum.mzs index = @db_spectrum.find_nearest_index(query_mz) _min = index - (num_hits-1) (_min >= 0) || (_min = 0) _max = index + (num_hits-1) (_max < db_mzs.size) || (_max = @db_spectrum - 1) delta_index_pairs = (_min.._max).map {|i| [query_mz.-(db_mzs[i]).abs, i] } closest_delta_index_pairs = delta_index_pairs.sort top_num_hits_delta_index_pairs = closest_delta_index_pairs[0, num_hits] top_num_hit_indices = top_num_hits_delta_index_pairs.map(&:last) hit_group = top_num_hit_indices.map do |index| Hit.new( :db_isobar_group => @db_isobar_groups_by_index[index], :observed_mz => query_mz) end HitGroup.new(hit_group) end |
#inspect ⇒ Object
67 68 69 |
# File 'lib/ms/lipid/search/bin.rb', line 67 def inspect "<(#{super}) @db_spectrum(points size)=#{db_spectrum.mzs.size} @probability_distribution=#{probability_distribution}>" end |
#queries_to_hit_groups!(num_hits = 1) ⇒ Object
returns the nearest num_hits MS::Lipid::Search::Hits sorted by delta
- with tie going to the lower m/z
-
searches all queries and removes them from the data queue
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ms/lipid/search/bin.rb', line 28 def queries_to_hit_groups!(num_hits=1) queries = @data.dup @data.clear @db_isobar_groups_by_index = @db_spectrum.intensities hit_groups = queries.map do |query| best_hits(query, num_hits) end all_top_hits = hit_groups.map(&:first) # updates the pvalues for all the hits pvalues = probability_distribution.pvalues( all_top_hits ) all_top_hits.zip(pvalues) {|hit, pvalue| hit.pvalue = pvalue } hit_groups end |
#to_range ⇒ Object
71 72 73 |
# File 'lib/ms/lipid/search/bin.rb', line 71 def to_range Range.new( self.begin, self.end, self.exclude_end? ) end |