1
2
3
4
5
6
7 package org.utgenome.gwt.utgb.server.app;
8
9 import java.awt.Color;
10 import java.io.IOException;
11 import java.util.HashMap;
12
13 import javax.servlet.ServletException;
14 import javax.servlet.http.HttpServletRequest;
15 import javax.servlet.http.HttpServletResponse;
16
17 import org.utgenome.graphics.GenomeCanvas;
18 import org.utgenome.graphics.GenomeWindow;
19 import org.utgenome.gwt.utgb.server.WebTrackBase;
20 import org.utgenome.gwt.utgb.server.util.graphic.GraphicUtil;
21 import org.xerial.util.log.Logger;
22
23
24
25
26
27 public class ACGT extends WebTrackBase {
28 private static final long serialVersionUID = 1L;
29 private static Logger _logger = Logger.getLogger(ACGT.class);
30
31
32
33
34
35 private static final int DEFAULT_HEIGHT = 12;
36
37 private static final String DEFAULT_COLOR_A = "50B6E8";
38 private static final String DEFAULT_COLOR_C = "E7846E";
39 private static final String DEFAULT_COLOR_G = "84AB51";
40 private static final String DEFAULT_COLOR_T = "FFA930";
41 private static final String DEFAULT_COLOR_N = "FFFFFF";
42
43 public String colorA = DEFAULT_COLOR_A;
44 public String colorC = DEFAULT_COLOR_C;
45 public String colorG = DEFAULT_COLOR_G;
46 public String colorT = DEFAULT_COLOR_T;
47 public String colorN = DEFAULT_COLOR_N;
48
49 public int fontWidth = 12;
50 public int height = DEFAULT_HEIGHT;
51 private static float fontSize = 10.5f;
52
53 private HashMap<Character, Color> colorTable = new HashMap<Character, Color>();
54
55 public ACGT() {
56 }
57
58 @Override
59 public void handle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
60
61 if (fontWidth < 1 || height < 1) {
62 return;
63 }
64
65 final int letterSize = 9;
66
67 boolean drawLetter = height >= DEFAULT_HEIGHT - 2;
68
69 final HashMap<Character, String> colorTable = new HashMap<Character, String>();
70 colorTable.put('A', colorA);
71 colorTable.put('C', colorC);
72 colorTable.put('G', colorG);
73 colorTable.put('T', colorT);
74 colorTable.put('N', colorN);
75 GenomeCanvas canvas = new GenomeCanvas(fontWidth * letterSize, height * 2, new GenomeWindow(1, letterSize));
76
77 final String letters = "ACGTacgtN";
78
79 final int repeatColorAlpha = 70;
80 final Color defaultTextColor = new Color(255, 255, 255);
81 final Color repeatTextColor = new Color(140, 140, 140);
82
83 for (int y = 0; y < 2; y++) {
84 int baseYPos = height * (y + 1) - 2;
85 long offset = 1;
86 for (int i = 0; i < letters.length(); ++i) {
87 char ch = letters.charAt(i);
88 boolean isRepeatChar = Character.isLowerCase(ch);
89 if (isRepeatChar)
90 ch = Character.toUpperCase(ch);
91
92 Color textColor = isRepeatChar ? repeatTextColor : defaultTextColor;
93 if (y == 0) {
94 String colorStr = colorTable.containsKey(ch) ? colorTable.get(ch) : "E0E0E0";
95 Color color = isRepeatChar ? GraphicUtil.parseColor(colorStr, repeatColorAlpha) : GraphicUtil.parseColor(colorStr);
96 canvas.drawGeneRect(offset, offset + 1L, 0, height, color);
97 }
98
99
100
101
102 if (drawLetter)
103 canvas.drawBase(letters.substring(i, i + 1), offset, offset + 1L, baseYPos, fontSize, textColor);
104
105 offset++;
106 }
107 }
108 canvas.outputImage(response, "png");
109 }
110
111 }