vienna_rna 0.3.0 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31ec4e6771f342a7ebc0093f628748a1d39ef940
4
- data.tar.gz: f3e2f41a3957ca6a84cd38aaa390ae383a49f712
3
+ metadata.gz: 125876026dfe4b5bf2af8e12fe1425c79ce2c41f
4
+ data.tar.gz: 28cff69aaabc513509da57f049928b7d1f62dc82
5
5
  SHA512:
6
- metadata.gz: 949a4476d1acda83e807966ccc34b6bdfa57b93fdae096bd848b83970fca94383502fa36e2f06b45158c2347d64e5dfc138461f6d5cd83d35233b388cecb5321
7
- data.tar.gz: 717e42a7999cffe4fa6994652c22edafcc66e01f35bb41b58305e2ab900572eb81c5e0d2aa4cea44fa5504a89b7f88e4ddc4e2c84833f3804d0423f9e2b5a300
6
+ metadata.gz: ce4c556d37c020f386d076a96372602eb68ff3bbc6248ce801f2e8048e550bb5aac94daae9e200cf3c2db2deb9704123141c3d07ef1ff6f63a5b44d0cd940961
7
+ data.tar.gz: dce9820a4cd5a0ae1b86b6aa329cff3b6373d5ea9892a156940097e58955f793be3e7ecbd902ab7340cc6db112169151302998805e1278842780ce3e6a3fb6d7
@@ -40,6 +40,7 @@ module ViennaRna
40
40
  alias :seq :sequence
41
41
  alias :str :structure
42
42
 
43
+
43
44
  def inspect
44
45
  case [sequence.present?, structure.present?]
45
46
  when [true, true] then
@@ -60,6 +61,10 @@ module ViennaRna
60
61
  end
61
62
  end
62
63
  end
64
+
65
+ def run(module_name, options = {})
66
+ ViennaRna.const_missing("#{module_name}".camelize).run(self, options)
67
+ end
63
68
 
64
69
  private
65
70
 
@@ -2,6 +2,7 @@ module ViennaRna
2
2
  module RnaExtensions
3
3
  def self.included(base)
4
4
  base.extend(ClassMethods)
5
+ base.send(:include, InstanceMethods)
5
6
  base.extend(StructureBasedClassAndInstanceMethods)
6
7
 
7
8
  base.class_eval do
@@ -25,6 +26,12 @@ module ViennaRna
25
26
  Shuffle.new(sequence).shuffle(token_length)
26
27
  end
27
28
  end
29
+
30
+ module InstanceMethods
31
+ def gc_content
32
+ seq.split(//).select { |i| i =~ /[GC]/i }.size.to_f / seq.size
33
+ end
34
+ end
28
35
 
29
36
  module StructureBasedClassAndInstanceMethods
30
37
  # All the methods in here are also copied in as instance methods, where the first argument is the ViennaRna::Rna#structure
@@ -91,23 +91,18 @@ module ViennaRna
91
91
  groups = (range.min + half).step(range.max, bin_size).map { |x| [x, data.count { |i| i >= x - half && i < x + half }] }
92
92
 
93
93
  options.merge!(output: "file") if options[:filename]
94
- options.merge!({
95
- plot: {
96
- title: title,
97
- yrange: "[0:#{groups.map(&:last).max * 1.1}]",
98
- xtics: "#{[bin_size, 5].max}",
99
- style: "fill solid 0.5 border"
100
- }
94
+ options[:plot] = (options[:plot] || {}).merge({
95
+ title: title,
96
+ yrange: "[0:#{groups.map(&:last).max * 1.1}]",
97
+ xtics: "#{[bin_size, 5].max}",
98
+ style: "fill solid 0.5 border"
101
99
  })
102
100
 
103
101
  plot([{ x: groups.map(&:first), y: groups.map(&:last), style: "boxes" }], options)
104
102
  end
105
103
 
106
104
  def roc(data, title = "", options = {})
107
- # data = [[true_score_1, true_score_2, ...], [false_score_1, false_score_2, ...]]
108
- # This 'twiddle' removes duplicates by adding a very small random number to any repeated value
109
- data = data.map { |scores| scores.group_by(&:_ident).values.inject([]) { |array, values| array + (values.size > 1 ? values.map { |i| i + 1e-8 * (rand - 0.5) } : values) } }
110
-
105
+ # data = [[true_score_1, true_score_2, ...], [false_score_1, false_score_2, ...]]~
111
106
  roc_curve = ROC.curve_points({ 1 => data[0], -1 => data[1] }.inject([]) { |data, (truth, values)| data.concat(values.map { |i| [i, truth] })})
112
107
  area = roc_curve.each_cons(2).inject(0) do |sum, (a, b)|
113
108
  delta_x, delta_y = b[0] - a[0], b[1] - a[1]
@@ -129,7 +124,7 @@ module ViennaRna
129
124
  options[:plot] = ((options[:plot] || {}).merge(title: title))
130
125
  options.merge!(output: "file") if options[:filename]
131
126
 
132
- plot(data.map { |hash| { title: hash[:label], x: hash[:data].map(&:first), y: hash[:data].map(&:last), style: "linespoints" } }, options)
127
+ plot(data.map { |hash| { title: hash[:label], x: hash[:data].map(&:first), y: hash[:data].map(&:last), style: "linespoints" }.merge(hash[:options] || {}) }, options)
133
128
  end
134
129
  end
135
130
  end
data/lib/vienna_rna.rb CHANGED
@@ -17,7 +17,9 @@ module ViennaRna
17
17
  end
18
18
 
19
19
  def self.const_missing(name)
20
- if Base.exec_exists?(name)
20
+ if const_defined?(name)
21
+ const_get(name)
22
+ elsif Base.exec_exists?(name)
21
23
  module_eval do
22
24
  const_set(name, Class.new(Base))
23
25
  end
@@ -31,4 +33,11 @@ module ViennaRna
31
33
  def self.debug=(value)
32
34
  @debug = value
33
35
  end
36
+ end
37
+
38
+ # This dirties up the public namespace, but I use it so many times that I want a shorthand to it
39
+ unless defined? RNA
40
+ def RNA(sequence, structure = nil)
41
+ ViennaRna::Rna.init_from_string(sequence, structure)
42
+ end
34
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vienna_rna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Senter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-29 00:00:00.000000000 Z
11
+ date: 2013-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bio
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.0.2
126
+ rubygems_version: 2.0.3
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Bindings to the Vienna RNA package.