1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import jalview.api.FeatureColourI; |
24 |
|
import jalview.bin.Cache; |
25 |
|
import jalview.datamodel.AlignmentAnnotation; |
26 |
|
import jalview.datamodel.SequenceI; |
27 |
|
import jalview.datamodel.features.FeatureMatcherSetI; |
28 |
|
import jalview.io.AnnotationFile; |
29 |
|
import jalview.io.FeaturesFile; |
30 |
|
import jalview.io.JalviewFileChooser; |
31 |
|
import jalview.io.JalviewFileView; |
32 |
|
import jalview.util.MessageManager; |
33 |
|
|
34 |
|
import java.awt.BorderLayout; |
35 |
|
import java.awt.Color; |
36 |
|
import java.awt.FlowLayout; |
37 |
|
import java.awt.event.ActionEvent; |
38 |
|
import java.awt.event.ActionListener; |
39 |
|
import java.io.FileWriter; |
40 |
|
import java.io.PrintWriter; |
41 |
|
import java.util.List; |
42 |
|
import java.util.Map; |
43 |
|
|
44 |
|
import javax.swing.BorderFactory; |
45 |
|
import javax.swing.ButtonGroup; |
46 |
|
import javax.swing.JButton; |
47 |
|
import javax.swing.JInternalFrame; |
48 |
|
import javax.swing.JLabel; |
49 |
|
import javax.swing.JLayeredPane; |
50 |
|
import javax.swing.JPanel; |
51 |
|
import javax.swing.JRadioButton; |
52 |
|
import javax.swing.SwingConstants; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
@author |
60 |
|
|
61 |
|
|
|
|
| 0% |
Uncovered Elements: 130 (130) |
Complexity: 28 |
Complexity Density: 0.29 |
|
62 |
|
public class AnnotationExporter extends JPanel |
63 |
|
{ |
64 |
|
private JInternalFrame frame; |
65 |
|
|
66 |
|
private AlignmentPanel ap; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
private boolean exportFeatures = true; |
72 |
|
|
73 |
|
private AlignmentAnnotation[] annotations; |
74 |
|
|
75 |
|
private boolean wholeView; |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
77 |
0 |
public AnnotationExporter(AlignmentPanel panel)... |
78 |
|
{ |
79 |
0 |
this.ap = panel; |
80 |
0 |
try |
81 |
|
{ |
82 |
0 |
jbInit(); |
83 |
|
} catch (Exception ex) |
84 |
|
{ |
85 |
0 |
ex.printStackTrace(); |
86 |
|
} |
87 |
|
|
88 |
0 |
frame = new JInternalFrame(); |
89 |
0 |
frame.setContentPane(this); |
90 |
0 |
frame.setLayer(JLayeredPane.PALETTE_LAYER); |
91 |
0 |
Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width, |
92 |
|
frame.getPreferredSize().height); |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
98 |
0 |
public void exportFeatures()... |
99 |
|
{ |
100 |
0 |
exportFeatures = true; |
101 |
0 |
CSVFormat.setVisible(false); |
102 |
0 |
frame.setTitle(MessageManager.getString("label.export_features")); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
108 |
0 |
public void exportAnnotations()... |
109 |
|
{ |
110 |
0 |
boolean showAnnotation = ap.av.isShowAnnotation(); |
111 |
0 |
exportAnnotation(showAnnotation ? null |
112 |
|
: ap.av.getAlignment().getAlignmentAnnotation(), true); |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
@param |
119 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
120 |
0 |
public void exportAnnotation(AlignmentAnnotation toExport)... |
121 |
|
{ |
122 |
0 |
exportAnnotation(new AlignmentAnnotation[] { toExport }, false); |
123 |
|
} |
124 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
125 |
0 |
private void exportAnnotation(AlignmentAnnotation[] toExport,... |
126 |
|
boolean forWholeView) |
127 |
|
{ |
128 |
0 |
wholeView = forWholeView; |
129 |
0 |
annotations = toExport; |
130 |
0 |
exportFeatures = false; |
131 |
0 |
GFFFormat.setVisible(false); |
132 |
0 |
CSVFormat.setVisible(true); |
133 |
0 |
frame.setTitle(MessageManager.getString("label.export_annotations")); |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
136 |
0 |
private void toFile_actionPerformed()... |
137 |
|
{ |
138 |
|
|
139 |
0 |
JalviewFileChooser chooser = new JalviewFileChooser( |
140 |
|
Cache.getProperty("LAST_DIRECTORY")); |
141 |
|
|
142 |
0 |
chooser.setFileView(new JalviewFileView()); |
143 |
0 |
chooser.setDialogTitle(exportFeatures |
144 |
|
? MessageManager.getString("label.save_features_to_file") |
145 |
|
: MessageManager.getString("label.save_annotation_to_file")); |
146 |
0 |
chooser.setToolTipText(MessageManager.getString("action.save")); |
147 |
|
|
148 |
0 |
int value = chooser.showSaveDialog(this); |
149 |
|
|
150 |
0 |
if (value == JalviewFileChooser.APPROVE_OPTION) |
151 |
|
{ |
152 |
0 |
String text = getText(); |
153 |
|
|
154 |
0 |
try |
155 |
|
{ |
156 |
0 |
PrintWriter out = new PrintWriter( |
157 |
|
new FileWriter(chooser.getSelectedFile())); |
158 |
0 |
out.print(text); |
159 |
0 |
out.close(); |
160 |
|
} catch (Exception ex) |
161 |
|
{ |
162 |
0 |
ex.printStackTrace(); |
163 |
|
} |
164 |
|
} |
165 |
|
|
166 |
0 |
close_actionPerformed(); |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
@return |
174 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
175 |
0 |
private String getText()... |
176 |
|
{ |
177 |
0 |
return exportFeatures ? getFeaturesText() : getAnnotationsText(); |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
@return |
185 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
186 |
0 |
private String getAnnotationsText()... |
187 |
|
{ |
188 |
0 |
String text; |
189 |
0 |
if (CSVFormat.isSelected()) |
190 |
|
{ |
191 |
0 |
text = new AnnotationFile().printCSVAnnotations(annotations); |
192 |
|
} |
193 |
|
else |
194 |
|
{ |
195 |
0 |
if (wholeView) |
196 |
|
{ |
197 |
0 |
text = new AnnotationFile().printAnnotationsForView(ap.av); |
198 |
|
} |
199 |
|
else |
200 |
|
{ |
201 |
0 |
text = new AnnotationFile().printAnnotations(annotations, null, |
202 |
|
null); |
203 |
|
} |
204 |
|
} |
205 |
0 |
return text; |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
@return |
213 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
214 |
0 |
private String getFeaturesText()... |
215 |
|
{ |
216 |
0 |
String text; |
217 |
0 |
SequenceI[] sequences = ap.av.getAlignment().getSequencesArray(); |
218 |
0 |
Map<String, FeatureColourI> featureColours = ap.getFeatureRenderer() |
219 |
|
.getDisplayedFeatureCols(); |
220 |
0 |
Map<String, FeatureMatcherSetI> featureFilters = ap.getFeatureRenderer() |
221 |
|
.getFeatureFilters(); |
222 |
0 |
List<String> featureGroups = ap.getFeatureRenderer() |
223 |
|
.getDisplayedFeatureGroups(); |
224 |
0 |
boolean includeNonPositional = ap.av.isShowNPFeats(); |
225 |
|
|
226 |
0 |
FeaturesFile formatter = new FeaturesFile(); |
227 |
0 |
if (GFFFormat.isSelected()) |
228 |
|
{ |
229 |
0 |
text = formatter.printGffFormat(sequences, featureColours, |
230 |
|
featureGroups, includeNonPositional); |
231 |
|
} |
232 |
|
else |
233 |
|
{ |
234 |
0 |
text = formatter.printJalviewFormat(sequences, featureColours, |
235 |
|
featureFilters, featureGroups, includeNonPositional); |
236 |
|
} |
237 |
0 |
return text; |
238 |
|
} |
239 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
240 |
0 |
private void toTextbox_actionPerformed()... |
241 |
|
{ |
242 |
0 |
CutAndPasteTransfer cap = new CutAndPasteTransfer(); |
243 |
|
|
244 |
0 |
try |
245 |
|
{ |
246 |
0 |
String text = getText(); |
247 |
0 |
cap.setText(text); |
248 |
0 |
Desktop.addInternalFrame(cap, (exportFeatures ? MessageManager |
249 |
|
.formatMessage("label.features_for_params", new String[] |
250 |
|
{ ap.alignFrame.getTitle() }) |
251 |
|
: MessageManager.formatMessage("label.annotations_for_params", |
252 |
|
new String[] |
253 |
|
{ ap.alignFrame.getTitle() })), |
254 |
|
600, 500); |
255 |
|
} catch (OutOfMemoryError oom) |
256 |
|
{ |
257 |
0 |
new OOMWarning((exportFeatures ? MessageManager.formatMessage( |
258 |
|
"label.generating_features_for_params", new String[] |
259 |
|
{ ap.alignFrame.getTitle() }) |
260 |
|
: MessageManager.formatMessage( |
261 |
|
"label.generating_annotations_for_params", |
262 |
|
new String[] |
263 |
|
{ ap.alignFrame.getTitle() })), |
264 |
|
oom); |
265 |
0 |
cap.dispose(); |
266 |
|
} |
267 |
|
|
268 |
0 |
close_actionPerformed(); |
269 |
|
} |
270 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
271 |
0 |
private void close_actionPerformed()... |
272 |
|
{ |
273 |
0 |
try |
274 |
|
{ |
275 |
0 |
frame.setClosed(true); |
276 |
|
} catch (java.beans.PropertyVetoException ex) |
277 |
|
{ |
278 |
|
} |
279 |
|
} |
280 |
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 1 |
Complexity Density: 0.03 |
|
281 |
0 |
private void jbInit() throws Exception... |
282 |
|
{ |
283 |
0 |
this.setLayout(new BorderLayout()); |
284 |
|
|
285 |
0 |
toFile.setText(MessageManager.getString("label.to_file")); |
286 |
0 |
toFile.addActionListener(new ActionListener() |
287 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
288 |
0 |
@Override... |
289 |
|
public void actionPerformed(ActionEvent e) |
290 |
|
{ |
291 |
0 |
toFile_actionPerformed(); |
292 |
|
} |
293 |
|
}); |
294 |
0 |
toTextbox.setText(MessageManager.getString("label.to_textbox")); |
295 |
0 |
toTextbox.addActionListener(new ActionListener() |
296 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
297 |
0 |
@Override... |
298 |
|
public void actionPerformed(ActionEvent e) |
299 |
|
{ |
300 |
0 |
toTextbox_actionPerformed(); |
301 |
|
} |
302 |
|
}); |
303 |
0 |
close.setText(MessageManager.getString("action.close")); |
304 |
0 |
close.addActionListener(new ActionListener() |
305 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
306 |
0 |
@Override... |
307 |
|
public void actionPerformed(ActionEvent e) |
308 |
|
{ |
309 |
0 |
close_actionPerformed(); |
310 |
|
} |
311 |
|
}); |
312 |
0 |
jalviewFormat.setOpaque(false); |
313 |
0 |
jalviewFormat.setSelected(true); |
314 |
0 |
jalviewFormat.setText("Jalview"); |
315 |
0 |
GFFFormat.setOpaque(false); |
316 |
0 |
GFFFormat.setText("GFF"); |
317 |
0 |
CSVFormat.setOpaque(false); |
318 |
0 |
CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet")); |
319 |
0 |
jLabel1.setHorizontalAlignment(SwingConstants.TRAILING); |
320 |
0 |
jLabel1.setText(MessageManager.getString("action.format") + " "); |
321 |
0 |
this.setBackground(Color.white); |
322 |
0 |
jPanel3.setBorder(BorderFactory.createEtchedBorder()); |
323 |
0 |
jPanel3.setOpaque(false); |
324 |
0 |
jPanel1.setOpaque(false); |
325 |
0 |
jPanel1.add(toFile); |
326 |
0 |
jPanel1.add(toTextbox); |
327 |
0 |
jPanel1.add(close); |
328 |
0 |
jPanel3.add(jLabel1); |
329 |
0 |
jPanel3.add(jalviewFormat); |
330 |
0 |
jPanel3.add(GFFFormat); |
331 |
0 |
jPanel3.add(CSVFormat); |
332 |
0 |
buttonGroup.add(jalviewFormat); |
333 |
0 |
buttonGroup.add(GFFFormat); |
334 |
0 |
buttonGroup.add(CSVFormat); |
335 |
0 |
this.add(jPanel3, BorderLayout.CENTER); |
336 |
0 |
this.add(jPanel1, BorderLayout.SOUTH); |
337 |
|
} |
338 |
|
|
339 |
|
JPanel jPanel1 = new JPanel(); |
340 |
|
|
341 |
|
JButton toFile = new JButton(); |
342 |
|
|
343 |
|
JButton toTextbox = new JButton(); |
344 |
|
|
345 |
|
JButton close = new JButton(); |
346 |
|
|
347 |
|
ButtonGroup buttonGroup = new ButtonGroup(); |
348 |
|
|
349 |
|
JRadioButton jalviewFormat = new JRadioButton(); |
350 |
|
|
351 |
|
JRadioButton GFFFormat = new JRadioButton(); |
352 |
|
|
353 |
|
JRadioButton CSVFormat = new JRadioButton(); |
354 |
|
|
355 |
|
JLabel jLabel1 = new JLabel(); |
356 |
|
|
357 |
|
JPanel jPanel3 = new JPanel(); |
358 |
|
|
359 |
|
FlowLayout flowLayout1 = new FlowLayout(); |
360 |
|
} |