Class: ViennaRna::Package::Xbor

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

Direct Known Subclasses

Fftbor, Rnabor

Instance Attribute Summary

Attributes inherited from Base

#data, #flags, #response, #runtime

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

bootstrap, #debugger, #initialize, #serialize

Methods included from Global::ChainExtensions

included

Methods included from Global::RunExtensions

included

Constructor Details

This class inherits a constructor from ViennaRna::Package::Base

Class Method Details

.parse(response) ⇒ Object



25
26
27
# File 'lib/vienna_rna/package/xbor.rb', line 25

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

Instance Method Details

#expected_kObject



38
39
40
# File 'lib/vienna_rna/package/xbor.rb', line 38

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

#full_distributionObject



29
30
31
32
# File 'lib/vienna_rna/package/xbor.rb', line 29

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

#inspectObject



58
59
60
# File 'lib/vienna_rna/package/xbor.rb', line 58

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

#k_p_pointsObject



34
35
36
# File 'lib/vienna_rna/package/xbor.rb', line 34

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

#quick_plot(filename: false) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/vienna_rna/package/xbor.rb', line 50

def quick_plot(filename: false)
  ViennaRna::Graphing::R.line_graph(
    k_p_points,
    title:    options[:title] || "%s\\n%s\\n%s" % [self.class.name, data.seq, data.safe_structure],
    filename: false
  )
end

#run_command(flags) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vienna_rna/package/xbor.rb', line 10

def run_command(flags)
  file = Tempfile.new("rna")
  file.write("%s\n" % data.seq)
  file.write("%s\n" % data.str)
  file.close

  ViennaRna.debugger { "Running FFTbor on #{data.inspect}" }

  "%s %s %s" % [
    exec_name, 
    stringify_flags(flags), 
    file.path
  ]
end

#to_csvObject



42
43
44
# File 'lib/vienna_rna/package/xbor.rb', line 42

def to_csv
  k_p_points.map { |k, p| "%d,%.8f" % [k, p] }.join(?\n) + ?\n
end

#to_csv!(filename) ⇒ Object



46
47
48
# File 'lib/vienna_rna/package/xbor.rb', line 46

def to_csv!(filename)
  File.open(filename, ?w) { |file| file.write(to_csv) }
end