class Bio::ExportPred::Wrapper

Public Instance Methods

calculate(sequence, options={}) click to toggle source

Use ExportPred called locally to predict whether a protein is exported or not. TODO: better doco here, explain options

# File lib/bio/appl/exportpred.rb, line 9
def calculate(sequence, options={})
  command = 'exportpred --input=-'
  #--no-RLE and -r seem to fail when running exportpred on the command line, so here I'll just set the thresholds very high instead
  command = "#{command} --KLD-threshold=99999" if options[:no_KLD]
  command = "#{command} --RLE-threshold=99999" if options[:no_RLE]
  
  Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
    stdin.puts '>wrapperSeq'
    stdin.puts "#{sequence}"
    stdin.close
    
    result = stdout.readlines
    error = stderr.readlines
    
    unless error.length == 1
      raise Exception, "There appears to be a problem while running ExportPred:\n#{error}"
    end
    parse_error = error[0].strip.match(/^(\d+) sequences read from stdin$/)
    unless parse_error[1].to_i == 1
      raise Exception, "There appears to be a problem while running ExportPred, unexpected output form: \n#{error}"
    end
    
    # Error checking
    unless [0,1].include?(result.length)
      raise Exception, "Unexpected number of lines found in ExportPred output (#{result.length}:\n#{result}"
    end
    
    return Result.create_from_line(result[0], options)
  end
end