semin-ulla 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ module Ulla
2
+ class Environment
3
+
4
+ attr_accessor :amino_acids,
5
+ :number,
6
+ :label,
7
+ :freq_array,
8
+ :prob_array,
9
+ :logo_array,
10
+ :smooth_prob_array
11
+
12
+ def initialize(number, label, amino_acids = "ACDEFGHIKLMNPQRSTVWYJ".split(''))
13
+ @amino_acids = amino_acids
14
+ @number = number
15
+ @label = label
16
+ @freq_array = $noweight ? NArray.int(@amino_acids.size) : NArray.float(@amino_acids.size)
17
+ @prob_array = NArray.float(@amino_acids.size)
18
+ @logo_array = NArray.float(@amino_acids.size)
19
+ @smooth_prob_array = NArray.float(@amino_acids.size)
20
+ end
21
+
22
+ def increase_residue_count(a, inc = 1.0)
23
+ @freq_array[@amino_acids.index(a.upcase)] += inc
24
+ end
25
+
26
+ def label_set
27
+ label.split("").map_with_index { |l, i| "#{i}#{l}" }.to_set
28
+ end
29
+
30
+ def to_s
31
+ "#{number}-#{label}"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,20 @@
1
+ module Ulla
2
+ class EnvironmentClassHash < Hash
3
+
4
+ def group_by_non_residue_labels
5
+ self.values.group_by { |env| env.label[1..-1] }
6
+ end
7
+
8
+ def groups_sorted_by_residue_labels
9
+ group_by_non_residue_labels.to_a.sort_by { |env_group|
10
+ env_group[0].split('').map_with_index { |l, i|
11
+ $env_features[i + 1].labels.index(l)
12
+ }
13
+ }
14
+ end
15
+
16
+ def group_size
17
+ group_by_non_residue_labels.size
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ module Ulla
2
+ class EnvironmentFeature
3
+
4
+ attr_accessor :name, :symbols, :labels, :constrained, :silent
5
+
6
+ def initialize(name, symbols, labels, constrained, silent)
7
+ @name = name
8
+ @symbols = symbols
9
+ @labels = labels
10
+ @constrained = constrained
11
+ @silent = silent
12
+ end
13
+
14
+ def to_s
15
+ [name, symbols.join, labels.join, constrained, silent].join(";")
16
+ end
17
+
18
+ def constrained?
19
+ constrained == "T"
20
+ end
21
+
22
+ def silent?
23
+ silent == "T"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module Ulla
2
+ class EnvironmentFeatureArray < Array
3
+
4
+ def label_combinations
5
+ self.inject([]) { |sum, ec|
6
+ sum << ec.labels
7
+ }.inject { |pro, lb|
8
+ pro.product(lb)
9
+ }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,111 @@
1
+ require 'rubygems'
2
+ require 'facets'
3
+
4
+ begin
5
+ require 'RMagick'
6
+ include Magick
7
+ rescue
8
+ $logger.warn "A RubyGems package, 'rmagick' is not found, so heat maps cannot be generated."
9
+ $no_rmagick = true
10
+ end
11
+
12
+
13
+
14
+ module Ulla
15
+ class HeatmapArray < Array
16
+
17
+ def heatmap(options = {})
18
+ if $no_rmagick
19
+ return nil
20
+ end
21
+
22
+ opts = {:columns => 4,
23
+ :rvg_width => nil,
24
+ :dpi => 100,
25
+ :title => '',
26
+ :max_val => nil,
27
+ :mid_val => nil,
28
+ :min_val => nil,
29
+ :print_gradient => true,
30
+ :gradient_beg_color => '#FFFFFF',
31
+ :gradient_mid_color => nil,
32
+ :gradient_end_color => '#FF0000',
33
+ :gradient_border_width => 1,
34
+ :gradient_border_color => '#000000'}.merge(options)
35
+
36
+ row_images = ImageList.new
37
+
38
+ self.each_by(opts[:columns]) { |maps|
39
+ images = ImageList.new
40
+ maps.each { |m| images << m }
41
+ row_images << images.append(false)
42
+ }
43
+
44
+ tbl_img = row_images.append(true)
45
+
46
+ unless opts[:print_gradient]
47
+ return tbl_img
48
+ else
49
+ RVG::dpi = opts[:dpi]
50
+ rvg_width = opts[:rvg_width] * opts[:columns]
51
+ rvg_height = rvg_width / 10.0
52
+
53
+ rvg = RVG.new(rvg_width, rvg_height) do |canvas|
54
+ canvas.viewbox(0, 0, rvg_width, rvg_height)
55
+ canvas.background_fill = 'white'
56
+ canvas.desc = 'gradient key'
57
+
58
+ gradient_width = rvg_width / 2.0
59
+ gradient_height = gradient_width / 15.0
60
+
61
+ if opts[:gradient_mid_color]
62
+ img1 = Image.new(gradient_width / 2,
63
+ gradient_height,
64
+ GradientFill.new(0, 0, 0, gradient_width / 2,
65
+ opts[:gradient_beg_color], opts[:gradient_mid_color]))
66
+
67
+ img2 = Image.new(gradient_width / 2,
68
+ gradient_height,
69
+ GradientFill.new(0, 0, 0, gradient_width / 2,
70
+ opts[:gradient_mid_color], opts[:gradient_end_color]))
71
+
72
+ img3 = ImageList.new
73
+ img3 << img1 << img2
74
+ img = img3.append(false)
75
+ else
76
+ img = Image.new(gradient_width,
77
+ gradient_height,
78
+ GradientFill.new(0, 0, 0, gradient_width,
79
+ opts[:gradient_beg_color], opts[:gradient_end_color]))
80
+ end
81
+
82
+ img.border!(opts[:gradient_border_width],
83
+ opts[:gradient_border_width],
84
+ opts[:gradient_border_color])
85
+
86
+ gradient_x = (rvg_width - gradient_width) / 2.0
87
+ gradient_y = (rvg_height - gradient_height) / 2.0
88
+ gradient_font_size = rvg_width / 45.0
89
+
90
+ canvas.image(img,
91
+ gradient_width,
92
+ gradient_height,
93
+ gradient_x,
94
+ gradient_y)
95
+
96
+ canvas.text(gradient_x,
97
+ gradient_y + gradient_height + gradient_font_size * 1.1,
98
+ "#{'%.1f' % opts[:min_val]}").styles(:font_size => gradient_font_size)
99
+
100
+ canvas.text(gradient_x + gradient_width,
101
+ gradient_y + gradient_height + gradient_font_size * 1.1,
102
+ "#{'%.1f' % opts[:max_val]}").styles(:font_size => gradient_font_size)
103
+ end
104
+
105
+ fin_img = ImageList.new
106
+ fin_img << tbl_img << rvg.draw
107
+ fin_img.append(true)
108
+ end
109
+ end
110
+ end
111
+ end
data/lib/ulla.rb ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Ulla
5
+ VERSION = '0.9.3'
6
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/egor.rb'}"
9
+ puts "Loading egor gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.dirname(__FILE__) + "/../Rakefile"
4
+ require 'rubyforge'
5
+ require 'redcloth'
6
+ require 'syntax/convertors/html'
7
+ require 'erb'
8
+
9
+ download = "http://rubyforge.org/projects/#{$hoe.rubyforge_name}"
10
+ version = $hoe.version
11
+
12
+ def rubyforge_project_id
13
+ RubyForge.new.configure.autoconfig["group_ids"][$hoe.rubyforge_name]
14
+ end
15
+
16
+ class Fixnum
17
+ def ordinal
18
+ # teens
19
+ return 'th' if (10..19).include?(self % 100)
20
+ # others
21
+ case self % 10
22
+ when 1: return 'st'
23
+ when 2: return 'nd'
24
+ when 3: return 'rd'
25
+ else return 'th'
26
+ end
27
+ end
28
+ end
29
+
30
+ class Time
31
+ def pretty
32
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
33
+ end
34
+ end
35
+
36
+ def convert_syntax(syntax, source)
37
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
38
+ end
39
+
40
+ if ARGV.length >= 1
41
+ src, template = ARGV
42
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
43
+ else
44
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
45
+ exit!
46
+ end
47
+
48
+ template = ERB.new(File.open(template).read)
49
+
50
+ title = nil
51
+ body = nil
52
+ File.open(src) do |fsrc|
53
+ title_text = fsrc.readline
54
+ body_text_template = fsrc.read
55
+ body_text = ERB.new(body_text_template).result(binding)
56
+ syntax_items = []
57
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
58
+ ident = syntax_items.length
59
+ element, syntax, source = $1, $2, $3
60
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
61
+ "syntax-temp-#{ident}"
62
+ }
63
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
64
+ body = RedCloth.new(body_text).to_html
65
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
66
+ end
67
+ stat = File.stat(src)
68
+ created = stat.ctime
69
+ modified = stat.mtime
70
+
71
+ $stdout << template.result(binding)
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/ulla'
@@ -0,0 +1,11 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require 'test/unit'
4
+ require 'math_extensions'
5
+
6
+ class TestMathExtensions < Test::Unit::TestCase
7
+
8
+ def test_log2
9
+ assert_equal(1, Math::log2(2))
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require "test/unit"
4
+ require "narray_extensions"
5
+
6
+ class TestArrayExtensions < Test::Unit::TestCase
7
+
8
+ def test_pretty_string(opts={})
9
+ m = NArray.float(3).indgen
10
+ result ="# A B C\n" +
11
+ "VAL 0.00 1.00 2.00"
12
+ assert_equal(result, m.pretty_string(:col_header => %w[A B C], :row_header => 'VAL'))
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require "test/unit"
4
+ require "nmatrix_extensions"
5
+
6
+ class TestNmatrixExtensions < Test::Unit::TestCase
7
+
8
+ def test_pretty_string(opts={})
9
+ m = NMatrix.float(3,3).indgen
10
+ result ="# A B C\n" +
11
+ "VAL 0.00 1.00 2.00\n" +
12
+ " 3.00 4.00 5.00\n" +
13
+ " 6.00 7.00 8.00"
14
+ assert_equal(result, m.pretty_string(:col_header => %w[A B C], :row_header => %w[VAL]))
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require "test/unit"
4
+ require "string_extensions"
5
+
6
+ class TestStringExtensions < Test::Unit::TestCase
7
+
8
+ def test_remove_internal_spaces
9
+ assert_equal("hellosemin", "he ll o\r\n sem in\r \n".remove_internal_spaces)
10
+ end
11
+ end
data/test/test_ulla.rb ADDED
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestUlla < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), "..", "test_helper.rb")
2
+ require 'ulla/cli'
3
+
4
+ class TestUllaCli < Test::Unit::TestCase
5
+ def test_execute
6
+ #Ulla::CLI.execute
7
+ assert(true)
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ulla')
2
+
3
+ require 'test/unit'
4
+ require 'environment_class_hash'
5
+
6
+ class TestEnvironmentClassHash < Test::Unit::TestCase
7
+
8
+ include Ulla
9
+
10
+ def setup
11
+ @env_cls = EnvironmentClassHash.new
12
+ end
13
+
14
+ def test_group_by_non_residue_labels
15
+ assert(true)
16
+ end
17
+
18
+ def test_groups_sorted_by_residue_labels
19
+ assert(true)
20
+ end
21
+
22
+ def group_size
23
+ assert(true)
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib', 'ulla')
2
+
3
+ require 'test/unit'
4
+ require 'environment_feature'
5
+
6
+ class TestEnvironmentFeature < Test::Unit::TestCase
7
+
8
+ include Ulla
9
+
10
+ def setup
11
+ @env_ftr = EnvironmentFeature.new('Secondary Structure',
12
+ 'HEPC'.split(''),
13
+ 'HEPC'.split(''),
14
+ 'T',
15
+ 'F')
16
+ end
17
+
18
+ def test_to_s
19
+ assert_equal('Secondary Structure;HEPC;HEPC;T;F', @env_ftr.to_s)
20
+ end
21
+
22
+ def test_constrained?
23
+ assert(@env_ftr.constrained?)
24
+ end
25
+
26
+ def silent?
27
+ assert(!@env_ftr.silent?)
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Refresh" content="5; URL=http://github.com/semin/ulla">
6
+ <title>
7
+ ulla: a program for calculating environment-specific substitution tables
8
+ </title>
9
+ </head>
10
+ <body>
11
+ <p>
12
+ Egor has been renamed to Ulla, and an official web site for Ulla will be available when our new web contents management system is ready. Until then, this page will be redirected to its Git repository, <a href="http://http://github.com/semin/ulla/">http://github.com/semin/ulla</a> in 5 seconds.
13
+ </p>
14
+ - Semin
15
+ </body>
16
+ </html>