From 461b359b7338934b198a22bd70c622f333ac4661 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 3 May 2016 16:53:21 +0100 Subject: [PATCH] JAL-2050 hide introns also when fetching Ensembl xrefs for Uniprot --- resources/lang/Messages.properties | 2 +- resources/lang/Messages_es.properties | 2 +- src/jalview/api/AlignViewControllerI.java | 2 +- src/jalview/controller/AlignViewController.java | 33 ++++++----- src/jalview/gui/AlignFrame.java | 30 ++++++++++ src/jalview/gui/SequenceFetcher.java | 21 +------ test/jalview/gui/AlignFrameTest.java | 71 +++++++++++++++++++++++ 7 files changed, 125 insertions(+), 36 deletions(-) create mode 100644 test/jalview/gui/AlignFrameTest.java diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 62c813a..be5f040 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1027,7 +1027,7 @@ error.implementation_error_need_to_have_httpresponse = Implementation Error: nee error.dbrefsource_implementation_exception =DBRefSource Implementation Exception error.implementation_error_dbinstance_must_implement_interface = Implmentation Error - getDbInstances must be given a class that implements jalview.ws.seqfetcher.DbSourceProxy (was given{0}) error.implementation_error_must_init_dbsources =Implementation error. Must initialise dbSources -label.view_controller_toggled_marked = {0} {1} columns {2} containing features of type {3} across {4} sequence(s) +label.view_controller_toggled_marked = {0} {1} columns containing features of type {2} across {3} sequence(s) label.toggled = Toggled label.marked = Marked label.not = not diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 3535f4b..8943860 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -962,7 +962,7 @@ error.implementation_error_need_to_have_httpresponse = Error de implementaci error.dbrefsource_implementation_exception = Excepción de implementación DBRefSource error.implementation_error_dbinstance_must_implement_interface = Error de Implementación- getDbInstances debe recibir una clase que implemente jalview.ws.seqfetcher.DbSourceProxy (recibió {0}) error.implementation_error_must_init_dbsources =Error de implementación. Debe inicializar dbSources -label.view_controller_toggled_marked = {0} {1} columnas {2} conteniendo características del tipo {3} en {4} secuencia(s) +label.view_controller_toggled_marked = {0} {1} columnas conteniendo características del tipo {2} en {3} secuencia(s) label.toggled = Invertida label.marked = Marcada label.not = no diff --git a/src/jalview/api/AlignViewControllerI.java b/src/jalview/api/AlignViewControllerI.java index 17a1563..26966ba 100644 --- a/src/jalview/api/AlignViewControllerI.java +++ b/src/jalview/api/AlignViewControllerI.java @@ -64,7 +64,7 @@ public interface AlignViewControllerI * @return true if operation affected state */ boolean markColumnsContainingFeatures(boolean invert, - boolean extendCurrent, boolean clearColumns, String featureType); + boolean extendCurrent, boolean toggle, String featureType); /** * sort the alignment or current selection by average score over the given set diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index ca2ae6d..24439ca 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -238,6 +238,7 @@ public class AlignViewController implements AlignViewControllerI ColumnSelection cs = viewport.getColumnSelection(); if (bs.cardinality() > 0 || invert) { + boolean changed = false; if (cs == null) { cs = new ColumnSelection(); @@ -246,6 +247,7 @@ public class AlignViewController implements AlignViewControllerI { if (!extendCurrent) { + changed = !cs.isEmpty(); cs.clear(); } } @@ -257,6 +259,7 @@ public class AlignViewController implements AlignViewControllerI { if (ibs < 0 || i < ibs) { + changed = true; if (toggle && cs.contains(i)) { cs.removeElement(i++); @@ -278,6 +281,7 @@ public class AlignViewController implements AlignViewControllerI for (int i = bs.nextSetBit(alStart); i >= alStart; i = bs .nextSetBit(i + 1)) { + changed = true; if (toggle && cs.contains(i)) { cs.removeElement(i); @@ -288,18 +292,21 @@ public class AlignViewController implements AlignViewControllerI } } } - viewport.setColumnSelection(cs); - alignPanel.paintAlignment(true); - avcg.setStatus(MessageManager.formatMessage( - "label.view_controller_toggled_marked", - new String[] { - (toggle ? MessageManager.getString("label.toggled") - : MessageManager.getString("label.marked")), - (invert ? (Integer.valueOf((alw - alStart) - - bs.cardinality()).toString()) : (Integer - .valueOf(bs.cardinality()).toString())), - featureType, Integer.valueOf(nseq).toString() })); - return true; + if (changed) + { + viewport.setColumnSelection(cs); + alignPanel.paintAlignment(true); + avcg.setStatus(MessageManager.formatMessage( + "label.view_controller_toggled_marked", + new String[] { + (toggle ? MessageManager.getString("label.toggled") + : MessageManager.getString("label.marked")), + (invert ? (Integer.valueOf((alw - alStart) + - bs.cardinality()).toString()) : (Integer + .valueOf(bs.cardinality()).toString())), + featureType, Integer.valueOf(nseq).toString() })); + return true; + } } else { @@ -311,8 +318,8 @@ public class AlignViewController implements AlignViewControllerI cs.clear(); alignPanel.paintAlignment(true); } - return false; } + return false; } @Override diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 8ec5366..7e7bdd3 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -74,6 +74,7 @@ import jalview.io.JalviewFileView; import jalview.io.JnetAnnotationMaker; import jalview.io.NewickFile; import jalview.io.TCoffeeScoreFile; +import jalview.io.gff.SequenceOntologyI; import jalview.jbgui.GAlignFrame; import jalview.schemes.Blosum62ColourScheme; import jalview.schemes.BuriedColourScheme; @@ -4713,6 +4714,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignFrame newFrame = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT); + if (Cache.getDefault("HIDE_INTRONS", true)) + { + newFrame.hideFeatureColumns(SequenceOntologyI.EXON, false); + } String newtitle = String.format("%s %s %s", MessageManager.getString(dna ? "label.proteins" : "label.nucleotides"), MessageManager @@ -6142,6 +6147,31 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, System.err.println("Can't run Groovy script as console not found"); } } + + /** + * Hides columns containing (or not containing) a specified feature, provided + * that would not leave all columns hidden + * + * @param featureType + * @param columnsContaining + * @return + */ + public boolean hideFeatureColumns(String featureType, + boolean columnsContaining) + { + boolean notForHiding = avc.markColumnsContainingFeatures( + columnsContaining, false, false, featureType); + if (notForHiding) + { + if (avc.markColumnsContainingFeatures(!columnsContaining, false, + false, featureType)) + { + getViewport().hideSelectedColumns(); + return true; + } + } + return false; + } } class PrintThread extends Thread diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index d5a04a9..e567d20 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -919,7 +919,7 @@ public class SequenceFetcher extends JPanel implements Runnable } if (Cache.getDefault("HIDE_INTRONS", true)) { - hideIntronsIfPresent(af); + af.hideFeatureColumns(SequenceOntologyI.EXON, false); } Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH, @@ -944,25 +944,6 @@ public class SequenceFetcher extends JPanel implements Runnable return al; } - /** - * Hide columns not containing 'exon' features, provided there are exon - * features on the alignment - * - * @param af - */ - public void hideIntronsIfPresent(AlignFrame af) - { - boolean hasExons = af.avc.markColumnsContainingFeatures(false, false, - false, - SequenceOntologyI.EXON); - if (hasExons) - { - af.avc.markColumnsContainingFeatures(true, false, true, - SequenceOntologyI.EXON); - af.getViewport().hideSelectedColumns(); - } - } - void showErrorMessage(final String error) { resetDialog(); diff --git a/test/jalview/gui/AlignFrameTest.java b/test/jalview/gui/AlignFrameTest.java new file mode 100644 index 0000000..80e3d5a --- /dev/null +++ b/test/jalview/gui/AlignFrameTest.java @@ -0,0 +1,71 @@ +package jalview.gui; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertTrue; + +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceI; + +import java.util.List; + +import org.testng.annotations.Test; + +public class AlignFrameTest +{ + + @Test + public void testHideFeatureColumns() + { + SequenceI seq1 = new Sequence("Seq1", "ABCDEFGHIJ"); + SequenceI seq2 = new Sequence("Seq2", "ABCDEFGHIJ"); + seq1.addSequenceFeature(new SequenceFeature("Metal", "", 1, 5, + Float.NaN, null)); + seq2.addSequenceFeature(new SequenceFeature("Metal", "", 6, 10, + Float.NaN, null)); + seq1.addSequenceFeature(new SequenceFeature("Turn", "", 2, 4, + Float.NaN, null)); + seq2.addSequenceFeature(new SequenceFeature("Turn", "", 7, 9, + Float.NaN, null)); + AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 }); + AlignFrame af = new AlignFrame(al, al.getWidth(), al.getHeight()); + + /* + * hiding a feature not present does nothing + */ + assertFalse(af.hideFeatureColumns("exon", true)); + assertTrue(af.getViewport().getColumnSelection().isEmpty()); + assertTrue(af.getViewport().getColumnSelection().getHiddenColumns() + .isEmpty()); + assertFalse(af.hideFeatureColumns("exon", false)); + assertTrue(af.getViewport().getColumnSelection().isEmpty()); + assertTrue(af.getViewport().getColumnSelection().getHiddenColumns() + .isEmpty()); + + /* + * hiding a feature in all columns does nothing + */ + assertFalse(af.hideFeatureColumns("Metal", true)); + assertTrue(af.getViewport().getColumnSelection().isEmpty()); + List hidden = af.getViewport().getColumnSelection() + .getHiddenColumns(); + assertTrue(hidden.isEmpty()); + + /* + * hide a feature present in some columns + * sequence positions [2-4], [7-9] are column positions + * [1-3], [6-8] base zero + */ + assertTrue(af.hideFeatureColumns("Turn", true)); + hidden = af.getViewport().getColumnSelection() + .getHiddenColumns(); + assertEquals(2, hidden.size()); + assertEquals(1, hidden.get(0)[0]); + assertEquals(3, hidden.get(0)[1]); + assertEquals(6, hidden.get(1)[0]); + assertEquals(8, hidden.get(1)[1]); + } +} -- 1.7.10.2