egor 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/egor.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 Egor
5
+ VERSION = '0.0.1'
6
+ end
@@ -0,0 +1,11 @@
1
+ module EnumerableExtensions
2
+ def cart_prod( *args )
3
+ args.inject([[]]){|old,lst|
4
+ new = []
5
+ lst.each{|e| new += old.map{|c| c.dup << e }}
6
+ new
7
+ }
8
+ end
9
+ end
10
+
11
+ Enumerable.extend(EnumerableExtensions)
@@ -0,0 +1,58 @@
1
+ require "rubygems"
2
+ require "set"
3
+ require "narray"
4
+ require "facets"
5
+
6
+ class Environment
7
+
8
+ @@amino_acids = "ACDEFGHIKLMNPQRSTVWYJ".split("")
9
+
10
+ attr_accessor :number,
11
+ :label,
12
+ :freq_array,
13
+ :prob_array,
14
+ :logodd_array,
15
+ :smooth_prob_array
16
+
17
+ def initialize(number, label)
18
+ @number = number
19
+ @label = label
20
+ @freq_array = $noweight ? NArray.int(21) : NArray.float(21)
21
+ @prob_array = NArray.float(21)
22
+ @logodd_array = NArray.float(21)
23
+ @smooth_prob_array = NArray.float(21)
24
+ end
25
+
26
+ def add_residue_count(a, inc = 1.0)
27
+ @freq_array[@@amino_acids.index(a.upcase)] += inc
28
+ end
29
+
30
+ def label_set
31
+ label.split("").map_with_index { |l, i| "#{i}#{l}" }.to_set
32
+ end
33
+
34
+ def to_s
35
+ "#{number}-#{label}"
36
+ end
37
+ end
38
+
39
+ if $0 == __FILE__
40
+
41
+ require "test/unit"
42
+
43
+ class TestEnvironment < Test::Unit::TestCase
44
+
45
+ def setup
46
+ @env = Environment.new(1, "AHaSon")
47
+ end
48
+
49
+ def test_label_set
50
+ assert_equal(%w[0A 1H 2a 3S 4o 5n].to_set, @env.label_set)
51
+ end
52
+
53
+ def test_to_s
54
+ assert_equal("1-AHaSon", @env.to_s)
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,14 @@
1
+ class EnvironmentFeature < Struct.new(:name, :symbols, :labels, :constrained, :silent)
2
+
3
+ def to_s
4
+ values.join(";")
5
+ end
6
+
7
+ def constrained?
8
+ constrained == "T"
9
+ end
10
+
11
+ def silent?
12
+ silent == "T"
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module MathExtensions
2
+ def log2(val)
3
+ log(val) / log(2)
4
+ end
5
+ end
6
+
7
+ Math.extend(MathExtensions)
@@ -0,0 +1,21 @@
1
+ require "rubygems"
2
+ require "facets"
3
+
4
+ module NArrayExtensions
5
+
6
+ def pretty_string(opts={})
7
+ { :col_header => nil,
8
+ :row_header => nil }.merge!(opts)
9
+
10
+ ("%-3s" % "#") + opts[:col_header].inject("") { |s, a| s + ("%7s" % a) } + "\n" +
11
+ self.to_a.inject("%-3s" % opts[:row_header]) { |s, v|
12
+ if v.is_a? Float
13
+ s + ("%7.2f" % v)
14
+ else
15
+ s + ("%7d" % v)
16
+ end
17
+ }
18
+ end
19
+ end
20
+
21
+ NArray.send(:include, NArrayExtensions)
@@ -0,0 +1,24 @@
1
+ require "rubygems"
2
+ require "facets"
3
+ require "narray"
4
+
5
+ module NMatrixExtensions
6
+ def pretty_string(opts={})
7
+ { :col_header => nil,
8
+ :row_header => nil }.merge!(opts)
9
+
10
+ ("%-3s" % "#") + opts[:col_header].inject("") { |s, a|
11
+ s + ("%7s" % a)
12
+ } + "\n" + self.to_a.map_with_index { |a, i|
13
+ ("%-3s" % opts[:row_header][i]) + a.inject("") { |s, v|
14
+ if v.is_a? Float
15
+ s + ("%7.2f" % v)
16
+ else
17
+ s + ("%7d" % v)
18
+ end
19
+ }
20
+ }.join("\n")
21
+ end
22
+ end
23
+
24
+ NMatrix.send(:include, NMatrixExtensions)
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)
data/test/test_egor.rb ADDED
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestEgor < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper.rb")
2
+ require 'egor/cli'
3
+
4
+ class TestEgorCli < Test::Unit::TestCase
5
+ def test_execute
6
+ Egor::CLI.execute
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require "test/unit"
4
+ require "enumerable_extensions"
5
+
6
+ class TestEnumerableExtensions < Test::Unit::TestCase
7
+
8
+ def test_cart_product
9
+ a = [1,2]
10
+ b = [3,4]
11
+ products = [[1,3], [1,4], [2,3], [2,4]]
12
+ results = Enumerable.cart_prod(a,b)
13
+ assert_equal(4, results.size)
14
+ products.each { |p| assert(results.include? p) }
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require "test/unit"
4
+ require "environment_feature"
5
+
6
+ class TestEnvironmentFeature < Test::Unit::TestCase
7
+
8
+ def test_true
9
+ assert(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/egor'
@@ -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,78 @@
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
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ egor: Environment-specific substitution table GeneratOR
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>egor: Environment-specific substitution table GeneratOR</h1>
34
+ <div class="sidebar">
35
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/egor"; return false'>
36
+ <p>Get Version</p>
37
+ <a href="http://rubyforge.org/projects/egor" class="numbers">0.0.1</a>
38
+ </div>
39
+ </div>
40
+ <h2>What</h2>
41
+ <p>&#8216;egor&#8217; is a program for calculating environment-specific substitution tables</p>
42
+ <h2>Installation</h2>
43
+ <p><pre class='syntax'><span class="global">$ </span><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">egor</span></pre></p>
44
+ <h2>Features</h2>
45
+ <ul>
46
+ <li>No more segmentation fault</li>
47
+ <li>Full smoothing supported</li>
48
+ <li>In theory, infinite number of environment features can be handled</li>
49
+ </ul>
50
+ <h2>Demonstration of usage</h2>
51
+ <p>It&#8217;s pretty much the same as Kenji&#8217;s subst, so in most cases, you just need swap &#8216;subst&#8217; with &#8216;egor&#8217;.</p>
52
+ <pre>$ egor -l TEMLIST-file -c classdef.dat</pre>
53
+ or
54
+ <pre>$ egor -l TEM-file -c classdef.dat</pre>
55
+ <h2>Repository</h2>
56
+ <p>You can download a pre-built RubyGem package from</p>
57
+ <ul>
58
+ <li>rubyforge: <a href="http://rubyforge.org/projects/egor">http://rubyforge.org/projects/egor</a></li>
59
+ </ul>
60
+ <p>or, You can fetch the source from</p>
61
+ <ul>
62
+ <li>github: <a href="http://github.com/semin/egor/tree/master">http://github.com/semin/egor/tree/master</a></li>
63
+ </ul>
64
+ <pre>$ git clone git://github.com/semin/egor.git</pre>
65
+ <h2>License</h2>
66
+ <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
67
+ <h2>Contact</h2>
68
+ <p>Comments are welcome, please send an email to me (seminlee at gmail dot com).</p>
69
+ <p class="coda">
70
+ <a href="FIXME email">Semin Lee</a>, 10th November 2008<br>
71
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
72
+ </p>
73
+ </div>
74
+
75
+ <!-- insert site tracking codes here, like Google Urchin -->
76
+
77
+ </body>
78
+ </html>
data/website/index.txt ADDED
@@ -0,0 +1,48 @@
1
+ h1. egor: Environment-specific substitution table GeneratOR
2
+
3
+
4
+ h2. What
5
+
6
+ 'egor' is a program for calculating environment-specific substitution tables
7
+
8
+
9
+ h2. Installation
10
+
11
+ <pre syntax="ruby">$ sudo gem install egor</pre>
12
+
13
+
14
+ h2. Features
15
+
16
+ * No more segmentation fault
17
+ * Full smoothing supported
18
+ * In theory, infinite number of environment features can be handled
19
+
20
+
21
+ h2. Demonstration of usage
22
+
23
+ It's pretty much the same as Kenji's subst, so in most cases, you just need swap 'subst' with 'egor'.
24
+
25
+ <pre>$ egor -l TEMLIST-file -c classdef.dat</pre>
26
+ or
27
+ <pre>$ egor -l TEM-file -c classdef.dat</pre>
28
+
29
+
30
+ h2. Repository
31
+
32
+ You can download a pre-built RubyGem package from
33
+
34
+ * rubyforge: "http://rubyforge.org/projects/egor":http://rubyforge.org/projects/egor
35
+
36
+ or, You can fetch the source from
37
+
38
+ * github: "http://github.com/semin/egor/tree/master":http://github.com/semin/egor/tree/master
39
+
40
+ <pre>$ git clone git://github.com/semin/egor.git</pre>
41
+
42
+ h2. License
43
+
44
+ This code is free to use under the terms of the MIT license.
45
+
46
+ h2. Contact
47
+
48
+ Comments are welcome, please send an email to me (seminlee at gmail dot com).