Class: TopPred::Parser_XML::DOM

Inherits:
Object
  • Object
show all
Includes:
TopPred::Parser_XML, XMLStyleParser
Defined in:
lib/transmembrane/toppred.rb

Direct Known Subclasses

AXML, LibXML

Instance Method Summary collapse

Methods included from TopPred::Parser_XML

new, #parse

Methods included from TopPred::Parser

#add_sequences_to_segments, #file_to_index, filetype, new

Instance Method Details

#to_index(io, index = {}) ⇒ Object

should return a index



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/transmembrane/toppred.rb', line 152

def to_index(io, index = {})
  get_root_node_from_io(io) do |toppreds_n|

    abort if toppreds_n.name != 'toppreds'
    toppreds_n.find('child::toppred').each do |toppred_n|
      att_hash = {}
      sequence_n = toppred_n.find_first('child::sequence')
      index[sequence_n['id']] = att_hash
      att_hash[:aaseq] = sequence_n.content.gsub(/[\s\n]/,'')
      abort if att_hash[:aaseq].size != sequence_n['size'].to_i
      tmsummary_n = sequence_n.find_first('following-sibling::tmsummary')

      num_found = tmsummary_n['segments'].to_i
      att_hash[:num_found] = num_found
      if num_found > 0

        num_certain_transmembrane_segments = 0
        num_putative_transmembrane_segments = 0
        tmsummary_n.find('child::segment').each do |segment_n|
          abort if segment_n.name != 'segment'
          case segment_n['type']
          when 'certain'
            num_certain_transmembrane_segments += 1
          else # putative
            num_putative_transmembrane_segments += 1
          end
        end
        att_hash[:num_putative_transmembrane_segments] = num_putative_transmembrane_segments
        att_hash[:num_certain_transmembrane_segments] = num_certain_transmembrane_segments

        topologies_n = tmsummary_n.next
        abort if topologies_n.name != 'topologies'
        # get the top probability topology:
        top_prob_topology_n = topologies_n.find('child::topology').to_a.max {|a,b| a['prob'].to_f <=> b['prob'].to_f }
        tmsegments = []
        top_prob_topology_n.find('child::tmsegment').each do |tmsegment_n|
          tmhash = {}
          tmhash[:start] = tmsegment_n['start'].to_i
          tmhash[:stop] = tmsegment_n['stop'].to_i
          ## WARNING! it appears the probability is broken on xml output!!
          tmhash[:probability] = tmsegment_n['prob'].to_f
          tmsegments << tmhash
        end
        add_sequences_to_segments(tmsegments, att_hash[:aaseq])
        att_hash[:transmembrane_segments] = tmsegments
      end
    end
  end
  index
end