Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

still not working, this is before removing rio from dependencies - it…

… seems to have problems working in Ruby 1.9.2
  • Loading branch information...
commit 0a0a7b22086b2e2fb5a20f4a2ebc2f17436a0748 1 parent 484900e
@wwood authored
View
1  Gemfile
@@ -2,6 +2,7 @@ source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"
+gem 'rio'
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
View
108 bin/tm_hmm_wrapper.rb
@@ -1,109 +1,7 @@
#!/usr/bin/env ruby
-$:.unshift File.join(File.dirname(__FILE__),'..','vendor/plugins/ben_bioinformatics/lib')
-
-require 'rubygems'
-require 'transmembrane'
-include Transmembrane
-require 'tempfile'
-gem 'rio'
-require 'rio'
-
-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)
- }
- }
- end
- end
- end
-end
-
-
-class TmHmmResult
- attr_reader :domains
-
- # initialise with the output line of a
- # eg.
- #PFF0290w len=293 ExpAA=145.77 First60=20.51 PredHel=7 Topology=o39-61i101-120o140-162i169-186o196-218i230-252o262-284i
- def self.create_from_short_line(line)
- protein = OrientedTransmembraneDomainProtein.new
-
- splits = line.strip.split("\t")
- if splits.length != 6
- raise Exception, "Incorrectly parsed short line from TMHMM: #{line}"
- end
-
- substrate = splits[5]
- if substrate.gsub!(/^Topology\=[io]/,'').nil?
- raise Exception, "Badly parsed Topology hit: #{substrate}"
- end
-
- matches = substrate.match('^(\d+?)\-')
- if !matches
- return protein #no transmembrane domains predicted
- end
-
- # eat the string from the beginning adding the transmembrane domains
- prev = matches[1]
- substrate.gsub!(/^(\d+?)-/,'')
- # match all the middle bits
- reg = /^(\d+?)([io])(\d+?)\-/
- while matches =substrate.match(reg)
- tmd = OrientedTransmembraneDomain.new
- tmd.start = prev.to_i
- tmd.stop = matches[1].to_i
- tmd.orientation = parse_orientation_from_last_location(matches[2])
- protein.push tmd
-
- prev = matches[3]
- substrate.gsub!(reg, '')
- end
- #match the last bit
- if !(matches = substrate.match('(\d+?)([io])$'))
- raise Exception, "Failed to parse the last bit of: #{substrate}"
- end
- tmd = OrientedTransmembraneDomain.new
- tmd.start = prev.to_i
- tmd.stop = matches[1].to_i
- tmd.orientation = parse_orientation_from_last_location(matches[2])
- protein.push tmd
-
- return protein
- end
-
- def self.parse_orientation_from_last_location(last_location)
- case last_location
- when 'i'
- return OrientedTransmembraneDomain::OUTSIDE_IN
- when 'o'
- return OrientedTransmembraneDomain::INSIDE_OUT
- else
- raise Exception, "Badly parsed topology hit due to orientation character: #{substrate}"
- end
- end
-end
-
+require 'bio'
+require 'bio-tm_hmm'
# If being run directly instead of being require'd,
# output one transmembrane per line, and
@@ -111,7 +9,7 @@ def self.parse_orientation_from_last_location(last_location)
if $0 == __FILE__
require 'bio'
- runner = TmHmmWrapper.new
+ runner = Bio::TMHMM::TmHmmWrapper.new
Bio::FlatFile.auto(ARGF).each do |seq|
result = runner.calculate(seq.seq)
View
5 lib/bio-tm_hmm.rb
@@ -1 +1,4 @@
-require 'lib/bio/transmembrane'
+# General transmembrane domain related data structures
+require 'bio/transmembrane'
+# TMHMM extras
+require 'bio/appl/tmhmm/tmhmm_runner'
View
96 lib/bio/appl/tmhmm/tmhmm_runner.rb
@@ -0,0 +1,96 @@
+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)
+ }
+ }
+ end
+ end
+ end
+ end
+
+ class TmHmmResult
+ attr_reader :domains
+
+ # initialise with the output line of a
+ # eg.
+ #PFF0290w len=293 ExpAA=145.77 First60=20.51 PredHel=7 Topology=o39-61i101-120o140-162i169-186o196-218i230-252o262-284i
+ def self.create_from_short_line(line)
+ protein = Bio::Transmembrane::OrientedTransmembraneDomainProtein.new
+
+ splits = line.strip.split("\t")
+ if splits.length != 6
+ raise Exception, "Incorrectly parsed short line from TMHMM: #{line}"
+ end
+
+ substrate = splits[5]
+ if substrate.gsub!(/^Topology\=[io]/,'').nil?
+ raise Exception, "Badly parsed Topology hit: #{substrate}"
+ end
+
+ matches = substrate.match('^(\d+?)\-')
+ if !matches
+ return protein #no transmembrane domains predicted
+ end
+
+ # eat the string from the beginning adding the transmembrane domains
+ prev = matches[1]
+ substrate.gsub!(/^(\d+?)-/,'')
+ # match all the middle bits
+ reg = /^(\d+?)([io])(\d+?)\-/
+ while matches =substrate.match(reg)
+ tmd = Bio::Transmembrane::OrientedTransmembraneDomain.new
+ tmd.start = prev.to_i
+ tmd.stop = matches[1].to_i
+ tmd.orientation = parse_orientation_from_last_location(matches[2])
+ protein.push tmd
+
+ prev = matches[3]
+ substrate.gsub!(reg, '')
+ end
+ #match the last bit
+ if !(matches = substrate.match('(\d+?)([io])$'))
+ raise Exception, "Failed to parse the last bit of: #{substrate}"
+ end
+ tmd = Bio::Transmembrane::OrientedTransmembraneDomain.new
+ tmd.start = prev.to_i
+ tmd.stop = matches[1].to_i
+ tmd.orientation = parse_orientation_from_last_location(matches[2])
+ protein.push tmd
+
+ return protein
+ end
+
+ def self.parse_orientation_from_last_location(last_location)
+ case last_location
+ when 'i'
+ return Bio::Transmembrane::OrientedTransmembraneDomain::OUTSIDE_IN
+ when 'o'
+ return Bio::Transmembrane::OrientedTransmembraneDomain::INSIDE_OUT
+ else
+ raise Exception, "Badly parsed topology hit due to orientation character: #{substrate}"
+ end
+ end
+ end
+ end
+end
View
5 lib/bio/transmembrane.rb
@@ -1,7 +1,4 @@
-# a simple class to represent a TMD
-
-require 'array_pair'
-
+# a simple class to represent a transmembrane domain, and a transmembrane domain containing protein
module Bio
module Transmembrane
class TransmembraneProtein
View
38 test/data/falciparum1.fa
@@ -0,0 +1,38 @@
+>Plasmodium_falciparum_3D7|MAL8|PF08_0142|Annotation|Plasmodium_falciparum_Sanger_Stanford_TIGR|(protein coding) erythrocyte membrane protein 1 (PfEMP1)
+MAAAGGGGKDKYKNAQDAKHLLDIIGEDIYKIANDAALKRSGSELKGLLSLAKFEKNPPD
+KQTPEDPCDLDYKYHTNVTSNVIEPCNKRSGKRFSEVSGAECANNRIKGNKGSNGDACAP
+FRRLHVCDRNLEQIDPAKITATHNLLVDVCQAAKFEGQSITQDYPKYLATYNDSPSQICT
+MLARSFADIGDIVRGKDLFRGYDDEEKNRRKKLEQKLKVIFGHIYEELKKHKKLKEEAEE
+RYKKDGDNYYKLREDWWALNRQEIWKAITCGHPGGTYFRQTACGGGTTPTPNKCRCATND
+VPTYFDYVPQYLRWFEEWAEDFCRKRKYKLENAIEKCRGKTKGEKYCDLNGFDCTQTASG
+EKKFVKGHNCHNCSVTCIPFGPWIDNQKKEFLKQRNKYQNEISSNSRKKRSTSNNNYKGY
+DEEFYKILKEDYGDVEQFLEKLSREGICQSQPTVGNQKADAANFTKDNPAKTFSH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DAIDCMINRLQDKIDKCKEKHPQPSAENQTTCDESTLVEDVDDY
+EEQNPENKVGKPAICGNVDTTEPVKEEDEEECKAAESPAEPEQAAEEESVPAAETKDTEN
+QPPQAPDVGPPPLAPAPADQPLDPTILQTTIPFGIAIALTSIVFLFLKKKTKSTIDLLRV
+INIPKSDYDIPTKLSPNRYIPYTSGKYRGKRYIYLEGDSGTDSGYTDHYSDITSSSESEY
+EELDINDIYVPRAPKYKTLIEVVLEPSGNNTTASGNNTTASDTQNDIQNDIPSDIPKTPS
+DTPPPITDDEWNQLKDEFISQYLQSEQPKDVPNDYSSGDIPLNTQPNTLYFDKPQEKPFI
+TSIHDRNLYSGEEYNYDMFNSGKNGPYSDKNDLYSGNHDSLSGNRDPTSANHDSYSGNHH
+PYSGIDLINDSISGNQHIDIYDELLKRKENELFGTNNPKRTSTYSVAKLTNSDPIHNQLE
+LFHTWLDRHRDMCEKWENHHERLAKLKEEWENETHSGNTHPSDSNKTLNTDVSIQIDMDH
+EKRMKEFTNMDTILEDLDKPFNEPYYYDMYDDDIYYDVNDHDTSTVDSNAMDVPSKVQIE
+MDVNTKLVKEKYPIGDVWDI
+
View
6 test/test_bio-tm_hmm.rb
@@ -1,7 +1,7 @@
require 'helper'
class TestBioTmHmm < Test::Unit::TestCase
- def test_something_for_real
- flunk "hey buddy, you should probably rename this file and start testing for real"
- end
+# def test_something_for_real
+# flunk "hey buddy, you should probably rename this file and start testing for real"
+# end
end
View
38 test/test_tm_hmm_wrapper.rb
@@ -1,73 +1,63 @@
-#
-# To change this template, choose Tools | Templates
-# and open the template in the editor.
-
-
-$:.unshift File.join(File.dirname(__FILE__),'..','lib')
-
-require 'test/unit'
-require 'tm_hmm_wrapper'
-require 'rubygems'
require 'bio'
-require 'transmembrane'
+require 'helper'
class TmHmmWrapperTest < Test::Unit::TestCase
- include Transmembrane
+ include Bio::Transmembrane
def test_parser
- result = TmHmmResult.create_from_short_line('PFA0635c len=555 ExpAA=0.00 First60=0.00 PredHel=0 Topology=o')
+ result = Bio::TMHMM::TmHmmResult.create_from_short_line('PFA0635c len=555 ExpAA=0.00 First60=0.00 PredHel=0 Topology=o')
assert result
assert_equal false, result.has_domain?
# test a single TMD
- result = TmHmmResult.create_from_short_line('PFA0685c len=324 ExpAA=20.36 First60=0.00 PredHel=1 Topology=o281-303i')
+ result = Bio::TMHMM::TmHmmResult.create_from_short_line('PFA0685c len=324 ExpAA=20.36 First60=0.00 PredHel=1 Topology=o281-303i')
assert result
assert_equal 1, result.transmembrane_domains.length
assert_equal 281, result.transmembrane_domains[0].start
assert_equal 303, result.transmembrane_domains[0].stop
- assert_equal OrientedTransmembraneDomain::OUTSIDE_IN,
+ assert_equal Bio::Transmembrane::OrientedTransmembraneDomain::OUTSIDE_IN,
result.transmembrane_domains[0].orientation
assert result.transmembrane_type_1?
assert_equal false, result.transmembrane_type_2?
# test 2 TMD
- result = TmHmmResult.create_from_short_line('PFA0680c len=209 ExpAA=43.03 First60=0.02 PredHel=2 Topology=i137-159o164-183i')
+ result = Bio::TMHMM::TmHmmResult.create_from_short_line('PFA0680c len=209 ExpAA=43.03 First60=0.02 PredHel=2 Topology=i137-159o164-183i')
assert result
assert_equal 2, result.transmembrane_domains.length
assert_equal 137, result.transmembrane_domains[0].start
assert_equal 159, result.transmembrane_domains[0].stop
- assert_equal OrientedTransmembraneDomain::INSIDE_OUT,
+ assert_equal Bio::Transmembrane::OrientedTransmembraneDomain::INSIDE_OUT,
result.transmembrane_domains[0].orientation
assert_equal 164, result.transmembrane_domains[1].start
assert_equal 183, result.transmembrane_domains[1].stop
- assert_equal OrientedTransmembraneDomain::OUTSIDE_IN,
+ assert_equal Bio::Transmembrane::OrientedTransmembraneDomain::OUTSIDE_IN,
result.transmembrane_domains[1].orientation
assert_equal false, result.transmembrane_type_1?
assert_equal false, result.transmembrane_type_2?
# test 3 TMD
- result = TmHmmResult.create_from_short_line('PFA0705c len=282 ExpAA=90.97 First60=22.20 PredHel=4 Topology=i22-44o185-207i212-234o259-281i')
+ result = Bio::TMHMM::TmHmmResult.create_from_short_line('PFA0705c len=282 ExpAA=90.97 First60=22.20 PredHel=4 Topology=i22-44o185-207i212-234o259-281i')
assert result
assert_equal 4, result.transmembrane_domains.length
assert_equal 22, result.transmembrane_domains[0].start
assert_equal 44, result.transmembrane_domains[0].stop
- assert_equal OrientedTransmembraneDomain::INSIDE_OUT,
+ assert_equal Bio::Transmembrane::OrientedTransmembraneDomain::INSIDE_OUT,
result.transmembrane_domains[0].orientation
assert_equal 185, result.transmembrane_domains[1].start
assert_equal 207, result.transmembrane_domains[1].stop
- assert_equal OrientedTransmembraneDomain::OUTSIDE_IN,
+ assert_equal Bio::Transmembrane::OrientedTransmembraneDomain::OUTSIDE_IN,
result.transmembrane_domains[1].orientation
assert_equal 259, result.transmembrane_domains[3].start
assert_equal 281, result.transmembrane_domains[3].stop
- assert_equal OrientedTransmembraneDomain::OUTSIDE_IN,
+ assert_equal Bio::Transmembrane::OrientedTransmembraneDomain::OUTSIDE_IN,
result.transmembrane_domains[3].orientation
assert_equal false, result.transmembrane_type_1?
assert_equal false, result.transmembrane_type_2?
end
def test_wrapper
- prog = TmHmmWrapper.new
- seq = Bio::FlatFile.auto('testFiles/falciparum1.fa').next_entry
+ prog = Bio::TMHMM::TmHmmWrapper.new
+ seq = Bio::FlatFile.auto(File.join(File.dirname(__FILE__),'data','falciparum1.fa')).next_entry
tmp = prog.calculate(seq.seq)
assert tmp
assert_equal false, tmp.has_domain?
View
2  test/test_transmembrane.rb
@@ -2,6 +2,8 @@
module Transmembrane
class TransmembraneTest < Test::Unit::TestCase
+ include Bio::Transmembrane
+
def test_confidenced_transmembrane_domain
one = ConfidencedTransmembraneDomain.new
two = ConfidencedTransmembraneDomain.new
Please sign in to comment.
Something went wrong with that request. Please try again.