class Phobius::ParserShort

Public Instance Methods

prediction_to_array(string) click to toggle source

takes a phobius prediction string (e.g., i12-31o37-56i63-84o96-116i123-143o149-169i) and returns an array of hashes with the keys :start and :stop

# File lib/transmembrane/phobius.rb, line 81
def prediction_to_array(string)
  segments = []
  string.scan(/[io](\d+)-(\d+)/) do |m1, m2|
    segments << { :start => m1.to_i, :stop => m2.to_i }
  end
  segments
end
to_index(io, index={}) click to toggle source

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.

# 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