Skip to content

Commit 30d2ae9

Browse files
committed
add cartoon to TagPileupWindow
This commit primarily takes care of adding the read fragment cartoon to clarify parameter selection for users. #71 TagPileupWindow: - create instance of cartoon component and add to the window frame - adjust other components as necessary to maintain balance and function - add method to update cartoon when read aspect or read type are toggled ReadFragmentCartoon: - create graphic component object that can be updated and repainted in response to changes to "aspect" and "read" - add JavaDocs comments PileupParameters - add and reorganize fields to include final static integers that track the encodings for each parameter (like aliases)
1 parent 0e4420a commit 30d2ae9

3 files changed

Lines changed: 246 additions & 45 deletions

File tree

src/objects/PileupParameters.java

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,42 @@
33
import java.io.File;
44
import java.io.PrintStream;
55

6+
/**
7+
* Object for storing pileup-related parameter information and constants.
8+
* @see scripts.Read_Analysis.PileupScripts.PileupExtract
9+
* @author William KM Lai
10+
*/
11+
612
public class PileupParameters {
7-
//Directory to save matrix and composite into
8-
private File OUTPUT = null;
9-
//Composite values file if output
10-
private PrintStream COMPOSITE = null;
13+
//Read aspect
14+
final static int FIVE = 0;
15+
final static int THREE = 1;
16+
final static int MIDPOINT = 2;
17+
final static int FRAGMENT = 3;
18+
private int ASPECT = PileupParameters.FIVE;
19+
20+
//Read type
21+
final static int READ1 = 0;
22+
final static int READ2 = 1;
23+
final static int ALLREADS = 2;
24+
private int READ = PileupParameters.READ1;
1125

12-
//Read aspect:
13-
// 0=5prime end, 1=3prime end, 2=midpoint, 3=fullfragment
14-
private int ASPECT = 0;
15-
//Read type:
16-
// 0=read1, 1=read2, 2=allreads
17-
private int READ = 0;
26+
//Strand type
27+
final static int COMBINED = 1;
28+
final static int SEPARATE = 0;
29+
private int STRAND = PileupParameters.SEPARATE;
1830

19-
//Strand type:
20-
// 0=separate, 1=combined
21-
private int STRAND = 0;
31+
//Transformation/smoothing type
32+
final static int NO_SMOOTH = 0;
33+
final static int WINDOW = 1;
34+
final static int GAUSSIAN = 2;
35+
private int TRANS = PileupParameters.NO_SMOOTH;
2236

23-
//Transformation/smoothing type:
24-
// 0=no_smooth, 1=window, 2=gaussian
25-
private int TRANS = 0;
2637
//TRANS=1 parameters: window size (#bins)
2738
private int SMOOTH = 0;
28-
//TRANS=2 parameters: stdev window size (#bins) and number of standard devations
39+
//TRANS=2 parameters: stdev window size (#bins) and number of standard deviations
2940
private int STDSIZE = 0;
30-
private int STDNUM = 0;
41+
private int STDNUM = 0;
3142

3243
private int SHIFT = 0;
3344
private int BIN = 1;
@@ -43,7 +54,12 @@ public class PileupParameters {
4354

4455
private int MIN_INSERT = -9999;
4556
private int MAX_INSERT = -9999;
46-
57+
58+
//Directory to save matrix and composite into
59+
private File OUTPUT = null;
60+
//Composite values file if output
61+
private PrintStream COMPOSITE = null;
62+
4763
public void printAll(){
4864
System.out.println( "<><><><><><><><><><><><><><><><><><><><>" );
4965
System.out.println( "private File OUTPUT = " + OUTPUT );
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
package objects;
2+
3+
import java.awt.Color;
4+
import java.awt.Dimension;
5+
import java.awt.Graphics;
6+
import java.awt.Polygon;
7+
8+
import java.util.ArrayList;
9+
10+
import javax.swing.JPanel;
11+
12+
/**
13+
* Component that displays a graphic of a sequenced DNA fragment with annotated
14+
* Read1, Read2, and dynamically updating encoding reference points marked by
15+
* arrows.
16+
*
17+
* @author Olivia Lang
18+
*
19+
*/
20+
public class ReadFragmentCartoon extends JPanel {
21+
22+
int readHeight = 20;
23+
int readWidth = 100;
24+
public int cartoonHeight = 80;
25+
public int arrowHeight = 15;
26+
public int arrowWidth = 6;
27+
int fragmentLength = 480;
28+
int fragmentThickness = 3;
29+
int edgePad = 20;
30+
int verticalPad;
31+
32+
public ArrayList<Polygon> arrows = new ArrayList<Polygon>(6);
33+
34+
@Override
35+
protected void paintComponent(Graphics g) {
36+
super.paintComponent(g);
37+
38+
// Determine distance from top of graphic
39+
verticalPad = (cartoonHeight - 2*(readHeight) - fragmentThickness - arrowHeight) / 2 + arrowHeight;
40+
41+
// Draw Read 1
42+
g.setColor(Color.CYAN);
43+
g.fillRect(edgePad, verticalPad, readWidth, readHeight);
44+
45+
// Draw Read 2
46+
g.setColor(Color.ORANGE);
47+
g.fillRect(edgePad+fragmentLength - readWidth, verticalPad + readHeight + fragmentThickness, readWidth, readHeight);
48+
49+
// Draw Fragment
50+
g.setColor(Color.BLACK);
51+
g.fillRect(edgePad, verticalPad + readHeight, fragmentLength, fragmentThickness);
52+
53+
// Label Reads
54+
g.drawString("Read1", edgePad, verticalPad + readHeight - 1);
55+
g.drawString("Read2", edgePad + fragmentLength - 37, verticalPad + 2*readHeight + fragmentThickness - 1);
56+
57+
// Draw arrows
58+
for (int p=0; p<arrows.size(); p++) {
59+
g.fillPolygon(arrows.get(p));
60+
}
61+
}
62+
63+
/**
64+
* Update graphic to reflect changes in aspect and read encodings.
65+
*
66+
* @param aspect
67+
* @param read
68+
*/
69+
public void redrawArrows(int aspect, int read) {
70+
verticalPad = (cartoonHeight - (2 * readHeight) - fragmentThickness - arrowHeight) / 2 + arrowHeight;
71+
arrows = new ArrayList<Polygon>(2);
72+
int topY = verticalPad - arrowHeight;
73+
if (aspect == PileupParameters.FRAGMENT) { // handle fragment
74+
// arrows.add(bigArrow());
75+
for (int i = 0; i < fragmentLength; i += 6) {
76+
arrows.add(arrow(edgePad + i, topY));
77+
}
78+
} else if (aspect == PileupParameters.MIDPOINT) { // handle midpoint
79+
arrows.add(arrow(edgePad + fragmentLength / 2, topY));
80+
} else if (aspect == PileupParameters.THREE) { // handle 3 prime ends
81+
if (read == PileupParameters.READ1 || read == PileupParameters.ALLREADS) {
82+
arrows.add(arrow(edgePad + readWidth, topY));
83+
}
84+
if (read == PileupParameters.READ2 || read == PileupParameters.ALLREADS) {
85+
arrows.add(arrow(edgePad + fragmentLength - readWidth, topY));
86+
}
87+
} else if (aspect == PileupParameters.FIVE) { // handle 5 prime ends
88+
if (read == PileupParameters.READ1 || read == PileupParameters.ALLREADS) {
89+
arrows.add(arrow(edgePad, topY));
90+
}
91+
if (read == PileupParameters.READ2 || read == PileupParameters.ALLREADS) {
92+
arrows.add(arrow(edgePad + fragmentLength, topY));
93+
}
94+
}
95+
repaint();
96+
}
97+
98+
/**
99+
* Unused legacy code for how Full Fragment was initially represented: a
100+
* rightward-pointing arrow across length of DNA fragment.
101+
* @return
102+
*/
103+
public Polygon bigArrow() {
104+
int arrowThickness = 5;
105+
int arrowHead = 20;
106+
int arrowflank = (arrowHeight - arrowThickness)/2;
107+
108+
int xPoly[] = {edgePad, edgePad+fragmentLength-arrowHead, edgePad+fragmentLength-arrowHead,
109+
edgePad+fragmentLength, edgePad +fragmentLength -arrowHead, edgePad+fragmentLength-arrowHead, edgePad};
110+
int yPoly[] = {verticalPad-arrowflank, verticalPad-arrowflank, verticalPad, verticalPad-arrowHeight/2,
111+
verticalPad-arrowHeight, verticalPad-arrowHeight+arrowflank, verticalPad-arrowHeight+arrowflank};
112+
return(new Polygon(xPoly,yPoly,xPoly.length));
113+
}
114+
115+
/**
116+
* Draw downward-pointing arrow at (x,y) coordinate (upper-center) for marking
117+
* where on the DNA fragment coverage is tallied on this graphic. Arrow size is
118+
* arrowHeight tall (15px) and flank*2 (6px) wide.
119+
*
120+
* (x,y)
121+
* ||
122+
* ||
123+
* ||
124+
* ||
125+
* \ /
126+
* \/
127+
*
128+
* @param x
129+
* @param y
130+
* @return
131+
*/
132+
public Polygon arrow(int x,int y) {
133+
134+
// arrowhead flank size
135+
int flank = arrowWidth/2;
136+
// arrow thickness
137+
int thick = 2;
138+
// arrowhead height
139+
int head = 5;
140+
141+
x = x-thick/2;
142+
143+
int xPoly[] = {x, x, x-flank, x+thick/2, x+thick+flank, x+thick, x+thick};
144+
int yPoly[] = {y, y+arrowHeight-head, y+arrowHeight-head, y+arrowHeight, y+arrowHeight-head, y+arrowHeight-head, y};
145+
return(new Polygon(xPoly,yPoly,xPoly.length));
146+
}
147+
148+
@Override
149+
public Dimension getPreferredSize() {
150+
return new Dimension(800,cartoonHeight);
151+
}
152+
}

0 commit comments

Comments
 (0)