Class: ViennaRna::Xbor

Inherits:
Base
  • Object
show all
Defined in:
lib/vienna_rna/modules/xbor.rb

Direct Known Subclasses

Fftbor, Rnabor

Constant Summary collapse

BASE_FLAGS =
{
  E: "/usr/local/bin/energy.par"
}

Instance Attribute Summary

Attributes inherited from Base

#data, #response, #runtime

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

batch, bootstrap, #debugger, debugger, exec_exists?, #exec_name, #exec_sequence_format, #initialize, method_added, #pre_run_check, run, #run, #run_with_hooks, #stringify_flags

Constructor Details

This class inherits a constructor from ViennaRna::Base

Class Method Details

.bootstrap_from_file(path, klass = self) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/vienna_rna/modules/xbor.rb', line 27

def self.bootstrap_from_file(path, klass = self)
  log       = File.read(path)
  sequence  = log.split(/\n/).first.split(/\s+/)[1]
  structure = log.split(/\n/).first.split(/\s+/)[2]
  
  klass.bootstrap(Rna.init_from_string(sequence, structure), log)
end

.parse(response) ⇒ Object



35
36
37
# File 'lib/vienna_rna/modules/xbor.rb', line 35

def self.parse(response)
  response.split(/\n/).select { |line| line =~ /^\d+\t-?\d+/ }.map { |line| line.split(/\t/) }
end

Instance Method Details

#expected_kObject



48
49
50
# File 'lib/vienna_rna/modules/xbor.rb', line 48

def expected_k
  k_p_points.map { |array| array.inject(&:*) }.inject(&:+)
end

#full_distributionObject



39
40
41
42
# File 'lib/vienna_rna/modules/xbor.rb', line 39

def full_distribution
  distribution      = run.distribution
  full_distribution = distribution + ([0.0] * ((differnece = data.seq.length - distribution.length + 1) < 0 ? 0 : differnece))
end

#inspectObject



60
61
62
# File 'lib/vienna_rna/modules/xbor.rb', line 60

def inspect
  "#<#{self.class.name} #{data.inspect}>"
end

#k_p_pointsObject



44
45
46
# File 'lib/vienna_rna/modules/xbor.rb', line 44

def k_p_points
  full_distribution.each_with_index.to_a.map(&:reverse)[0..data.seq.length]
end

#quick_plot(options = {}) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/vienna_rna/modules/xbor.rb', line 52

def quick_plot(options = {})
  ViennaRna::Graphing::Gnuplot.quick_plot(
    k_p_points,
    options[:title] || "%s\\n%s\\n%s" % [self.class.name, data.seq, data.safe_structure],
    options
  )
end

#run_command(flags = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vienna_rna/modules/xbor.rb', line 12

def run_command(flags = {})
  file = Tempfile.new("rna")
  file.write("%s\n" % data.seq)
  file.write("%s\n" % data.str)
  file.close
  
  debugger { "Running FFTbor on #{data.inspect}" }
  
  "%s %s %s" % [
    exec_name, 
    stringify_flags(BASE_FLAGS.merge(self.class.const_defined?(:FLAGS) ? self.class.const_get(:FLAGS) : {}).merge(flags)), 
    file.path
  ]
end