From: Jim Procter Date: Mon, 28 Mar 2016 15:52:21 +0000 (+0100) Subject: JAL-250 prototype ‘hide redundant sequences’ - redundant seqs are represented by... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=32e2eb517a57952fd8be507f2ca19bedf145897b;p=jalview.git JAL-250 prototype ‘hide redundant sequences’ - redundant seqs are represented by nearest non-redundant sequence --- diff --git a/src/jalview/gui/RedundancyPanel.java b/src/jalview/gui/RedundancyPanel.java index 7fb0593..4ef82c8 100755 --- a/src/jalview/gui/RedundancyPanel.java +++ b/src/jalview/gui/RedundancyPanel.java @@ -31,6 +31,7 @@ import jalview.util.MessageManager; 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 +67,8 @@ public class RedundancyPanel extends GSliderPanel implements Runnable Vector redundantSeqs; + private SequenceI[] redreps; + /** * Creates a new RedundancyPanel object. * @@ -89,7 +92,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); @@ -164,9 +167,13 @@ 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; @@ -209,21 +216,88 @@ public class RedundancyPanel extends GSliderPanel implements Runnable */ 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); + } + } } } + for (SequenceI repseq: reps.keySet()) + { + sg = reps.get(repseq); + sg.addSequence(repseq, false); + sg.setSeqrep(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 +308,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();