1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.gwt.utgb.server.app;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.io.Serializable;
30 import java.util.List;
31
32 import javax.servlet.ServletException;
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpServletResponse;
35
36 import org.utgenome.UTGBException;
37 import org.utgenome.format.bed.BEDDatabase;
38 import org.utgenome.graphics.GeneCanvas;
39 import org.utgenome.graphics.GenomeWindow;
40 import org.utgenome.gwt.utgb.client.bio.ChrLoc;
41 import org.utgenome.gwt.utgb.client.bio.OnGenome;
42 import org.utgenome.gwt.utgb.server.WebTrackBase;
43 import org.xerial.lens.SilkLens;
44 import org.xerial.util.log.Logger;
45
46
47
48
49
50
51
52 public class BEDViewer extends WebTrackBase implements Serializable {
53
54 private static final long serialVersionUID = 1L;
55
56 private static Logger _logger = Logger.getLogger(BEDViewer.class);
57
58 public String species = "human";
59 public String revision = "hg18";
60 public String name = "chr22";
61 public int start = 1;
62 public int end = 1000000;
63 public int width = 700;
64 public String fileName;
65
66 @Override
67 public void handle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
68
69 try {
70 List<OnGenome> geneList = BEDDatabase.overlapQuery(new File(getProjectRootPath(), fileName), new ChrLoc(name, start, end));
71
72 String suffix = getActionSuffix(request);
73
74 if (suffix != null && suffix.equals("silk")) {
75 response.setContentType("text/plain");
76 response.getWriter().print(SilkLens.toSilk(geneList));
77 }
78 else {
79 GeneCanvas geneCanvas = new GeneCanvas(width, 300, new GenomeWindow(start, end));
80 geneCanvas.draw(geneList);
81
82 response.setContentType("image/png");
83 geneCanvas.toPNG(response.getOutputStream());
84 }
85 }
86 catch (UTGBException e) {
87 _logger.error(e);
88 e.printStackTrace();
89 }
90 }
91
92 }