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.client.bio;
26
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.ListIterator;
30
31
32
33
34
35
36
37 public class InfoSilkGenerator extends OnGenomeDataVisitorBase {
38
39 public ArrayList<String> lines = new ArrayList<String>();
40
41 public String getSilk() {
42 StringBuilder buf = new StringBuilder();
43 for (String each : lines) {
44 buf.append(each);
45 buf.append("\n");
46 }
47 return buf.toString();
48 }
49
50 public List<String> getLines() {
51 return lines;
52 }
53
54 public void addLine(String text) {
55 lines.add(text);
56 }
57
58 @Override
59 public void visitBEDGene(BEDGene g) {
60 visitGene(g);
61 addLine("-score:" + g.score);
62
63 if (!g.getCDS().isEmpty()) {
64
65 CDS cds = g.getCDS().get(0);
66 addLine("-thick start: " + cds.start);
67 addLine("-thick end: " + cds.end);
68 addLine("-thick width: " + (cds.end - cds.start));
69
70
71 int cdsLength = 0;
72 for (Exon e : g.getExon()) {
73 Interval overlap = e.intersect(cds);
74 if (overlap == null)
75 continue;
76 cdsLength += overlap.length();
77 }
78 addLine("-thick length: " + cdsLength);
79
80 int len_UTR5 = 0;
81 for (Exon e : g.getExon()) {
82 Interval overlap = e.intersect(cds);
83 if (overlap == null) {
84 len_UTR5 += e.length();
85 continue;
86 }
87 else {
88 len_UTR5 += (overlap.getStart() - e.getStart());
89 break;
90 }
91 }
92
93 int len_UTR3 = 0;
94 for (ListIterator<Exon> it = g.getExon().listIterator(g.getExon().size()); it.hasPrevious();) {
95 Exon e = it.previous();
96 Interval overlap = e.intersect(cds);
97 if (overlap == null) {
98 len_UTR3 += e.length();
99 continue;
100 }
101 else {
102 len_UTR3 += (e.getEnd() - overlap.getEnd());
103 break;
104 }
105 }
106
107 if (g.isAntiSense()) {
108
109 int tmp = len_UTR5;
110 len_UTR5 = len_UTR3;
111 len_UTR3 = tmp;
112 }
113
114 if (len_UTR5 > 0)
115 addLine("-UTR length 5': " + len_UTR5);
116 if (len_UTR3 > 0)
117 addLine("-UTR length 3': " + len_UTR3);
118 }
119
120 }
121
122 @Override
123 public void visitGap(Gap g) {
124
125 }
126
127 @Override
128 public void visitInterval(Interval interval) {
129 addLine("-name: " + interval.getName());
130 addLine("-start: " + interval.getStart());
131 addLine("-end: " + interval.getEnd());
132 addLine("-length: " + interval.length());
133 }
134
135 @Override
136 public void visitRead(Read r) {
137 visitInterval(r);
138 addLine("-strand: " + r.getStrand());
139 }
140
141 @Override
142 public void visitSAMRead(SAMRead r) {
143 visitSAMReadLight(r);
144
145 if (r.iSize != 0)
146 addLine("-insert size: " + r.iSize);
147 addLine("-mapq: " + r.mapq);
148 if (r.isPairedRead()) {
149 addLine("-mate ref: " + r.mrnm);
150 addLine("-mate start: " + r.mStart);
151 }
152
153 addLine("-tag");
154 for (String key : r.tag.keySet()) {
155 addLine(" -" + key + ": " + r.tag.get(key));
156 }
157 }
158
159 @Override
160 public void visitSAMReadLight(SAMReadLight r) {
161 visitInterval(r);
162 addLine("-flag: " + Integer.toBinaryString(r.flag));
163 addLine("-strand: " + (r.isSense() ? "+" : "-"));
164 addLine("-cigar: " + r.cigar);
165 }
166
167 @Override
168 public void visitSequence(ReferenceSequence referenceSequence) {
169
170 }
171
172 @Override
173 public void visitReadCoverage(ReadCoverage readCoverage) {
174 addLine("-name: " + readCoverage.getName());
175 addLine("-start: " + readCoverage.getStart());
176 addLine("-end: " + readCoverage.getEnd());
177 addLine("-pixel width: " + readCoverage.pixelWidth);
178 }
179
180 @Override
181 public void visitSAMReadPairFragment(SAMReadPairFragment fragment) {
182 super.visitSAMReadPairFragment(fragment);
183 addLine("-mate start: " + fragment.mateStart);
184
185 }
186
187 @Override
188 public void visitGraph(GraphData graph) {
189 addLine("graph data");
190 }
191
192 @Override
193 public void visitReadList(ReadList readList) {
194 visitInterval(readList);
195 }
196
197 }