vienna_rna 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ A simple gem for facilitating bindings to the ViennaRNA package (http://www.tbi.univie.ac.at/~ivo/RNA/). Note that this gem makes no effort to build and install the ViennaRNA suite locally at this time, and instead relies on its presence on the host machine. Leverages the BioRuby gem (http://bioruby.open-bio.org/) libraries for file parsing.
2
+
3
+ Simple use case:
4
+ ruby-1.9.3-p125 :001 > require "vienna_rna"
5
+ => true
6
+ ruby-1.9.3-p125 :002 > rna = ViennaRna::Fold.run(seq: "CCUCGAGGGGAACCCGAAAGGGACCCGAGAGG")
7
+ => #<ViennaRna::Fold:0x007f9c48839dc0>
8
+ ruby-1.9.3-p125 :003 > rna.structure
9
+ => "((((..(((...(((....))).)))..))))"
10
+ ruby-1.9.3-p125 :004 > rna.mfe
11
+ => -19.7
@@ -2,25 +2,6 @@ require "benchmark"
2
2
 
3
3
  module ViennaRna
4
4
  class Base
5
- class Rna
6
- attr_reader :sequence, :structure
7
-
8
- def initialize(sequence, structure = nil)
9
- @sequence = sequence
10
- @structure = (structure == :mfe ? ViennaRna::Fold.run(seq).structure : structure)
11
- end
12
-
13
- alias :seq :sequence
14
-
15
- def safe_structure
16
- structure || empty_structure
17
- end
18
-
19
- def empty_structure
20
- "." * seq.length
21
- end
22
- end
23
-
24
5
  class_attribute :executable_name
25
6
 
26
7
  class << self
@@ -69,7 +50,12 @@ module ViennaRna
69
50
  end
70
51
 
71
52
  def exec_sequence_format
72
- data.seq
53
+ if data.str
54
+ '"%s
55
+ %s"' % [data.seq, data.str]
56
+ else
57
+ data.seq
58
+ end
73
59
  end
74
60
 
75
61
  def initialize(data)
@@ -104,14 +90,18 @@ module ViennaRna
104
90
  end
105
91
 
106
92
  def stringify_flags(flags)
107
- flags.inject("") { |string, (flag, value)| (string + (value == :empty ? " -%s" % flag : " -%s %s" % [flag, value])).strip }
93
+ base_flags = self.class.const_defined?(:BASE_FLAGS) ? self.class.const_get(:BASE_FLAGS) : {}
94
+
95
+ flags.merge(base_flags).inject("") do |string, (flag, value)|
96
+ (string + (value == :empty ? " -%s" % flag : " -%s %s" % [flag, value])).strip
97
+ end
108
98
  end
109
99
 
110
100
  def run(flags = {})
111
101
  command = if respond_to?(:run_command)
112
102
  method(:run_command).arity.zero? ? run_command : run_command(flags)
113
103
  else
114
- "echo #{exec_sequence_format} | #{exec_name} -noPS #{stringify_flags(flags)}"
104
+ "echo #{exec_sequence_format} | #{exec_name} #{stringify_flags(flags)}"
115
105
  end
116
106
 
117
107
  debugger { command }
@@ -0,0 +1,9 @@
1
+ module ViennaRna
2
+ class Eval < Base
3
+ attr_reader :mfe
4
+
5
+ def post_process
6
+ @mfe = Parser.mfe(@response)
7
+ end
8
+ end
9
+ end
@@ -1,14 +1,18 @@
1
1
  module ViennaRna
2
2
  class Fold < Base
3
+ BASE_FLAGS = {
4
+ "-noPS" => :empty
5
+ }
6
+
3
7
  attr_reader :structure, :mfe
4
8
 
5
9
  def post_process
6
- structure = @response.split(/\n/).last.gsub(/ \(\s*(-?\d*\.\d*)\)$/, "")
10
+ structure = @response.split(/\n/).last.gsub(Parser::REGEXP[:mfe], "")
7
11
 
8
12
  unless data.seq.length == structure.length
9
13
  raise "Sequence: '#{data.seq}'\nStructure: '#{structure}'"
10
14
  else
11
- @structure, @mfe = structure, $1.to_f
15
+ @structure, @mfe = structure, Parser.mfe(@response)
12
16
  end
13
17
  end
14
18
 
@@ -0,0 +1,13 @@
1
+ module ViennaRna
2
+ module Parser
3
+ REGEXP = {
4
+ mfe: / \(\s*(-?\d*\.\d*)\)$/
5
+ }
6
+
7
+ class << self
8
+ def mfe(response)
9
+ response.split(/\n/).last.match(REGEXP[:mfe])[1].to_f
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module ViennaRna
2
+ class Rna
3
+ attr_reader :sequence, :structure
4
+
5
+ def initialize(sequence, structure = nil)
6
+ @sequence = sequence
7
+ @structure = (structure == :mfe ? ViennaRna::Fold.run(seq).structure : structure)
8
+ end
9
+
10
+ alias :seq :sequence
11
+ alias :str :structure
12
+
13
+ def safe_structure
14
+ structure || empty_structure
15
+ end
16
+
17
+ def empty_structure
18
+ "." * seq.length
19
+ end
20
+ end
21
+ end
@@ -35,9 +35,9 @@ module ViennaRna
35
35
  full_distribution.each_with_index.to_a.map(&:reverse)[0..data.seq.length]
36
36
  end
37
37
 
38
- def quick_plot
38
+ def quick_plot(title = nil)
39
39
  ViennaRna::Utils.quick_plot(
40
- "%s\\n%s\\n%s" % [self.class.name, data.seq, data.safe_structure],
40
+ title || "%s\\n%s\\n%s" % [self.class.name, data.seq, data.safe_structure],
41
41
  k_p_points
42
42
  )
43
43
  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.1.5
4
+ version: 0.1.6
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-25 00:00:00.000000000 Z
12
+ date: 2012-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bio
@@ -49,16 +49,20 @@ executables: []
49
49
  extensions: []
50
50
  extra_rdoc_files: []
51
51
  files:
52
- - ./lib/vienna_rna/modules/base.rb
53
- - ./lib/vienna_rna/modules/batch.rb
54
- - ./lib/vienna_rna/modules/fftbor.rb
55
- - ./lib/vienna_rna/modules/fold.rb
56
- - ./lib/vienna_rna/modules/heat.rb
57
- - ./lib/vienna_rna/modules/rnabor.rb
58
- - ./lib/vienna_rna/modules/subopt.rb
59
- - ./lib/vienna_rna/modules/utils.rb
60
- - ./lib/vienna_rna/modules/xbor.rb
61
- - ./lib/vienna_rna.rb
52
+ - lib/vienna_rna/modules/base.rb
53
+ - lib/vienna_rna/modules/batch.rb
54
+ - lib/vienna_rna/modules/eval.rb
55
+ - lib/vienna_rna/modules/fftbor.rb
56
+ - lib/vienna_rna/modules/fold.rb
57
+ - lib/vienna_rna/modules/heat.rb
58
+ - lib/vienna_rna/modules/parser.rb
59
+ - lib/vienna_rna/modules/rna.rb
60
+ - lib/vienna_rna/modules/rnabor.rb
61
+ - lib/vienna_rna/modules/subopt.rb
62
+ - lib/vienna_rna/modules/utils.rb
63
+ - lib/vienna_rna/modules/xbor.rb
64
+ - lib/vienna_rna.rb
65
+ - README.md
62
66
  homepage: http://rubygems.org/gems/vienna_rna
63
67
  licenses: []
64
68
  post_install_message: