Class: RawFormatter

Inherits:
Object show all
Defined in:
lib/bioinform/formatters/raw_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(motif, options = {}) ⇒ RawFormatter

Returns a new instance of RawFormatter.



4
5
6
7
8
9
# File 'lib/bioinform/formatters/raw_formatter.rb', line 4

def initialize(motif, options = {})
  @motif = motif
  
  default_options = {with_name: true, letters_as_rows: false}
  @options = default_options.merge(options)
end

Instance Attribute Details

#motifObject

Returns the value of attribute motif.



2
3
4
# File 'lib/bioinform/formatters/raw_formatter.rb', line 2

def motif
  @motif
end

#optionsObject

Returns the value of attribute options.



2
3
4
# File 'lib/bioinform/formatters/raw_formatter.rb', line 2

def options
  @options
end

Instance Method Details



32
33
34
35
# File 'lib/bioinform/formatters/raw_formatter.rb', line 32

def footer
  # "\n"
  ''
end

#headerObject



15
16
17
18
19
20
21
# File 'lib/bioinform/formatters/raw_formatter.rb', line 15

def header
  if options[:with_name] && name
    name + "\n"
  else
    ''
  end
end

#matrix_stringObject



23
24
25
26
27
28
29
30
# File 'lib/bioinform/formatters/raw_formatter.rb', line 23

def matrix_string
  if options[:letters_as_rows]
    hsh = motif.to_hash
    [:A,:C,:G,:T].collect{|letter| "#{letter}|" + hsh[letter].join("\t")}.join("\n")
  else
    motif.each_position.map{|pos| pos.join("\t")}.join("\n")
  end
end

#nameObject



11
12
13
# File 'lib/bioinform/formatters/raw_formatter.rb', line 11

def name
  motif.name
end

#to_sObject



38
39
40
# File 'lib/bioinform/formatters/raw_formatter.rb', line 38

def to_s
  header + matrix_string + footer
end