Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 20:42:03 GMT
  2. Package jalview.appletgui

File RedundancyPanel.java

 

Coverage histogram

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

Code metrics

26
92
14
1
306
216
29
0.32
6.57
14
2.07

Classes

Class Line # Actions
RedundancyPanel 43 92 29
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.appletgui;
22   
23    import jalview.analysis.AlignSeq;
24    import jalview.commands.CommandI;
25    import jalview.commands.EditCommand;
26    import jalview.commands.EditCommand.Action;
27    import jalview.datamodel.AlignmentI;
28    import jalview.datamodel.SequenceGroup;
29    import jalview.datamodel.SequenceI;
30    import jalview.util.MessageManager;
31   
32    import java.awt.Frame;
33    import java.awt.event.ActionEvent;
34    import java.awt.event.AdjustmentEvent;
35    import java.awt.event.AdjustmentListener;
36    import java.awt.event.WindowEvent;
37    import java.awt.event.WindowListener;
38    import java.util.ArrayList;
39    import java.util.List;
40    import java.util.Stack;
41    import java.util.Vector;
42   
 
43    public class RedundancyPanel extends SliderPanel
44    implements Runnable, WindowListener
45    {
46    Stack historyList = new Stack(); // simpler than synching with alignFrame.
47   
48    float[] redundancy;
49   
50    SequenceI[] originalSequences;
51   
52    Frame frame;
53   
54    Vector redundantSeqs;
55   
 
56  0 toggle public RedundancyPanel(AlignmentPanel ap)
57    {
58  0 super(ap, 0, false, null);
59   
60  0 redundantSeqs = new Vector();
61  0 this.ap = ap;
62  0 undoButton.setVisible(true);
63  0 applyButton.setVisible(true);
64  0 allGroupsCheck.setVisible(false);
65   
66  0 label.setText(
67    MessageManager.getString("label.enter_redundancy_threshold"));
68  0 valueField.setText("100");
69   
70  0 slider.setVisibleAmount(1);
71  0 slider.setMinimum(0);
72  0 slider.setMaximum(100 + slider.getVisibleAmount());
73  0 slider.setValue(100);
74   
75  0 slider.addAdjustmentListener(new AdjustmentListener()
76    {
 
77  0 toggle @Override
78    public void adjustmentValueChanged(AdjustmentEvent evt)
79    {
80  0 valueField.setText(String.valueOf(slider.getValue()));
81  0 sliderValueChanged();
82    }
83    });
84   
85  0 frame = new Frame();
86  0 frame.add(this);
87  0 jalview.bin.JalviewLite.addFrame(frame, MessageManager
88    .getString("label.redundancy_threshold_selection"), 400, 100);
89   
90  0 frame.addWindowListener(this);
91   
92  0 Thread worker = new Thread(this);
93  0 worker.start();
94    }
95   
96    /**
97    * This is a copy of remove redundancy in jalivew.datamodel.Alignment except
98    * we dont want to remove redundancy, just calculate once so we can use the
99    * slider to dynamically hide redundant sequences
100    *
101    * @param threshold
102    * DOCUMENT ME!
103    * @param sel
104    * DOCUMENT ME!
105    *
106    * @return DOCUMENT ME!
107    */
 
108  0 toggle @Override
109    public void run()
110    {
111  0 label.setText(MessageManager.getString("label.calculating"));
112   
113  0 slider.setVisible(false);
114  0 applyButton.setEnabled(false);
115  0 valueField.setVisible(false);
116   
117  0 validate();
118   
119  0 String[] omitHidden = null;
120   
121  0 SequenceGroup sg = ap.av.getSelectionGroup();
122  0 int height;
123   
124  0 int start, end;
125   
126  0 if ((sg != null) && (sg.getSize() >= 1))
127    {
128  0 originalSequences = sg.getSequencesInOrder(ap.av.getAlignment());
129  0 start = sg.getStartRes();
130  0 end = sg.getEndRes();
131    }
132    else
133    {
134  0 originalSequences = ap.av.getAlignment().getSequencesArray();
135  0 start = 0;
136  0 end = ap.av.getAlignment().getWidth();
137    }
138   
139  0 height = originalSequences.length;
140   
141  0 redundancy = AlignSeq.computeRedundancyMatrix(originalSequences,
142    omitHidden, start, end, false);
143  0 label.setText(
144    MessageManager.getString("label.enter_redundancy_threshold"));
145  0 slider.setVisible(true);
146  0 applyButton.setEnabled(true);
147  0 valueField.setVisible(true);
148   
149  0 validate();
150  0 sliderValueChanged();
151    // jalview.bin.Console.outPrintln("blob done "+
152    // (System.currentTimeMillis()-start));
153    }
154   
 
155  0 toggle void sliderValueChanged()
156    {
157  0 if (redundancy == null)
158    {
159  0 return;
160    }
161   
162  0 float value = slider.getValue();
163   
164  0 List<SequenceI> redundantSequences = new ArrayList<>();
165  0 for (int i = 0; i < redundancy.length; i++)
166    {
167  0 if (value <= redundancy[i])
168    {
169  0 redundantSequences.add(originalSequences[i]);
170    }
171    }
172   
173  0 ap.idPanel.idCanvas.setHighlighted(redundantSequences);
174  0 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
175   
176    }
177   
 
178  0 toggle @Override
179    public void applyButton_actionPerformed()
180    {
181  0 Vector del = new Vector();
182   
183  0 undoButton.setEnabled(true);
184   
185  0 float value = slider.getValue();
186  0 SequenceGroup sg = ap.av.getSelectionGroup();
187   
188  0 for (int i = 0; i < redundancy.length; i++)
189    {
190  0 if (value <= redundancy[i])
191    {
192  0 del.addElement(originalSequences[i]);
193    }
194    }
195   
196    // This has to be done before the restoreHistoryItem method of alignFrame
197    // will
198    // actually restore these sequences.
199  0 if (del.size() > 0)
200    {
201  0 SequenceI[] deleted = new SequenceI[del.size()];
202   
203  0 int width = 0;
204  0 for (int i = 0; i < del.size(); i++)
205    {
206  0 deleted[i] = (SequenceI) del.elementAt(i);
207  0 if (deleted[i].getLength() > width)
208    {
209  0 width = deleted[i].getLength();
210    }
211    }
212   
213  0 EditCommand cut = new EditCommand(
214    MessageManager.getString("action.remove_redundancy"),
215    Action.CUT, deleted, 0, width, ap.av.getAlignment());
216  0 AlignmentI alignment = ap.av.getAlignment();
217  0 for (int i = 0; i < del.size(); i++)
218    {
219  0 alignment.deleteSequence(deleted[i]);
220  0 if (sg != null)
221    {
222  0 sg.deleteSequence(deleted[i], false);
223    }
224    }
225   
226  0 historyList.push(cut);
227   
228  0 ap.alignFrame.addHistoryItem(cut);
229   
230  0 PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true);
231  0 ap.av.firePropertyChange("alignment", null,
232    ap.av.getAlignment().getSequences());
233    }
234   
235    }
236   
 
237  0 toggle @Override
238    public void undoButton_actionPerformed()
239    {
240  0 CommandI command = (CommandI) historyList.pop();
241  0 command.undoCommand(null);
242   
243  0 if (ap.av.getHistoryList().contains(command))
244    {
245  0 ap.av.getHistoryList().remove(command);
246  0 ap.alignFrame.updateEditMenuBar();
247  0 ap.av.firePropertyChange("alignment", null,
248    ap.av.getAlignment().getSequences());
249    }
250   
251  0 ap.paintAlignment(true, true);
252   
253  0 if (historyList.size() == 0)
254    {
255  0 undoButton.setEnabled(false);
256    }
257    }
258   
 
259  0 toggle public void valueField_actionPerformed(ActionEvent e)
260    {
261  0 try
262    {
263  0 int i = Integer.parseInt(valueField.getText());
264  0 slider.setValue(i);
265    } catch (Exception ex)
266    {
267  0 valueField.setText(slider.getValue() + "");
268    }
269    }
270   
 
271  0 toggle @Override
272    public void windowOpened(WindowEvent evt)
273    {
274    }
275   
 
276  0 toggle @Override
277    public void windowClosing(WindowEvent evt)
278    {
279  0 ap.idPanel.idCanvas.setHighlighted(null);
280    }
281   
 
282  0 toggle @Override
283    public void windowClosed(WindowEvent evt)
284    {
285    }
286   
 
287  0 toggle @Override
288    public void windowActivated(WindowEvent evt)
289    {
290    }
291   
 
292  0 toggle @Override
293    public void windowDeactivated(WindowEvent evt)
294    {
295    }
296   
 
297  0 toggle @Override
298    public void windowIconified(WindowEvent evt)
299    {
300    }
301   
 
302  0 toggle @Override
303    public void windowDeiconified(WindowEvent evt)
304    {
305    }
306    }