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.format.bed;
26
27 import java.sql.ResultSet;
28 import java.sql.SQLException;
29 import java.util.ArrayList;
30 import java.util.StringTokenizer;
31
32 import org.utgenome.gwt.utgb.client.bio.BEDGene;
33 import org.utgenome.gwt.utgb.client.bio.CDS;
34 import org.utgenome.gwt.utgb.client.bio.Exon;
35 import org.utgenome.gwt.utgb.client.bio.Gene;
36 import org.utgenome.gwt.utgb.client.bio.OnGenome;
37
38
39
40
41
42
43
44 public class BEDEntry extends BEDGene {
45
46 private static final long serialVersionUID = 1L;
47
48 public static BEDEntry createFromResultSet(String chr, ResultSet rs) throws SQLException {
49
50 BEDEntry gene = new BEDEntry();
51 gene.coordinate = chr;
52 gene.setStart(rs.getInt(1));
53 gene.setEnd(rs.getInt(2));
54
55 gene.setName(rs.getString(3));
56 gene.score = rs.getInt(4);
57 gene.setStrand(rs.getString(5));
58
59 ArrayList<int[]> regionList = readRegions(rs.getString(6));
60 for (int[] region : regionList) {
61 CDS cds = new CDS(region[0], region[1]);
62 gene.addCDS(cds);
63 }
64
65 regionList = readRegions(rs.getString(7));
66 for (int[] region : regionList) {
67 Exon exon = new Exon(region[0], region[1]);
68 gene.addExon(exon);
69 }
70
71 gene.setColor(rs.getString(8));
72
73 return gene;
74 }
75
76 private static ArrayList<int[]> readRegions(String string) {
77 ArrayList<int[]> res = new ArrayList<int[]>();
78
79 StringTokenizer st = new StringTokenizer(string, "[] ,");
80 while (st.hasMoreTokens()) {
81 String str = st.nextToken();
82
83
84 if (str.startsWith("(")) {
85 int[] region = new int[2];
86 region[0] = Integer.valueOf(str.substring(1)).intValue();
87
88
89 while (st.hasMoreTokens()) {
90 str = st.nextToken();
91 if (str.endsWith(")")) {
92 region[1] = Integer.valueOf(str.substring(0, str.length() - 1)).intValue();
93 res.add(region);
94 break;
95 }
96 }
97 }
98 }
99 return res;
100 }
101
102 @Override
103 public String toString() {
104 return String.format("%s: %s:%d-%d\t%s\t%s\t%s\t%s", getName(), coordinate, getStart(), getEnd(), getStrand(), getCDS(), getExon(), getColor());
105
106 }
107
108 }