Class: MS::Lipid::Search::ProbabilityDistribution
- Inherits:
-
Object
- Object
- MS::Lipid::Search::ProbabilityDistribution
- Defined in:
- lib/ms/lipid/search/probability_distribution.rb
Constant Summary collapse
- DEFAULT_TYPE =
:ppm
- R =
Rserve::Simpler.new
Instance Attribute Summary collapse
-
#location ⇒ Object
takes location, scale and shape parameters.
-
#scale ⇒ Object
takes location, scale and shape parameters.
-
#shape ⇒ Object
takes location, scale and shape parameters.
-
#type ⇒ Object
type is :ppm or :delta_abs.
Class Method Summary collapse
-
.deviations_to_probability_distribution(type, devs) ⇒ Object
returns an EVD object.
- .require_r_library(lib) ⇒ Object
Instance Method Summary collapse
-
#initialize(location, scale, shape, type = DEFAULT_TYPE) ⇒ ProbabilityDistribution
constructor
A new instance of ProbabilityDistribution.
-
#pvalue(hit) ⇒ Object
takes a deviation and returns the pvalue.
-
#pvalues(hits) ⇒ Object
same as pvalue, just tries to limit the number of calls to R to speed things up!.
Constructor Details
#initialize(location, scale, shape, type = DEFAULT_TYPE) ⇒ ProbabilityDistribution
Returns a new instance of ProbabilityDistribution.
13 14 15 16 |
# 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 |
Instance Attribute Details
#location ⇒ Object
takes location, scale and shape parameters
10 11 12 |
# File 'lib/ms/lipid/search/probability_distribution.rb', line 10 def location @location end |
#scale ⇒ Object
takes location, scale and shape parameters
10 11 12 |
# File 'lib/ms/lipid/search/probability_distribution.rb', line 10 def scale @scale end |
#shape ⇒ Object
takes location, scale and shape parameters
10 11 12 |
# File 'lib/ms/lipid/search/probability_distribution.rb', line 10 def shape @shape end |
#type ⇒ Object
type is :ppm or :delta_abs
12 13 14 |
# File 'lib/ms/lipid/search/probability_distribution.rb', line 12 def type @type end |
Class Method Details
.deviations_to_probability_distribution(type, devs) ⇒ Object
returns an EVD object
41 42 43 44 45 |
# 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 |
.require_r_library(lib) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# 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 |
Instance Method Details
#pvalue(hit) ⇒ Object
takes a deviation and returns the pvalue
19 20 21 |
# 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) ⇒ Object
same as pvalue, just tries to limit the number of calls to R to speed things up!
25 26 27 28 |
# 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 |