X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FRedundancyPanel.java;h=37458a711acdcc5cad7c485d1deb4435213aea10;hb=refs%2Fheads%2Ffeatures%2FJAL-250_hideredundantseqs;hp=7fb0593a431b3b5365331255b20228bae3edd2e5;hpb=4d7f98a6dd54d9863ba449ec79dcd95d25ed863d;p=jalview.git diff --git a/src/jalview/gui/RedundancyPanel.java b/src/jalview/gui/RedundancyPanel.java index 7fb0593..37458a7 100755 --- a/src/jalview/gui/RedundancyPanel.java +++ b/src/jalview/gui/RedundancyPanel.java @@ -29,8 +29,10 @@ import jalview.datamodel.SequenceI; import jalview.jbgui.GSliderPanel; import jalview.util.MessageManager; +import java.awt.Color; import java.awt.event.ActionEvent; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Stack; import java.util.Vector; @@ -66,6 +68,8 @@ public class RedundancyPanel extends GSliderPanel implements Runnable Vector redundantSeqs; + private SequenceI[] redreps; + /** * Creates a new RedundancyPanel object. * @@ -82,6 +86,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable slider.addChangeListener(new ChangeListener() { + @Override public void stateChanged(ChangeEvent evt) { valueField.setText(slider.getValue() + ""); @@ -89,7 +94,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable } }); - applyButton.setText(MessageManager.getString("action.remove")); + applyButton.setText(MessageManager.getString("action.hide")); allGroupsCheck.setVisible(false); slider.setMinimum(0); slider.setMaximum(100); @@ -100,11 +105,13 @@ public class RedundancyPanel extends GSliderPanel implements Runnable frame = new JInternalFrame(); frame.setContentPane(this); - Desktop.addInternalFrame(frame, MessageManager - .getString("label.redundancy_threshold_selection"), 400, 100, - false); + Desktop.addInternalFrame(frame, + MessageManager + .getString("label.redundancy_threshold_selection"), + 400, 100, false); frame.addInternalFrameListener(new InternalFrameAdapter() { + @Override public void internalFrameClosing(InternalFrameEvent evt) { ap.getIdPanel().getIdCanvas().setHighlighted(null); @@ -125,6 +132,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable * * @return DOCUMENT ME! */ + @Override public void run() { JProgressBar progress = new JProgressBar(); @@ -164,15 +172,19 @@ public class RedundancyPanel extends GSliderPanel implements Runnable { omitHidden = ap.av.getViewAsString(sg != null); } - redundancy = AlignSeq.computeRedundancyMatrix(originalSequences, + Object rr[] = AlignSeq.computeRedundancyMatrixWithRep( + originalSequences, omitHidden, start, end, false); + redundancy = (float[]) rr[0]; + redreps = (SequenceI[]) rr[1]; + progress.setIndeterminate(false); progress.setVisible(false); progress = null; - label.setText(MessageManager - .getString("label.enter_redundancy_thereshold")); + label.setText( + MessageManager.getString("label.enter_redundancy_threshold")); slider.setVisible(true); applyButton.setEnabled(true); valueField.setVisible(true); @@ -207,23 +219,106 @@ public class RedundancyPanel extends GSliderPanel implements Runnable * @param e * DOCUMENT ME! */ + @Override public void applyButton_actionPerformed(ActionEvent e) { - Vector del = new Vector(); undoButton.setEnabled(true); float value = slider.getValue(); SequenceGroup sg = ap.av.getSelectionGroup(); - + // delete_seqs(value, sg); + hide_seqs(value, sg); + } + private void hide_seqs(float value, SequenceGroup sg) + { + /** + * hash to look up the representative for a sequence + */ + HashMap rep = new HashMap(); + /** + * hash to collect lists of sequences represented by a sequence + */ + HashMap reps = new HashMap(); for (int i = 0; i < redundancy.length; i++) { if (value <= redundancy[i]) { - del.addElement(originalSequences[i]); + // does this sequence represent other sequences ? + SequenceGroup repset; + // is the representative also redundant ? + SequenceI repForI = rep.get(redreps[i]); + if (repForI==null) { + // the representative is still in the alignment. + // is it representing anything already ? + repset = reps.get(redreps[i]); + if (repset==null) + { + repset = new SequenceGroup(); + } + repset.addSequence(originalSequences[i], false); + rep.put(originalSequences[i], redreps[i]); + reps.put(redreps[i], repset); + // and save the representative sequence for originalSeq + repForI = redreps[i]; + } else { + // already hidden the representative for this sequence, so look up its redundant peers + repset = reps.get(repForI); + if (repset==null) + { + throw new Error("Implementation failure for redundancy set creation"); + } + // add the sequence to the peerset, and mark sequence's representative in hash + repset.addSequence(originalSequences[i], false); + rep.put(originalSequences[i], repForI); + } + // merge any sequences represented by this with its new containing group + SequenceGroup existingreps = reps.remove(originalSequences[i]); + if (existingreps!=null) + { + for (SequenceI sq:existingreps.getSequences()) + { + rep.put(sq, repForI); + repset.addSequence(sq, false); + } + } } } + int s = 0, e = ap.av.getAlignment().getWidth(); + if (sg != null) + { + s = sg.getStartRes(); + e = sg.getEndRes(); + } + List sgs = new ArrayList(); + for (SequenceI repseq: reps.keySet()) + { + sg = reps.get(repseq); + sg.addSequence(repseq, false); + sg.setSeqrep(repseq); + sg.setStartRes(s); + sg.setEndRes(e); + sgs.add(sg); + } + ap.alignFrame.avc.showRandomColoursForGroups(sgs); + for (SequenceI repseq : reps.keySet()) + { + sg = reps.get(repseq); + ap.av.hideRepSequences(repseq, sg); + } + } + private void delete_seqs(float value, SequenceGroup sg) + { + ArrayList del = new ArrayList(); + + for (int i = 0; i < redundancy.length; i++) + { + if (value <= redundancy[i]) + { + del.add(originalSequences[i]); + } + } // This has to be done before the restoreHistoryItem method of alignFrame // will // actually restore these sequences. @@ -234,7 +329,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable int width = 0; for (int i = 0; i < del.size(); i++) { - deleted[i] = (SequenceI) del.elementAt(i); + deleted[i] = del.get(i); if (deleted[i].getLength() > width) { width = deleted[i].getLength(); @@ -259,8 +354,8 @@ public class RedundancyPanel extends GSliderPanel implements Runnable ap.alignFrame.addHistoryItem(cut); PaintRefresher.Refresh(this, ap.av.getSequenceSetId(), true, true); - ap.av.firePropertyChange("alignment", null, ap.av.getAlignment() - .getSequences()); + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); } } @@ -271,6 +366,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable * @param e * DOCUMENT ME! */ + @Override public void undoButton_actionPerformed(ActionEvent e) { if (historyList == null || historyList.isEmpty()) @@ -284,8 +380,8 @@ public class RedundancyPanel extends GSliderPanel implements Runnable { command.undoCommand(af.getViewAlignments()); ap.av.getHistoryList().remove(command); - ap.av.firePropertyChange("alignment", null, ap.av.getAlignment() - .getSequences()); + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); af.updateEditMenuBar(); } @@ -303,6 +399,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable * @param e * DOCUMENT ME! */ + @Override public void valueField_actionPerformed(ActionEvent e) { try