vienna_rna 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/modules/base.rb CHANGED
@@ -82,14 +82,18 @@ module ViennaRna
82
82
  end
83
83
 
84
84
  def run_with_hooks(flags = {})
85
- tap do
86
- @runtime = Benchmark.measure do
87
- pre_run_check unless respond_to?(:run_command)
88
- @response = run_without_hooks(flags)
89
- post_process if respond_to?(:post_process)
90
- end
85
+ unless @response
86
+ tap do
87
+ @runtime = Benchmark.measure do
88
+ pre_run_check unless respond_to?(:run_command)
89
+ @response = run_without_hooks(flags)
90
+ post_process if respond_to?(:post_process)
91
+ end
91
92
 
92
- debugger { "Total runtime: %.3f sec." % runtime.real }
93
+ debugger { "Total runtime: %.3f sec." % runtime.real }
94
+ end
95
+ else
96
+ self
93
97
  end
94
98
  end
95
99
 
@@ -3,12 +3,16 @@ require "bigdecimal"
3
3
 
4
4
  module ViennaRna
5
5
  class Rnabor < Xbor
6
+ FLAGS = {
7
+ nodangle: :empty
8
+ }
9
+
6
10
  def partition
7
- non_zero_shells.sum
11
+ non_zero_shells.inject(&:+)
8
12
  end
9
13
 
10
14
  def total_count
11
- counts.sum
15
+ counts.inject(&:+)
12
16
  end
13
17
 
14
18
  def counts
data/lib/modules/utils.rb CHANGED
@@ -34,24 +34,32 @@ module ViennaRna
34
34
  end
35
35
 
36
36
  def plot(data, options = {})
37
- options = { title: "Title", x_label: "X Axis", y_label: "Y Axis" }.merge(options)
38
-
39
37
  Gnuplot.open do |gnuplot|
40
38
  Gnuplot::Plot.new(gnuplot) do |plot|
41
-
39
+ case options[:output]
40
+ when /file/i then
41
+ plot.output(options[:filename])
42
+ plot.terminal("png size 800,600")
43
+ end
44
+
42
45
  plot.title(options[:title])
43
46
  plot.xlabel(options[:x_label])
44
47
  plot.ylabel(options[:y_label])
45
48
 
46
49
  plot.data = data.map do |data_hash|
47
50
  Gnuplot::DataSet.new([data_hash[:x], data_hash[:y]]) do |dataset|
48
- dataset.with = "points"
51
+ dataset.with = data_hash[:style] || "points"
49
52
  data_hash[:title] ? dataset.title = data_hash[:title] : dataset.notitle
50
53
  end
51
54
  end
52
55
  end
53
56
  end
54
57
  end
58
+
59
+ def quick_plot(title, data)
60
+ # data = [[x_0, y_0], [x_1, y_1], ...]
61
+ plot([{ x: data.map(&:first), y: data.map(&:last), style: "linespoints" }], title: title)
62
+ end
55
63
  end
56
64
  end
57
65
  end
data/lib/modules/xbor.rb CHANGED
@@ -3,6 +3,10 @@ require "bigdecimal"
3
3
 
4
4
  module ViennaRna
5
5
  class Xbor < Base
6
+ BASE_FLAGS = {
7
+ E: "/usr/local/bin/energy.par"
8
+ }
9
+
6
10
  self.executable_name = -> { name.demodulize.gsub(/^([A-Z].*)bor$/) { |match| $1.upcase + "bor" } }
7
11
 
8
12
  def run_command(flags)
@@ -11,11 +15,27 @@ module ViennaRna
11
15
  file.write("%s\n" % data.safe_structure)
12
16
  file.close
13
17
 
14
- "%s -nodangle -E /usr/local/bin/energy.par %s" % [exec_name, file.path]
18
+ "%s %s %s" % [
19
+ exec_name,
20
+ stringify_flags(BASE_FLAGS.merge(self.class.const_defined?(:FLAGS) ? self.class.const_get(:FLAGS) : {})),
21
+ file.path
22
+ ]
15
23
  end
16
24
 
17
25
  def self.parse(response)
18
26
  response.split(/\n/).select { |line| line =~ /^\d+\t-?\d+/ }.map { |line| line.split(/\t/) }
19
27
  end
28
+
29
+ def full_distribution
30
+ distribution = run.distribution
31
+ full_distribution = distribution + ([0] * (data.seq.length - distribution.length + 1))
32
+ end
33
+
34
+ def quick_plot
35
+ ViennaRna::Utils.quick_plot(
36
+ "%s\\n%s\\n%s" % [self.class.name, data.seq, data.safe_structure],
37
+ full_distribution.each_with_index.to_a.map(&:reverse)
38
+ )
39
+ end
20
40
  end
21
41
  end
data/lib/vienna_rna.rb CHANGED
@@ -3,12 +3,6 @@ require "active_support/inflector"
3
3
  require "active_support/core_ext/class"
4
4
  require "active_support/core_ext/module/aliasing"
5
5
 
6
- module Enumerable
7
- def sum
8
- inject(&:+)
9
- end
10
- end
11
-
12
6
  module ViennaRna
13
7
  @debug = true
14
8
 
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.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-11 00:00:00.000000000 Z
12
+ date: 2012-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bio