Class: Phobius::ParserShort
- Includes:
- Parser
- Defined in:
- lib/transmembrane/phobius.rb
Instance Method Summary collapse
-
#prediction_to_array(string) ⇒ Object
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.
-
#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..
Methods included from Parser
Instance Method Details
#prediction_to_array(string) ⇒ Object
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
81 82 83 84 85 86 87 |
# 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 = {}) ⇒ 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 |