iroki 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a089968db7de186aa8276b1964e496b65fbac4a
4
- data.tar.gz: 1d1d3db465f5741256f6937a8884f0d4e95a6b56
3
+ metadata.gz: 4e8e1eeaa50a23a42dd81714d8d5301c3acc1fd5
4
+ data.tar.gz: 150d12ff4ba7d6a6b34643fba5da48b48535ae0e
5
5
  SHA512:
6
- metadata.gz: 7294d161e7988f562bdb17ab32d343763df1af2fa3431cf64ea22d6300849bbb6af083872bab5288cde5e9d7eedf67d90a26283d40d971c879911bd96c3a28b5
7
- data.tar.gz: 560fbd14e2da7cf0ac33f282f44511d934bb893beb349a068c31c0b8fee0ede5041906b2a4019d7d7d559fcea844991221009daf20c991c5decc3fce719df6fb
6
+ metadata.gz: 13ca08512ff4122f5ac178de610a9b7de166a1f8a2f3b4ae80ebe561e237d4f44d9e970c7c622140ea58a2a0fd5086cda231b8a946ca2294ed5dac728260fd33
7
+ data.tar.gz: 2877db8a1435c34ad939cda11130858445ba012ed235c0a61e1c9b413a133b7f78890c72c573704a1119fb945590aa59a04c3985069d50e939916d963fb880cc
data/README.md CHANGED
@@ -104,3 +104,12 @@ Add branch length and bootstraps to `newick_to_phyloxml`.
104
104
  ### 0.0.7 ###
105
105
 
106
106
  Add `reorder_nodes` script.
107
+
108
+ ### 0.0.8 ###
109
+
110
+ - Add auto coloring with Kelly theme
111
+ - Add ability to color branches and labels separately
112
+
113
+ ### 0.0.9 ###
114
+
115
+ - Add single sample color gradients (one and two color)
data/lib/iroki.rb CHANGED
@@ -18,9 +18,16 @@
18
18
 
19
19
  require "abort_if"
20
20
 
21
+ require "iroki/biom"
21
22
  require "iroki/version"
23
+
22
24
  require "iroki/const/const"
25
+
23
26
  require "iroki/color/color"
27
+ require "iroki/color/gradient"
28
+ require "iroki/color/single_sample_gradient"
29
+ require "iroki/color/palette/palette"
30
+
24
31
  require "iroki/core_ext/hash/hash"
25
32
  require "iroki/core_ext/string/string"
26
33
  require "iroki/core_ext/file/file"
data/lib/iroki/biom.rb ADDED
@@ -0,0 +1,56 @@
1
+ # Copyright 2016 Ryan Moore
2
+ # Contact: moorer@udel.edu
3
+ #
4
+ # This file is part of Iroki.
5
+ #
6
+ # Iroki is free software: you can redistribute it and/or modify it
7
+ # under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Iroki is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Iroki. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module Iroki
20
+ class Biom < File
21
+ def parse_single_sample
22
+ samples = []
23
+ counts = []
24
+
25
+ self.each_line do |line|
26
+ unless line.start_with? "#"
27
+ sample, count = line.chomp.split "\t"
28
+
29
+ samples << sample
30
+ counts << count.to_f
31
+ end
32
+ end
33
+
34
+ [samples, counts]
35
+ end
36
+
37
+
38
+ def parse_two_sample
39
+ samples = []
40
+ counts_group1 = []
41
+ counts_group2 = []
42
+
43
+ self.each_line do |line|
44
+ unless line.start_with? "#"
45
+ sample, count1, count2 = line.chomp.split "\t"
46
+
47
+ samples << sample
48
+ counts_group1 << count1.to_f
49
+ counts_group2 << count2.to_f
50
+ end
51
+ end
52
+
53
+ [samples, counts_group1, counts_group2]
54
+ end
55
+ end
56
+ end
@@ -16,67 +16,30 @@
16
16
  # You should have received a copy of the GNU General Public License
17
17
  # along with Iroki. If not, see <http://www.gnu.org/licenses/>.
18
18
 
19
+ require "color"
20
+
19
21
  module Iroki
20
22
  module Color
21
- module Palette
22
- # BASIC =
23
- # { "1" => "#FF3814", # red
24
- # "2" => "#712BFF", # blue
25
- # "3" => "#FFDF14", # yellow
26
- # "4" => "#14FF63", } # green
27
-
28
- # BASIC_LIGHT =
29
- # { "1" => "#FF8872",
30
- # "2" => "#A97FFE",
31
- # "3" => "#FFEC72",
32
- # "4" => "#71FEA1", }
23
+ GREEN_HUE = 1 / 3.0
24
+ BLUE_HUE = 2 / 3.0
25
+ WHITE_HUE = 1.0
26
+ FULLY_SATURATED = 1
27
+ PURE_COLOR = 0.5
28
+ PURE_LIGHT = 1.0
33
29
 
34
- # BASIC_DARK =
35
- # { "1" => "#FF2800",
36
- # "2" => "#4901DD",
37
- # "3" => "#FFDD00",
38
- # "4" => "#00E24D", }
39
30
 
40
- # FUNKY =
41
- # { "1" => "#FF7314",
42
- # "2" => "#9F23FF",
43
- # "3" => "#FFF814",
44
- # "4" => "#14FFD8", }
45
31
 
46
- # FUNKY_LIGHT =
47
- # { "1" => "#FFAB72",
48
- # "2" => "#C57AFE",
49
- # "3" => "#FFFB72",
50
- # "4" => "#71FEE6", }
32
+ GREEN = Object::Color::HSL.from_fraction GREEN_HUE,
33
+ FULLY_SATURATED,
34
+ PURE_COLOR
51
35
 
52
- # FUNKY_DARK =
53
- # { "1" => "#FF6700",
54
- # "2" => "#7C01DC",
55
- # "3" => "#FFF700",
56
- # "4" => "#00D7B3", }
36
+ BLUE = Object::Color::HSL.from_fraction BLUE_HUE,
37
+ FULLY_SATURATED,
38
+ PURE_COLOR
57
39
 
58
- KELLY = {
59
- "1" => { name: "purple", hex: "#875692" },
60
- "2" => { name: "orange", hex: "#F38400" },
61
- "3" => { name: "light_blue", hex: "#A1CAF1" },
62
- "4" => { name: "red", hex: "#BE0032" },
63
- "5" => { name: "buff", hex: "#C2B280" },
64
- "6" => { name: "grey", hex: "#848482" },
65
- "7" => { name: "green", hex: "#008856" },
66
- "8" => { name: "purplish_pink", hex: "#E68FAC" },
67
- "9" => { name: "blue", hex: "#0067A5" },
68
- "10" => { name: "yellowish_pink", hex: "#F99379" },
69
- "11" => { name: "violet", hex: "#604E97" },
70
- "12" => { name: "orange_yellow", hex: "#F6A600" },
71
- "13" => { name: "purplish_red", hex: "#B3446C" },
72
- "14" => { name: "reddish_brown", hex: "#882D17" },
73
- "15" => { name: "yellow_green", hex: "#8DB600" },
74
- "16" => { name: "yellowish_brown", hex: "#654522" },
75
- "17" => { name: "reddish_orange", hex: "#E25822" },
76
- "18" => { name: "olive_green", hex: "#2B3D26" },
77
- "19" => { name: "yellow", hex: "#F3C300" },
78
- }
79
- end
40
+ WHITE = Object::Color::HSL.from_fraction WHITE_HUE,
41
+ FULLY_SATURATED,
42
+ PURE_LIGHT
80
43
 
81
44
  def self.get_tag str, palette=nil
82
45
  if str.hex?
@@ -89,7 +52,7 @@ module Iroki
89
52
  def self.tag_from_hex hex
90
53
  assert hex.hex?, "'#{hex}' was not a valid hex code"
91
54
 
92
- %Q{[&!color="#{hex}"]}
55
+ %Q{[&!color="#{hex.upcase}"]}
93
56
  end
94
57
 
95
58
  def self.tag_from_color color, palette=nil
@@ -110,7 +73,7 @@ module Iroki
110
73
  hex = colors["black"]
111
74
  end
112
75
 
113
- %Q{[&!color="#{hex}"]}
76
+ %Q{[&!color="#{hex.upcase}"]}
114
77
  end
115
78
 
116
79
  COLORS = {
@@ -773,6 +736,6 @@ module Iroki
773
736
  "yellowgreen" => "#9ACD32",
774
737
  }
775
738
 
776
-
739
+ DARK_GREEN = Object::Color::RGB.by_hex(COLORS["darkgreen"])
777
740
  end
778
741
  end
@@ -0,0 +1,45 @@
1
+ # Copyright 2016 Ryan Moore
2
+ # Contact: moorer@udel.edu
3
+ #
4
+ # This file is part of Iroki.
5
+ #
6
+ # Iroki is free software: you can redistribute it and/or modify it
7
+ # under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Iroki is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Iroki. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module Iroki
20
+ module Color
21
+ class Gradient
22
+ attr_accessor :samples, :color_hex_codes, :lumins
23
+
24
+ # scales [min, max] to [A, B]
25
+ def self.scale x, new_min=0.05, new_max=0.9, old_min=0.0, old_max=1.0
26
+ ((((new_max - new_min) * (x - old_min.to_f)) / (old_max - old_min)) + new_min)
27
+ end
28
+
29
+ # scales [old_min, old_max] to [new_max, new_min]
30
+ def self.scale_reverse x, new_min=0, new_max=0, old_min=0.0, old_max=1.0
31
+ (new_max - ((((new_max - new_min) * (x - old_min.to_f)) / (old_max - old_min)) + new_min)) + new_min
32
+ end
33
+
34
+ def patterns
35
+ hash = {}
36
+ @samples.zip(@color_hex_codes).each do |(sample, hexcode)|
37
+ tag = Iroki::Color.get_tag hexcode
38
+ hash[sample] = { label: tag, branch: tag }
39
+ end
40
+
41
+ hash
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,39 @@
1
+ module Iroki
2
+ module Color
3
+ module Palette
4
+ # BASIC =
5
+ # { "1" => "#FF3814", # red
6
+ # "2" => "#712BFF", # blue
7
+ # "3" => "#FFDF14", # yellow
8
+ # "4" => "#14FF63", } # green
9
+
10
+ # FUNKY =
11
+ # { "1" => "#FF7314",
12
+ # "2" => "#9F23FF",
13
+ # "3" => "#FFF814",
14
+ # "4" => "#14FFD8", }
15
+
16
+ KELLY = {
17
+ "1" => { name: "purple", hex: "#875692" },
18
+ "2" => { name: "orange", hex: "#F38400" },
19
+ "3" => { name: "light_blue", hex: "#A1CAF1" },
20
+ "4" => { name: "red", hex: "#BE0032" },
21
+ "5" => { name: "buff", hex: "#C2B280" },
22
+ "6" => { name: "grey", hex: "#848482" },
23
+ "7" => { name: "green", hex: "#008856" },
24
+ "8" => { name: "purplish_pink", hex: "#E68FAC" },
25
+ "9" => { name: "blue", hex: "#0067A5" },
26
+ "10" => { name: "yellowish_pink", hex: "#F99379" },
27
+ "11" => { name: "violet", hex: "#604E97" },
28
+ "12" => { name: "orange_yellow", hex: "#F6A600" },
29
+ "13" => { name: "purplish_red", hex: "#B3446C" },
30
+ "14" => { name: "reddish_brown", hex: "#882D17" },
31
+ "15" => { name: "yellow_green", hex: "#8DB600" },
32
+ "16" => { name: "yellowish_brown", hex: "#654522" },
33
+ "17" => { name: "reddish_orange", hex: "#E25822" },
34
+ "18" => { name: "olive_green", hex: "#2B3D26" },
35
+ "19" => { name: "yellow", hex: "#F3C300" },
36
+ }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,80 @@
1
+ # Copyright 2016 Ryan Moore
2
+ # Contact: moorer@udel.edu
3
+ #
4
+ # This file is part of Iroki.
5
+ #
6
+ # Iroki is free software: you can redistribute it and/or modify it
7
+ # under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Iroki is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Iroki. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ module Iroki
20
+ module Color
21
+ class SingleSampleGradient < Gradient
22
+ attr_accessor :counts, :rel_abunds, :single_color
23
+
24
+ def initialize samples, counts, single_color=false
25
+ @single_color = single_color
26
+ @samples = samples
27
+ @counts = counts
28
+ @rel_abunds = counts_to_rel_abunds
29
+ @lumins = rel_abunds_to_lumins
30
+
31
+ if @single_color
32
+ @color_hex_codes = single_color_gradient_hex_codes
33
+ else
34
+ @color_hex_codes = two_color_gradient_hex_codes
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def counts_to_rel_abunds
41
+ max_count = @counts.max.to_f
42
+
43
+ @counts.map do |count|
44
+ count / max_count
45
+ end
46
+ end
47
+
48
+ def rel_abunds_to_lumins
49
+ @rel_abunds.map do |count|
50
+ Gradient.scale_reverse count, new_min=50, new_max=97
51
+ end
52
+ end
53
+
54
+ def two_color_gradient_hex_codes
55
+ @rel_abunds.map.with_index do |rel_abund, idx|
56
+ lumin = @lumins[idx]
57
+
58
+ col =
59
+ Iroki::Color::GREEN.mix_with Iroki::Color::BLUE, rel_abund
60
+
61
+ col.luminosity = lumin
62
+
63
+ col.html
64
+ end
65
+ end
66
+
67
+ def single_color_gradient_hex_codes
68
+ @rel_abunds.zip(@lumins).map do |rel_abund, lumin|
69
+ amt_of_orig_color =
70
+ Gradient.scale rel_abund, new_min=10, new_max=95
71
+
72
+ col =
73
+ Iroki::Color::DARK_GREEN.lighten_by amt_of_orig_color
74
+
75
+ col.html
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -18,6 +18,7 @@
18
18
 
19
19
  require "bio"
20
20
  require "set"
21
+ require "trollop"
21
22
 
22
23
  module Iroki
23
24
  module Main
@@ -26,6 +27,8 @@ module Iroki
26
27
  exact: nil,
27
28
  remove_bootstraps_below: nil,
28
29
  color_map_f: nil,
30
+ biom_f: nil,
31
+ single_color: nil,
29
32
  name_map_f: nil,
30
33
  auto_color: nil,
31
34
  display_auto_color_options: nil,
@@ -33,19 +36,15 @@ module Iroki
33
36
  out_f: nil)
34
37
 
35
38
  if display_auto_color_options
36
- puts "\n Choices for --auto-color ..."
37
- print " - kelly: up to 19 high contrast colors (purple, orange, light blue, red, ...)\n\n"
39
+ STDERR.puts "\n Choices for --auto-color ..."
40
+ STDERR.print " - kelly: up to 19 high contrast colors (purple, orange, light blue, red, ...)\n\n"
38
41
  exit
39
42
  end
40
43
 
41
44
  auto_color_options = ["kelly"]
42
45
 
43
- if !auto_color.nil? && !auto_color_options.include?(auto_color)
44
- puts "\n Choices for --auto-color ..."
45
- print " - kelly: up to 19 high contrast colors (purple, orange, light blue, red, ...)\n\n"
46
-
47
- Trollop.die :auto_color, "#{auto_color} is not a valid option"
48
- end
46
+ abort_if !auto_color.nil? && !auto_color_options.include?(auto_color),
47
+ "'#{auto_color}' is not a valid option. Try iroki --help for help."
49
48
 
50
49
  case auto_color
51
50
  when nil
@@ -54,10 +53,13 @@ module Iroki
54
53
  auto_color_hash = Iroki::Color::Palette::KELLY
55
54
  end
56
55
 
56
+ abort_if biom_f && color_map_f,
57
+ "--color-map and --biom-file cannot both be specified. Try iroki --help for help."
58
+
57
59
  newick = check_file newick_f, :newick
58
60
 
59
61
  color_f = nil
60
- if color_taxa_names || color_branches
62
+ if !biom_f && (color_taxa_names || color_branches)
61
63
  color_f = check_file color_map_f, :color_map_f
62
64
  end
63
65
 
@@ -74,6 +76,9 @@ module Iroki
74
76
  patterns = parse_color_map color_f,
75
77
  exact_matching: exact,
76
78
  auto_color: auto_color_hash
79
+ else
80
+ samples, counts = Biom.open(biom_f).parse_single_sample
81
+ patterns = SingleSampleGradient.new(samples, counts, single_color).patterns
77
82
  end
78
83
 
79
84
  treeio = Bio::FlatFile.open(Bio::Newick, newick)
data/lib/iroki/version.rb CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  # Library metadata
20
20
  module Iroki
21
- VERSION = "0.0.8"
21
+ VERSION = "0.0.9"
22
22
  COPYRIGHT = "2015 - 2016 Ryan Moore"
23
23
  CONTACT = "moorer@udel.edu"
24
24
  WEBSITE = "https://github.com/mooreryan/iroki"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iroki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Moore
@@ -194,7 +194,11 @@ files:
194
194
  - exe/reorder_nodes
195
195
  - iroki.gemspec
196
196
  - lib/iroki.rb
197
+ - lib/iroki/biom.rb
197
198
  - lib/iroki/color/color.rb
199
+ - lib/iroki/color/gradient.rb
200
+ - lib/iroki/color/palette/palette.rb
201
+ - lib/iroki/color/single_sample_gradient.rb
198
202
  - lib/iroki/const/const.rb
199
203
  - lib/iroki/core_ext/file/file.rb
200
204
  - lib/iroki/core_ext/hash/hash.rb