rraxml 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.8.3"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.3)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.6.6)
11
+ rake (0.9.2.2)
12
+ rcov (1.0.0)
13
+ rdoc (3.12)
14
+ json (~> 1.4)
15
+ shoulda (3.0.1)
16
+ shoulda-context (~> 1.0.0)
17
+ shoulda-matchers (~> 1.0.0)
18
+ shoulda-context (1.0.0)
19
+ shoulda-matchers (1.0.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ jeweler (~> 1.8.3)
27
+ rcov
28
+ rdoc (~> 3.12)
29
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Fernando Izquierdo-Carrasco
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = rraxml
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to rraxml
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Fernando Izquierdo-Carrasco. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rraxml"
18
+ gem.homepage = "http://github.com/fizquierdo/rraxml"
19
+ gem.license = "MIT"
20
+ gem.summary = "RAxML wrappers for ruby"
21
+ gem.description = "desc"
22
+ gem.email = "fer.izquierdo@gmail.com"
23
+ gem.authors = ["Fernando Izquierdo-Carrasco"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "rraxml #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/rraxml.rb ADDED
@@ -0,0 +1,196 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rphylip'
3
+ require 'rnewick'
4
+ require 'fileutils'
5
+
6
+ def binary_available(name)
7
+ available = false
8
+ ENV['PATH'].split(':').each do |folder|
9
+ available = true if File.exists?(File.join folder, name)
10
+ end
11
+ available
12
+ end
13
+
14
+ class Raxml
15
+ attr_reader :stdout, :stderr, :infofile, :name, :outdir, :phylip, :binary, :ops
16
+ def initialize(opts)
17
+ raise "No alignment in #{opts[:phylip]}" if opts[:phylip].nil? or not File.exist?(opts[:phylip])
18
+ @phylip = opts[:phylip]
19
+ @name = opts[:name] || "RUN_NAME"
20
+ @seed = opts[:seed] || "12345"
21
+ @outdir = opts[:outdir] || "test/outdir/#{@name}"
22
+ @stderr = opts[:stderr] || File.join(@outdir, 'stderr')
23
+ @stdout = opts[:stdout] || File.join(@outdir, 'stdout')
24
+ @binary = ""
25
+ @flags = opts[:flags] || ""
26
+ @ops = "-s #{@phylip} -n #{@name} #{@flags}"
27
+ end
28
+ def before_run
29
+ FileUtils.mkdir_p @outdir unless File.exist?(@outdir)
30
+ self.complete_call
31
+ end
32
+ def after_run
33
+ @infofile = File.join Dir.pwd, "RAxML_info.#{@name}"
34
+ @outfiles = [@stdout, @stderr, @infofile]
35
+ self.gather_outfiles
36
+ @outfiles.each do |f|
37
+ unless f.nil? or not File.exist?(f)
38
+ FileUtils.move(f, @outdir) unless File.join(@outdir, File.basename(f)) == f
39
+ end
40
+ end
41
+ end
42
+ def run
43
+ self.before_run
44
+ raise "#{@binary} not found" unless binary_available(@binary)
45
+ puts "#{@binary} #{@ops} "
46
+ system "(#{@binary} #{@ops} 2> #{@stderr}) > #{@stdout}"
47
+ self.after_run
48
+ end
49
+ end
50
+
51
+ module TreeCheck
52
+ def check_fulltree
53
+ newick_taxa = NewickFile.new(@starting_newick).newickStrings[0].numtaxa
54
+ alignment_taxa = Phylip.new(@phylip).numtaxa
55
+ if alignment_taxa != newick_taxa
56
+ raise "Tree #{@starting_newick} includes #{newick_taxa} taxa, #{alignment_taxa} expected"
57
+ end
58
+ end
59
+ def check_correctAlignment
60
+ rexec = RaxmlAlignmentChecker.new(:phylip => @phylip)
61
+ rexec.run
62
+ lastline = File.open(rexec.stdout).readlines.last.chomp.strip
63
+ if lastline != "Alignment format can be read by RAxML"
64
+ raise "File #{@phylip} does not seem to be a correct alignment"
65
+ ret = false
66
+ else
67
+ FileUtils.rm_rf rexec.outdir
68
+ ret = true
69
+ end
70
+ end
71
+ end
72
+ class Parsimonator < Raxml
73
+ include TreeCheck
74
+ attr_reader :seed, :num_trees, :newick
75
+ def initialize(opts)
76
+ super(opts)
77
+ check_correctAlignment
78
+ @num_trees = opts[:num_trees] || 1
79
+ @newick = opts[:newick] || ""
80
+ @binary = 'parsimonator-SSE3'
81
+ end
82
+ def complete_call
83
+ @ops += " -N #{@num_trees} -p #{@seed}"
84
+ unless @newick.empty? then
85
+ raise "No newick starting tree?" unless File.exists?(@newick)
86
+ @ops += " -t #{@newick}"
87
+ end
88
+ end
89
+ def gather_outfiles
90
+ @num_trees.times{|i| @outfiles << "RAxML_parsimonyTree.#{name}.#{i}"}
91
+ end
92
+ end
93
+ class RaxmlLight < Raxml
94
+ include TreeCheck
95
+ attr_reader :starting_newick
96
+ def initialize(opts)
97
+ super(opts)
98
+ check_correctAlignment
99
+ if opts[:starting_newick].nil? or not File.exists?(opts[:starting_newick])
100
+ raise "Raxml Light requires a starting tree"
101
+ end
102
+ @starting_newick = opts[:starting_newick]
103
+ check_fulltree # makes sure the tree is comprenhensive in relation to the phylip file
104
+ #@name = @starting_newick.split(".").last
105
+ if opts[:num_threads].nil?
106
+ @binary = 'raxmlLight'
107
+ @num_threads = 0
108
+ else
109
+ @binary = 'raxmlLight-PTHREADS'
110
+ @num_threads = opts[:num_threads].to_i
111
+ end
112
+ end
113
+ def complete_call
114
+ @ops += " -m GTRCAT -t #{@starting_newick} "
115
+ @ops += " -T #{@num_threads} " if @num_threads > 0
116
+ end
117
+ def resultfilename
118
+ "RAxML_result.#{@name}"
119
+ end
120
+ def logfilename
121
+ "RAxML_log.#{@name}"
122
+ end
123
+ def gather_outfiles
124
+ @outfiles += [self.resultfilename, self.logfilename]
125
+ Dir.entries(Dir.pwd).select{|f| f=~ /^RAxML_binaryCheckpoint.#{@name}_/}.each{ |f| @outfiles << f}
126
+ @outfiles
127
+ end
128
+ end
129
+ class GammaScorer < Raxml
130
+ #TODO no tests for the gamma scorer class :(
131
+ include TreeCheck
132
+ def initialize(opts)
133
+ super(opts)
134
+ check_correctAlignment
135
+ if opts[:starting_newick].nil? or not File.exists?(opts[:starting_newick])
136
+ raise "Scorer requires a starting bunch of trees to score"
137
+ end
138
+ @starting_newick = opts[:starting_newick]
139
+ check_fulltree # makes sure the tree is comprenhensive in relation to the phylip file
140
+ if opts[:num_threads].nil?
141
+ @binary = 'raxmlHPC-SSE3'
142
+ @num_threads = 0
143
+ else
144
+ @binary = 'raxmlHPC-PTHREADS-SSE3'
145
+ @num_threads = opts[:num_threads].to_i
146
+ end
147
+ end
148
+ def complete_call
149
+ @ops += " -m GTRGAMMA -z #{@starting_newick} -f n"
150
+ @ops += " -T #{@num_threads} " if @num_threads > 0
151
+ end
152
+ def gather_outfiles
153
+ @outfiles += ["RAxML_result.#{@name}"]
154
+ end
155
+ end
156
+ class RaxmlAlignmentChecker < Raxml
157
+ def initialize(phylipfile)
158
+ super(phylipfile)
159
+ @binary = 'raxmlHPC-SSE3'
160
+ end
161
+ def complete_call
162
+ @ops += " -m GTRCAT -f c"
163
+ end
164
+ def gather_outfiles
165
+ end
166
+ end
167
+
168
+ class RaxmlGammaSearch < Raxml
169
+ #TODO no tests for the gamma search class :(
170
+ include TreeCheck
171
+ def initialize(opts)
172
+ super(opts)
173
+ check_correctAlignment
174
+ @num_trees = opts[:num_gamma_trees]
175
+ if opts[:num_threads].nil?
176
+ @binary = 'raxmlHPC-SSE3'
177
+ @num_threads = 0
178
+ else
179
+ @binary = 'raxmlHPC-PTHREADS-SSE3'
180
+ @num_threads = opts[:num_threads].to_i
181
+ end
182
+ end
183
+ def complete_call
184
+ @ops += " -m GTRCAT -p #{@seed} -N #{@num_trees}"
185
+ @ops += " -T #{@num_threads} " if @num_threads > 0
186
+ end
187
+ def gather_outfiles
188
+ @outfiles += ["RAxML_bestTree.#{@name}"]
189
+ other_files = ["result", "log", "parsimonyTree"]
190
+ if @num_trees > 1
191
+ @num_trees.times{|num| @outfiles += other_files.map{|n| "RAxML_" + n + ".#{@name}.RUN.#{num.to_s}"} }
192
+ else
193
+ @outfiles += other_files.map{|n| "RAxML_" + n + ".#{@name}"}
194
+ end
195
+ end
196
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'rraxml'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRraxml < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rraxml
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Fernando Izquierdo-Carrasco
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-27 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :development
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ version_requirements: *id001
32
+ name: shoulda
33
+ prerelease: false
34
+ - !ruby/object:Gem::Dependency
35
+ type: :development
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ hash: 31
42
+ segments:
43
+ - 3
44
+ - 12
45
+ version: "3.12"
46
+ version_requirements: *id002
47
+ name: rdoc
48
+ prerelease: false
49
+ - !ruby/object:Gem::Dependency
50
+ type: :development
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ hash: 23
57
+ segments:
58
+ - 1
59
+ - 0
60
+ - 0
61
+ version: 1.0.0
62
+ version_requirements: *id003
63
+ name: bundler
64
+ prerelease: false
65
+ - !ruby/object:Gem::Dependency
66
+ type: :development
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ hash: 49
73
+ segments:
74
+ - 1
75
+ - 8
76
+ - 3
77
+ version: 1.8.3
78
+ version_requirements: *id004
79
+ name: jeweler
80
+ prerelease: false
81
+ - !ruby/object:Gem::Dependency
82
+ type: :development
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ version_requirements: *id005
93
+ name: rcov
94
+ prerelease: false
95
+ description: desc
96
+ email: fer.izquierdo@gmail.com
97
+ executables: []
98
+
99
+ extensions: []
100
+
101
+ extra_rdoc_files:
102
+ - LICENSE.txt
103
+ - README.rdoc
104
+ files:
105
+ - .document
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.rdoc
110
+ - Rakefile
111
+ - VERSION
112
+ - lib/rraxml.rb
113
+ - test/helper.rb
114
+ - test/test_rraxml.rb
115
+ homepage: http://github.com/fizquierdo/rraxml
116
+ licenses:
117
+ - MIT
118
+ post_install_message:
119
+ rdoc_options: []
120
+
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ requirements: []
142
+
143
+ rubyforge_project:
144
+ rubygems_version: 1.8.6
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: RAxML wrappers for ruby
148
+ test_files: []
149
+