Permalink
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...
1 parent 5004980 commit 94d00b66a2c0402cffa03fae08a1dfe9148084ff Ben J Woodcroft committed Jan 20, 2012
Showing with 47 additions and 15 deletions.
  1. +26 −9 lib/bio/appl/exportpred.rb
  2. +21 −6 test/test_bio-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,41 +33,51 @@ 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
# line is going to be something like
# 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
@@ -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

0 comments on commit 94d00b6

Please sign in to comment.