Skip to content

Commit 73ca966

Browse files
committed
handle alpha colors in CLI heatmaps
Both TwoColorHeatMap and ThreeColorHeatMap CLI should also handle alpha channel color values so that CLI mimics GUI functionality (#66). Both CLI contain lines that validate alpha value as numeric 0 to 255 and update the color's alpha channel. Their flags are related to the letter "t" for transparency. Also contains bug fix in ThreeColorHM such that more than one color can be specified in a single call (before there was a restriction imposed for one color being changed at a time). TwoColorHM was also adjusted to avoid redundancy. The check for custom color being selected occurred more than once so the hexcode decoding block was moved.
1 parent 7727d94 commit 73ca966

2 files changed

Lines changed: 38 additions & 12 deletions

File tree

src/cli/Figure_Generation/ThreeColorHeatMapCLI.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static class MaxGroup {
7676
@Option(names = {"-0", "--include-zeros"}, description = "used with `-p` flag, indicating exclusion of zero values when calculating percentile thresholds")
7777
private boolean includeZeros = false;
7878

79-
@ArgGroup(multiplicity = "0..1", heading = "%nSelect heatmap colors:%n")
79+
@ArgGroup(multiplicity = "0..1", exclusive=false, heading = "%nSelect heatmap colors:%n")
8080
private ColorGroup color = new ColorGroup();
8181
static class ColorGroup {
8282
@Option(names = {"-cn", "--color-min"}, description = "Color indicating minimum values (default=YELLOW) For custom color: type hexadecimal string to represent colors (e.g. \"FF0000\" is hexadecimal for red).\n See <http://www.javascripter.net/faq/rgbtohex.htm> for some color options with their corresponding hex strings.\n")
@@ -88,7 +88,20 @@ static class ColorGroup {
8888
@Option(names = {"-ca", "--color-nan"}, description = "Color indicating not-a-number values (default=GRAY) For custom color: type hexadecimal string to represent colors (e.g. \"FF0000\" is hexadecimal for red).\n See <http://www.javascripter.net/faq/rgbtohex.htm> for some color options with their corresponding hex strings.\n")
8989
private String nan = null;
9090
}
91-
91+
92+
@ArgGroup(multiplicity = "0..1", exclusive=false, heading = "%nSelect transparency of heatmap colors (alpha channel):%n")
93+
private AlphaGroup alpha = new AlphaGroup();
94+
static class AlphaGroup {
95+
@Option(names = {"-tn", "--transparent-min"}, description = "Value indicating transparency of minimum values, 0 to 255 (default=255)\n")
96+
private int min = 255;
97+
@Option(names = {"-td", "--transparent-mid"}, description = "Value indicating transparency of middle values, 0 to 255 (default=255)\n")
98+
private int mid = 255;
99+
@Option(names = {"-tx", "--transparent-max"}, description = "Value indicating transparency of maximum values, 0 to 255 (default=255)\n")
100+
private int max = 255;
101+
@Option(names = {"-ta", "--transparent-nan"}, description = "Value indicating transparency of not-a-number values, 0 to 255 (default=255)\n")
102+
private int nan = 255;
103+
}
104+
92105
String scaleType = "treeview";
93106
//Colors from JavaTreeview microarray software
94107
Color CMAX = new Color(254,255,0,255);
@@ -217,6 +230,16 @@ private String validateInput() throws IOException {
217230
System.err.println("Decoding NaN color: 0x" + color.nan);
218231
CNAN = Color.decode("0x" + color.nan);
219232
}
233+
// check that Alpha channel/transparency values are formatted properly and decode/assign colors
234+
if (alpha.max<0 || alpha.max>255) { r += "(!)Alpha/transparency value for higher values (max) must be a numeric 0 to 255\n"; }
235+
else { CMAX = new Color(CMAX.getRed(), CMAX.getGreen(), CMAX.getBlue(), alpha.max); }
236+
if (alpha.mid<0 || alpha.mid>255) { r += "(!)Alpha/transparency value for middling values (mid) must be a numeric 0 to 255\n"; }
237+
else { CMID = new Color(CMID.getRed(), CMID.getGreen(), CMID.getBlue(), alpha.mid); }
238+
if (alpha.min<0 || alpha.min>255) { r += "(!)Alpha/transparency value for lower values(min) must be a numeric 0 to 255\n"; }
239+
else { CMIN = new Color(CMIN.getRed(), CMIN.getGreen(), CMIN.getBlue(), alpha.min); }
240+
if (alpha.nan<0 || alpha.nan>255) { r += "(!)Alpha/transparency value for invalid/non-numeric values(NaN) must be a numeric 0 to 255\n"; }
241+
else { CNAN = new Color(CNAN.getRed(), CNAN.getGreen(), CNAN.getBlue(), alpha.nan); }
242+
220243
// assign vals for contrast thresholds and set bools
221244
if(maxGroup.percentile!=null) {
222245
MAX = maxGroup.percentile;

src/cli/Figure_Generation/TwoColorHeatMapCLI.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public class TwoColorHeatMapCLI implements Callable<Integer> {
5656

5757
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect heatmap color:%n\t@|fg(red) (select no more than one of these options)|@%n")
5858
private ColorGroup color = new ColorGroup();
59-
6059
static class ColorGroup {
6160
@Option(names = { "--black" }, description = "Use the color black for generating the heatmap (default)")
6261
private boolean black = false;
@@ -68,6 +67,9 @@ static class ColorGroup {
6867
"--color" }, description = "For custom color: type hexadecimal string to represent colors (e.g. \"FF0000\" is hexadecimal for red).\n See <http://www.javascripter.net/faq/rgbtohex.htm> for some color options with their corresponding hex strings.\n")
6968
private String custom = null;
7069
}
70+
@Option(names = { "-t",
71+
"--transparent" }, description = "Value indicating transparency of heatmap, 0 to 255 (default=255)\\n")
72+
private int alpha = 255;
7173

7274
String scaleType = "treeview";
7375
Color MAXCOLOR = Color.BLACK;
@@ -140,14 +142,7 @@ private String validateInput() throws IOException {
140142
if (compression < 1 || compression > 4) {
141143
r += "(!)Compression must be integer 1-4. Please select from the available compression types.";
142144
}
143-
// check that hex string is formatted properly
144-
if (color.custom != null) {
145-
Pattern hexColorPat = Pattern.compile("[0-9A-Fa-f]{6}");
146-
Matcher m = hexColorPat.matcher(color.custom);
147-
if (!m.matches()) {
148-
r += "(!)Color must be formatted as a hexidecimal String!\n\tExpected input string format: \"[0-9A-Fa-f]{6}\"";
149-
}
150-
}
145+
151146
// check scaling is valid input
152147
if (absolute == -999 && percentile == -999) {
153148
absolute = 10;
@@ -169,8 +164,16 @@ private String validateInput() throws IOException {
169164
MAXCOLOR = Color.BLUE;
170165
} else if (color.custom != null) {
171166
System.err.println("Decoding color: 0x" + color.custom);
172-
MAXCOLOR = Color.decode("0x" + color.custom);
167+
// check that hex string is formatted properly
168+
Pattern hexColorPat = Pattern.compile("[0-9A-Fa-f]{6}");
169+
Matcher m = hexColorPat.matcher(color.custom);
170+
if (!m.matches()) {
171+
r += "(!)Color must be formatted as a hexidecimal String!\n\tExpected input string format: \"[0-9A-Fa-f]{6}\"";
172+
} else { MAXCOLOR = Color.decode("0x" + color.custom); }
173173
}
174+
// check that Alpha channel/transparency values are formatted properly and decode/assign colors
175+
if (alpha<0 || alpha>255) { r += "(!)Alpha/transparency value for higher values (max) must be a numeric 0 to 255\n"; }
176+
else { MAXCOLOR = new Color(MAXCOLOR.getRed(), MAXCOLOR.getGreen(), MAXCOLOR.getBlue(), alpha); }
174177

175178
return (r);
176179
}

0 commit comments

Comments
 (0)