iroki 0.0.35 → 0.0.36
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.
- checksums.yaml +4 -4
- data/exe/iroki +3 -3
- data/lib/iroki/biom.rb +2 -1
- data/lib/iroki/color/color.rb +10 -2
- data/lib/iroki/color/gradient.rb +1 -1
- data/lib/iroki/color/palette/palette.rb +0 -12
- data/lib/iroki/color/single_group_gradient.rb +0 -3
- data/lib/iroki/const/const.rb +0 -11
- data/lib/iroki/core_ext/file/file.rb +46 -113
- data/lib/iroki/core_ext/string/string.rb +0 -8
- data/lib/iroki/main/main.rb +13 -0
- data/lib/iroki/tree.rb +26 -9
- data/lib/iroki/utils/utils.rb +12 -4
- data/lib/iroki/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: cc9840c73024ff89c424b094e52f70b474d1ffa1
         | 
| 4 | 
            +
              data.tar.gz: 9c6cbea037206118e5e2bd3174b3553f0a00df2d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e278234fdd472f4ce6452701d2c1151b7a433df70081eaaf867b7011a64edfd5ef306061ea94c7c9526d2d2892b3f2ca317f1341e56216d5ccfd107992d55915
         | 
| 7 | 
            +
              data.tar.gz: a621bf4408197fa5db28c28b51b8c12a13284e2328a28e39cdb8ed81a46544c8d879a5b009f39235158cd2eac575c40b5d5fa22536cbb216a777ffb2ed81adf2
         | 
    
        data/exe/iroki
    CHANGED
    
    | @@ -39,9 +39,9 @@ opts = Trollop.options do | |
| 39 39 | 
             
                  "Color branches?",
         | 
| 40 40 | 
             
                  short: "-b")
         | 
| 41 41 |  | 
| 42 | 
            -
              opt(: | 
| 42 | 
            +
              opt(:color_labels,
         | 
| 43 43 | 
             
                  "Color label names?",
         | 
| 44 | 
            -
                  short: "- | 
| 44 | 
            +
                  short: "-l")
         | 
| 45 45 |  | 
| 46 46 | 
             
              opt(:exact,
         | 
| 47 47 | 
             
                  "Exact pattern matching")
         | 
| @@ -99,7 +99,7 @@ end | |
| 99 99 |  | 
| 100 100 | 
             
            Iroki::Main.main(
         | 
| 101 101 | 
             
              color_branches:             opts[:color_branches],
         | 
| 102 | 
            -
              color_taxa_names:           opts[: | 
| 102 | 
            +
              color_taxa_names:           opts[:color_labels],
         | 
| 103 103 | 
             
              exact:                      opts[:exact],
         | 
| 104 104 | 
             
              remove_bootstraps_below:    opts[:remove_bootstraps_below],
         | 
| 105 105 | 
             
              color_map_f:                opts[:color_map],
         | 
    
        data/lib/iroki/biom.rb
    CHANGED
    
    | @@ -49,7 +49,8 @@ module Iroki | |
| 49 49 | 
             
                        first_line_count = the_counts.count
         | 
| 50 50 | 
             
                      else
         | 
| 51 51 | 
             
                        abort_unless first_line_count == the_counts.count,
         | 
| 52 | 
            -
                                     "Line number #{idx+1} (#{line.inspect})  | 
| 52 | 
            +
                                     "Line number #{idx+1} (#{line.inspect}) " +
         | 
| 53 | 
            +
                                     "in the " +
         | 
| 53 54 | 
             
                                     "biom file has #{the_counts.count} " +
         | 
| 54 55 | 
             
                                     "columns when it should have " +
         | 
| 55 56 | 
             
                                     "#{first_line_count} columns like the " +
         | 
    
        data/lib/iroki/color/color.rb
    CHANGED
    
    | @@ -725,8 +725,16 @@ module Iroki | |
| 725 725 | 
             
                    colors = COLORS
         | 
| 726 726 | 
             
                  end
         | 
| 727 727 |  | 
| 728 | 
            -
                   | 
| 729 | 
            -
             | 
| 728 | 
            +
                  unless colors.has_key? col
         | 
| 729 | 
            +
                    if col.match(/\A[0-9]+\Z/)
         | 
| 730 | 
            +
                      msg = "Color '#{col}' is not defined. " +
         | 
| 731 | 
            +
                            "Did you forget the --auto-color option?"
         | 
| 732 | 
            +
                    else
         | 
| 733 | 
            +
                      msg = "Color '#{col}' is not defined."
         | 
| 734 | 
            +
                    end
         | 
| 735 | 
            +
             | 
| 736 | 
            +
                    abort_if true, msg
         | 
| 737 | 
            +
                  end
         | 
| 730 738 |  | 
| 731 739 | 
             
                  hex = colors[col]
         | 
| 732 740 | 
             
                  %Q{[&!color="#{hex.upcase}"]}
         | 
    
        data/lib/iroki/color/gradient.rb
    CHANGED
    
    | @@ -55,7 +55,7 @@ module Iroki | |
| 55 55 | 
             
                    old_min = old_min.to_f
         | 
| 56 56 | 
             
                    old_max = old_max.to_f
         | 
| 57 57 |  | 
| 58 | 
            -
            (new_max - ((((new_max - new_min) * (x - old_min.to_f)) / (old_max - old_min)) + new_min)) + new_min
         | 
| 58 | 
            +
                    (new_max - ((((new_max - new_min) * (x - old_min.to_f)) / (old_max - old_min)) + new_min)) + new_min
         | 
| 59 59 | 
             
                  end
         | 
| 60 60 |  | 
| 61 61 | 
             
                  def patterns
         | 
| @@ -1,18 +1,6 @@ | |
| 1 1 | 
             
            module Iroki
         | 
| 2 2 | 
             
              module Color
         | 
| 3 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 4 | 
             
                  KELLY = {
         | 
| 17 5 | 
             
                    "1"  => { name: "purple",          hex: "#875692" },
         | 
| 18 6 | 
             
                    "2"  => { name: "orange",          hex: "#F38400" },
         | 
| @@ -53,8 +53,6 @@ module Iroki | |
| 53 53 |  | 
| 54 54 | 
             
                      col =
         | 
| 55 55 | 
             
                        Iroki::Color::GREEN.mix_with Iroki::Color::BLUE, rel_abund
         | 
| 56 | 
            -
                      # col =
         | 
| 57 | 
            -
                      #   Iroki::Color::BLUE.mix_with Iroki::Color::GREEN, rel_abund
         | 
| 58 56 |  | 
| 59 57 | 
             
                      col.luminosity = lumin
         | 
| 60 58 |  | 
| @@ -65,7 +63,6 @@ module Iroki | |
| 65 63 | 
             
                  def single_color_gradient_hex_codes
         | 
| 66 64 | 
             
                    @rel_abunds.zip(@lumins).map do |rel_abund, lumin|
         | 
| 67 65 | 
             
                      amt_of_orig_color =
         | 
| 68 | 
            -
                        # scale rel_abund, new_min=10, new_max=95
         | 
| 69 66 | 
             
                        scale rel_abund, new_min=@min_lumin, new_max=@max_lumin
         | 
| 70 67 |  | 
| 71 68 | 
             
                      col =
         | 
    
        data/lib/iroki/const/const.rb
    CHANGED
    
    | @@ -18,17 +18,6 @@ | |
| 18 18 |  | 
| 19 19 | 
             
            module Iroki
         | 
| 20 20 | 
             
              module Const
         | 
| 21 | 
            -
                COPYRIGHT = "2016 Ryan Moore"
         | 
| 22 | 
            -
                CONTACT   = "moorer@udel.edu"
         | 
| 23 | 
            -
                WEBSITE   = "https://github.com/mooreryan/color_tree"
         | 
| 24 | 
            -
                LICENSE   = "GPLv3"
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                VERSION_BANNER = "  # Version: #{Iroki::VERSION}
         | 
| 27 | 
            -
              # Copyright #{COPYRIGHT}
         | 
| 28 | 
            -
              # Contact: #{CONTACT}
         | 
| 29 | 
            -
              # Website: #{WEBSITE}
         | 
| 30 | 
            -
              # License: #{LICENSE}"
         | 
| 31 | 
            -
             | 
| 32 21 | 
             
                FIG = 'begin figtree;
         | 
| 33 22 | 
             
            	set appearance.backgroundColorAttribute="Default";
         | 
| 34 23 | 
             
            	set appearance.backgroundColour=#-1;
         | 
| @@ -21,14 +21,14 @@ def color_given? str | |
| 21 21 | 
             
            end
         | 
| 22 22 |  | 
| 23 23 | 
             
            # TODO spec this for hex matching
         | 
| 24 | 
            -
            def  | 
| 24 | 
            +
            def label_tag? str
         | 
| 25 25 | 
             
              m = str.match(/\Alabel:(#?\p{Alnum}+)\Z/i)
         | 
| 26 26 |  | 
| 27 27 | 
             
              m[1] if m
         | 
| 28 28 | 
             
            end
         | 
| 29 29 |  | 
| 30 30 | 
             
            # TODO spec this for hex matching
         | 
| 31 | 
            -
            def  | 
| 31 | 
            +
            def branch_tag? str
         | 
| 32 32 | 
             
              m = str.match(/\Abranch:(#?\p{Alnum}+)\Z/i)
         | 
| 33 33 |  | 
| 34 34 | 
             
              m[1] if m
         | 
| @@ -60,87 +60,8 @@ module Iroki | |
| 60 60 | 
             
                    arg
         | 
| 61 61 | 
             
                  end
         | 
| 62 62 |  | 
| 63 | 
            -
                  # TODO  | 
| 64 | 
            -
                   | 
| 65 | 
            -
                                      exact_matching: true,
         | 
| 66 | 
            -
                                      auto_color: false
         | 
| 67 | 
            -
             | 
| 68 | 
            -
                    check_file fname, :color_map
         | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
                    patterns = {}
         | 
| 72 | 
            -
                    Object::File.open(fname, "rt").each_line do |line|
         | 
| 73 | 
            -
                      unless line.start_with? "#"
         | 
| 74 | 
            -
                        label_tag = ""
         | 
| 75 | 
            -
                        branch_tag = ""
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                        pattern, label_color, branch_color = line.chomp.split "\t"
         | 
| 78 | 
            -
             | 
| 79 | 
            -
                        # color = "black" if color.nil? || color.empty?
         | 
| 80 | 
            -
             | 
| 81 | 
            -
                        assert pattern, "found no pattern"
         | 
| 82 | 
            -
             | 
| 83 | 
            -
                        if exact_matching # TODO should this really be everytime?
         | 
| 84 | 
            -
                          pattern = pattern#.clean_name
         | 
| 85 | 
            -
                        else
         | 
| 86 | 
            -
                          # TODO flag bad regexp
         | 
| 87 | 
            -
                          pattern = Regexp.new pattern
         | 
| 88 | 
            -
                        end
         | 
| 89 | 
            -
             | 
| 90 | 
            -
                        if color_given?(label_color) && color_given?(branch_color)
         | 
| 91 | 
            -
                          abort_if(has_label_tag?(label_color) &&
         | 
| 92 | 
            -
                                   has_label_tag?(branch_color),
         | 
| 93 | 
            -
                                   "Label tag specified twice for '#{line}'")
         | 
| 94 | 
            -
             | 
| 95 | 
            -
                          abort_if(has_branch_tag?(label_color) &&
         | 
| 96 | 
            -
                                   has_branch_tag?(branch_color),
         | 
| 97 | 
            -
                                   "Branch tag specified twice for '#{line}'")
         | 
| 98 | 
            -
                        end
         | 
| 99 | 
            -
             | 
| 100 | 
            -
                        if color_given?(label_color) && !color_given?(branch_color)
         | 
| 101 | 
            -
                          if (color = has_label_tag? label_color)
         | 
| 102 | 
            -
                            label_tag = Iroki::Color.get_tag color, auto_color
         | 
| 103 | 
            -
                          elsif (color = has_branch_tag? label_color)
         | 
| 104 | 
            -
                            branch_tag = Iroki::Color.get_tag color, auto_color
         | 
| 105 | 
            -
                          else
         | 
| 106 | 
            -
                            label_tag = Iroki::Color.get_tag label_color, auto_color
         | 
| 107 | 
            -
                            branch_tag = Iroki::Color.get_tag label_color, auto_color
         | 
| 108 | 
            -
                          end
         | 
| 109 | 
            -
                        else
         | 
| 110 | 
            -
                          if color_given? label_color
         | 
| 111 | 
            -
                            if (color = has_label_tag? label_color)
         | 
| 112 | 
            -
                              label_tag = Iroki::Color.get_tag color, auto_color
         | 
| 113 | 
            -
                            elsif (color = has_branch_tag? label_color)
         | 
| 114 | 
            -
                              branch_tag = Iroki::Color.get_tag color, auto_color
         | 
| 115 | 
            -
                            else
         | 
| 116 | 
            -
                              label_tag = Iroki::Color.get_tag label_color, auto_color
         | 
| 117 | 
            -
                            end
         | 
| 118 | 
            -
                          end
         | 
| 119 | 
            -
             | 
| 120 | 
            -
                          if color_given? branch_color
         | 
| 121 | 
            -
                            if (color = has_branch_tag? branch_color)
         | 
| 122 | 
            -
                              branch_tag = Iroki::Color.get_tag color, auto_color
         | 
| 123 | 
            -
                            elsif (color = has_label_tag? branch_color)
         | 
| 124 | 
            -
                              label_tag = Iroki::Color.get_tag color, auto_color
         | 
| 125 | 
            -
                            else
         | 
| 126 | 
            -
                              branch_tag = Iroki::Color.get_tag branch_color, auto_color
         | 
| 127 | 
            -
                            end
         | 
| 128 | 
            -
                          end
         | 
| 129 | 
            -
                        end
         | 
| 130 | 
            -
             | 
| 131 | 
            -
                        # if auto_color
         | 
| 132 | 
            -
                        #   patterns[pattern] = "[&!color=\"#{auto_colors[color]}\"]"
         | 
| 133 | 
            -
                        # else
         | 
| 134 | 
            -
                        #   patterns[pattern] = Iroki::Color.get_tag color, auto_color
         | 
| 135 | 
            -
                        # end
         | 
| 136 | 
            -
             | 
| 137 | 
            -
                        patterns[pattern] = { label: label_tag, branch: branch_tag }
         | 
| 138 | 
            -
                      end
         | 
| 139 | 
            -
                    end
         | 
| 140 | 
            -
             | 
| 141 | 
            -
                    patterns
         | 
| 142 | 
            -
                  end
         | 
| 143 | 
            -
             | 
| 63 | 
            +
                  # TODO what's the point of the iroki_to_name? To allow wonky
         | 
| 64 | 
            +
                  # chars maybe?
         | 
| 144 65 | 
             
                  def parse_color_map_iroki(fname,
         | 
| 145 66 | 
             
                                            iroki_to_name,
         | 
| 146 67 | 
             
                                            exact_matching: true,
         | 
| @@ -168,7 +89,6 @@ module Iroki | |
| 168 89 | 
             
                        assert pattern, "found no pattern"
         | 
| 169 90 |  | 
| 170 91 | 
             
                        if exact_matching # TODO should this really be everytime?
         | 
| 171 | 
            -
                        # pattern = pattern.clean_name
         | 
| 172 92 | 
             
                          if name_to_iroki.has_key? pattern
         | 
| 173 93 | 
             
                            pattern = name_to_iroki[pattern]
         | 
| 174 94 | 
             
                          else
         | 
| @@ -181,56 +101,72 @@ module Iroki | |
| 181 101 | 
             
                          pattern = Regexp.new pattern
         | 
| 182 102 | 
             
                        end
         | 
| 183 103 |  | 
| 184 | 
            -
                        if color_given?(label_color) && color_given?(branch_color)
         | 
| 185 | 
            -
                          abort_if(has_label_tag?(label_color) &&
         | 
| 186 | 
            -
                                   has_label_tag?(branch_color),
         | 
| 187 | 
            -
                                   "Label tag specified twice for '#{line}'")
         | 
| 188 104 |  | 
| 189 | 
            -
             | 
| 190 | 
            -
             | 
| 191 | 
            -
             | 
| 105 | 
            +
                        if color_given?(label_color) && color_given?(branch_color)
         | 
| 106 | 
            +
                          if label_tag?(label_color) &&
         | 
| 107 | 
            +
                             label_tag?(branch_color)
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                            abort_unless label_color == branch_color,
         | 
| 110 | 
            +
                                         "Label tags specified twice for " +
         | 
| 111 | 
            +
                                         "#{line.inspect}, but the tags don't " +
         | 
| 112 | 
            +
                                         "match."
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                            # ie both are label tags specifying the same color
         | 
| 115 | 
            +
                            branch_color = nil
         | 
| 116 | 
            +
                          elsif branch_tag?(label_color) &&
         | 
| 117 | 
            +
                                branch_tag?(branch_color)
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                            abort_unless label_color == branch_color,
         | 
| 120 | 
            +
                                         "Branch tags specified twice for " +
         | 
| 121 | 
            +
                                         "#{line.inspect}, but the tags don't " +
         | 
| 122 | 
            +
                                         "match."
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                            # ie both are branch tags specifying the same color
         | 
| 125 | 
            +
                            label_color = nil
         | 
| 126 | 
            +
                          end
         | 
| 192 127 | 
             
                        end
         | 
| 193 128 |  | 
| 194 129 | 
             
                        if color_given?(label_color) && !color_given?(branch_color)
         | 
| 195 | 
            -
                          if (color =  | 
| 130 | 
            +
                          if (color = label_tag? label_color)
         | 
| 196 131 | 
             
                            label_tag = Iroki::Color.get_tag color, auto_color
         | 
| 197 | 
            -
                          elsif (color =  | 
| 132 | 
            +
                          elsif (color = branch_tag? label_color)
         | 
| 198 133 | 
             
                            branch_tag = Iroki::Color.get_tag color, auto_color
         | 
| 199 | 
            -
                          elsif line.match(/\t\Z/) # empty branch color, branch | 
| 200 | 
            -
             | 
| 134 | 
            +
                          elsif line.match(/\t\Z/) # empty branch color, branch
         | 
| 135 | 
            +
                                                   # will be black
         | 
| 136 | 
            +
                            label_tag = Iroki::Color.get_tag label_color,
         | 
| 137 | 
            +
                                                             auto_color
         | 
| 201 138 | 
             
                          else
         | 
| 202 | 
            -
                            label_tag = Iroki::Color.get_tag label_color, | 
| 203 | 
            -
             | 
| 139 | 
            +
                            label_tag = Iroki::Color.get_tag label_color,
         | 
| 140 | 
            +
                                                             auto_color
         | 
| 141 | 
            +
                            branch_tag = Iroki::Color.get_tag label_color,
         | 
| 142 | 
            +
                                                              auto_color
         | 
| 204 143 | 
             
                          end
         | 
| 205 144 | 
             
                        else
         | 
| 206 145 | 
             
                          if color_given? label_color
         | 
| 207 | 
            -
                            if (color =  | 
| 146 | 
            +
                            if (color = label_tag? label_color)
         | 
| 208 147 | 
             
                              label_tag = Iroki::Color.get_tag color, auto_color
         | 
| 209 | 
            -
                            elsif (color =  | 
| 148 | 
            +
                            elsif (color = branch_tag? label_color)
         | 
| 210 149 | 
             
                              branch_tag = Iroki::Color.get_tag color, auto_color
         | 
| 211 150 | 
             
                            else
         | 
| 212 | 
            -
                              label_tag = Iroki::Color.get_tag label_color, | 
| 151 | 
            +
                              label_tag = Iroki::Color.get_tag label_color,
         | 
| 152 | 
            +
                                                               auto_color
         | 
| 213 153 | 
             
                            end
         | 
| 214 154 | 
             
                          end
         | 
| 215 155 |  | 
| 216 156 | 
             
                          if color_given? branch_color
         | 
| 217 | 
            -
                            if (color =  | 
| 157 | 
            +
                            if (color = branch_tag? branch_color)
         | 
| 218 158 | 
             
                              branch_tag = Iroki::Color.get_tag color, auto_color
         | 
| 219 | 
            -
                            elsif (color =  | 
| 159 | 
            +
                            elsif (color = label_tag? branch_color)
         | 
| 220 160 | 
             
                              label_tag = Iroki::Color.get_tag color, auto_color
         | 
| 221 161 | 
             
                            else
         | 
| 222 | 
            -
                              branch_tag = Iroki::Color.get_tag branch_color, | 
| 162 | 
            +
                              branch_tag = Iroki::Color.get_tag branch_color,
         | 
| 163 | 
            +
                                                                auto_color
         | 
| 223 164 | 
             
                            end
         | 
| 224 165 | 
             
                          end
         | 
| 225 166 | 
             
                        end
         | 
| 226 167 |  | 
| 227 | 
            -
                         | 
| 228 | 
            -
             | 
| 229 | 
            -
                        # else
         | 
| 230 | 
            -
                        #   patterns[pattern] = Iroki::Color.get_tag color, auto_color
         | 
| 231 | 
            -
                        # end
         | 
| 232 | 
            -
             | 
| 233 | 
            -
                        patterns[pattern] = { label: label_tag, branch: branch_tag }
         | 
| 168 | 
            +
                        patterns[pattern] = { label: label_tag,
         | 
| 169 | 
            +
                                              branch: branch_tag }
         | 
| 234 170 | 
             
                      end
         | 
| 235 171 | 
             
                    end
         | 
| 236 172 |  | 
| @@ -258,9 +194,6 @@ module Iroki | |
| 258 194 | 
             
                        abort_if newname.nil? || newname.empty?,
         | 
| 259 195 | 
             
                                 "Column 2 missing for line: #{line.inspect}"
         | 
| 260 196 |  | 
| 261 | 
            -
                        # oldname = oldname.clean_name
         | 
| 262 | 
            -
                        # newname = newname.clean_name
         | 
| 263 | 
            -
             | 
| 264 197 | 
             
                        abort_if name_map.has_key?(oldname),
         | 
| 265 198 | 
             
                                 "#{oldname} is repeated in column 1"
         | 
| 266 199 |  | 
| @@ -12,16 +12,13 @@ module Iroki | |
| 12 12 | 
             
                  end
         | 
| 13 13 |  | 
| 14 14 | 
             
                  def clean
         | 
| 15 | 
            -
                    # puts %Q{clean: #{self}, #{self.gsub(/'/, '"')}}
         | 
| 16 15 | 
             
                    self.gsub(/'/, '"')
         | 
| 17 16 | 
             
                  end
         | 
| 18 17 |  | 
| 19 18 | 
             
                  def single_quote
         | 
| 20 19 | 
             
                    if self.match /\A'.*'\Z/
         | 
| 21 | 
            -
                      # puts %Q{single_quote if: #{self}, outputing #{self.dup}}
         | 
| 22 20 | 
             
                      self.dup
         | 
| 23 21 | 
             
                    else
         | 
| 24 | 
            -
                      # puts %Q{single_quote else: #{self}, returning '#{self.clean}'}
         | 
| 25 22 | 
             
                      %Q['#{self.clean}']
         | 
| 26 23 | 
             
                    end
         | 
| 27 24 | 
             
                  end
         | 
| @@ -31,11 +28,8 @@ module Iroki | |
| 31 28 | 
             
                      name = match[1]
         | 
| 32 29 | 
             
                      color = match[2]
         | 
| 33 30 |  | 
| 34 | 
            -
                      # puts %Q{clean_name if: #{self}, returning #{name.single_quote + color}}
         | 
| 35 31 | 
             
                      name.single_quote + color
         | 
| 36 | 
            -
                      # name + color
         | 
| 37 32 | 
             
                    else
         | 
| 38 | 
            -
                      # puts %Q{clean_name else: #{self}, returning #{self.single_quote}}
         | 
| 39 33 | 
             
                      self.single_quote
         | 
| 40 34 | 
             
                    end
         | 
| 41 35 | 
             
                  end
         | 
| @@ -44,11 +38,9 @@ module Iroki | |
| 44 38 | 
             
                    self.strip.gsub(/[^\p{Alnum}_]+/, "_").gsub(/_+/, "_")
         | 
| 45 39 | 
             
                  end
         | 
| 46 40 |  | 
| 47 | 
            -
             | 
| 48 41 | 
             
                  def has_single_quote?
         | 
| 49 42 | 
             
                    self.match(/'/)
         | 
| 50 43 | 
             
                  end
         | 
| 51 | 
            -
             | 
| 52 44 | 
             
                end
         | 
| 53 45 | 
             
              end
         | 
| 54 46 | 
             
            end
         | 
    
        data/lib/iroki/main/main.rb
    CHANGED
    
    | @@ -261,6 +261,19 @@ module Iroki | |
| 261 261 | 
             
                  # newick = treeio.next_entry
         | 
| 262 262 | 
             
                  str = File.read newick
         | 
| 263 263 | 
             
                  newick = Bio::Newick.new str, parser: :iroki
         | 
| 264 | 
            +
             | 
| 265 | 
            +
                  # Warn if there is extra info in the newick file
         | 
| 266 | 
            +
                  if newick &&
         | 
| 267 | 
            +
                     newick.entry_overrun &&
         | 
| 268 | 
            +
                     !newick.entry_overrun.chomp.empty?
         | 
| 269 | 
            +
             | 
| 270 | 
            +
                    AbortIf.logger.warn {
         | 
| 271 | 
            +
                      "Extra info (#{newick.entry_overrun}) in newick file " +
         | 
| 272 | 
            +
                        "(#{newick_f}) will be ignored. " +
         | 
| 273 | 
            +
                        "Does your newick file contain multiple trees?"
         | 
| 274 | 
            +
                    }
         | 
| 275 | 
            +
                  end
         | 
| 276 | 
            +
             | 
| 264 277 | 
             
                  tree = newick.tree
         | 
| 265 278 |  | 
| 266 279 | 
             
                  # puts [:tree_first_parsed, tree.newick(indent: false)]
         | 
    
        data/lib/iroki/tree.rb
    CHANGED
    
    | @@ -15,6 +15,9 @@ module Iroki | |
| 15 15 | 
             
                # @param [Bio::Tree] a bio ruby tree object
         | 
| 16 16 | 
             
                #
         | 
| 17 17 | 
             
                # @return [Hash] iroki_name (string) => quoted_orig_name (string)
         | 
| 18 | 
            +
                #
         | 
| 19 | 
            +
                # @todo not a good name as it doesn't actually change the names in
         | 
| 20 | 
            +
                #   the tree
         | 
| 18 21 | 
             
                def self.change_names tree
         | 
| 19 22 | 
             
                  idx = -1
         | 
| 20 23 | 
             
                  realname = {}
         | 
| @@ -50,12 +53,15 @@ module Iroki | |
| 50 53 | 
             
                  hash.values.map(&:single_quote)
         | 
| 51 54 | 
             
                end
         | 
| 52 55 |  | 
| 53 | 
            -
                def self.gsub_iroki_newick_string tre_str, | 
| 56 | 
            +
                def self.gsub_iroki_newick_string tre_str,
         | 
| 57 | 
            +
                                                  iroki_to_name,
         | 
| 58 | 
            +
                                                  name_map=nil
         | 
| 54 59 | 
             
                  if name_map
         | 
| 55 60 | 
             
                    vals = self.quoted_vals name_map
         | 
| 56 61 | 
             
                    name_map_quoted = Hash[name_map.keys.zip(vals)]
         | 
| 57 62 |  | 
| 58 | 
            -
                    iroki_to_new_name = | 
| 63 | 
            +
                    iroki_to_new_name =
         | 
| 64 | 
            +
                      self.combine_hashes iroki_to_name, name_map_quoted
         | 
| 59 65 | 
             
                  else
         | 
| 60 66 | 
             
                    vals = self.quoted_vals iroki_to_name
         | 
| 61 67 |  | 
| @@ -65,22 +71,33 @@ module Iroki | |
| 65 71 | 
             
                  tre_str.gsub(/iroki[0-9]+iroki/, iroki_to_new_name)
         | 
| 66 72 | 
             
                end
         | 
| 67 73 |  | 
| 68 | 
            -
                def self.iroki_to_color iroki_to_name, | 
| 74 | 
            +
                def self.iroki_to_color iroki_to_name,
         | 
| 75 | 
            +
                                        color_map,
         | 
| 76 | 
            +
                                        name_map,
         | 
| 77 | 
            +
                                        nil_val=nil
         | 
| 69 78 | 
             
                  if name_map
         | 
| 70 79 | 
             
                    old_names = name_map.keys
         | 
| 71 80 | 
             
                    new_names = name_map.values
         | 
| 72 81 |  | 
| 73 | 
            -
                    color_map_is_for_old_names = | 
| 74 | 
            -
             | 
| 82 | 
            +
                    color_map_is_for_old_names =
         | 
| 83 | 
            +
                      color_map.keys.all? { |key| old_names.include? key }
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                    color_map_is_for_new_names =
         | 
| 86 | 
            +
                      color_map.keys.all? { |key| new_names.include? key }
         | 
| 75 87 |  | 
| 76 88 | 
             
                    if color_map_is_for_old_names
         | 
| 77 | 
            -
                      iroki_to_color = | 
| 89 | 
            +
                      iroki_to_color =
         | 
| 90 | 
            +
                        self.combine_hashes iroki_to_name, color_map, nil_val
         | 
| 78 91 | 
             
                    elsif color_map_is_for_new_names
         | 
| 79 | 
            -
                      iroki_to_new_name = | 
| 92 | 
            +
                      iroki_to_new_name =
         | 
| 93 | 
            +
                        self.combine_hashes iroki_to_name, name_map
         | 
| 80 94 |  | 
| 81 | 
            -
                      iroki_to_color = | 
| 95 | 
            +
                      iroki_to_color =
         | 
| 96 | 
            +
                        self.combine_hashes iroki_to_new_name, color_map, nil_val
         | 
| 82 97 | 
             
                    else # some old, some new
         | 
| 83 | 
            -
                      abort_if true, | 
| 98 | 
            +
                      abort_if true,
         | 
| 99 | 
            +
                               "The color map has both old and new names in " +
         | 
| 100 | 
            +
                               "the first column."
         | 
| 84 101 | 
             
                    end
         | 
| 85 102 |  | 
| 86 103 | 
             
                    iroki_to_color
         | 
    
        data/lib/iroki/utils/utils.rb
    CHANGED
    
    | @@ -42,16 +42,21 @@ module Iroki | |
| 42 42 | 
             
                    end
         | 
| 43 43 | 
             
                  else
         | 
| 44 44 | 
             
                    assert iroki_to_name, "iroki_to_name arg is nil"
         | 
| 45 | 
            -
                    assert iroki_to_name[node.to_s], | 
| 45 | 
            +
                    assert iroki_to_name[node.to_s],
         | 
| 46 | 
            +
                           "iroki_to_name is missing #{node.to_s}"
         | 
| 46 47 | 
             
                    node_s = iroki_to_name[node.to_s]
         | 
| 47 48 |  | 
| 48 49 | 
             
                    patterns.each do |pattern, this_color|
         | 
| 49 50 | 
             
                      if node_s =~ pattern
         | 
| 50 51 | 
             
                        abort_if already_matched,
         | 
| 51 | 
            -
                                 "Non specific matching for #{node_s}"
         | 
| 52 | 
            +
                                 "Non specific matching for #{node_s}. " +
         | 
| 53 | 
            +
                                 "Previously matched pattern was " +
         | 
| 54 | 
            +
                                 "#{already_matched.inspect}. Current pattern " +
         | 
| 55 | 
            +
                                 "is " +
         | 
| 56 | 
            +
                                 "#{pattern.inspect}. Color was #{this_color}."
         | 
| 52 57 |  | 
| 53 58 | 
             
                        color = this_color
         | 
| 54 | 
            -
                        already_matched =  | 
| 59 | 
            +
                        already_matched = pattern
         | 
| 55 60 | 
             
                      end
         | 
| 56 61 | 
             
                    end
         | 
| 57 62 |  | 
| @@ -93,7 +98,10 @@ module Iroki | |
| 93 98 |  | 
| 94 99 | 
             
                    # NOTE: this was originally before cleaning the node name a
         | 
| 95 100 | 
             
                    # couple lines up, does it matter that it is after?
         | 
| 96 | 
            -
                    color = add_color_to_leaf_branch patterns, | 
| 101 | 
            +
                    color = add_color_to_leaf_branch patterns,
         | 
| 102 | 
            +
                                                     node,
         | 
| 103 | 
            +
                                                     exact,
         | 
| 104 | 
            +
                                                     iroki_to_name
         | 
| 97 105 |  | 
| 98 106 | 
             
                    # add color to the name
         | 
| 99 107 | 
             
                    node.name = node.name + color[:branch] if color
         | 
    
        data/lib/iroki/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: iroki
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.36
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ryan Moore
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017- | 
| 11 | 
            +
            date: 2017-07-07 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         |