Permalink
Browse files

fixed the majority of error incorporating the code into a biogem (but…

… not yet bioruby) framework
  • Loading branch information...
1 parent 0a0a7b2 commit 3b59ad76b66c2673510d87af8829540a27c60e92 @wwood committed Mar 24, 2011
Showing with 16 additions and 20 deletions.
  1. +15 −20 lib/bio/appl/tmhmm/tmhmm_runner.rb
  2. +1 −0 test/test_transmembrane.rb
@@ -1,30 +1,25 @@
+require 'tempfile'
+
module Bio
class TMHMM
class TmHmmWrapper
# Given an amino acid sequence, return a TransmembraneProtein
# made up of the predicted transmembrane domains
def calculate(sequence)
- rio(:tempdir) do |d|
- FileUtils.cd(d.to_s) do
- Tempfile.open('tmhmmin') { |tempfilein|
- # Write a fasta to the tempfile
- tempfilein.puts '>wrapperSeq'
- tempfilein.puts "#{sequence}"
- tempfilein.close #required. Maybe because it doesn't flush otherwise?
-
- Tempfile.open('signalpout') {|out|
- result = system("tmhmm -short #{tempfilein.path} >#{out.path}")
-
- if !result
- raise Exception, "Running TMHMM program failed. See $? for details."
- end
-
-
- line = rio(out.path).readline
- return TmHmmResult.create_from_short_line(line)
- }
- }
+ Bio::Command.mktmpdir do |d|
+ line = nil
+ Bio::Command.call_command(['tmhmm','-short'], :chdir => d) do |io|
+ io.puts '>wrapperSeq'
+ io.puts sequence
+ io.close_write
+ line = io.readline
end
+
+ if line.nil?
+ raise Exception, "Error running locally installed TMHMM program 'tmhmm'. Is it properly installed?"
+ end
+
+ return TmHmmResult.create_from_short_line(line)
end
end
end
@@ -29,6 +29,7 @@ def test_sequence_offsets
end
class TransmembraneProteinTest < Test::Unit::TestCase
+ include Bio::Transmembrane
def test_simple
protein = TransmembraneProtein.new
tmd = TransmembraneDomainDefinition.new

0 comments on commit 3b59ad7

Please sign in to comment.