semin-ulla 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ pkg
2
+ doc
3
+ .DS_Store
4
+ tmp
5
+ data
6
+ *.log
7
+ *.swp
8
+ *~
data/History.txt ADDED
@@ -0,0 +1,38 @@
1
+ == 0.9.0 13/2/2009
2
+
3
+ * Added --heatmap option for heat map generation from substitution tables
4
+ * Added --heatmap-format option for heat map figure format (PNG, GIF, JPG, BMP, and PDF)
5
+ * Added --heatmap-stem option to set a file name of total heat maps figure when --heatmap 1 or 2 is set
6
+ * Added --heatmap-columns option to set the number of tables in a row when --heatmap 1 or 2 is set
7
+ * Added --heatmap-values option to print values in the cells of heat maps
8
+ * Renamed --noround option to --noroundoff
9
+ * 'simple_memoize' RubyGem package is no longer required
10
+
11
+ == 0.0.5 23/1/2009
12
+
13
+ * Warns if your sigma value is too big for any amino acid count (minimum ratio of amino acid count to sigma value: 500.0)
14
+ * Added --augosigma option to avoid excessive influence of background frequencies
15
+ * Added --noround option was added to get original log odds ratios
16
+ * Added --p1smooth option was added to enable p1 probability smoothing when partial smoothing
17
+ * Fixed a bug in p2 probability calculation of the partial smoothing procedure
18
+ * Fixed a bug in total probability/log odds ratio calculation
19
+ * Changed default verbosity from ERROR to WARN
20
+ * Refactored codes to be more human readable and DRY
21
+
22
+ == 0.0.4 15/12/2008
23
+
24
+ * Fixed a bug to generated log-odds ratio matrices with --nosmooth option
25
+ * Copes with no observations or mutations
26
+
27
+ == 0.0.3 09/12/2008
28
+
29
+ * Added --cys (-j) 2 not to distinguish J from C, so 'disulphide bond' environment feature is not prerequisite
30
+ * Fixed a bug to make masking works for target amino acid, too
31
+
32
+ == 0.0.2 13/11/2008
33
+
34
+ * Supports user provided constrained environment features are properly handled
35
+
36
+ == 0.0.1 07/11/2008
37
+
38
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,90 @@
1
+ .git/COMMIT_EDITMSG
2
+ .git/HEAD
3
+ .git/config
4
+ .git/description
5
+ .git/hooks/applypatch-msg.sample
6
+ .git/hooks/commit-msg.sample
7
+ .git/hooks/post-commit.sample
8
+ .git/hooks/post-receive.sample
9
+ .git/hooks/post-update.sample
10
+ .git/hooks/pre-applypatch.sample
11
+ .git/hooks/pre-commit.sample
12
+ .git/hooks/pre-rebase.sample
13
+ .git/hooks/prepare-commit-msg.sample
14
+ .git/hooks/update.sample
15
+ .git/index
16
+ .git/info/exclude
17
+ .git/logs/HEAD
18
+ .git/logs/refs/heads/master
19
+ .git/logs/refs/remotes/origin/HEAD
20
+ .git/objects/06/9494e479f28b5751fb135b8e55e8fef3d3a02e
21
+ .git/objects/22/0df784191ad94983ca1d943e49fe482c9d1069
22
+ .git/objects/3b/b6f2b7f563175a13a0ccd723aab761552f448b
23
+ .git/objects/41/f48aefb4d7a6a87eb423eaae77ae1e8a58dd6c
24
+ .git/objects/44/d1f1782e3ea1d9fd2f9054784b53e8e810a8ca
25
+ .git/objects/4f/364c2eac29f5c7fcbf06419c4f58074cd32ace
26
+ .git/objects/57/1326145a7a4b3e58f3d3008ba343135f213b05
27
+ .git/objects/6c/4f0844f62b7345f0651b0fb2829a8f157469fb
28
+ .git/objects/73/8dc79450de050f12d48a32602f2ddbe6807029
29
+ .git/objects/7b/4acb3aee6616d80e295ee21fe8bb7ee93ebe96
30
+ .git/objects/9e/0a9235b0d70a8029098070007fb414cb52504e
31
+ .git/objects/9e/bfcad2906aac4a23a7c9689a47b76723f5d152
32
+ .git/objects/a6/578c95f2f474303464b572e9dac716432472b2
33
+ .git/objects/a8/65ef5700ff04601c6fc40fa5ede3cc25534723
34
+ .git/objects/aa/285cb176668c5e49c54c6e1d3cc27bd47fd4f4
35
+ .git/objects/b8/e3828a1082137c4aa4595386bdfb73e3c75b9d
36
+ .git/objects/c2/fb6afc000952b56354fe195682645000d2aea2
37
+ .git/objects/c4/a0553ca0e3c4628e688ecb5e3304a8a8ac0c28
38
+ .git/objects/c8/d49f83c4a32cff2d87dd4aa5f83eb7aac3a753
39
+ .git/objects/ca/c25e8049075ed4bff993705acb4750b2b62ba9
40
+ .git/objects/d2/ff2e939339eb3fb776e064c258e71dfa1cf396
41
+ .git/objects/d7/cedf9e2a8ff35b5d7dafdc0f20daed9c65ce44
42
+ .git/objects/e2/e81af59e3a6c4aa8daac62add62860ae776ba4
43
+ .git/objects/e5/7c47d183ce5dda1a944c7ee1c19c8a0c4bb278
44
+ .git/objects/eb/f4a4e1e50bb30731597f776e56b0ccb0c9959f
45
+ .git/objects/f6/39d6f6cf883fde4b9052012919c1df3288c7da
46
+ .git/objects/f8/2346f308f49053df108b7c31ac3089e8b4b4ac
47
+ .git/objects/fb/4b193bb1cbe9041d2f00176f6caa6acfb1fc12
48
+ .git/objects/pack/pack-aebf617a0b8e016433238d2f21f542bc5b21bd15.idx
49
+ .git/objects/pack/pack-aebf617a0b8e016433238d2f21f542bc5b21bd15.pack
50
+ .git/packed-refs
51
+ .git/refs/heads/master
52
+ .git/refs/remotes/origin/HEAD
53
+ .gitignore
54
+ History.txt
55
+ Manifest.txt
56
+ PostInstall.txt
57
+ README.rdoc
58
+ Rakefile
59
+ bin/ulla
60
+ config/website.yml
61
+ config/website.yml.sample
62
+ lib/math_extensions.rb
63
+ lib/narray_extensions.rb
64
+ lib/nmatrix_extensions.rb
65
+ lib/string_extensions.rb
66
+ lib/ulla.rb
67
+ lib/ulla/cli.rb
68
+ lib/ulla/environment.rb
69
+ lib/ulla/environment_class_hash.rb
70
+ lib/ulla/environment_feature.rb
71
+ lib/ulla/environment_feature_array.rb
72
+ lib/ulla/heatmap_array.rb
73
+ script/console
74
+ script/destroy
75
+ script/generate
76
+ script/txt2html
77
+ test/test_helper.rb
78
+ test/test_math_extensions.rb
79
+ test/test_narray_extensions.rb
80
+ test/test_nmatrix_extensions.rb
81
+ test/test_string_extensions.rb
82
+ test/test_ulla.rb
83
+ test/ulla/test_cli.rb
84
+ test/ulla/test_environment_class_hash.rb
85
+ test/ulla/test_environment_feature.rb
86
+ website/index.html
87
+ website/index.txt
88
+ website/javascripts/rounded_corners_lite.inc.js
89
+ website/stylesheets/screen.css
90
+ website/template.html.erb
data/PostInstall.txt ADDED
@@ -0,0 +1,5 @@
1
+ HELP/OPTIONS: ulla -h
2
+
3
+ For more information on ulla, see http://ulla.rubyforge.org
4
+
5
+
data/README.rdoc ADDED
@@ -0,0 +1,259 @@
1
+ = ulla
2
+
3
+ http://www-cryst.bioc.cam.ac.uk/ulla
4
+
5
+
6
+ == Description
7
+
8
+ 'ulla' is a program for calculating environment-specific substitution tables from user providing environmental class definitions and sequence alignments with the annotations of the environment classes.
9
+
10
+
11
+ == Features
12
+
13
+ * Environment-specific substitution table generation based on user providing environmental class definition
14
+ * Entropy-based smoothing procedures to cope with sparse data problem
15
+ * BLOSUM-like weighting procedures using PID threshold
16
+ * Heat Map generation for substitution tables
17
+
18
+
19
+ == Requirements
20
+
21
+ * ruby 1.8.7 or above (http://www.ruby-lang.org)
22
+ * rubygems 1.2.0 or above (http://rubyforge.org/projects/rubygems)
23
+
24
+ Following RubyGems will be automatically installed if you have rubygems installed on your machine
25
+
26
+ * narray (http://narray.rubyforge.org)
27
+ * facets (http://facets.rubyforge.org)
28
+ * bio (http://bioruby.open-bio.org)
29
+ * RMagick (http://rmagick.rubyforge.org)
30
+
31
+
32
+ == Installation
33
+
34
+ ~user $ sudo gem install ulla
35
+
36
+
37
+ == Basic Usage
38
+
39
+ It's pretty much the same as Kenji's subst (http://www-cryst.bioc.cam.ac.uk/~kenji/subst/), so in most cases, you can swap 'subst' with 'ulla'.
40
+
41
+ ~user $ ulla -l TEMLIST-file -c classdef.dat
42
+ or
43
+ ~user $ ulla -f TEM-file -c classdef.dat
44
+
45
+
46
+ == Options
47
+ --tem-file (-f) FILE: a tem file
48
+ --tem-list (-l) FILE: a list for tem files
49
+ --classdef (-c) FILE: a file for the defintion of environments (default: 'classdef.dat')
50
+ --outfile (-o) FILE: output filename (default 'allmat.dat')
51
+ --weight (-w) INTEGER: clustering level (PID) for the BLOSUM-like weighting (default: 60)
52
+ --noweight: calculate substitution count with no weights
53
+ --smooth (-s) INTEGER:
54
+ 0 for partial smoothing (default)
55
+ 1 for full smoothing
56
+ --p1smooth: perform smoothing for p1 probability calculation when partial smoothing
57
+ --nosmooth: perform no smoothing operation
58
+ --cys (-y) INTEGER:
59
+ 0 for using C and J only for structure (default)
60
+ 1 for both structure and sequence
61
+ 2 for using only C for both (must be set when you have no 'disulphide' or 'disulfide' annotation in templates)
62
+ --output INTEGER:
63
+ 0 for raw count (no smoothing performed)
64
+ 1 for probabilities
65
+ 2 for log odds ratios (default)
66
+ --noroundoff: do not round off log odds ratio
67
+ --scale INTEGER: log odds ratio matrices in 1/n bit units (default 3)
68
+ --sigma DOUBLE: change the sigma value for smoothing (default 5.0)
69
+ --autosigma: automatically adjust the sigma value for smoothing
70
+ --add DOUBLE: add this value to raw count when deriving log odds ratios without smoothing (default 1/#classes)
71
+ --pidmin DOUBLE: count substitutions only for pairs with PID equal to or greater than this value (default none)
72
+ --pidmax DOUBLE: count substitutions only for pairs with PID smaller than this value (default none)
73
+ --heatmap INTEGER:
74
+ 0 create a heat map file for each substitution table
75
+ 1 create one big file containing all heat maps from substitution tables
76
+ 2 do both 0 and 1
77
+ --heatmap-format INTEGER:
78
+ 0 for Portable Network Graphics (PNG) Format (default)
79
+ 1 for Graphics Interchange Format (GIF)
80
+ 2 for Joint Photographic Experts Group (JPEG) Format
81
+ 3 for Microsoft Windows bitmap (BMP) Format
82
+ 4 for Portable Document Format (PDF)
83
+ --heatmap-columns INTEGER: number of tables to print in a row when --heatmap 1 or 2 set (default: sqrt(no. of tables))
84
+ --heatmap-stem STRING: stem for a file name when --heatmap 1 or 2 set (default: 'heatmap')
85
+ --heatmap-values: print values in the cells when generating heat maps
86
+ --verbose (-v) INTEGER
87
+ 0 for ERROR level
88
+ 1 for WARN or above level (default)
89
+ 2 for INFO or above level
90
+ 3 for DEBUG or above level
91
+ --version: print version
92
+ --help (-h): show help
93
+
94
+
95
+ == Usage
96
+
97
+ 1. Prepare an environmental class definition file. For more details, please check this notes (http://www-cryst.bioc.cam.ac.uk/~kenji/subst/NOTES).
98
+
99
+ ~user $ cat classdef.dat
100
+ #
101
+ # name of feature (string); values adopted in .tem file (string); class labels assigned for each value (string);
102
+ # constrained or not (T or F); silent (used as masks)? (T or F)
103
+ #
104
+ secondary structure and phi angle;HEPC;HEPC;T;F
105
+ solvent accessibility;TF;Aa;F;F
106
+
107
+ 2. Prepare structural alignments and their annotations of above environmental classes in PIR format.
108
+
109
+ ~user $ cat sample1.tem
110
+ >P1;1mnma
111
+ sequence
112
+ QKERRKIEIKFIENKTRRHVTFSKRKHGIMKKAFELSVLTGTQVLLLVVSETGLVYTFSTPKFEPIVTQQEGRNL
113
+ IQACLNAPDD*
114
+ >P1;1egwa
115
+ sequence
116
+ --GRKKIQITRIMDERNRQVTFTKRKFGLMKKAYELSVLCDCEIALIIFNSSNKLFQYASTDMDKVLLKYTEY--
117
+ ----------*
118
+ >P1;1mnma
119
+ secondary structure and phi angle
120
+ CPCCCCCCCCCCCCHHHHHHHHHHHHHHHHHHHHHHHHHHPCCCEEEEECCCPCEEEEECCCCCHHHHCHHHHHH
121
+ HHHHHCCCCP*
122
+ >P1;1egwa
123
+ secondary structure and phi angle
124
+ --CCCCCCCCCCCCHHHHHHHHHHHHHHHHHHHHHHHHHCPCCCEEEEECCCPCEEEEECCCHHHHHHHHHHC--
125
+ ----------*
126
+ >P1;1mnma
127
+ solvent accessibility
128
+ TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTFTTTTTTTTTTTTTTTT
129
+ TTTTTTTTTT*
130
+ >P1;1egwa
131
+ solvent accessibility
132
+ --TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTFTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT--
133
+ ----------*
134
+ ...
135
+
136
+ 3. When you have two or more alignment files, you should make a separate file containing all the paths for the alignment files.
137
+
138
+ ~user $ ls -1 *.tem > TEMLIST
139
+ ~user $ cat TEMLIST
140
+ sample1.tem
141
+ sample2.tem
142
+ ...
143
+
144
+ 4. To produce substitution count matrices, type
145
+
146
+ ~user $ ulla -l TEMLIST --output 0 -o substcount.mat
147
+
148
+ 5. To produce substitution probability matrices, type
149
+
150
+ ~user $ ulla -l TEMLIST --output 1 -o substprob.mat
151
+
152
+ 6. To produce log odds ratio matrices, type
153
+
154
+ ~user $ ulla -l TEMLIST --output 2 -o substlogo.mat
155
+
156
+ 7. To produce substitution data only from the sequence pairs within a given PID range, type (if you don't provide any name for output, 'allmat.dat' will be used.)
157
+
158
+ ~user $ ulla -l TEMLIST --pidmin 60 --pidmax 80 --output 1
159
+
160
+ 8. To change the clustering level (default 60), type
161
+
162
+ ~user $ ulla -l TEMLIST --weight 80 --output 2
163
+
164
+ 9. In case positions are masked with the character 'X' in any environmental features, all mutations from/to the position will be excluded from the calculation of substitution counts.
165
+
166
+ 10. Then, it will produce a file containing all the matrices, which will look like the one below. For more details, please check this notes (http://www-cryst.bioc.cam.ac.uk/~kenji/subst/NOTES).
167
+
168
+ # Environment-specific amino acid substitution matrices
169
+ # Creator: ulla version 0.0.5
170
+ # Creation Date: 05/02/2009 17:29
171
+ #
172
+ # Definitions for structural environments:
173
+ # 2 features used
174
+ #
175
+ # secondary structure and phi angle;HEPC;HEPC;F;F
176
+ # solvent accessibility;TF;Aa;F;F
177
+ # (read in from classdef.dat)
178
+ #
179
+ # Number of alignments: 1187
180
+ # (list of .tem files read in from TEMLIST)
181
+ #
182
+ # Total number of environments: 8
183
+ #
184
+ # There are 21 amino acids considered.
185
+ # ACDEFGHIKLMNPQRSTVWYJ
186
+ #
187
+ # C: Cystine (the disulfide-bonded form)
188
+ # J: Cysteine (the free thiol form)
189
+ #
190
+ # Weighting scheme: clustering at PID 60 level
191
+ # ...
192
+ #
193
+ >HA 0
194
+ # A C D E F G H I K L M N P Q R S T V W Y J
195
+ A 3 -5 0 0 -1 2 0 0 1 0 0 0 1 1 0 1 1 1 -1 0 2
196
+ C -16 19 -16 -18 -11 -14 -13 -13 -14 -14 -14 -11 -17 -16 -13 -16 -14 -12 -12 -10 -4
197
+ D 1 -7 6 3 -3 1 0 -3 1 -3 -2 2 1 2 0 1 0 -2 -3 -2 -2
198
+ E 3 -7 5 7 -1 2 2 0 3 0 0 3 2 4 3 3 2 1 -1 0 -1
199
+ F -4 -4 -6 -6 7 -5 -1 0 -4 1 0 -5 -5 -4 -4 -4 -3 -1 3 3 0
200
+ G -2 -6 -3 -4 -5 5 -4 -5 -4 -5 -4 -2 -3 -4 -4 -2 -3 -5 -6 -4 -3
201
+ H 0 -6 0 0 1 0 8 -1 0 0 0 1 -2 1 1 0 0 0 1 3 0
202
+ I -3 -7 -6 -5 0 -5 -3 4 -4 1 1 -5 -4 -4 -3 -5 -2 2 -2 -1 0
203
+ K 2 -6 2 2 -1 1 2 0 5 1 1 2 0 3 4 2 2 0 -2 0 -1
204
+ L -2 -6 -5 -4 1 -4 -2 2 -3 4 2 -3 -4 -3 -2 -4 -2 1 0 0 1
205
+ M -2 -7 -4 -3 1 -2 -1 2 -2 2 6 -3 -4 -2 -1 -2 -1 1 0 0 1
206
+ N 0 -5 1 0 -3 1 1 -3 0 -2 -2 6 -2 0 0 1 1 -2 -3 -1 -1
207
+ P -1 -7 -1 -2 -4 -1 -3 -3 -2 -3 -4 -2 9 -2 -3 0 -1 -2 -4 -4 -4
208
+ Q 2 -7 2 2 -1 1 2 -1 2 0 0 2 0 5 2 1 1 0 -2 -1 0
209
+ R 1 -6 1 1 -1 0 2 0 3 0 1 1 -1 2 6 1 1 0 -1 0 0
210
+ S 0 -6 -1 -1 -3 0 -2 -3 -1 -3 -3 0 0 -1 -1 3 1 -2 -4 -3 0
211
+ T -1 -7 -2 -2 -3 -2 -2 -2 -2 -2 -2 -1 -2 -2 -2 0 3 -1 -3 -3 0
212
+ V -3 -6 -6 -5 -1 -4 -3 1 -4 0 0 -5 -3 -4 -4 -4 -2 2 -2 -2 0
213
+ W -4 -6 -6 -5 2 -6 -2 -2 -5 -1 -2 -5 -5 -4 -4 -5 -4 -2 12 2 -3
214
+ Y -3 -5 -5 -5 3 -4 1 -1 -3 -1 -1 -3 -5 -3 -3 -4 -3 -2 3 7 -1
215
+ J -2 0 -4 -5 0 -2 -1 0 -3 0 0 -3 -6 -2 -2 -1 -1 0 -1 0 9
216
+ U -5 16 -7 -8 -3 -5 -4 -3 -6 -3 -3 -5 -9 -6 -5 -4 -4 -3 -4 -3 6
217
+ ...
218
+
219
+ 11. To generate a heat map for each table with values in it,
220
+
221
+ ~user $ ulla -l TEMLIST --heatmap 0 --heatmap-values
222
+
223
+ which will look like this,
224
+
225
+ http://www-cryst.bioc.cam.ac.uk/~semin/images/0.HA.png
226
+
227
+ 12. To generate one big figure, 'myheatmaps.gif' containing all the heat maps (4 maps in a row),
228
+
229
+ ~user $ ulla -l TEMLIST --heatmap 1 --heatmap-stem myheatmaps --heatmap-format 1 --heatmap-columns 4
230
+
231
+ which will look like this,
232
+
233
+ http://www-cryst.bioc.cam.ac.uk/~semin/images/myheatmaps.gif
234
+
235
+ == TODO
236
+
237
+ * Substitution table generation considering both the source and the target environmental classes
238
+ * Remove dependency on NMatrix package
239
+
240
+ == Repository
241
+
242
+ You can download a pre-built RubyGems package from
243
+
244
+ * rubyforge: http://rubyforge.org/projects/ulla
245
+
246
+ or, You can fetch the source from
247
+
248
+ * github: http://github.com/semin/ulla/tree/master
249
+
250
+
251
+ == Contact
252
+
253
+ Comments are welcome, please send an email to me (seminlee at gmail dot com).
254
+
255
+
256
+ == License
257
+
258
+ http://i.creativecommons.org/l/by-nc/2.0/uk/88x31.png
259
+ This work is licensed under a {Creative Commons Attribution-Noncommercial 2.0 UK: England & Wales License}[http://creativecommons.org/licenses/by-nc/2.0/uk/].
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/ulla'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('ulla', Ulla::VERSION) do |p|
7
+ p.developer('Semin Lee', 'seminlee@gmail.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
+ p.rubyforge_name = p.name # TODO this is default value
11
+ p.extra_deps = [
12
+ ['narray', '>= 0.5.9.5'],
13
+ ['bio', '>= 1.2.1'],
14
+ ['facets', '>= 2.4.5'],
15
+ ['rmagick', '>= 2.9.1'],
16
+ ]
17
+
18
+ p.extra_dev_deps = [
19
+ ['newgem', ">= #{::Newgem::VERSION}"]
20
+ ]
21
+
22
+ p.clean_globs |= %w[**/.DS_Store tmp *.log *.swp]
23
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
24
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
25
+ p.rsync_args = '-av --delete --ignore-errors'
26
+ end
27
+
28
+ require 'newgem/tasks' # load /tasks/*.rake
29
+ Dir['tasks/**/*.rake'].each { |t| load t }
30
+
31
+ # TODO - want other tests/tasks run by default? Add them to the list
32
+ # task :default => [:spec, :features]
data/bin/ulla ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2008-11-7.
4
+ # Copyright (c) 2008. All rights reserved.
5
+
6
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/ulla")
7
+
8
+ require "ulla/cli"
9
+
10
+ Ulla::CLI.execute(ARGV)
@@ -0,0 +1,2 @@
1
+ host: semin@rubyforge.org
2
+ remote_dir: /var/www/gforge-projects/ulla
@@ -0,0 +1,2 @@
1
+ host: unknown@rubyforge.org
2
+ remote_dir: /var/www/gforge-projects/egor
@@ -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,22 @@
1
+ require 'rubygems'
2
+ require 'narray'
3
+ require 'facets'
4
+
5
+ module NArrayExtensions
6
+
7
+ def pretty_string(opts={})
8
+ { :col_header => nil,
9
+ :row_header => nil }.merge!(opts)
10
+
11
+ ("%-3s" % "#") + opts[:col_header].inject("") { |s, a| s + ("%7s" % a) } + "\n" +
12
+ self.to_a.inject("%-3s" % opts[:row_header]) { |s, v|
13
+ if v.is_a? Float
14
+ s + ("%7.2f" % v)
15
+ else
16
+ s + ("%7d" % v)
17
+ end
18
+ }
19
+ end
20
+ end
21
+
22
+ NArray.send(:include, NArrayExtensions)