Skip to content

Commit e15b347

Browse files
committed
Merge branch 'master' into dev
2 parents f1fcd97 + ea80229 commit e15b347

12 files changed

Lines changed: 733 additions & 307 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: 17 additions & 21 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,12 @@ 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", "--transparent" }, description = "Value indicating transparency of heatmap, 0 to 255 (default=255)\n")
71+
private int alpha = 255;
72+
73+
@Option(names = { "-b", "--background" }, description = "Set a transparent background for the heatmap minimum values (default=white)\n")
74+
private boolean transparentBackground = false;
75+
7176

7277
String scaleType = "treeview";
7378
Color MAXCOLOR = Color.BLACK;
@@ -84,7 +89,7 @@ public Integer call() throws Exception {
8489

8590
// Generate HeatMap
8691
TwoColorHeatMap script_object = new TwoColorHeatMap(CDT, MAXCOLOR, startROW, startCOL, pixelHeight, pixelWidth,
87-
scaleType, absolute, percentile, output, true);
92+
scaleType, absolute, percentile, output, true, transparentBackground);
8893
script_object.run();
8994

9095
System.err.println("Image Generated.");
@@ -114,16 +119,6 @@ private String validateInput() throws IOException {
114119
output = new File(NAME + "_" + scaleType + ".png");
115120
// check output filename is valid
116121
} else {
117-
// check ext
118-
try {
119-
if (!"png".equals(ExtensionFileFilter.getExtension(output))) {
120-
r += "(!)Use PNG extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output)
121-
+ ".png\n";
122-
}
123-
} catch (NullPointerException e) {
124-
r += "(!)Output filename must have extension: use PNG extension for output filename. Try: " + output
125-
+ ".png\n";
126-
}
127122
// check directory
128123
if (output.getParent() == null) {
129124
// System.err.println("default to current directory");
@@ -136,14 +131,7 @@ private String validateInput() throws IOException {
136131
if (compression < 1 || compression > 4) {
137132
r += "(!)Compression must be integer 1-4. Please select from the available compression types.";
138133
}
139-
// check that hex string is formatted properly
140-
if (color.custom != null) {
141-
Pattern hexColorPat = Pattern.compile("[0-9A-Fa-f]{6}");
142-
Matcher m = hexColorPat.matcher(color.custom);
143-
if (!m.matches()) {
144-
r += "(!)Color must be formatted as a hexidecimal String!\n\tExpected input string format: \"[0-9A-Fa-f]{6}\"";
145-
}
146-
}
134+
147135
// check scaling is valid input
148136
if (absolute == -999 && percentile == -999) {
149137
absolute = 10;
@@ -165,8 +153,16 @@ private String validateInput() throws IOException {
165153
MAXCOLOR = Color.BLUE;
166154
} else if (color.custom != null) {
167155
System.err.println("Decoding color: 0x" + color.custom);
168-
MAXCOLOR = Color.decode("0x" + color.custom);
156+
// check that hex string is formatted properly
157+
Pattern hexColorPat = Pattern.compile("[0-9A-Fa-f]{6}");
158+
Matcher m = hexColorPat.matcher(color.custom);
159+
if (!m.matches()) {
160+
r += "(!)Color must be formatted as a hexidecimal String!\n\tExpected input string format: \"[0-9A-Fa-f]{6}\"";
161+
} else { MAXCOLOR = Color.decode("0x" + color.custom); }
169162
}
163+
// check that Alpha channel/transparency values are formatted properly and decode/assign colors
164+
if (alpha<0 || alpha>255) { r += "(!)Alpha/transparency value for higher values (max) must be a numeric 0 to 255\n"; }
165+
else { MAXCOLOR = new Color(MAXCOLOR.getRed(), MAXCOLOR.getGreen(), MAXCOLOR.getBlue(), alpha); }
170166

171167
return (r);
172168
}

src/cli/Read_Analysis/TagPileupCLI.java

Lines changed: 50 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ static class OutputOptions{
5858
private boolean tab = false;
5959
}
6060

61+
//Aspect
62+
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Aspect of Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n")
63+
AspectType aspectType = new AspectType();
64+
static class AspectType {
65+
@Option(names = {"-5", "--five-prime"}, description = "pileup of 5' end of read(default)")
66+
boolean fiveprime = false;
67+
@Option(names = {"-3", "--three-prime"}, description = "pileup of 3' end of read")
68+
boolean threeprime = false;
69+
@Option(names = {"-m", "--midpoint"}, description = "pileup fragment midpoints (require PE, combined)")
70+
boolean midpoint = false;
71+
}
72+
6173
//Read
6274
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n")
6375
ReadType readType = new ReadType();
@@ -68,9 +80,6 @@ static class ReadType {
6880
boolean read2 = false;
6981
@Option(names = {"-a", "--all-reads"}, description = "pileup all reads")
7082
boolean allreads = false;
71-
@Option(names = {"-m", "--midpoint"}, description = "pile midpoint (require PE and combined, -p --combined)")
72-
boolean midpoint = false;
73-
int finalRead = 0;
7483
}
7584

7685
//Strand
@@ -148,15 +157,15 @@ public Integer call() throws Exception {
148157
private String validateInput() throws IOException {
149158
String r = "";
150159

151-
//check ReadType, interpret booleans for int value
152-
if(readType.read1){ readType.finalRead = 0; }
153-
else if(readType.read2){ readType.finalRead = 1; }
154-
else if(readType.allreads){ readType.finalRead = 2; }
155-
else if(readType.midpoint){
156-
readType.finalRead = 3;
157-
filterOptions.requirePE = true;
158-
combStatus = true;
159-
}
160+
// Set ASPECT
161+
if(aspectType.fiveprime) { p.setAspect(0); }
162+
else if(aspectType.threeprime) { p.setAspect(1); }
163+
else if(aspectType.midpoint) { p.setAspect(2); }
164+
165+
// Set READ
166+
if(readType.read1){ p.setRead(0); }
167+
else if(readType.read2){ p.setRead(1); }
168+
else if(readType.allreads){ p.setRead(2); }
160169

161170
//check input extensions
162171
if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){
@@ -192,39 +201,15 @@ else if(readType.midpoint){
192201
}
193202
}
194203

195-
//set default output MATRIX (if output MATRIX not to be output)
196-
if(outputOptions.outputMatrix.size()>1){
197-
outputOptions.outputMatrix.set(0,null);
198-
//set default output MATRIX basename (allow scripts/*/TagPileup to generate ret of filename)
199-
} else if(outputOptions.outputMatrix.size()==0){ //generate default basename
200-
String readString = "read1";
201-
if(readType.finalRead == 1) { readString = "read2"; }
202-
else if(readType.finalRead == 2) { readString = "allreads"; }
203-
else if(readType.finalRead == 3) { readString = "midpoint"; }
204-
outputOptions.outputMatrix.add(
205-
ExtensionFileFilter.stripExtension(new File(bedFile.getName())) + "_" +
206-
ExtensionFileFilter.stripExtension(new File(bamFile.getName())) + "_" + readString);
207-
//check output filename is valid
208-
}else{ //check basename
209-
File output = new File(outputOptions.outputMatrix.get(0));
210-
//no extension check b/c basename should have no extension
211-
//check directory
212-
if(output.getParent()==null){
213-
// System.err.println("default to current directory");
214-
} else if(!new File(output.getParent()).exists()){
215-
r += "(!)Check output.MATRIX directory exists: " + output.getParent() + "\n";
216-
}
217-
}
218-
219204
//validate smooth params
220205
if(smoothType.winVals!=-9999 && smoothType.winVals<1){ r += "(!)Invalid Smoothing Window Size. Must be larger than 0 bins, winSize=" + smoothType.winVals + "\n"; }
221206
if(smoothType.winVals!=-9999 && smoothType.winVals%2==0){ r += "(!)Invalid Smoothing Window Size. Must be odd for symmetrical smoothing (so that the window is centered properly), winSize=" + smoothType.winVals + "\n"; }
222207
if(smoothType.gaussVals[0]!=-9999 && smoothType.gaussVals[0]<1){ r += "(!)Invalid Standard Deviation Size. Must be larger than 0 bins, stdSize=" + smoothType.gaussVals[0] + "\n"; }
223208
if(smoothType.gaussVals[1]!=-9999 && smoothType.gaussVals[1]<1){ r += "(!)Invalid Number of Standard Deviations. Must be larger than 0 standard deviations, stdNum=" + smoothType.gaussVals[1] + "\n"; }
224209

225210
//set require PE for appropriate flags
226-
if( filterOptions.MIN_INSERT!=-9999 || filterOptions.MAX_INSERT!=-9999){ filterOptions.requirePE = true; }
227-
if( readType.midpoint ){ filterOptions.requirePE = true; }
211+
p.setPErequire(filterOptions.requirePE);
212+
if( filterOptions.MIN_INSERT!=-9999 || filterOptions.MAX_INSERT!=-9999 || p.getAspect()==2) { p.setPErequire(true); }
228213

229214
//validate shift, binSize, and CPUs
230215
if(calcOptions.shift<0){ r += "(!)Invalid shift! Must be non-negative, shift=" + calcOptions.shift + "\n"; }
@@ -238,38 +223,41 @@ else if(readType.midpoint){
238223
r += "(!)MAX_INSERT must be larger/equal to MIN_INSERT: " + filterOptions.MIN_INSERT + "," + filterOptions.MAX_INSERT + "\n";
239224
}
240225

241-
// LOAD UP PileupParameters OBJECT!
242-
243-
//Set OUTPUT
244-
if(outputOptions.outputMatrix.size()<=1){
245-
p.setOutputType(2); //default behavior
246-
//check output type
247-
if(outputOptions.cdt && outputOptions.tab) { //both set? write error
248-
r += "(!)Cannot flag both --cdt and --tab. Please choose one.";
249-
} else if(outputOptions.tab){ //set tab
250-
p.setOutputType(1);
251-
}
252-
}else{
253-
outputOptions.outputMatrix.set(0,null);
254-
p.setOutputType(0); //no matrix output
255-
if(outputOptions.cdt){
256-
p.setOutputType(2);
257-
outputOptions.outputMatrix.set(0,null);
258-
} else if(outputOptions.tab) {
259-
p.setOutputType(1);
260-
outputOptions.outputMatrix.set(0,null);
226+
// No Matrix Output
227+
if(outputOptions.outputMatrix.size() > 1){
228+
p.setOutputType(0);
229+
if(outputOptions.cdt || outputOptions.tab) { r += "(!)Cannot flag --cdt or --tab without -M."; }
230+
// Output Matrix
231+
} else {
232+
// Determine output type
233+
p.setOutputType(2);
234+
if(outputOptions.cdt && outputOptions.tab) { r += "(!)Cannot flag both --cdt and --tab. Please choose one."; }
235+
else if(outputOptions.tab) { p.setOutputType(1); }
236+
// No matrix basename specified
237+
if(outputOptions.outputMatrix.size() == 0) {
238+
outputOptions.outputMatrix.add(null);
239+
if(p.getOutputDirectory() == null) {
240+
p.setOutputDirectory(new File(System.getProperty("user.dir")));
241+
}
242+
// Validate matrix specified basename
243+
} else if(outputOptions.outputMatrix.size() == 1) {
244+
File output = new File(outputOptions.outputMatrix.get(0));
245+
// Check parent directory is non-null and exists
246+
if(output.getParent()!=null){
247+
if(!new File(output.getParent()).exists()) {
248+
r += "(!)Check output.MATRIX directory exists: " + output.getParent() + "\n";
249+
}
250+
}
261251
}
262252
}
263-
p.setOutputCompositeStatus(true);
264253

265254
//Set COMPOSITE file
255+
p.setOutputCompositeStatus(true);
266256
p.setCompositePrintStream(new PrintStream(outputOptions.outputComposite));
267257

268-
//Set READ
269-
p.setRead(readType.finalRead);
270258
//Set STRAND
271259
p.setStrand(0);
272-
if(combStatus) { p.setStrand(1); }
260+
if(combStatus || p.getAspect() == 2) { p.setStrand(1); }
273261

274262
//Set smooth type and parameters
275263
if(smoothType.noSmooth){ //default behavior
@@ -299,9 +287,6 @@ else if(readType.midpoint){
299287
p.setBlacklist(filterOptions.blacklistFilter);
300288
p.setStandard(calcOptions.tagsEqual);
301289

302-
//Set PE requirement
303-
p.setPErequire(filterOptions.requirePE);
304-
305290
//Set output statuses
306291
p.setGZIPstatus(outputOptions.zip);
307292

0 commit comments

Comments
 (0)