Skip to content

Commit 66aa8c1

Browse files
authored
Merge pull request #119 from CEGRcode/working-dev
Rework TagPileup Window Graphics
2 parents 0323fa5 + 40b569c commit 66aa8c1

File tree

69 files changed

+1804
-952
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1804
-952
lines changed

singularity/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Singularity
2+
3+
### Build Singularity Image
4+
```
5+
$ cd scriptmanager
6+
$ singularity build --fakeroot scriptmanager.sif scriptmanager.def
7+
```
8+
9+
### Run from Singularity Image
10+
```
11+
$ singularity exec scriptmanager.sif scriptmanager ${command}
12+
```
13+
14+
**Example:**
15+
```
16+
$ singularity exec scriptmanager.sif scriptmanager coordinate-manipulation bed-to-gff BEDFILE.bed -o OUTPUT.gff
17+
```

src/main/java/scriptmanager/charts/CompositePlot.java

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,31 @@
1616
import org.jfree.data.xy.XYSeries;
1717
import org.jfree.data.xy.XYSeriesCollection;
1818

19+
/**
20+
* Collection of static methods for plotting lines of sense {@literal &}
21+
* antisense or combined composite plots with customizable titles, colors, and
22+
* legends.
23+
*
24+
* @author William KM Lai
25+
* @see scriptmanager.scripts.Sequence_Analysis.DNAShapefromBED
26+
* @see scriptmanager.scripts.Sequence_Analysis.DNAShapefromFASTA
27+
* @see scriptmanager.window_interface.Read_Analysis.TagPileupOutput
28+
*/
1929
public class CompositePlot {
2030

21-
public CompositePlot() {
22-
23-
}
24-
31+
/**
32+
* Create a two-line plot (sense and antisense composites) with a title and
33+
* custom colors. There are no checks on input array lengths (line plot
34+
* determined by length of domain array).
35+
*
36+
* @param x the domain values array
37+
* @param y1 "Sense Strand" values array
38+
* @param y2 "Anti Strand" values array
39+
* @param name title of the plot
40+
* @param COLORS a 2-element array of colors of the sense and antisense lines
41+
* (first color = sense, second color = anti)
42+
* @return the line plot for display
43+
*/
2544
public static ChartPanel createCompositePlot(double[] x, double[] y1, double[] y2, String name, ArrayList<Color> COLORS){
2645
final XYSeriesCollection dataset = new XYSeriesCollection();
2746
final XYSeries seriesF = new XYSeries("Sense Strand");
@@ -39,7 +58,19 @@ public static ChartPanel createCompositePlot(double[] x, double[] y1, double[] y
3958
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
4059
return chartPanel;
4160
}
42-
61+
62+
/**
63+
* Create a one-line plot (combined composites) with a title and custom color.
64+
* There are no checks on input array lengths (line plot determined by length of
65+
* domain array).
66+
*
67+
* @param x the domain values array
68+
* @param y1 "Combined" values array
69+
* @param name title of the plot
70+
* @param COLORS a 1-element array of colors of the sense and antisense lines
71+
* (first color = sense, second color = anti)
72+
* @return the line plot for display
73+
*/
4374
public static Component createCompositePlot(double[] x, double[] y1, String name, ArrayList<Color> COLORS){
4475
final XYSeriesCollection dataset = new XYSeriesCollection();
4576
final XYSeries seriesC = new XYSeries("Data");
@@ -53,17 +84,45 @@ public static Component createCompositePlot(double[] x, double[] y1, String name
5384
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
5485
return chartPanel;
5586
}
56-
87+
88+
/**
89+
* Create a one-line plot (combined composites) with a title using a black line.
90+
* There are no checks on input array lengths (line plot determined by length of
91+
* domain array).
92+
*
93+
* @param x the domain values array
94+
* @param y1 "Combined" values array
95+
* @param name title of the plot
96+
* @return the line plot for display
97+
*/
5798
public static Component createCompositePlot(double[] x, double[] y1, String name){
5899
ArrayList<Color> COLORS = new ArrayList<Color>();
59100
COLORS.add(Color.BLACK);
60101
return(createCompositePlot(x, y1, name, COLORS));
61102
}
62-
103+
104+
/**
105+
* Create line chart with a legend
106+
*
107+
* @param dataset the (x,y) values (agnostic to number of series)
108+
* @param TITLE title of the plot
109+
* @param COLORS colors to use for each data series (depends on dataset)
110+
* @return the line plot
111+
*/
112+
63113
public static JFreeChart createChart(final XYDataset dataset, String TITLE, ArrayList<Color> COLORS) {
64114
return(createChart(dataset, TITLE, COLORS, true));
65115
}
66-
116+
117+
/**
118+
* Create line chart with an optional legend
119+
*
120+
* @param dataset the (x,y) values (agnostic to number of series)
121+
* @param TITLE title of the plot
122+
* @param COLORS colors to use for each dataseries (depends on dataset)
123+
* @param legend to print legend describing series
124+
* @return the line plot
125+
*/
67126
public static JFreeChart createChart(final XYDataset dataset, String TITLE, ArrayList<Color> COLORS, boolean legend) {
68127
//Call Chart
69128
final JFreeChart chart = ChartFactory.createXYLineChart(

src/main/java/scriptmanager/charts/HeatMap.java

Lines changed: 104 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,59 @@
1818
import org.jfree.chart.ui.RectangleEdge;
1919
import org.jfree.chart.ui.RectangleInsets;
2020

21+
/**
22+
* Collection of static methods for formatting and plotting data into heatmaps
23+
* of matrix values
24+
*
25+
* @author William KM Lai
26+
* @see scriptmanager.scripts.BAM_Statistics.BAMGenomeCorrelation
27+
*/
2128
public class HeatMap {
22-
23-
public HeatMap() {
24-
25-
}
26-
27-
public static ChartPanel createCorrelationHeatmap(String[] labels, double[][] MATRIX, File output) {
28-
// create a paint-scale and a legend showing it
29-
LookupPaintScale paintScale = new LookupPaintScale(0, 1, Color.black);
29+
30+
/**
31+
* Constant value encoding the blue to white to red color scale. (0)
32+
*/
33+
public final static short BLUEWHITERED = 0;
34+
/**
35+
* Constant value encoding the jet-like color scale. (0)
36+
*/
37+
public final static short JETLIKE = 1;
38+
39+
/**
40+
* Create a multi-color color scale inspired by Matplotlib's "jet" color scheme.
41+
* 15 starting colors are set to 15 values.
42+
*
43+
* @return jet-like paintscale
44+
*/
45+
private static LookupPaintScale getJetLikeScale() {
46+
LookupPaintScale paintScale = new LookupPaintScale(0, 1, Color.black);
47+
paintScale.add(0.938, Color.decode("#75140C")); //dark blue
48+
paintScale.add(0.871, Color.decode("#C0281B"));
49+
paintScale.add(0.804, Color.decode("#EB4826"));
50+
paintScale.add(0.737, Color.decode("#FF7500"));
51+
paintScale.add(0.670, Color.decode("#F4BC41"));
52+
paintScale.add(0.603, Color.decode("#F3FC53"));
53+
paintScale.add(0.536, Color.decode("#C6FD64"));
54+
paintScale.add(0.469, Color.decode("#9EFC8A"));
55+
paintScale.add(0.402, Color.decode("#81FBBB"));
56+
paintScale.add(0.335, Color.decode("#6DE9EF"));
57+
paintScale.add(0.268, Color.decode("#08A3FF"));
58+
paintScale.add(0.201, Color.decode("#255AF6"));
59+
paintScale.add(0.134, Color.decode("#0912F5"));
60+
paintScale.add(0.134, Color.decode("#0912F5"));
61+
paintScale.add(0.067, Color.decode("#0600C9"));
62+
paintScale.add(0.000, Color.decode("#020080")); //dark red
63+
return paintScale;
64+
}
65+
66+
/**
67+
* Create a paint scale using original BAM Genome Correlation color scale scheme:
68+
* blue (low) to white (mid) to red (high).
69+
*
70+
* @return original blue-white-red paintscale
71+
*/
72+
private static LookupPaintScale getBlueWhiteRedScale() {
73+
LookupPaintScale paintScale = new LookupPaintScale(0, 1, Color.black);
3074
paintScale.add(0.0, new Color(0, 0, 255));
3175
paintScale.add(0.11, new Color(63, 63, 255));
3276
paintScale.add(0.22, new Color(126, 126, 255));
@@ -36,11 +80,39 @@ public static ChartPanel createCorrelationHeatmap(String[] labels, double[][] MA
3680
paintScale.add(0.66, new Color(255, 126, 126));
3781
paintScale.add(0.77, new Color(255, 63, 63));
3882
paintScale.add(0.88, new Color(255, 0, 0));
39-
40-
NumberAxis xAxis = new NumberAxis(null);
41-
xAxis.setVisible(false);
42-
String[] reverselabels = new String[labels.length];
43-
for(int x = 0; x < labels.length; x++) { reverselabels[labels.length - x - 1] = labels[x]; }
83+
return paintScale;
84+
}
85+
86+
/**
87+
* Get paint scale based on scale encoding value.
88+
*
89+
* @param type scale encoding for one of the preset paint scales (e.g.
90+
* REDWHITEBLUE, JETLIKE).
91+
* @return paintscale for the given encoding
92+
*/
93+
public static LookupPaintScale getPresetPaintscale(short type) {
94+
if (type == BLUEWHITERED) { return getBlueWhiteRedScale(); }
95+
else if (type == JETLIKE) { return getJetLikeScale(); }
96+
// Use original red-white-blue paintscale as default
97+
return getBlueWhiteRedScale();
98+
}
99+
100+
/**
101+
* Create a correlation heatmap plot based on a square matrix of inputs with a
102+
* strict percentile-based blue-to-red paint scale (9 levels).
103+
*
104+
* @param labels (sample names) for labeling the y-axis (symmetrical plot so
105+
* x-axis labels are implied)
106+
* @param MATRIX the symmetrical 2D array of values
107+
* @param output the file to write the PNG chart to. File not written if this
108+
* value is null.
109+
* @return the resulting correlation heatmap chart
110+
*/
111+
public static ChartPanel createCorrelationHeatmap(String[] labels, double[][] MATRIX, File output, LookupPaintScale paintScale) {
112+
NumberAxis xAxis = new NumberAxis(null);
113+
xAxis.setVisible(false);
114+
String[] reverselabels = new String[labels.length];
115+
for(int x = 0; x < labels.length; x++) { reverselabels[labels.length - x - 1] = labels[x]; }
44116
SymbolAxis yAxis = new SymbolAxis("Experiments", reverselabels);
45117
XYPlot plot = new XYPlot(createDataset(MATRIX), xAxis, yAxis, null);
46118
XYBlockRenderer r = new XYBlockRenderer();
@@ -52,7 +124,7 @@ public static ChartPanel createCorrelationHeatmap(String[] labels, double[][] MA
52124
JFreeChart chart = new JFreeChart("Correlation Matrix", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
53125
NumberAxis scaleAxis = new NumberAxis("Scale");
54126
scaleAxis.setAxisLinePaint(Color.white);
55-
scaleAxis.setTickMarkPaint(Color.white);
127+
scaleAxis.setTickMarkPaint(Color.white);
56128
PaintScaleLegend legend = new PaintScaleLegend(paintScale, scaleAxis);
57129
legend.setSubdivisionCount(128);
58130
legend.setAxisLocation(AxisLocation.TOP_OR_RIGHT);
@@ -64,19 +136,28 @@ public static ChartPanel createCorrelationHeatmap(String[] labels, double[][] MA
64136
chart.addSubtitle(legend);
65137
chart.setBackgroundPaint(Color.white);
66138

67-
if(output!=null){
68-
int width = 640;
69-
int height = 480;
70-
try{ ChartUtils.saveChartAsPNG(output, chart, width, height); }
71-
catch( IOException e ){ e.printStackTrace(); }
139+
// Save PNG if output filepath given
140+
if (output!=null) {
141+
int width = 640;
142+
int height = 480;
143+
try{ ChartUtils.saveChartAsPNG(output, chart, width, height); }
144+
catch( IOException ioe ){ ioe.printStackTrace(); }
145+
catch( Exception e ){ e.printStackTrace(); }
72146
}
73-
147+
74148
return new ChartPanel(chart);
75149
}
76-
150+
151+
152+
/**
153+
* Helper method for formatting data into the XYZDatset type
154+
*
155+
* @param MATRIX the 2-d array of values to convert
156+
* @return the formatted data series
157+
*/
77158
private static XYZDataset createDataset(double[][] MATRIX) {
78-
//The heatmap is based on a standard XY scatterplot as as such, is built with 0,0 in the lower left
79-
//The matrix must be rotated such that the final output is consistent
159+
//The heatmap is based on a standard XY scatterplot as as such, is built with 0,0 in the lower left
160+
//The matrix must be rotated such that the final output is consistent
80161
DefaultXYZDataset dataset = new DefaultXYZDataset();
81162
int N = MATRIX.length;
82163
for (int i = 0; i < N; i++) {

src/main/java/scriptmanager/charts/Histogram.java

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,54 @@
1616
import org.jfree.data.xy.XYSeries;
1717
import org.jfree.data.xy.XYSeriesCollection;
1818

19+
/**
20+
* Collection of static methods for plotting interactive histograms.
21+
*
22+
* @author William KM Lai
23+
* @see scriptmanager.scripts.BAM_Statistics.PEStats
24+
*/
1925
public class Histogram {
20-
21-
public Histogram() {
2226

23-
}
24-
27+
/**
28+
* Plot a set of bar-style plots using the frequencies (y) of values (x)
29+
* parallel input arrays.
30+
*
31+
* @param y the list of frequencies
32+
* @param x the list of values that have frequencies (same len as y)
33+
* @return the bar-style histogram chart
34+
* @throws IOException
35+
*/
2536
public static ChartPanel createBarChart(double[] y, int[] x) throws IOException {
2637
final XYSeries series = new XYSeries("Frequency");
2738
for(int i = 0; i < x.length; i++) {
2839
series.add((double)x[i], (double)y[i]);
2940
}
3041
final XYSeriesCollection dataset = new XYSeriesCollection(series);
3142

32-
JFreeChart chart = createChart(dataset);
43+
JFreeChart chart = createChart(dataset);
3344
final ChartPanel chartPanel = new ChartPanel(chart);
3445
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
35-
return chartPanel;
46+
return chartPanel;
3647
}
37-
48+
49+
/**
50+
* Plot a set of bar-style plots using the frequencies (y) of values (x)
51+
* parallel input arrays and save the chart as a PNG.
52+
*
53+
* @param y the list of frequencies
54+
* @param x the list of values that have frequencies (same len as y)
55+
* @param output the path of the PNG file to save the chart image to
56+
* @return the bar-style histogram chart
57+
* @throws IOException
58+
*/
3859
public static ChartPanel createBarChart(double[] y, int[] x, File output) throws IOException {
3960
final XYSeries series = new XYSeries("Frequency");
4061
for(int i = 0; i < x.length; i++) {
4162
series.add((double)x[i], (double)y[i]);
4263
}
4364
final XYSeriesCollection dataset = new XYSeriesCollection(series);
4465

45-
JFreeChart chart = createChart(dataset);
66+
JFreeChart chart = createChart(dataset);
4667
final ChartPanel chartPanel = new ChartPanel(chart);
4768
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
4869

@@ -51,9 +72,18 @@ public static ChartPanel createBarChart(double[] y, int[] x, File output) throws
5172
int height = 480;
5273
ChartUtils.saveChartAsPNG(output, chart, width, height);
5374
}
54-
return chartPanel;
75+
return chartPanel;
5576
}
56-
77+
78+
/**
79+
* Helper method to turn a formatted dataset into a standard chart with specific
80+
* look configurations including hard coded titles, axis labels, orientation,
81+
* legend, tooltips, grid colors, etc).
82+
*
83+
* @param dataset the formatted dataset to plot
84+
* @return the formatted and configured histogram chart
85+
* @throws IOException
86+
*/
5787
private static JFreeChart createChart(IntervalXYDataset dataset) throws IOException {
5888
final JFreeChart chart = ChartFactory.createXYBarChart(
5989
"Paired-End Insert Size Frequency Histogram", // chart title
@@ -88,6 +118,6 @@ private static JFreeChart createChart(IntervalXYDataset dataset) throws IOExcept
88118
//target.setPaint(new Color(222, 222, 255, 128));
89119
//plot.addRangeMarker(target, Layer.BACKGROUND);
90120

91-
return chart;
121+
return chart;
92122
}
93123
}

0 commit comments

Comments
 (0)