Class: Bio::SignalP::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/appl/common.rb

Instance Method Summary collapse

Instance Method Details

#calculate(sequence, options = {}) ⇒ Object

Given an amino acid sequence, return a SignalP Result representing it taken from the file. The version of SignalP used is auto-detected (versions 3 and 4 are supported)

options: :binary_path: full path to signalp binary e.g. ‘/usr/local/bin/signalp-4.0/signalp’ [default: ‘signalp’ i.e. signalp is in the PATH]

Returns nil if the sequence is empty



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bio/appl/common.rb', line 19

def calculate(sequence, options={})
  return nil if sequence.nil? or sequence == ''
  
  default_options = {
    :binary_path => 'signalp'
  }
  options = default_options.merge options
  raise "Unexpected option parameters passed in #{options.inspect}" unless options.length == default_options.length
  options[:binary_path] ||= default_options[:binary_path] #in case nil is passed here
  
  # This command needs to work with all versions of SignalP (currently v3 and v4)
  command = "#{options[:binary_path]} -f short -t euk"
  log.debug "Running signalp command: #{command}" if log.debug?
  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.empty?
      raise Exception, "There appears to be a problem while running signalp:\n#{error}"
    end
    
    # Error checking
    num_expected_result_lines = 3
    unless result.length == num_expected_result_lines
      raise Exception, "Unexpected number of lines found in SignalP output (#{result.length}, expected #{num_expected_result_lines}):\n#{result}"
    end
    
    splits = result[2].strip.split(/[ \t]+/)
    if splits.length == NUM_FIELDS_IN_VERSION3_SHORT_OUTPUT
      # SignalP 3 detected, use that
      log.debug "Detected SignalP version 3 type output, parsing" if log.debug?
      return Bio::SignalP::Version3::Result.create_from_line(result[2].strip)
    elsif splits.length == NUM_FIELDS_IN_VERSION4_SHORT_OUTPUT
      log.debug "Detected SignalP version 4 type output, parsing" if log.debug?
      return Bio::SignalP::Version4::Result.create_from_line(result[2].strip)
    else
      error_description = "Bad SignalP output line found. Are you using SignalP 3.0 or 4.0? (found #{splits.length} fields in the third line of the output):\n#{result[2]}"
      log.error error_description
      raise Exception, error_description
    end
  end
end

#logObject



7
8
9
# File 'lib/bio/appl/common.rb', line 7

def log
  log = Bio::Log::LoggerPlus['bio-signalp']
end