Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Split up prediction of KLD and RLE so they can be accessed, add testi…

…ng for actually running the program
  • Loading branch information...
commit 94d00b66a2c0402cffa03fae08a1dfe9148084ff 1 parent 5004980
Ben J Woodcroft authored
Showing with 47 additions and 15 deletions.
  1. +26 −9 lib/bio/appl/exportpred.rb
  2. +21 −6 test/test_bio-exportpred.rb
35 lib/bio/appl/exportpred.rb
View
@@ -3,8 +3,15 @@
module Bio
class ExportPred
class Wrapper
- def calculate(sequence)
+ # Use ExportPred called locally to predict whether a protein is exported or
+ # not.
+ # TODO: better doco here, explain options
+ 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}"
@@ -26,25 +33,29 @@ def calculate(sequence)
raise Exception, "Unexpected number of lines found in ExportPred output (#{result.length}:\n#{result}"
end
- return Result.create_from_line(result[0])
+ return Result.create_from_line(result[0], options)
end
end
end
class Result
@@all_result_names = [
- :predicted,
+ :predicted_rle,
+ :predicted_kld,
:score
]
@@all_result_names.each do |rn|
attr_accessor rn
end
-
+
# Given the STDOUT from the ExportPred program, create a programmatically manipulatable Bio::ExportPred::Result object
- def self.create_from_line(line)
+ #
+ # TODO: explain options={}
+ def self.create_from_line(line, options={})
result = Result.new
- if !line or line == '' #possible bug that scores below 2.3 don't work?
- result.predicted = false
+ if !line or line == ''
+ result.predicted_rle = false unless options[:no_RLE]
+ result.predicted_kld = false unless options[:no_KLD]
return result
end
@@ -52,15 +63,21 @@ def self.create_from_line(line)
# metoo RLE 6.44141 [a-met:M][a-leader:AVSTYNNTRRNGLRYVLKRR][a-hydrophobic:TILSVFAVICMLSL][a-spacer:NLSIFENNNNNYGFHCNKRH][a-RLE:FKSLAEA][a-tail:SPEEHNNLRSHSTSDPKKNEEKSLSDEINKCDMKKYTAEEINEMINSSNEFINRNDMNIIFSYVHESEREKFKKVEENIFKFIQSIVETYKIPDEYKMRKFKFAHFEMQGYALKQEKFLLEYAFLSLNGKLCERKKFKEVLEYVKREWIEFRKSMFDVWKEKLASEFREHGEMLNQKRKLKQHELDRRAQREKMLEEHSRGIFAKGYLGEVESETIKKKTEHHENVNEDNVEKPKLQQHKVQPPKVQQQKVQPPKSQQQKVQPPKSQQQKVQPPKVQQQKVQPPKVQKPKLQNQKGQKQVSPKAKGNNQAKPTKGNKLKKN]
splits = line.split("\t")
raise Exception, "Badly parsed line: #{line}" if splits.length != 4
- result.predicted = true
+ if splits[1] == 'RLE'
+ result.predicted_rle = true
+ elsif splits[1] = 'KLD'
+ result.predicted_kld = true
+ end
result.score = splits[2].to_f
return result
end
def predicted?
- @predicted
+ @predicted_rle or @predicted_kld
end
alias_method :signal?, :predicted?
+ alias_method :predicted_rle?, :predicted_rle
+ alias_method :predicted_kld?, :predicted_kld
def self.all_result_names
@@all_result_names
27 test/test_bio-exportpred.rb
View
@@ -1,10 +1,6 @@
require 'helper'
class TestBioExportpred < Test::Unit::TestCase
- def setup
- @exportpred = Bio::ExportPred::Wrapper.new
- end
-
def test_create_from_line
# test empty
line = ''
@@ -21,13 +17,32 @@ def test_create_from_line
assert_equal 6.44141, r.score
end
+ def test_create_from_line_options
+ # test empty
+ line = ''
+ r = Bio::ExportPred::Result.create_from_line(line, :no_RLE => true)
+ assert r
+ assert_kind_of Bio::ExportPred::Result, r
+ assert_equal false, r.predicted_kld
+ assert_equal nil, r.predicted_rle
+ end
+
def test_wrapper_positive
positive = 'MAVSTYNNTRRNGLRYVLKRRTILSVFAVICMLSLNLSIFENNNNNYGFHCNKRHFKSLAEASPEEHNNLRSHSTSDPKKNEEKSLSDEINKCDMKKYTAEEINEMINSSNEFINRNDMNIIFSYVHESEREKFKKVEENIFKFIQSIVETY'
- assert_equal true, @exportpred.calculate(positive).signal?
+ result = Bio::ExportPred::Wrapper.new.calculate(positive)
+ assert_equal true, result.signal?
+ assert result.predicted_rle?
end
def test_wrapper_negative
negative = 'MKILLLCIIFLYYVNAFKNTQKDGVSLQILKKKRSNQVNFLNRKNDYNLIKNKNPSSSLKSTFDDIKKIISKQLSVEEDKIQMNSNFTKDLGADSLDLVELIMALEEKFNVTISDQDALKINTVQDAIDYIEKNNKQ'
- assert_equal false, @exportpred.calculate(negative).signal?
+ assert_equal false, Bio::ExportPred::Wrapper.new.calculate(negative).signal?
+ end
+
+ def test_no_rle
+ positive = 'MAVSTYNNTRRNGLRYVLKRRTILSVFAVICMLSLNLSIFENNNNNYGFHCNKRHFKSLAEASPEEHNNLRSHSTSDPKKNEEKSLSDEINKCDMKKYTAEEINEMINSSNEFINRNDMNIIFSYVHESEREKFKKVEENIFKFIQSIVETY'
+ result = Bio::ExportPred::Wrapper.new.calculate(positive, :no_RLE => true)
+ assert_equal nil, result.predicted_rle?
+ assert_equal false, result.signal?
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.