class SpectrumHash::Splash
Constants
- DEFAULT_SPECTRUM_TYPE
- DEFAULT_SPLASH_API_URI
- RETRIES
- RETRY_WAIT
- SPECTRUM_TYPES
Attributes
api_uri[R]
response[R]
spectrum[R]
spectrum_type[R]
splash[R]
Public Class Methods
new(spectrum, options={})
click to toggle source
# File lib/spectrum_hash/splash.rb, line 15 def initialize(spectrum, options={}) # options can be version or uri to use a different end point @spectrum = spectrum @spectrum_type = options[:spectrum_type] || DEFAULT_SPECTRUM_TYPE @api_uri = options[:uri] || DEFAULT_SPLASH_API_URI # Load the splash if given @splash = options[:splash] fetch! if @splash.nil? end
Public Instance Methods
distance_to(other)
click to toggle source
# 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!()
click to toggle source
TODO handle retries
# File lib/spectrum_hash/splash.rb, line 31 def fetch! return @splash unless @splash.nil? @response = fetch_splash @splash = @response.body end
hash_block()
click to toggle source
# File lib/spectrum_hash/splash.rb, line 70 def hash_block split_splash[3] end
histogram_block()
click to toggle source
# File lib/spectrum_hash/splash.rb, line 66 def histogram_block split_splash[2] end
histogram_list()
click to toggle source
# File lib/spectrum_hash/splash.rb, line 74 def histogram_list @histogram_list ||= histogram_block.chars.map{|v| v.to_i } end
payload()
click to toggle source
# File lib/spectrum_hash/splash.rb, line 43 def payload { ions: peak_list, type: spectrum_type.to_s.upcase } end
peak_list()
click to toggle source
# 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()
click to toggle source
# File lib/spectrum_hash/splash.rb, line 50 def split_splash @split_splash ||= splash.split(/-/) end
to_s()
click to toggle source
# File lib/spectrum_hash/splash.rb, line 78 def to_s splash end
top_ten_block()
click to toggle source
# File lib/spectrum_hash/splash.rb, line 62 def top_ten_block split_splash[1] end
version()
click to toggle source
# File lib/spectrum_hash/splash.rb, line 54 def version "1" end
version_block()
click to toggle source
# File lib/spectrum_hash/splash.rb, line 58 def version_block split_splash[0] end
Private Instance Methods
fetch_splash()
click to toggle source
# File lib/spectrum_hash/splash.rb, line 93 def fetch_splash HTTParty.post api_uri, body: payload.to_json, headers: { 'Content-Type' => 'application/json' } end