Class: TransfacFormatter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



4
5
6
7
8
9
# File 'lib/bioinform/formatters/transfac_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/transfac_formatter.rb', line 2

def motif
  @motif
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details



31
32
33
34
# File 'lib/bioinform/formatters/transfac_formatter.rb', line 31

def footer
  #"XX\n//\n"

  "\nXX\n//"
end

#headerObject



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

def header
  if options[:with_name] && name
    "ID #{name}\nBF StubSpeciesName\nP0\tA\tC\tG\tT\n"
  else
    raise 'Transfac should have the name field'
  end
end

#matrix_stringObject



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

def matrix_string
  motif.each_position.map.with_index{|pos,ind| 
    line_number = ind.to_s
    line_number = (line_number.size == 1) ? "0#{line_number}" : line_number
    line_number + ' ' + pos.join("\t")
  }.join("\n")
end

#nameObject



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

def name
  motif.name
end

#to_sObject



36
37
38
# File 'lib/bioinform/formatters/transfac_formatter.rb', line 36

def to_s
  header + matrix_string + footer
end