Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 15:05:32 GMT
  2. Package jalview.gui

File PaSiMapPanel.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

20
117
16
1
389
285
32
0.27
7.31
16
2

Classes

Class Line # Actions
PaSiMapPanel 59 117 32
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.gui;
22   
23    import jalview.analysis.scoremodels.ScoreModels;
24    import jalview.api.analysis.ScoreModelI;
25    import jalview.api.analysis.SimilarityParamsI;
26    import jalview.bin.Console;
27    import jalview.datamodel.Alignment;
28    import jalview.datamodel.AlignmentI;
29    import jalview.datamodel.AlignmentView;
30    import jalview.datamodel.HiddenColumns;
31    import jalview.datamodel.SequenceGroup;
32    import jalview.datamodel.SequenceI;
33    import jalview.gui.ImageExporter.ImageWriterI;
34    import jalview.jbgui.GPCAPanel;
35    import jalview.util.ImageMaker;
36    import jalview.util.MessageManager;
37    import jalview.viewmodel.AlignmentViewport;
38    import jalview.viewmodel.PaSiMapModel;
39   
40    import java.awt.BorderLayout;
41    import java.awt.Dimension;
42    import java.awt.Graphics;
43    import java.awt.event.ActionEvent;
44    import java.awt.event.ActionListener;
45    import java.awt.print.PageFormat;
46    import java.awt.print.Printable;
47    import java.awt.print.PrinterException;
48    import java.awt.print.PrinterJob;
49   
50    import javax.swing.ButtonGroup;
51    import javax.swing.JMenuItem;
52    import javax.swing.JRadioButtonMenuItem;
53    import javax.swing.event.InternalFrameAdapter;
54    import javax.swing.event.InternalFrameEvent;
55   
56    /**
57    * The panel holding the Pairwise Similarity Map 3-D visualisation
58    */
 
59    public class PaSiMapPanel extends SpatialPanel<PaSiMapModel>
60    implements Runnable, IProgressIndicator
61    {
62   
63    private static final int MAX_PASIMAP_SEQ = 20000;
64   
65    private final int GAP_OPEN_COST = 100;
66   
67    private final int GAP_EXTEND_COST = 5;
68    private String newPasimapTitle;
69   
 
70  0 toggle @Override
71    public String getSpatialName() {
72  0 return MessageManager.getString("label.pasimap");
73    }
74   
 
75  0 toggle @Override
76    public String getSpatialNameDetails() {
77  0 return MessageManager.getString("label.pasimap_details");
78    }
79   
80    /**
81    * Constructor given sequence data, a similarity (or distance) score model
82    * name, and score calculation parameters
83    *
84    * @param alignPanel
85    * @param modelName
86    */
 
87  0 toggle public PaSiMapPanel(AlignmentPanel alignPanel, String modelName)
88    {
89  0 super();
90  0 init(alignPanel);
91  0 boolean nucleotide = av.getAlignment().isNucleotide();
92   
93  0 boolean selected = av.getSelectionGroup() != null
94    && av.getSelectionGroup().getSize() > 0;
95  0 SequenceI[] seqs;
96  0 if (!selected)
97    {
98  0 seqs = av.getAlignment().getSequencesArray();
99    }
100    else
101    {
102  0 seqs = av.getSelectionGroup().getSequencesInOrder(av.getAlignment());
103    }
104   
105  0 ScoreModelI scoreModel = ScoreModels.getInstance()
106    .getScoreModel(modelName, ap);
107  0 setPasimapModel(new PaSiMapModel(av, seqs, nucleotide, scoreModel));
108   
109  0 newPasimapTitle = alignPanel.alignFrame.formCalculationTitle(
110    MessageManager.formatMessage("label.calc_title", "PaSiMap",
111    scoreModel.getName()),
112    selected, ap.alignFrame.getTitle());
113   
114  0 PaintRefresher.Register(this, av.getSequenceSetId());
115   
116  0 setRotatableCanvas(new RotatableCanvas(alignPanel));
117  0 this.getContentPane().add(getRotatableCanvas(), BorderLayout.CENTER);
118   
119  0 addKeyListener(getRotatableCanvas());
120  0 validate();
121    }
122   
123    /**
124    * Calculates the PaSiMap and displays the results
125    */
 
126  0 toggle @Override
127    public void run()
128    {
129  0 working = true;
130  0 progId = System.currentTimeMillis();
131  0 progressBar = new jalview.gui.ProgressBar(statusPanel, statusBar);
132  0 String message = MessageManager
133    .getString("label.pasimap_recalculating");
134  0 if (getParent() == null)
135    {
136  0 progressBar = ap.alignFrame;
137  0 message = MessageManager.getString("label.pasimap_calculating");
138    }
139  0 progressBar.setProgressBar(message, progId);
140  0 try
141    {
142  0 SequenceGroup selGroup = av.getSelectionGroup();
143   
144  0 if (selGroup == null)
145    {
146  0 selGroup = new SequenceGroup(av.getAlignment().getSequences());
147  0 selGroup.setStartRes(0);
148  0 selGroup.setEndRes(av.getAlignment().getWidth() - 1);
149    }
150   
151  0 if (selGroup.getSize() > MAX_PASIMAP_SEQ)
152    {
153  0 int start = selGroup.getStartRes(), end = selGroup.getEndRes();
154  0 selGroup = new SequenceGroup(
155    selGroup.getSequences().subList(0, MAX_PASIMAP_SEQ));
156  0 selGroup.setStartRes(start);
157  0 selGroup.setEndRes(end);
158  0 Console.warn("Truncated input sequences for PASIMAP analysis to "
159    + MAX_PASIMAP_SEQ);
160    }
161   
162  0 final PairwiseAlignPanel pap = new PairwiseAlignPanel(av, selGroup, true,
163    GAP_OPEN_COST, GAP_EXTEND_COST, false, null);
164  0 pap.setDiscardAlignments(true);
165  0 pap.setQuiet(true);
166   
167  0 System.out.println(pap != null);
168  0 addProgressListenerFor(pap);
169  0 progressBar.registerHandler(progId, new IProgressIndicatorHandler()
170    {
 
171  0 toggle @Override
172    public boolean cancelActivity(long id)
173    {
174  0 getPasimapModel().cancel();
175  0 return true;
176    }
177   
 
178  0 toggle @Override
179    public boolean canCancel()
180    {
181  0 return getPasimapModel().canCancel();
182    }
183    });
184  0 getPasimapModel().calculate(pap);
185  0 if (!getPasimapModel().isCancelled())
186    {
187    // TODO: fix outputAlignment so it uses the compact form if no text report is available
188  0 outputAlignment.setVisible(!pap.isDiscardAlignments() && !pap.isQuiet());
189  0 xCombobox.setSelectedIndex(0);
190  0 yCombobox.setSelectedIndex(1);
191  0 zCombobox.setSelectedIndex(2);
192   
193  0 getPasimapModel().updateRc(getRotatableCanvas());
194    // rc.invalidate();
195  0 setTop(getPasimapModel().getTop());
196  0 initClusterMenu();
197    }
198    } catch (OutOfMemoryError er)
199    {
200  0 new OOMWarning("calculating PaSiMap", er);
201  0 working = false;
202  0 return;
203    } finally
204    {
205  0 if (!getPasimapModel().isCancelled()) {
206    // finish up the progress bar if we weren't cancelled.
207  0 progressBar.setProgressBar("", progId);
208    }
209    }
210   
211  0 repaint();
212  0 if (!getPasimapModel().isCancelled() && getParent() == null)
213    {
214  0 Desktop.addInternalFrame(this,
215    newPasimapTitle,
216    475, 450);
217  0 this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
218    }
219  0 working = false;
220    }
221   
222   
 
223  0 toggle @Override
224    protected void viewMenu_menuSelected()
225    {
226  0 buildAssociatedViewMenu();
227    }
228   
229    /**
230    * Builds the menu showing the choice of possible views (for the associated
231    * sequence data) to which the PaSiMap may be linked
232    */
 
233  0 toggle void buildAssociatedViewMenu()
234    {
235  0 AlignmentPanel[] aps = PaintRefresher
236    .getAssociatedPanels(av.getSequenceSetId());
237  0 if (aps.length == 1 && getRotatableCanvas().av == aps[0].av)
238    {
239  0 associateViewsMenu.setVisible(false);
240  0 return;
241    }
242   
243  0 associateViewsMenu.setVisible(true);
244   
245  0 if ((viewMenu
246    .getItem(viewMenu.getItemCount() - 2) instanceof JMenuItem))
247    {
248  0 viewMenu.insertSeparator(viewMenu.getItemCount() - 1);
249    }
250   
251  0 associateViewsMenu.removeAll();
252   
253  0 JRadioButtonMenuItem item;
254  0 ButtonGroup buttonGroup = new ButtonGroup();
255  0 int iSize = aps.length;
256   
257  0 for (int i = 0; i < iSize; i++)
258    {
259  0 final AlignmentPanel panel = aps[i];
260  0 item = new JRadioButtonMenuItem(panel.av.getViewName(),
261    panel.av == getRotatableCanvas().av);
262  0 buttonGroup.add(item);
263  0 item.addActionListener(new ActionListener()
264    {
 
265  0 toggle @Override
266    public void actionPerformed(ActionEvent evt)
267    {
268  0 selectAssociatedView(panel);
269    }
270    });
271   
272  0 associateViewsMenu.add(item);
273    }
274   
275  0 final JRadioButtonMenuItem itemf = new JRadioButtonMenuItem(
276    "All Views");
277   
278  0 buttonGroup.add(itemf);
279   
280  0 itemf.setSelected(getRotatableCanvas().isApplyToAllViews());
281  0 itemf.addActionListener(new ActionListener()
282    {
 
283  0 toggle @Override
284    public void actionPerformed(ActionEvent evt)
285    {
286  0 getRotatableCanvas().setApplyToAllViews(itemf.isSelected());
287    }
288    });
289  0 associateViewsMenu.add(itemf);
290   
291    }
292   
293    /*
294    * (non-Javadoc)
295    *
296    * @see
297    * jalview.jbgui.GPaSiMapPanel#outputPoints_actionPerformed(java.awt.event.ActionEvent
298    * )
299    */
 
300  0 toggle @Override
301    protected void outputPoints_actionPerformed()
302    {
303  0 CutAndPasteTransfer cap = new CutAndPasteTransfer();
304  0 try
305    {
306  0 cap.setText(getPasimapModel().getPointsasCsv(false,
307    xCombobox.getSelectedIndex(), yCombobox.getSelectedIndex(),
308    zCombobox.getSelectedIndex()));
309  0 Desktop.addInternalFrame(cap, MessageManager
310    .formatMessage("label.points_for_params", new String[]
311    { this.getTitle() }), 500, 500);
312    } catch (OutOfMemoryError oom)
313    {
314  0 new OOMWarning("exporting PaSiMap points", oom);
315  0 cap.dispose();
316    }
317    }
318   
319    /*
320    * (non-Javadoc)
321    *
322    * @see
323    * jalview.jbgui.GPaSiMapPanel#outputProjPoints_actionPerformed(java.awt.event
324    * .ActionEvent)
325    */
 
326  0 toggle @Override
327    protected void outputProjPoints_actionPerformed()
328    {
329  0 CutAndPasteTransfer cap = new CutAndPasteTransfer();
330  0 try
331    {
332  0 cap.setText(getPasimapModel().getPointsasCsv(true,
333    xCombobox.getSelectedIndex(), yCombobox.getSelectedIndex(),
334    zCombobox.getSelectedIndex()));
335  0 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
336    "label.transformed_points_for_params", new String[]
337    { this.getTitle() }), 500, 500);
338    } catch (OutOfMemoryError oom)
339    {
340  0 new OOMWarning("exporting transformed PaSiMap points", oom);
341  0 cap.dispose();
342    }
343    }
344   
345    /*
346    * (non-Javadoc)
347    *
348    * @see
349    * jalview.jbgui.GPaSiMapPanel#outputAlignment_actionPerformed(java.awt.event
350    * .ActionEvent)
351    */
 
352  0 toggle @Override
353    protected void outputAlignment_actionPerformed()
354    {
355  0 CutAndPasteTransfer cap = new CutAndPasteTransfer();
356  0 try
357    {
358  0 cap.setText(getPasimapModel().getAlignmentOutput());
359  0 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
360    "label.pairwise_alignment_for_params", new String[]
361    { this.getTitle() }), 500, 500);
362    } catch (OutOfMemoryError oom)
363    {
364  0 new OOMWarning("exporting pairwise alignments", oom);
365  0 cap.dispose();
366    }
367    }
368   
 
369  0 toggle @Override
370    protected void resetButton_actionPerformed()
371    {
372  0 int t = getTop();
373  0 setTop(0); // ugly - prevents dimensionChanged events from being processed
374  0 xCombobox.setSelectedIndex(0);
375  0 yCombobox.setSelectedIndex(1);
376  0 setTop(t);
377  0 zCombobox.setSelectedIndex(2);
378    }
379   
 
380  0 toggle public PaSiMapModel getPasimapModel()
381    {
382  0 return spatialModel;
383    }
384   
 
385  0 toggle public void setPasimapModel(PaSiMapModel pasimapModel)
386    {
387  0 this.spatialModel = pasimapModel;
388    }
389    }