Module: TopPred::Parser
- Included in:
- Parser_Text, Parser_XML
- Defined in:
- lib/transmembrane/toppred.rb
Class Method Summary collapse
-
.filetype(file) ⇒ Object
returns :xml or :text.
-
.new(parser_type = :xml) ⇒ Object
type = :xml or :text.
Instance Method Summary collapse
-
#add_sequences_to_segments(segments, aaseq) ⇒ Object
where each segment = [prob, first, last] and aaseq is a string each segment may also be a hash => first, last, probability (adding key ‘aaseq’) first/last ‘1’ indexed returns segments where each is [prob, first, last, aaseq] or hash (above).
- #file_to_index(file, index = {}) ⇒ Object
Class Method Details
.filetype(file) ⇒ Object
returns :xml or :text
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/transmembrane/toppred.rb', line 61 def self.filetype(file) File.open(file) do |fh| case fh.gets when /<\?xml version.*>/ :xml when /Algorithm specific/ :text else nil end end end |
.new(parser_type = :xml) ⇒ Object
type = :xml or :text
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/transmembrane/toppred.rb', line 75 def self.new(parser_type=:xml) klass = case parser_type when :xml TopPred::Parser_XML when :text TopPred::Parser_Text else abort "don't recognize parser type: #{parser_type}" end klass.new end |
Instance Method Details
#add_sequences_to_segments(segments, aaseq) ⇒ Object
where each segment = [prob, first, last] and aaseq is a string each segment may also be a hash => first, last, probability (adding key ‘aaseq’) first/last ‘1’ indexed returns segments where each is [prob, first, last, aaseq] or hash (above)
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/transmembrane/toppred.rb', line 97 def add_sequences_to_segments(segments, aaseq) if segments.first.is_a? Array segments.each do |seg| first_index = seg[1] - 1 length = (seg[2] - seg[1]) + 1 seg.push( aaseq[first_index, length] ) end else segments.each do |seg| first_index = seg[:start] - 1 length = (seg[:stop] - seg[:start]) + 1 seg[:aaseq] = ( aaseq[first_index, length] ) end end segments end |
#file_to_index(file, index = {}) ⇒ Object
88 89 90 |
# File 'lib/transmembrane/toppred.rb', line 88 def file_to_index(file, index={}) File.open(file) {|fh| to_index(fh, index) } end |