Class: Ulla::Essts

Inherits:
Object
  • Object
show all
Defined in:
lib/ulla/essts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, type = :logo) ⇒ Essts

Returns a new instance of Essts.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ulla/essts.rb', line 8

def initialize(file, type = :logo)
  @file         = file
  @type         = type
  @environments = []
  @essts        = []
  @total_table  = nil
  parse_tag     = nil

  IO.readlines(@file).each_with_index do |line, li|
    line.chomp!
    if    line =~ /^#\s+(ACDEFGHIKLMNPQRSTV\w+)/
      @aa_symbols = $1.split('')
    elsif line =~ /^#\s+(.*;\w+;\w+;[T|F];[T|F])/
      elems = $1.split(';')
      @environments << (env = OpenStruct.new)
      @environments[-1].name        = elems[0]
      @environments[-1].values      = elems[1].split('')
      @environments[-1].labels      = elems[2].split('')
      @environments[-1].constraind  = elems[3] == 'T' ? true : false
      @environments[-1].silent      = elems[4] == 'T' ? true : false
    elsif line =~ /^#\s+Total\s+number\s+of\s+environments:\s+(\d+)/
      @number_of_environments = Integer($1)
    elsif line =~ /^#\s+Number\s+of\s+alignments:\s+(\d+)/
      @number_of_alignments = Integer($1)
    elsif line =~ /^#/ # skip other comments!
      next
    elsif line =~ /^>Total/i
      @total_table  = Esst.new(type, 'total', @essts.size, @aa_symbols)
      parse_tag     = :tot_row
    elsif line =~ /^>Total\s+(\S+)/i
      @total_table  = Esst.new(type, 'total', Integer($1), @aa_symbols)
      parse_tag     = :tot_row
    elsif line =~ /^>(\S+)\s+(\S+)/
      break if parse_tag == :tot_row
      @essts    << Esst.new(type, $1, Integer($2), @aa_symbols)
      parse_tag = :esst_row
    elsif line =~ /^(\S+)\s+(\S+.*)$/ && (parse_tag == :esst_row || parse_tag == :tot_row)
      row_name    = $1
      row_values  = $2.strip.split(/\s+/).map { |v| Float(v) }
      if parse_tag == :esst_row
        @essts[-1].rownames << row_name
        @essts[-1].matrix = NMatrix[*(@essts[-1].matrix.to_a << row_values)]
      elsif parse_tag == :tot_row
        @total_table.rownames << row_name
        @total_table.matrix = NMatrix[*(@total_table.matrix.to_a << row_values)]
      else
        $logger.error "Something wrong at line #{li}: #{line}"
        exit 1
      end
    else
      raise "Something wrong at line, #{li}: #{line}"
    end
  end
end

Instance Attribute Details

#aa_symbolsObject (readonly)

Returns the value of attribute aa_symbols.



4
5
6
# File 'lib/ulla/essts.rb', line 4

def aa_symbols
  @aa_symbols
end

#environmentsObject (readonly)

Returns the value of attribute environments.



4
5
6
# File 'lib/ulla/essts.rb', line 4

def environments
  @environments
end

#esstsObject (readonly)

Returns the value of attribute essts.



4
5
6
# File 'lib/ulla/essts.rb', line 4

def essts
  @essts
end

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/ulla/essts.rb', line 4

def file
  @file
end

#number_of_alignmentsObject (readonly)

Returns the value of attribute number_of_alignments.



4
5
6
# File 'lib/ulla/essts.rb', line 4

def number_of_alignments
  @number_of_alignments
end

#number_of_environmentsObject (readonly)

Returns the value of attribute number_of_environments.



4
5
6
# File 'lib/ulla/essts.rb', line 4

def number_of_environments
  @number_of_environments
end

#total_tableObject (readonly)

Returns the value of attribute total_table.



4
5
6
# File 'lib/ulla/essts.rb', line 4

def total_table
  @total_table
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/ulla/essts.rb', line 4

def type
  @type
end

Instance Method Details

#[](index) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ulla/essts.rb', line 71

def [](index)
  case index
  when Integer
    @essts[index]
  when String
    @essts.find { |e| e.label == index }
  else
    $logger.error "#{index} is not available for indexing ESSTs"
    exit
  end
end

#colnamesObject



63
64
65
# File 'lib/ulla/essts.rb', line 63

def colnames
  @essts[0].colnames
end

#rownamesObject



67
68
69
# File 'lib/ulla/essts.rb', line 67

def rownames
  @essts[0].rownames
end