bio-krona 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - rbx-19mode
7
+ # - 1.8.7
8
+ # - jruby-18mode # JRuby in 1.8 mode
9
+ # - rbx-18mode
10
+
11
+ # uncomment this line if your project needs to run something other than `rake`:
12
+ # script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'bio'
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "rspec", "~> 2.8.0"
11
+ gem "yard", "~> 0.7"
12
+ gem "rdoc", "~> 3.12"
13
+ gem "cucumber", ">= 0"
14
+ gem "jeweler", "~> 1.8.3"
15
+ gem "bundler", ">= 1.0.21"
16
+ gem "rdoc", "~> 3.12"
17
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Ben J. Woodcroft
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.
@@ -0,0 +1,64 @@
1
+ # bio-krona
2
+
3
+ [![Build Status](https://secure.travis-ci.org/wwood/bioruby-krona.png)](http://travis-ci.org/wwood/bioruby-krona)
4
+
5
+ This biogem is built around [Krona](http://krona.sourceforge.net/), a flashy way of representing hierarchical data.
6
+
7
+ ## Usage
8
+
9
+ ```bio-krona``` is a pretty simple gem, at this stage, and only implements two useful methods.
10
+ The first, the static method ```Bio::Krona#html``` is to call the krona software itself (specifically, ```ktImportText```) to generate
11
+ the visualisation in HTML form.
12
+
13
+ ```ruby
14
+ require 'bio-krona'
15
+
16
+ html = Bio::Krona.html({
17
+ ['Sponge','Amphimedon']=>3,
18
+ ['Sponge','Calciums']=>4,
19
+ })
20
+
21
+ ```
22
+
23
+ It takes as input a hash, where the keys are arrays representing the metadata, and the values are the weightings. In the example above,
24
+ the data has two levels of hierarchy - first Sponge, second Ampphimedon/Calciums.
25
+
26
+ The second method ```collapse``` implements a pre-processing step that might be of use when the data is overly complex.
27
+ It collapses the data so that only a limited number of hierarchy levels are accounted for.
28
+ The weightings are preseverd by adding up the individual abundances.
29
+
30
+ ```ruby
31
+ Bio::Krona.collapse({
32
+ ['Sponge','Amphimedon']=>3,
33
+ ['Sponge','Calciums']=>4,
34
+ }, 1)
35
+ #=> {['Sponge'] => 7}
36
+ ```
37
+
38
+ ## Installation
39
+
40
+ ```sh
41
+ gem install bio-krona
42
+ ```
43
+
44
+ ## Project home page
45
+
46
+ Information on the source tree, documentation, examples, issues and
47
+ how to contribute, see
48
+
49
+ http://github.com/wwood/bioruby-krona
50
+
51
+ The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.
52
+
53
+ ## Cite
54
+
55
+ ```bio-krona``` is currently unpublished. However Krona itself is - see http://krona.sourceforge.net
56
+
57
+ ## Biogems.info
58
+
59
+ This Biogem is published at [#bio-krona](http://biogems.info/index.html)
60
+
61
+ ## Copyright
62
+
63
+ Copyright (c) 2012 Ben J. Woodcroft. See LICENSE.txt for further details.
64
+
@@ -0,0 +1,45 @@
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 = "bio-krona"
18
+ gem.homepage = "http://github.com/wwood/bioruby-krona"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{This biogem is built around Krona, a flashy way of representing hierarchical data.}
21
+ gem.description = %Q{This biogem is built around Krona, a flashy way of representing hierarchical data.}
22
+ gem.email = "donttrustben near gmail.com"
23
+ gem.authors = ["Ben J. Woodcroft"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ require 'cucumber/rake/task'
40
+ Cucumber::Rake::Task.new(:features)
41
+
42
+ task :default => :spec
43
+
44
+ require 'yard'
45
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,12 @@
1
+ # Please require your code below, respecting the naming conventions in the
2
+ # bioruby directory tree.
3
+ #
4
+ # For example, say you have a plugin named bio-plugin, the only uncommented
5
+ # line in this file would be
6
+ #
7
+ # require 'bio/bio-plugin/plugin'
8
+ #
9
+ # In this file only require other files. Avoid other source code.
10
+
11
+ require 'bio-krona/krona.rb'
12
+
@@ -0,0 +1,61 @@
1
+ require 'bio'
2
+ require 'tempfile'
3
+
4
+ module Bio
5
+ class Krona
6
+ # Given a count_hash, return the html generated by krona
7
+ # * count_hash: hash of Array => Numeric, where the array is a list of descriptors (e.g. [Eukaryota, Metazoa, Chordata]), and the Numeric is a count for the number of observations of that description
8
+ # * options:
9
+ # ** :krona_path: path to the ktImportText script in the krona directory (default 'ktImportText' i.e. assuming it is already in the PATH)
10
+ def self.html(count_hash, options={})
11
+ raise unless count_hash.kind_of?(Hash)
12
+ options[:krona_path] ||= %(ktImportText)
13
+
14
+ Tempfile.open('krona') do |tempfile|
15
+ count_hash.each do |array, count|
16
+ raise unless array.kind_of?(Array)
17
+ raise unless count.kind_of?(Numeric)
18
+
19
+ tempfile.puts [
20
+ count,
21
+ array
22
+ ].flatten.join("\t")
23
+ end
24
+ tempfile.close
25
+
26
+ Tempfile.open('krona_out') do |output|
27
+ output.close
28
+
29
+ command = [
30
+ options[:krona_path],
31
+ '-o',
32
+ output.path,
33
+ tempfile.path,
34
+ ].flatten
35
+ Bio::Command.call_command_open3(command) do |stdin, stdout, stderr|
36
+ err = stderr.read
37
+ raise err unless err==''
38
+ end
39
+
40
+ return File.open(output.path).read
41
+ end
42
+ end
43
+ end
44
+
45
+ # Take a count_hash (hash of Array => Numeric), and collapse the array down to some maximum number of levels. In krona, the collapsed output would now have less (max_level) rings.
46
+ #
47
+ # Returns the collapsed count_hash
48
+ def self.collapse(count_hash, max_level)
49
+ raise unless max_level.kind_of?(Integer) and max_level > 0
50
+ new_count_hash = {}
51
+ count_hash.each do |array, count|
52
+ raise unless array.kind_of?(Array)
53
+ raise unless count.kind_of?(Numeric)
54
+
55
+ new_count_hash[array[0...max_level]] ||= 0
56
+ new_count_hash[array[0...max_level]] += count
57
+ end
58
+ return new_count_hash
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,74 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "BioKrona" do
4
+ it "should give a html when you give it a simple hash" do
5
+ html = Bio::Krona.html({
6
+ ['Sponge','Amphimedon']=>3,
7
+ ['Sponge','Calciums']=>4,
8
+ })
9
+ expected = <<EOF
10
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
11
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
+ <head>
13
+ <meta charset="utf-8"/>
14
+ <link rel="shortcut icon" href="http://krona.sourceforge.net/img/favicon.ico"/>
15
+ <script id="notfound">window.onload=function(){document.body.innerHTML="Could not get resources from \\"http://krona.sourceforge.net\\"."}</script>
16
+ <script src="http://krona.sourceforge.net/src/krona-2.0.js"></script>
17
+ </head>
18
+ <body>
19
+ <img id="hiddenImage" src="http://krona.sourceforge.net/img/hidden.png" style="display:none"/>
20
+ <img id="loadingImage" src="http://krona.sourceforge.net/img/loading.gif" style="display:none"/>
21
+ <noscript>Javascript must be enabled to view this page.</noscript>
22
+ <div style="display:none">
23
+ <krona collapse="true" key="true">
24
+ <attributes magnitude="magnitude">
25
+ <list>members</list>
26
+ <attribute display="Total">magnitude</attribute>
27
+ </attributes>
28
+ <datasets>
29
+ <dataset>input</dataset>
30
+ </datasets>
31
+ <node name="all">
32
+ <magnitude><val>7</val></magnitude>
33
+ <node name="Sponge">
34
+ <magnitude><val>7</val></magnitude>
35
+ <node name="Amphimedon">
36
+ <magnitude><val>3</val></magnitude>
37
+ </node>
38
+ <node name="Calciums">
39
+ <magnitude><val>4</val></magnitude>
40
+ </node>
41
+ </node>
42
+ </node>
43
+ </krona>
44
+ </div></body></html>
45
+ EOF
46
+ make_comparable = lambda do |string|
47
+ string.split("\n").reject{|line| line.match(/<dataset>/)}
48
+ end
49
+ expected = make_comparable.call(expected)
50
+ html = make_comparable.call(html)
51
+
52
+ html.should eq(expected)
53
+ end
54
+
55
+ # it "should give back the html split up for re-use" do
56
+ # h = Bio::Krona.reusable_html_chunks({
57
+ # ['Sponge','Amphimedon']=>3,
58
+ # ['Sponge','Calciums']=>4,
59
+ # })
60
+ # end
61
+
62
+ it "should collapse hashes right" do
63
+ big = {%w(a b c)=>2, %w(a b f)=>4, %w(g)=>5}
64
+
65
+ expected = {%w(a)=>6, %w(g)=>5}
66
+ Bio::Krona.collapse(big, 1).should eq(expected)
67
+
68
+ expected = {%w(a b)=>6, %w(g)=>5}
69
+ Bio::Krona.collapse(big, 2).should eq(expected)
70
+
71
+ Bio::Krona.collapse(big, 3).should eq(big)
72
+ Bio::Krona.collapse(big, 4).should eq(big)
73
+ end
74
+ end
@@ -0,0 +1,2 @@
1
+ 3 Sponge Amphimedon
2
+ 4 Sponge Calciums
@@ -0,0 +1,35 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <link rel="shortcut icon" href="http://krona.sourceforge.net/img/favicon.ico"/>
6
+ <script id="notfound">window.onload=function(){document.body.innerHTML="Could not get resources from \"http://krona.sourceforge.net\"."}</script>
7
+ <script src="http://krona.sourceforge.net/src/krona-2.0.js"></script>
8
+ </head>
9
+ <body>
10
+ <img id="hiddenImage" src="http://krona.sourceforge.net/img/hidden.png" style="display:none"/>
11
+ <img id="loadingImage" src="http://krona.sourceforge.net/img/loading.gif" style="display:none"/>
12
+ <noscript>Javascript must be enabled to view this page.</noscript>
13
+ <div style="display:none">
14
+ <krona collapse="true" key="true">
15
+ <attributes magnitude="magnitude">
16
+ <list>members</list>
17
+ <attribute display="Total">magnitude</attribute>
18
+ </attributes>
19
+ <datasets>
20
+ <dataset>input</dataset>
21
+ </datasets>
22
+ <node name="all">
23
+ <magnitude><val>7</val></magnitude>
24
+ <node name="Sponge">
25
+ <magnitude><val>7</val></magnitude>
26
+ <node name="Amphimedon">
27
+ <magnitude><val>3</val></magnitude>
28
+ </node>
29
+ <node name="Calciums">
30
+ <magnitude><val>4</val></magnitude>
31
+ </node>
32
+ </node>
33
+ </node>
34
+ </krona>
35
+ </div></body></html>
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'bio-krona'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bio-krona
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben J. Woodcroft
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bio
16
+ requirement: &75478020 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *75478020
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &75477510 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.8.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *75477510
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ requirement: &75477060 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.7'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *75477060
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdoc
49
+ requirement: &75547720 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *75547720
58
+ - !ruby/object:Gem::Dependency
59
+ name: cucumber
60
+ requirement: &75546890 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *75546890
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &75546480 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.8.3
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *75546480
80
+ - !ruby/object:Gem::Dependency
81
+ name: bundler
82
+ requirement: &75545940 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 1.0.21
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *75545940
91
+ - !ruby/object:Gem::Dependency
92
+ name: rdoc
93
+ requirement: &75545420 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: '3.12'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *75545420
102
+ description: This biogem is built around Krona, a flashy way of representing hierarchical
103
+ data.
104
+ email: donttrustben near gmail.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files:
108
+ - LICENSE.txt
109
+ - README.md
110
+ files:
111
+ - .document
112
+ - .rspec
113
+ - .travis.yml
114
+ - Gemfile
115
+ - LICENSE.txt
116
+ - README.md
117
+ - Rakefile
118
+ - VERSION
119
+ - lib/bio-krona.rb
120
+ - lib/bio-krona/krona.rb
121
+ - spec/bio-krona_spec.rb
122
+ - spec/data/krona/input.txt
123
+ - spec/data/krona/input.txt.krona
124
+ - spec/spec_helper.rb
125
+ homepage: http://github.com/wwood/bioruby-krona
126
+ licenses:
127
+ - MIT
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ segments:
139
+ - 0
140
+ hash: 415100237
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 1.8.17
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: This biogem is built around Krona, a flashy way of representing hierarchical
153
+ data.
154
+ test_files: []