class MS::Lipid::Search::ProbabilityDistribution

Constants

DEFAULT_TYPE
R

Attributes

location[RW]

takes location, scale and shape parameters

scale[RW]

takes location, scale and shape parameters

shape[RW]

takes location, scale and shape parameters

type[RW]

type is :ppm or :delta_abs

Public Class Methods

deviations_to_probability_distribution(type, devs) click to toggle source

returns an EVD object

# File lib/ms/lipid/search/probability_distribution.rb, line 41
def self.deviations_to_probability_distribution(type, devs)
  %w(ismev evd).each {|lib| require_r_library(lib) }
  params = R.converse("m <- gev.fit(log(devs_r))\n c(m$mle[1], m$mle[2], m$mle[3])", :devs_r => devs )
  self.new(*params, type)
end
new(location, scale, shape, type=DEFAULT_TYPE) click to toggle source
# File lib/ms/lipid/search/probability_distribution.rb, line 13
def initialize(location, scale, shape, type=DEFAULT_TYPE)
  @location, @scale, @shape = location, scale, shape
  @type = type
end
require_r_library(lib) click to toggle source
# File lib/ms/lipid/search/probability_distribution.rb, line 30
def self.require_r_library(lib)
  reply = R.converse "library(#{lib})"
  unless reply.size > 4  # ~roughly
    $stderr.puts "The libraries ismev and evd must be installed in your R env!"
    $stderr.puts "From within R (works best if R is started with sudo or root for installing):"
    $stderr.puts %Q{install.packages("ismev") ; install.packages("evd")}
    raise "must have R (rserve) and ismev and evd installed!"
  end
end

Public Instance Methods

pvalue(hit) click to toggle source

takes a deviation and returns the pvalue

# File lib/ms/lipid/search/probability_distribution.rb, line 19
def pvalue(hit)
  R.converse "pgev(log(#{hit.send(type)}), #{@location}, #{@scale}, #{@shape})"
end
pvalues(hits) click to toggle source

same as pvalue, just tries to limit the number of calls to R to speed things up!

# File lib/ms/lipid/search/probability_distribution.rb, line 25
def pvalues(hits)
  deltas = hits.map {|v| v.send(type).abs }
  R.converse("sapply(r_devs, function(elt) pgev(log(elt), #{@location}, #{@scale}, #{@shape}))", :r_devs => deltas)
end