Class: ODDB::Interaction::HayesWriter

Inherits:
NullWriter show all
Defined in:
src/plugin/hayes.rb,
test/test_plugin/hayes.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NullWriter

#new_linkhandler, #send_image, #send_meta

Constructor Details

- (HayesWriter) initialize

A new instance of HayesWriter



11
12
13
14
15
# File 'src/plugin/hayes.rb', line 11

def initialize
  @tablehandlers = []
  @substances = []
  @cytochromes = {}
end

Instance Attribute Details

- (Object) category (readonly)

Returns the value of attribute category



15
16
17
# File 'test/test_plugin/hayes.rb', line 15

def category
  @category
end

- (Object) current_substance

Returns the value of attribute current_substance



17
18
19
# File 'test/test_plugin/hayes.rb', line 17

def current_substance
  @current_substance
end

- (Object) cytochromes (readonly)

Returns the value of attribute cytochromes



15
16
17
# File 'test/test_plugin/hayes.rb', line 15

def cytochromes
  @cytochromes
end

- (Object) function

Returns the value of attribute function



16
17
18
# File 'test/test_plugin/hayes.rb', line 16

def function
  @function
end

- (Object) function_one

Returns the value of attribute function_one



16
17
18
# File 'test/test_plugin/hayes.rb', line 16

def function_one
  @function_one
end

- (Object) function_two

Returns the value of attribute function_two



16
17
18
# File 'test/test_plugin/hayes.rb', line 16

def function_two
  @function_two
end

- (Object) hr_function (readonly)

Returns the value of attribute hr_function



18
19
20
# File 'test/test_plugin/hayes.rb', line 18

def hr_function
  @hr_function
end

- (Object) hr_row (readonly)

Returns the value of attribute hr_row



18
19
20
# File 'test/test_plugin/hayes.rb', line 18

def hr_row
  @hr_row
end

- (Object) hs_cyts (readonly)

Returns the value of attribute hs_cyts



19
20
21
# File 'test/test_plugin/hayes.rb', line 19

def hs_cyts
  @hs_cyts
end

- (Object) hs_substance (readonly)

Returns the value of attribute hs_substance



19
20
21
# File 'test/test_plugin/hayes.rb', line 19

def hs_substance
  @hs_substance
end

- (Object) substances (readonly)

Returns the value of attribute substances



15
16
17
# File 'test/test_plugin/hayes.rb', line 15

def substances
  @substances
end

Instance Method Details

- (Object) check_cytochrome(cyt)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'src/plugin/hayes.rb', line 16

def check_cytochrome(cyt)
  cytochromes = []
=begin
  if(cyt.match(/-/))
    arr = cyt.split("-")
    start = arr.first[-1,1].to_i
    stop = arr.last.to_i
    (start..stop).each { |digit|
      cytochromes.push(arr.first.chop << digit.to_s)
    }
  else
    cytochromes.push(cyt)
  end
=end


  cytochromes.push(cyt)
  cytochromes
end

- (Object) check_string(string)



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'src/plugin/hayes.rb', line 33

def check_string(string)
  case string
  when "^\302\240$"
    return false
  when [] 
    return false
  when ""
    return false
  when nil
    return false
  else
    return true
  end
end

- (Object) create_connection(name, function)



47
48
49
50
51
52
53
54
55
56
57
# File 'src/plugin/hayes.rb', line 47

def create_connection(name, function)
  case function
  when 'substrate'
    new_class = ODDB::Interaction::SubstrateConnection
  when 'inhibits'
    new_class = ODDB::Interaction::InhibitorConnection
  when 'induces'
    new_class = ODDB::Interaction::InducerConnection
  end
  new_class.new(name, 'en')
end

- (Object) extract_data



58
59
60
61
# File 'src/plugin/hayes.rb', line 58

def extract_data
  parse_substances
  @cytochromes
end

- (Object) handle_cytochrome(cytochrome_arr, conn)



62
63
64
65
66
67
68
69
# File 'src/plugin/hayes.rb', line 62

def handle_cytochrome(cytochrome_arr, conn)
  cytochrome_arr.each { |cytochrome|
    unless(@cytochromes.has_key?(cytochrome))
      @cytochromes.store(cytochrome, ODDB::Interaction::Cytochrome.new(cytochrome))
    end
    @cytochromes[cytochrome].add_connection(conn)
  }
end

- (Object) handle_functions(row_one, row_two)



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'src/plugin/hayes.rb', line 70

def handle_functions(row_one, row_two)
  cyts = []
  if(check_string(row_one))
    if(@function)
      cyts.push(handle_row(row_one, @function))
    elsif(@function_one)
      cyts.push(handle_row(row_one, @function_one))
    end
  end
  if(check_string(row_two))
    cyts.push(handle_row(row_two, @function_two))
  end
  handle_substance(@current_substance, cyts)
end

- (Object) handle_row(row, function)



84
85
86
87
88
89
90
91
92
93
94
# File 'src/plugin/hayes.rb', line 84

def handle_row(row, function)
  cyts = {}
  if(row.is_a?(Array))
    row.each { |rw|
      cyts.store(rw,function)   
    }
  else
    cyts.store(row, function)
  end
  cyts
end

- (Object) handle_substance(substance, cytochromes)



95
96
97
98
99
100
101
102
# File 'src/plugin/hayes.rb', line 95

def handle_substance(substance, cytochromes)
  cytochromes.each { |hsh|
    hsh.each { |cyt, function|
      conn = create_connection(substance, function)
      handle_cytochrome(check_cytochrome(cyt), conn)
    }
  }
end

- (Object) new_fonthandler(handler)



103
104
105
106
107
108
109
110
111
# File 'src/plugin/hayes.rb', line 103

def new_fonthandler(handler)
  if(handler!=nil \
    && (handler.attribute('color')=='Blue' \
    || handler.attribute('color')=='#000080'))
     @category = "start"
   else
     @category = nil 
  end
end

- (Object) new_tablehandler(handler)



112
113
114
115
# File 'src/plugin/hayes.rb', line 112

def new_tablehandler(handler)
  @current_tablehandler = handler
  @tablehandlers.push(handler)
end

- (Object) parse_substances



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'src/plugin/hayes.rb', line 116

def parse_substances
  @parsing = nil
  @tablehandlers.each { |th|
    unless(th.nil?)
      th.each_row { |row|
        if(!row.cdata(0).is_a?(Array) \
          && @parsing=="start" \
          && check_string(row.cdata(0)))
          @current_substance = row.cdata(0)
          handle_functions(row.cdata(1), row.cdata(2))
        elsif(@parsing=="start")
          handle_functions(row.cdata(1), row.cdata(2))
        end
        unless(@function_set)
          if(!row.cdata(0).is_a?(Array) \
            && row.cdata(0).match(/>>>>/u))
            if(row.cdata(0).match(/Substrate/u))
              arr = row.cdata(0).split(/>>>>/u)
              @function = arr.first.downcase
            elsif(row.cdata(0).match(/DRUG/u))
              arr_one = row.cdata(1).split(/>>>>/u)
              arr_two = row.cdata(2).split(/>>>>/u)
              @function_one = arr_one.first.downcase
              @function_two = arr_two.first.downcase
            end
            @function_set = true
            @parsing = "start"
          end
        end
      }
    end
  }
end

- (Object) send_flowing_data(data)



149
150
151
152
153
154
155
156
157
# File 'src/plugin/hayes.rb', line 149

def send_flowing_data(data) 
  unless(@current_tablehandler.nil?)
    if(@category=="start")
      @current_tablehandler.send_cdata(data << ">>>>")
    else
      @current_tablehandler.send_cdata(data)
    end
  end
end

- (Object) send_line_break



158
159
160
161
162
# File 'src/plugin/hayes.rb', line 158

def send_line_break
  unless(@current_tablehandler.nil?)
    @current_tablehandler.next_line
  end
end