Class: SpectrumHash::Splash
- Inherits:
-
Object
- Object
- SpectrumHash::Splash
- Defined in:
- lib/spectrum_hash/splash.rb
Constant Summary collapse
- DEFAULT_SPLASH_API_URI =
'http://splash.fiehnlab.ucdavis.edu/splash/it'- DEFAULT_SPECTRUM_TYPE =
:ms- SPECTRUM_TYPES =
{ms: 1, nmr: 2, uv_vis: 3, ir: 4, raman: 5}.freeze
- RETRIES =
3- RETRY_WAIT =
0.1
Instance Attribute Summary collapse
-
#api_uri ⇒ Object
readonly
Returns the value of attribute api_uri.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#spectrum ⇒ Object
readonly
Returns the value of attribute spectrum.
-
#spectrum_type ⇒ Object
readonly
Returns the value of attribute spectrum_type.
-
#splash ⇒ Object
readonly
Returns the value of attribute splash.
Instance Method Summary collapse
- #distance_to(other) ⇒ Object
-
#fetch! ⇒ Object
TODO handle retries.
- #hash_block ⇒ Object
- #histogram_block ⇒ Object
- #histogram_list ⇒ Object
-
#initialize(spectrum, options = {}) ⇒ Splash
constructor
A new instance of Splash.
- #payload ⇒ Object
- #peak_list ⇒ Object
- #split_splash ⇒ Object
- #to_s ⇒ Object
- #top_ten_block ⇒ Object
- #version ⇒ Object
- #version_block ⇒ Object
Constructor Details
#initialize(spectrum, options = {}) ⇒ Splash
Returns a new instance of Splash.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/spectrum_hash/splash.rb', line 15 def initialize(spectrum, ={}) # options can be version or uri to use a different end point @spectrum = spectrum @spectrum_type = [:spectrum_type] || DEFAULT_SPECTRUM_TYPE @api_uri = [:uri] || DEFAULT_SPLASH_API_URI # Load the splash if given @splash = [:splash] fetch! if @splash.nil? end |
Instance Attribute Details
#api_uri ⇒ Object (readonly)
Returns the value of attribute api_uri.
8 9 10 |
# File 'lib/spectrum_hash/splash.rb', line 8 def api_uri @api_uri end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/spectrum_hash/splash.rb', line 8 def response @response end |
#spectrum ⇒ Object (readonly)
Returns the value of attribute spectrum.
8 9 10 |
# File 'lib/spectrum_hash/splash.rb', line 8 def spectrum @spectrum end |
#spectrum_type ⇒ Object (readonly)
Returns the value of attribute spectrum_type.
8 9 10 |
# File 'lib/spectrum_hash/splash.rb', line 8 def spectrum_type @spectrum_type end |
#splash ⇒ Object (readonly)
Returns the value of attribute splash.
8 9 10 |
# File 'lib/spectrum_hash/splash.rb', line 8 def splash @splash end |
Instance Method Details
#distance_to(other) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/spectrum_hash/splash.rb', line 82 def distance_to(other) sum = 0 other_histo = other.histogram_list histogram_list.each.with_index(0) do |my_value,i| sum += ( my_value - other_histo[i] ).abs end sum end |
#fetch! ⇒ Object
TODO handle retries
31 32 33 34 35 |
# File 'lib/spectrum_hash/splash.rb', line 31 def fetch! return @splash unless @splash.nil? @response = fetch_splash @splash = @response.body end |
#hash_block ⇒ Object
70 71 72 |
# File 'lib/spectrum_hash/splash.rb', line 70 def hash_block split_splash[3] end |
#histogram_block ⇒ Object
66 67 68 |
# File 'lib/spectrum_hash/splash.rb', line 66 def histogram_block split_splash[2] end |
#histogram_list ⇒ Object
74 75 76 |
# File 'lib/spectrum_hash/splash.rb', line 74 def histogram_list @histogram_list ||= histogram_block.chars.map{|v| v.to_i } end |
#payload ⇒ Object
43 44 45 46 47 48 |
# File 'lib/spectrum_hash/splash.rb', line 43 def payload { ions: peak_list, type: spectrum_type.to_s.upcase } end |
#peak_list ⇒ Object
37 38 39 40 41 |
# File 'lib/spectrum_hash/splash.rb', line 37 def peak_list @peak_list ||= spectrum.map do |peak| {mass: peak.first, intensity: peak.last} end end |
#split_splash ⇒ Object
50 51 52 |
# File 'lib/spectrum_hash/splash.rb', line 50 def split_splash @split_splash ||= splash.split(/-/) end |
#to_s ⇒ Object
78 79 80 |
# File 'lib/spectrum_hash/splash.rb', line 78 def to_s splash end |
#top_ten_block ⇒ Object
62 63 64 |
# File 'lib/spectrum_hash/splash.rb', line 62 def top_ten_block split_splash[1] end |
#version ⇒ Object
54 55 56 |
# File 'lib/spectrum_hash/splash.rb', line 54 def version "1" end |
#version_block ⇒ Object
58 59 60 |
# File 'lib/spectrum_hash/splash.rb', line 58 def version_block split_splash[0] end |