Method: Phobius::ParserShort#to_index

Defined in:
lib/transmembrane/phobius.rb

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

returns a hash structure in this form: { identifier => { :num_certain_transmembrane_segments => Int, :transmembrane_segments => [:start => Int, :stop

> Int] }

can parse io even if there is no header to key in on.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/transmembrane/phobius.rb', line 94

def to_index(io, index={})
  init_pos = io.pos
  cnt = 0
  found_header = false
  loop do
    if io.gets =~ /SEQENCE/ 
      found_header = true
      break
    end
    cnt += 1
    break if cnt > 10
  end
  if !found_header
    io.pos = init_pos
  end
  current_record = nil
  io.each do |line|
    line.chomp!
    # grab values
    ar = line.split(/\s+/)
    next if ar.size != 4
    (key, num_tms, signal_peptide, prediction) = ar
    # cast the values
    num_tms = num_tms.to_i
    signal_peptide = 
      case signal_peptide
      when 'Y'
        true
      when '0'
        false
      end
    index[key] = { 
      :num_certain_transmembrane_segments => num_tms, 
      :signal_peptide => signal_peptide,
    }
    if num_tms > 0
      index[key][:transmembrane_segments] = prediction_to_array(prediction)
    end
  end
  index
end