module TopPred::Parser

Public Class Methods

filetype(file) click to toggle source

returns :xml or :text

# 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) click to toggle source

type = :xml or :text

# 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

Public Instance Methods

add_sequences_to_segments(segments, aaseq) click to toggle source

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 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={}) click to toggle source
# File lib/transmembrane/toppred.rb, line 88
def file_to_index(file, index={})
  File.open(file) {|fh| to_index(fh, index) }
end