From 334013f9dc7b599af9062ca053d9d091a474472e Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 19 Dec 2023 17:50:33 +0000 Subject: [PATCH] JAL-4290 Fixed one test --- src/jalview/bin/argparser/ArgValuesMap.java | 18 ++++ src/jalview/gui/AlignmentPanel.java | 2 +- src/jalview/gui/AnnotationLabels.java | 4 +- test/jalview/bin/CommandsTest.java | 130 +++++++++++++++++++++------ 4 files changed, 125 insertions(+), 29 deletions(-) diff --git a/src/jalview/bin/argparser/ArgValuesMap.java b/src/jalview/bin/argparser/ArgValuesMap.java index 219983f..7385db0 100644 --- a/src/jalview/bin/argparser/ArgValuesMap.java +++ b/src/jalview/bin/argparser/ArgValuesMap.java @@ -653,6 +653,24 @@ public class ArgValuesMap return pref != null ? (invertPref ? !prefVal : prefVal) : def; } + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(); + for (Arg a : this.getArgKeys()) + { + sb.append(a.argString()); + sb.append(":\n"); + for (ArgValue av : this.getArgValueList(a)) + { + sb.append(" "); + sb.append(av.getValue()); + sb.append("\n"); + } + } + return sb.toString(); + } + public class ArgInfo implements Comparable { private Arg arg; diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 8e7c745..358560b 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -1379,7 +1379,7 @@ public class AlignmentPanel extends GAlignmentPanel implements // need to obtain default alignment width and then add in any // additional allowance for id margin // this duplicates the calculation in getWrappedHeight but adjusts for - // offscreen idWith + // offscreen idWidth width = alignFrame.getWidth() - vscroll.getPreferredSize().width - alignFrame.getInsets().left - alignFrame.getInsets().right - getVisibleIdWidth() + getVisibleIdWidth(false); diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 94f8790..70fef2a 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -1206,8 +1206,8 @@ public class AnnotationLabels extends JPanel if (ap != null) { iwa = ap.idwidthAdjuster; - if ((Cache.getDefault(ADJUST_ANNOTATION_LABELS_WIDTH_PREF, true) - || Jalview.isHeadlessMode())) + if (Cache.getDefault(ADJUST_ANNOTATION_LABELS_WIDTH_PREF, true) + || Jalview.isHeadlessMode()) { Graphics2D g2d = (Graphics2D) g; Graphics dummy = g2d.create(); diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index e6d69cd..80354f9 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -99,7 +99,7 @@ public class CommandsTest public static void callJalviewMain(String[] args, boolean newJalview) { - if (!newJalview || Jalview.getInstance() != null) + if (Jalview.getInstance() != null && !newJalview) { Jalview.getInstance().doMain(args); } @@ -185,7 +185,7 @@ public class CommandsTest throws IOException { cleanupFiles(filenames); - String[] args = (cmdLine + " --gui").split("\\s+"); + String[] args = (cmdLine + "").split("\\s+"); try { callJalviewMain(args); @@ -198,7 +198,7 @@ public class CommandsTest x); } finally { - cleanupFiles(filenames); + // cleanupFiles(filenames); tearDown(); } } @@ -229,8 +229,14 @@ public class CommandsTest timeOut -= 25; } } - verifyOrderedFileSet(cmdLines[0] + " vs " + cmdLines[1], filenames, - false); + /* + * larger margin between IDs and alignment/annotations when in --gui mode + * + verifyOrderedFileSet(cmdLines[0] + " vs " + cmdLines[1], filenames, false); + */ + + verifySimilarEnoughImages(cmdLines[0] + " vs " + cmdLines[1], + filenames, 0.6f, 0f); } catch (Exception x) { Assert.fail("Unexpected exception during structureImageOutputTest", @@ -251,17 +257,17 @@ public class CommandsTest + "--structure [seqid=FER1_SPIOL,tempfac=plddt,showssannotations,structureviewer=jmol]" + "examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json --image=" - + testfiles + + testfiles + "/" + "test-al-pae-ss-gui.png --overwrite --gui --quit", "--open examples/uniref50.fa " + "--structure [seqid=FER1_SPIOL,tempfac=plddt,showssannotations,structureviewer=jmol]" + "examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json --image=" - + testfiles - + "test-al-pae-ss-nogui.png --overwrite --nogui" - - }, new String[] { testfiles + "test-al-pae-ss-gui.png", - testfiles + "test-al-pae-ss-nogui.png", } } }; + + testfiles + "/" + + "test-al-pae-ss-nogui.png --overwrite --nogui" }, + new String[] + { testfiles + "/test-al-pae-ss-gui.png", + testfiles + "/test-al-pae-ss-nogui.png", } } }; } private static void verifyIncreasingSize(String cmdLine, @@ -310,6 +316,71 @@ public class CommandsTest } + private static void verifySimilarEnoughImages(String cmdLine, + String[] filenames, float w_tolerance_pc, float h_tolerance_pc) + throws Exception + { + int min_w = -1; + int max_w = -1; + int min_h = -1; + int max_h = -1; + for (String filename : filenames) + { + File file = new File(filename); + Assert.assertTrue(file.exists(), "File '" + filename + + "' was not created by '" + cmdLine + "'"); + Assert.assertTrue(file.isFile(), "File '" + filename + + "' is not a file from '" + cmdLine + "'"); + Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename + + "' has no content from '" + cmdLine + "'"); + + BufferedImage img = ImageIO.read(file); + if (img.getWidth() < min_w || min_w == -1) + { + min_w = img.getWidth(); + } + if (img.getWidth() > max_w || max_w == -1) + { + max_w = img.getWidth(); + } + if (img.getHeight() < min_h || min_h == -1) + { + min_h = img.getHeight(); + } + if (img.getHeight() > max_h || max_h == -1) + { + max_h = img.getHeight(); + } + } + Assert.assertTrue(min_w > 0, + "Minimum width is not positive (" + min_w + ")"); + Assert.assertTrue(max_w > 0, + "Maximum width is not positive (" + max_w + ")"); + Assert.assertTrue(min_h > 0, + "Minimum height is not positive (" + min_h + ")"); + Assert.assertTrue(max_h > 0, + "Maximum height is not positive (" + max_h + ")"); + // tolerance + Assert.assertTrue(100 * (max_w - min_w) / min_w < w_tolerance_pc, + "Width variation (" + (max_w - min_w) + + " not within tolerance of minimum width (" + min_w + + ")"); + if (max_w != min_w) + { + System.out.println("Widths within tolerance (" + w_tolerance_pc + + "%), min_w=" + min_w + " < max_w=" + max_w); + } + Assert.assertTrue(100 * (max_h - min_h) / min_h < w_tolerance_pc, + "Height variation (" + (max_h - min_h) + + " not within tolerance of minimum height (" + min_h + + ")"); + if (max_h != min_h) + { + System.out.println("Heights within tolerance (" + h_tolerance_pc + + "%), min_h=" + min_h + " < max_h=" + max_h); + } + } + private static long waitForLastWrite(File file, int i) throws IOException { long lastSize, stableSize = Files.size(file.toPath()); @@ -382,6 +453,7 @@ public class CommandsTest { return new Object[][] { // + /* { "--gui --nonews --nosplash --open=./examples/test_fab41.result/sample.a2m " + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb " + "--structureimage=" + testfiles + "/structureimage1.png " @@ -412,6 +484,7 @@ public class CommandsTest { testfiles + "/structureimage1.png", testfiles + "/structureimage2.png", testfiles + "/structureimage3.png" } }, + */ { "--gui --nonews --nosplash --open examples/1gaq.txt --append ./examples/3W5V.pdb " + "--structure examples/1gaq.txt --seqid \"1GAQ|A\" " + "--structureimage " + testfiles @@ -420,19 +493,17 @@ public class CommandsTest + "/3w5v.png --overwrite", new String[] - { testfiles + "/1gaq.png", - testfiles + "/3w5v.png" } }, + { testfiles + "/1gaq.png", testfiles + "/3w5v.png" } }, + /* { "--headless --noquit --open ./examples/1gaq.txt --append ./examples/3W5V.pdb " + "--structure examples/1gaq.txt --seqid \"1GAQ|A\" " + "--structureimage " + testfiles + "/1gaq.png --structure examples/3W5V.pdb " + "--seqid \"3W5V|A\" --structureimage " + testfiles + "/3w5v.png --overwrite", - + new String[] { testfiles + "/1gaq.png", testfiles + "/3w5v.png" } } - - /* */ // }; @@ -799,7 +870,6 @@ public class CommandsTest String[] args = (cmdLine).split("\\s+"); callJalviewMain(args, true); // Create new instance of Jalview each time for // linkedIds - BufferedImage img = ImageIO.read(new File(filename)); Assert.assertEquals(height, img.getHeight(), "Output image '" + filename + "' is not in the expected height range, possibly because of the wrong number of annotations"); @@ -813,68 +883,76 @@ public class CommandsTest { String filename = "test/jalview/bin/argparser/testfiles/test_annotations.png"; return new Object[][] { - // - { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa " + // MUST use --noquit with --headless to avoid a System.exit() + { "--noquit --headless --nonews --nosplash --open=./examples/uniref50.fa " + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + "--seqid=FER1_SPIOL --structureviewer=jmol " + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json " + "--image=" + filename + " " + "--tempfac=plddt " + + "--overwrite " // + "--noshowssannotations " + "--noshowannotations", // filename, // 252 }, // - { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa " + { "--noquit --headless --nonews --nosplash --open=./examples/uniref50.fa " + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + "--seqid=FER1_SPIOL --structureviewer=jmol " + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json " + "--image=" + filename + " " + "--tempfac=plddt " + + "--overwrite " // + "--showssannotations " + "--noshowannotations", // filename, // 368 }, // - { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa " + { "--noquit --headless --nonews --nosplash --open=./examples/uniref50.fa " + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + "--seqid=FER1_SPIOL --structureviewer=jmol " + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json " + "--image=" + filename + " " + "--tempfac=plddt " + + "--overwrite " // + "--noshowssannotations " + "--showannotations", // filename, // 524 }, // - { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa " + { "--noquit --headless --nonews --nosplash --open=./examples/uniref50.fa " + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + "--seqid=FER1_SPIOL --structureviewer=jmol " + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json " + "--image=" + filename + " " + "--tempfac=plddt " + + "--overwrite " // + "--showssannotations " + "--showannotations", // filename, // 660 }, // - { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa " + { "--gui --nonews --nosplash --open=./examples/uniref50.fa " + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + "--seqid=FER1_SPIOL --structureviewer=jmol " + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json " + "--image=" + filename + " " + "--tempfac=plddt " + + "--overwrite " // + "--noshowssannotations " + "--noshowannotations", // filename, // 252 }, // - { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa " + { "--gui --nonews --nosplash --open=./examples/uniref50.fa " + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + "--seqid=FER1_SPIOL --structureviewer=jmol " + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json " + "--image=" + filename + " " + "--tempfac=plddt " + + "--overwrite " // + "--showssannotations " + "--noshowannotations", // filename, // 368 }, // - { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa " + { "--gui --nonews --nosplash --open=./examples/uniref50.fa " + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + "--seqid=FER1_SPIOL --structureviewer=jmol " + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json " + "--image=" + filename + " " + "--tempfac=plddt " + + "--overwrite " // + "--noshowssannotations " + "--showannotations", // filename, // 524 }, // - { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa " + { "--gui --nonews --nosplash --open=./examples/uniref50.fa " + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + "--seqid=FER1_SPIOL --structureviewer=jmol " + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json " + "--image=" + filename + " " + "--tempfac=plddt " + + "--overwrite " // + "--showssannotations " + "--showannotations", // filename, // 660 }, // -- 1.7.10.2