vienna_rna 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/modules/base.rb CHANGED
@@ -70,11 +70,15 @@ module ViennaRna
70
70
  end
71
71
 
72
72
  def run(flags = {})
73
- if respond_to?(:run_command)
74
- %x[#{method(:run_command).arity.zero? ? run_command : run_command(flags)}]
73
+ command = if respond_to?(:run_command)
74
+ method(:run_command).arity.zero? ? run_command : run_command(flags)
75
75
  else
76
- %x[echo #{exec_sequence_format} | #{exec_name} #{stringify_flags(flags)}]
76
+ "echo #{exec_sequence_format} | #{exec_name} #{stringify_flags(flags)}"
77
77
  end
78
+
79
+ puts command if ViennaRna.debug
80
+
81
+ %x[#{command}]
78
82
  end
79
83
  end
80
84
  end
@@ -0,0 +1,26 @@
1
+ module ViennaRna
2
+ class FftInR < Base
3
+ attr_reader :processed_response, :points, :total_count, :precision
4
+
5
+ def initialize(points, total_count, precision)
6
+ @points = points
7
+ @total_count = total_count
8
+ @precision = precision
9
+ end
10
+
11
+ def run_command
12
+ vector = "c(%s)" % points.map { |point| 10 ** precision * point / total_count }.join(", ")
13
+ "Rscript -e 'vector <- #{vector}; fft(vector) / length(vector);'" % vector
14
+ end
15
+
16
+ def post_process
17
+ @processed_response = response.split(/\n/).map do |line|
18
+ line.strip.match(/\[\d+\]\s+(.*)$/)[1].split(/\s+/)
19
+ end.flatten.map do |i|
20
+ i.match(/(-?\d+\.\d+e[\+-]\d+)/)[1].to_f
21
+ end.map do |i|
22
+ precision.zero? ? i : i.truncate / 10.0 ** precision
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,7 +1,7 @@
1
1
  module ViennaRna
2
2
  class Rnabor < Base
3
3
  def run_command(flags)
4
- "./RNAbor -s %s -c %s" % [fasta.seq, flags[:scaling_factor]]
4
+ "./RNAbor -s %s -c %s" % [fasta.seq, flags[:scaling_factor] || 1]
5
5
  end
6
6
 
7
7
  def parse_total_count
@@ -16,6 +16,20 @@ module ViennaRna
16
16
  self.class.parse(response, "UNSCALED SUM") { |line| line.strip.split(/:\s*/).map(&:to_f) }
17
17
  end
18
18
 
19
+ def in_r(options = {})
20
+ results = solve_in_r(options).processed_response
21
+
22
+ options[:unscale] ? results.map { |i| i * parse_total_count } : results
23
+ end
24
+
25
+ def solve_in_r(options = {})
26
+ options = { precision: 0, unscale: false }.merge(options)
27
+
28
+ run unless response
29
+
30
+ ViennaRna::FftInR.new(parse_points.map(&:last), parse_total_count, options[:precision]).run
31
+ end
32
+
19
33
  def self.parse(response, delimiter)
20
34
  response.split(/\n/).reject do |line|
21
35
  line.empty?
data/lib/vienna_rna.rb CHANGED
@@ -8,7 +8,15 @@ Dir[File.join(File.dirname(__FILE__), "/modules/*")].each do |file|
8
8
  require file
9
9
  end
10
10
 
11
+ module Enumerable
12
+ def sum
13
+ inject { |sum, i| sum + i }
14
+ end
15
+ end
16
+
11
17
  module ViennaRna
18
+ @debug = false
19
+
12
20
  def self.const_missing(name)
13
21
  if Base.exec_exists?(name)
14
22
  module_eval do
@@ -16,4 +24,12 @@ module ViennaRna
16
24
  end
17
25
  end
18
26
  end
27
+
28
+ def self.debug
29
+ @debug
30
+ end
31
+
32
+ def self.debug=(value)
33
+ @debug = value
34
+ end
19
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vienna_rna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 1.4.2
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 1.4.2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: activesupport
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -53,6 +53,8 @@ files:
53
53
  Li9saWIvbW9kdWxlcy9iYXNlLnJi
54
54
  - !binary |-
55
55
  Li9saWIvbW9kdWxlcy9iYXRjaC5yYg==
56
+ - !binary |-
57
+ Li9saWIvbW9kdWxlcy9mZnRfaW5fci5yYg==
56
58
  - !binary |-
57
59
  Li9saWIvbW9kdWxlcy9mb2xkLnJi
58
60
  - !binary |-