vienna_rna 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,48 +1,33 @@
1
+ require "tempfile"
2
+
1
3
  module ViennaRna
2
4
  class Fftbor < Base
3
- attr_reader :flags
4
-
5
5
  def run_command(flags)
6
- @flags = flags
6
+ file = Tempfile.new("rna")
7
+ file.write("%s\n" % data.seq)
8
+ file.write("%s\n" % data.safe_structure)
9
+ file.close
7
10
 
8
- "./FFTbor -s %s -r %s -c %s -p %s" % [
9
- data.seq,
10
- data.safe_structure,
11
- flags[:scaling_factor] ||= 1,
12
- flags[:precision] ||= 6
13
- ]
14
- end
15
-
16
- def parse_partition
17
- response.split(/\n/).find { |line| line =~ /^Z\[1\]\[\d+\]:/ }.match(/^Z\[1\]\[\d+\]:\s*(.*)/)[1].to_f
11
+ "./FFTbor %s" % file.path
18
12
  end
19
13
 
20
- def parse_total_count
21
- response.split(/\n/).find { |line| line =~ /^Z\[\d+\]\[1\]:/ }.match(/^Z\[\d+\]\[1\]:\s*(.*)/)[1].to_i
14
+ def partition
15
+ # Scaling factor (Z{1, n}): 586.684
16
+ response.split(/\n/).find { |line| line =~ /^Scaling factor.*:\s+(\d+\.\d+)/ }
17
+ $1.to_f
22
18
  end
23
19
 
24
- def parse_points
25
- self.class.parse(response, "ROOTS AND SOLUTIONS") { |line| line.strip.split(/\s\s+/).map { |value| eval("Complex(#{value})") } }
20
+ def total_count
21
+ response.split(/\n/).find { |line| line =~ /^Number of structures: (\d+)/ }
22
+ $1.to_i
26
23
  end
27
24
 
28
- def parse_distribution
29
- if flags[:scaling_factor] != 1
30
- puts "Warning: The scaling factor was set to #{flags[:scaling_factor]}. The Boltzmann distribution is not setup to handle scaling in this fashion."
31
- end
32
-
33
- self.class.parse(response, "DISTRIBUTION") { |line| line.strip.split(/:\s*/).last.to_f }
25
+ def distribution
26
+ self.class.parse(response).map { |row| row[1].to_f }
34
27
  end
35
28
 
36
- def self.parse(response, delimiter)
37
- response.split(/\n/).reject do |line|
38
- line.empty?
39
- end.drop_while do |line|
40
- line !~ /^START #{delimiter}/i
41
- end.reverse.drop_while do |line|
42
- line !~ /^END #{delimiter}/i
43
- end.reverse[1..-2].map do |line|
44
- yield line
45
- end
29
+ def self.parse(response)
30
+ response.split(/\n/).select { |line| line =~ /^\d+\t\d+(\.\d+)?/ }.map { |line| line.split(/\t/) }
46
31
  end
47
32
  end
48
33
  end
@@ -8,26 +8,26 @@ module ViennaRna
8
8
  file.write("%s\n" % data.safe_structure)
9
9
  file.close
10
10
 
11
- "./RNAbor %s" % file.path
11
+ "./RNAbor -nodangle %s" % file.path
12
12
  end
13
13
 
14
- def parse_partition
15
- parse_non_zero_shells.sum
14
+ def partition
15
+ non_zero_shells.sum
16
16
  end
17
17
 
18
- def parse_total_count
19
- parse_counts.sum
18
+ def total_count
19
+ counts.sum
20
20
  end
21
21
 
22
- def parse_counts
22
+ def counts
23
23
  (non_zero_counts = self.class.parse(response).map { |row| row[2].to_i }) + [0] * (data.seq.length - non_zero_counts.length + 1)
24
24
  end
25
25
 
26
- def parse_distribution
27
- (non_zero_distribution = parse_non_zero_shells.map { |i| i / parse_partition }) + [0.0] * (data.seq.length - non_zero_distribution.length + 1)
26
+ def distribution
27
+ (non_zero_distribution = non_zero_shells.map { |i| i / partition }) + [0.0] * (data.seq.length - non_zero_distribution.length + 1)
28
28
  end
29
29
 
30
- def parse_non_zero_shells
30
+ def non_zero_shells
31
31
  self.class.parse(response).map { |row| row[1].to_f }
32
32
  end
33
33
 
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.6
4
+ version: 0.1.0
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-03-26 00:00:00.000000000 Z
12
+ date: 2012-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bio