From: tcofoegbu Date: Mon, 11 Apr 2016 15:28:12 +0000 (+0100) Subject: JAL-2054 Renamed getStartEnd in AlignFrame to getVisibleStartAndEndIndex, and refacto... X-Git-Tag: Release_2_10_0~267 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3ef0beaad016ac06b8947feb0f36d06b1e956d59;p=jalview.git JAL-2054 Renamed getStartEnd in AlignFrame to getVisibleStartAndEndIndex, and refactored method to Alignment class, and created a test for it accordingly --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index d1ea70d..a9b0d53 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -1793,4 +1793,40 @@ public class Alignment implements AlignmentI } return null; } + + @Override + public int[] getVisibleStartAndEndIndex(List hiddenCols) + { + int[] alignmentStartEnd = new int[] { 0, getWidth() - 1 }; + int startPos = alignmentStartEnd[0]; + int endPos = alignmentStartEnd[1]; + + int[] lowestRange = new int[] { -1, -1 }; + int[] higestRange = new int[] { -1, -1 }; + + for (int[] hiddenCol : hiddenCols) + { + lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange; + higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange; + } + + if (lowestRange[0] == -1 && lowestRange[1] == -1) + { + startPos = alignmentStartEnd[0]; + } + else + { + startPos = lowestRange[1] + 1; + } + + if (higestRange[0] == -1 && higestRange[1] == -1) + { + endPos = alignmentStartEnd[1]; + } + else + { + endPos = higestRange[0] - 1; + } + return new int[] { startPos, endPos }; + } } diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 396ef2d..76d1a48 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -543,4 +543,13 @@ public interface AlignmentI extends AnnotatedCollectionI * @return */ AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo); + + /** + * Calculate the visible start and end index of an alignment. The result is + * returned an int array where: int[0] = startIndex, and int[1] = endIndex. + * + * @param hiddenCols + * @return + */ + public int[] getVisibleStartAndEndIndex(List hiddenCols); } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index d1f3421..cb769bb 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1276,13 +1276,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignmentI alignmentToExport = null; AlignExportSettingI settings = exportSettings; String[] omitHidden = null; - int[] alignmentStartEnd = new int[2]; HiddenSequences hiddenSeqs = viewport.getAlignment() .getHiddenSequences(); alignmentToExport = viewport.getAlignment(); - alignmentStartEnd = new int[] { 0, alignmentToExport.getWidth() - 1 }; boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0; if (settings == null) @@ -1297,6 +1295,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, omitHidden = viewport.getViewAsString(false); } + int[] alignmentStartEnd = new int[2]; if (hasHiddenSeqs && settings.isExportHiddenSequences()) { alignmentToExport = hiddenSeqs.getFullAlignment(); @@ -1304,7 +1303,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, else { alignmentToExport = viewport.getAlignment(); - alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport + alignmentStartEnd = viewport.getAlignment() + .getVisibleStartAndEndIndex( + viewport .getColumnSelection().getHiddenColumns()); } AlignmentExportData ed = new AlignmentExportData(alignmentToExport, @@ -1312,55 +1313,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return ed; } - public static int[] getStartEnd(int[] aligmentStartEnd, - List hiddenCols) - { - int startPos = aligmentStartEnd[0]; - int endPos = aligmentStartEnd[1]; - - int[] lowestRange = new int[] { -1, -1 }; - int[] higestRange = new int[] { -1, -1 }; - - for (int[] hiddenCol : hiddenCols) - { - lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange; - higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange; - } - - if (lowestRange[0] == -1 && lowestRange[1] == -1) - { - startPos = aligmentStartEnd[0]; - } - else - { - startPos = lowestRange[1] + 1; - } - - if (higestRange[0] == -1 && higestRange[1] == -1) - { - endPos = aligmentStartEnd[1]; - } - else - { - endPos = higestRange[0] - 1; - } - - // System.out.println("Export range : " + startPos + " - " + endPos); - return new int[] { startPos, endPos }; - } - - public static void main(String[] args) - { - ArrayList hiddenCols = new ArrayList(); - hiddenCols.add(new int[] { 0, 0 }); - hiddenCols.add(new int[] { 6, 9 }); - hiddenCols.add(new int[] { 11, 12 }); - hiddenCols.add(new int[] { 33, 33 }); - hiddenCols.add(new int[] { 50, 50 }); - - int[] x = getStartEnd(new int[] { 0, 50 }, hiddenCols); - // System.out.println("Export range : " + x[0] + " - " + x[1]); - } /** * DOCUMENT ME! diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index d4300e4..3105ab9 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -213,6 +213,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void actionPerformed(ActionEvent evt) { AlignmentAnnotation[] aa = ap.av.getAlignment() @@ -331,6 +332,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mousePressed(MouseEvent evt) { getSelectedRow(evt.getY() - getScrollOffset()); @@ -343,6 +345,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseReleased(MouseEvent evt) { int start = selectedRow; @@ -377,6 +380,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseEntered(MouseEvent evt) { if (evt.getY() < 10) @@ -392,6 +396,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseExited(MouseEvent evt) { if (dragEvent == null) @@ -407,6 +412,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseDragged(MouseEvent evt) { dragEvent = evt; @@ -443,6 +449,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseMoved(MouseEvent evt) { resizePanel = evt.getY() < 10; @@ -527,6 +534,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseClicked(MouseEvent evt) { final AlignmentAnnotation[] aa = ap.av.getAlignment() @@ -711,6 +719,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, final AlignmentAnnotation aaa = aa[selectedRow]; cbmi.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { if (aaa.groupRef != null) @@ -735,6 +744,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, aa[selectedRow].groupRef.isShowConsensusHistogram()); chist.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { // TODO: pass on reference @@ -754,6 +764,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, aa[selectedRow].groupRef.isShowSequenceLogo()); cprofl.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { // TODO: pass on reference @@ -773,6 +784,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, aa[selectedRow].groupRef.isNormaliseSequenceLogo()); cproflnorm.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { @@ -798,6 +810,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, av.isShowConsensusHistogram()); chist.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { // TODO: pass on reference @@ -818,6 +831,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, av.isShowSequenceLogo()); cprof.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { // TODO: pass on reference @@ -838,6 +852,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, av.isNormaliseSequenceLogo()); cprofnorm.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { // TODO: pass on reference @@ -893,7 +908,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, List hiddenCols = av.getColumnSelection().getHiddenColumns(); if (hiddenCols != null) { - alignmentStartEnd = AlignFrame.getStartEnd(alignmentStartEnd, + alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex( hiddenCols); } String output = new FormatAdapter().formatSequences("Fasta", seqs, @@ -926,6 +941,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, * @param g1 * DOCUMENT ME! */ + @Override public void paintComponent(Graphics g) { diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index bd445c4..5a45176 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -32,6 +32,7 @@ import jalview.io.FormatAdapter; import jalview.util.MapList; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; @@ -474,4 +475,33 @@ public class AlignmentTest align.addCodonFrame(acf2); assertTrue(align.getDataset().getCodonFrames().contains(acf)); } + + @Test(groups = "Functional") + public void getVisibleStartAndEndIndexTest() + { + Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + AlignmentI align = new Alignment(new SequenceI[] { seq }); + ArrayList hiddenCols = new ArrayList(); + + int[] startEnd = align.getVisibleStartAndEndIndex(hiddenCols); + assertEquals(0, startEnd[0]); + assertEquals(25, startEnd[1]); + + hiddenCols.add(new int[] { 0, 0 }); + startEnd = align.getVisibleStartAndEndIndex(hiddenCols); + assertEquals(1, startEnd[0]); + assertEquals(25, startEnd[1]); + + hiddenCols.add(new int[] { 6, 9 }); + hiddenCols.add(new int[] { 11, 12 }); + startEnd = align.getVisibleStartAndEndIndex(hiddenCols); + assertEquals(1, startEnd[0]); + assertEquals(25, startEnd[1]); + + hiddenCols.add(new int[] { 24, 25 }); + startEnd = align.getVisibleStartAndEndIndex(hiddenCols); + System.out.println(startEnd[0] + " : " + startEnd[1]); + assertEquals(1, startEnd[0]); + assertEquals(23, startEnd[1]); + } }