JAL-4290 fixed tests
[jalview.git] / test / jalview / bin / CommandsTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.bin;
22
23 import java.awt.image.BufferedImage;
24 import java.io.File;
25 import java.io.IOException;
26 import java.nio.file.Files;
27 import java.util.Date;
28 import java.util.HashSet;
29 import java.util.Set;
30
31 import javax.imageio.ImageIO;
32 import javax.swing.SwingUtilities;
33
34 import org.testng.Assert;
35 import org.testng.annotations.AfterClass;
36 import org.testng.annotations.AfterMethod;
37 import org.testng.annotations.BeforeClass;
38 import org.testng.annotations.DataProvider;
39 import org.testng.annotations.Test;
40
41 import jalview.gui.AlignFrame;
42 import jalview.gui.Desktop;
43 import jalview.gui.JvOptionPane;
44 import jalview.util.ArrayUtils;
45
46 public class CommandsTest
47 {
48   private static final String testfiles = "test/jalview/bin/argparser/testfiles";
49
50   @BeforeClass(alwaysRun = true)
51   public static void setUpBeforeClass() throws Exception
52   {
53     Cache.loadProperties("test/jalview/gui/quitProps.jvprops");
54     Date oneHourFromNow = new Date(
55             System.currentTimeMillis() + 3600 * 1000);
56     Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", oneHourFromNow);
57   }
58
59   @AfterClass(alwaysRun = true)
60   public static void resetProps()
61   {
62     Cache.loadProperties("test/jalview/testProps.jvprops");
63   }
64
65   @BeforeClass(alwaysRun = true)
66   public void setUpJvOptionPane()
67   {
68     JvOptionPane.setInteractiveMode(false);
69     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
70   }
71
72   @AfterMethod(alwaysRun = true)
73   public void tearDown()
74   {
75     try
76     {
77       // occasionally we are blocked by Jmol redraws
78       SwingUtilities.invokeAndWait(new Runnable()
79       {
80
81         @Override
82         public void run()
83         {
84           Desktop.closeDesktop();
85         }
86       });
87     } catch (Exception foo)
88     {
89       System.err.println("Failed during teardown with exception");
90       foo.printStackTrace();
91     }
92
93   }
94
95   public static void callJalviewMain(String[] args)
96   {
97     callJalviewMain(args, false);
98   }
99
100   public static void callJalviewMain(String[] args, boolean newJalview)
101   {
102     if (Jalview.getInstance() != null && !newJalview)
103     {
104       Jalview.getInstance().doMain(args);
105     }
106     else
107     {
108       Jalview.main(args);
109     }
110   }
111
112   /* --setprops is currently disabled so this test won't work
113   @Test(groups = "Functional")
114   public void setpropsTest()
115   {
116     final String MOSTLY_HARMLESS = "MOSTLY_HARMLESS";
117     String cmdLine = "--setprop=" + MOSTLY_HARMLESS + "=Earth";
118     String[] args = cmdLine.split("\\s+");
119     Jalview.main(args);
120     Assert.assertEquals(Cache.getDefault(MOSTLY_HARMLESS, "Magrathea"),
121             "Earth");
122   }
123   */
124
125   @Test(
126     groups =
127     { "Functional", "testTask3" },
128     dataProvider = "cmdLines",
129     singleThreaded = true)
130
131   public void commandsOpenTest(String cmdLine, boolean cmdArgs,
132           int numFrames, String[] sequences)
133   {
134     try
135     {
136       String[] args = (cmdLine + " --gui").split("\\s+");
137       callJalviewMain(args);
138       Commands cmds = Jalview.getInstance().getCommands();
139       Assert.assertNotNull(cmds);
140       Assert.assertEquals(cmds.commandArgsProvided(), cmdArgs,
141               "Commands were not provided in the args");
142       Assert.assertEquals(cmds.argsWereParsed(), cmdArgs,
143               "Overall command parse and operation is false");
144
145       Assert.assertEquals(Desktop.getDesktopAlignFrames().length, numFrames,
146               "Wrong number of AlignFrames");
147
148       if (sequences != null)
149       {
150         Set<String> openedSequenceNames = new HashSet<>();
151         AlignFrame[] afs = Desktop.getDesktopAlignFrames();
152         for (AlignFrame af : afs)
153         {
154           openedSequenceNames.addAll(
155                   af.getViewport().getAlignment().getSequenceNames());
156         }
157         for (String sequence : sequences)
158         {
159           Assert.assertTrue(openedSequenceNames.contains(sequence),
160                   "Sequence '" + sequence
161                           + "' was not found in opened alignment files: "
162                           + cmdLine + ".\nOpened sequence names are:\n"
163                           + String.join("\n", openedSequenceNames));
164         }
165       }
166
167       Assert.assertFalse(
168               lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST"));
169     } catch (Exception x)
170     {
171       Assert.fail("Unexpected exception during commandsOpenTest", x);
172     } finally
173     {
174       tearDown();
175
176     }
177   }
178
179   @Test(
180     groups =
181     { "Functional", "testTask3" },
182     dataProvider = "structureImageOutputFiles",
183     singleThreaded = true)
184   public void structureImageOutputTest(String cmdLine, String[] filenames)
185           throws IOException
186   {
187     cleanupFiles(filenames);
188     String[] args = (cmdLine).split("\\s+");
189     try
190     {
191       callJalviewMain(args, true);
192       Commands cmds = Jalview.getInstance().getCommands();
193       Assert.assertNotNull(cmds);
194       verifyIncreasingSize(cmdLine, filenames);
195     } catch (Exception x)
196     {
197       Assert.fail("Unexpected exception during structureImageOutputTest",
198               x);
199     } finally
200     {
201       // cleanupFiles(filenames);
202       tearDown();
203     }
204   }
205
206   /**
207    * given two command lines, compare the output files produced - they should
208    * exist and be equal in size
209    */
210   @Test(
211     groups =
212     { "Functional", "testTask3" },
213     dataProvider = "compareHeadlessAndGUIOps",
214     singleThreaded = true)
215   public void headlessOrGuiImageOutputTest(String[] cmdLines,
216           String[] filenames) throws IOException
217   {
218     cleanupFiles(filenames);
219     try
220     {
221       for (String cmdLine : cmdLines)
222       {
223         CommandLineOperations.Worker runner = CommandLineOperations
224                 .getJalviewDesktopRunner(false, cmdLine, 1000);
225         long timeOut = 10000;
226         while (runner.isAlive() && timeOut > 0)
227         {
228           Thread.sleep(25);
229           timeOut -= 25;
230         }
231       }
232       /*
233        *  larger margin between IDs and alignment/annotations when in --gui mode
234        *  
235       verifyOrderedFileSet(cmdLines[0] + " vs " + cmdLines[1], filenames, false);
236        */
237
238       verifySimilarEnoughImages(cmdLines[0] + " vs " + cmdLines[1],
239               filenames, 0.6f, 0f);
240     } catch (Exception x)
241     {
242       Assert.fail("Unexpected exception during structureImageOutputTest",
243               x);
244     } finally
245     {
246       cleanupFiles(filenames);
247       tearDown();
248     }
249   }
250
251   @DataProvider(name = "compareHeadlessAndGUIOps")
252   public Object[][] compareHeadlessAndGUIOps()
253   {
254     return new Object[][] {
255         new Object[]
256         { new String[] { "--open examples/uniref50.fa "
257                 + "--structure [seqid=FER1_SPIOL,tempfac=plddt,showssannotations,structureviewer=jmol]"
258                 + "examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
259                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json --image="
260                 + testfiles + "/"
261                 + "test-al-pae-ss-gui.png --overwrite --gui --quit",
262             "--open examples/uniref50.fa "
263                     + "--structure [seqid=FER1_SPIOL,tempfac=plddt,showssannotations,structureviewer=jmol]"
264                     + "examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
265                     + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json --image="
266                     + testfiles + "/"
267                     + "test-al-pae-ss-nogui.png --overwrite --nogui" },
268             new String[]
269             { testfiles + "/test-al-pae-ss-gui.png",
270                 testfiles + "/test-al-pae-ss-nogui.png", } } };
271   }
272
273   private static void verifyIncreasingSize(String cmdLine,
274           String[] filenames) throws Exception
275   {
276     verifyOrderedFileSet(cmdLine, filenames, true);
277   }
278
279   private static void verifyOrderedFileSet(String cmdLine,
280           String[] filenames, boolean increasingSize) throws Exception
281   {
282     File lastFile = null;
283     for (String filename : filenames)
284     {
285       File file = new File(filename);
286       Assert.assertTrue(file.exists(), "File '" + filename
287               + "' was not created by '" + cmdLine + "'");
288       Assert.assertTrue(file.isFile(), "File '" + filename
289               + "' is not a file from '" + cmdLine + "'");
290       Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename
291               + "' has no content from '" + cmdLine + "'");
292       // make sure the successive output files get bigger!
293       if (lastFile != null)
294       {
295         waitForLastWrite(file, 25);
296
297         if (increasingSize)
298         {
299           Assert.assertTrue(
300                   Files.size(file.toPath()) > Files.size(lastFile.toPath()),
301                   "Expected " + file.toPath() + " to be larger than "
302                           + lastFile.toPath());
303         }
304         else
305         {
306           Assert.assertEquals(Files.size(file.toPath()),
307                   Files.size(lastFile.toPath()),
308                   "New file " + file.toPath()
309                           + " (actual size) not same as last file's size "
310                           + lastFile.toString());
311         }
312       }
313       // remember it for next file
314       lastFile = file;
315     }
316
317   }
318
319   private static void verifySimilarEnoughImages(String cmdLine,
320           String[] filenames, float w_tolerance_pc, float h_tolerance_pc)
321           throws Exception
322   {
323     int min_w = -1;
324     int max_w = -1;
325     int min_h = -1;
326     int max_h = -1;
327     for (String filename : filenames)
328     {
329       File file = new File(filename);
330       Assert.assertTrue(file.exists(), "File '" + filename
331               + "' was not created by '" + cmdLine + "'");
332       Assert.assertTrue(file.isFile(), "File '" + filename
333               + "' is not a file from '" + cmdLine + "'");
334       Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename
335               + "' has no content from '" + cmdLine + "'");
336
337       BufferedImage img = ImageIO.read(file);
338       if (img.getWidth() < min_w || min_w == -1)
339       {
340         min_w = img.getWidth();
341       }
342       if (img.getWidth() > max_w || max_w == -1)
343       {
344         max_w = img.getWidth();
345       }
346       if (img.getHeight() < min_h || min_h == -1)
347       {
348         min_h = img.getHeight();
349       }
350       if (img.getHeight() > max_h || max_h == -1)
351       {
352         max_h = img.getHeight();
353       }
354     }
355     Assert.assertTrue(min_w > 0,
356             "Minimum width is not positive (" + min_w + ")");
357     Assert.assertTrue(max_w > 0,
358             "Maximum width is not positive (" + max_w + ")");
359     Assert.assertTrue(min_h > 0,
360             "Minimum height is not positive (" + min_h + ")");
361     Assert.assertTrue(max_h > 0,
362             "Maximum height is not positive (" + max_h + ")");
363     // tolerance
364     Assert.assertTrue(100 * (max_w - min_w) / min_w < w_tolerance_pc,
365             "Width variation (" + (max_w - min_w)
366                     + " not within tolerance of minimum width (" + min_w
367                     + ")");
368     if (max_w != min_w)
369     {
370       System.out.println("Widths within tolerance (" + w_tolerance_pc
371               + "%), min_w=" + min_w + " < max_w=" + max_w);
372     }
373     Assert.assertTrue(100 * (max_h - min_h) / min_h < w_tolerance_pc,
374             "Height variation (" + (max_h - min_h)
375                     + " not within tolerance of minimum height (" + min_h
376                     + ")");
377     if (max_h != min_h)
378     {
379       System.out.println("Heights within tolerance (" + h_tolerance_pc
380               + "%), min_h=" + min_h + " < max_h=" + max_h);
381     }
382   }
383
384   private static long waitForLastWrite(File file, int i) throws IOException
385   {
386     long lastSize, stableSize = Files.size(file.toPath());
387     // wait around until we are sure the file has been completely written.
388     do
389     {
390       lastSize = stableSize;
391       try
392       {
393         Thread.sleep(i);
394       } catch (Exception x)
395       {
396       }
397       stableSize = Files.size(file.toPath());
398     } while (stableSize != lastSize);
399     return stableSize;
400   }
401
402   @Test(
403     groups = "Functional",
404     dataProvider = "argfileOutputFiles",
405     singleThreaded = true)
406
407   public void argFilesGlobAndSubstitutionsTest(String cmdLine,
408           String[] filenames) throws IOException
409   {
410     cleanupFiles(filenames);
411     String[] args = (cmdLine + " --gui").split("\\s+");
412     try
413     {
414       callJalviewMain(args);
415       Commands cmds = Jalview.getInstance().getCommands();
416       Assert.assertNotNull(cmds);
417       File lastFile = null;
418       for (String filename : filenames)
419       {
420         File file = new File(filename);
421         Assert.assertTrue(file.exists(), "File '" + filename
422                 + "' was not created by '" + cmdLine + "'");
423         Assert.assertTrue(file.isFile(), "File '" + filename
424                 + "' is not a file from '" + cmdLine + "'");
425         Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename
426                 + "' has no content from '" + cmdLine + "'");
427         // make sure the successive output files get bigger!
428         if (lastFile != null)
429         {
430           Assert.assertTrue(Files.size(file.toPath()) > Files
431                   .size(lastFile.toPath()));
432           System.out.println("this file: " + file + " +"
433                   + Files.size(file.toPath()) + " greater than "
434                   + Files.size(lastFile.toPath()));
435         }
436         // remember it for next file
437         lastFile = file;
438       }
439     } catch (Exception x)
440     {
441       Assert.fail(
442               "Unexpected exception during argFilesGlobAndSubstitutions",
443               x);
444     } finally
445     {
446       cleanupFiles(filenames);
447       tearDown();
448     }
449   }
450
451   @DataProvider(name = "structureImageOutputFiles")
452   public Object[][] structureImageOutputFiles()
453   {
454     return new Object[][] {
455         //
456         /*
457                 */
458         { "--gui --nonews --nosplash --open=./examples/test_fab41.result/sample.a2m "
459                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
460                 + "--structureimage=" + testfiles
461                 + "/structureimage0-1.png "
462                 + "--open=./examples/test_fab41.result/sample.a2m "
463                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
464                 + "--structureimage=" + testfiles
465                 + "/structureimage0-2.png --scale=1.5 "
466                 + "--open=./examples/test_fab41.result/sample.a2m "
467                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
468                 + "--structureimage=" + testfiles
469                 + "/structureimage0-3.png --scale=2.0 ",
470             new String[]
471             { testfiles + "/structureimage0-1.png",
472                 testfiles + "/structureimage0-2.png",
473                 testfiles + "/structureimage0-3.png" } },
474         { "--headless --noquit --open=./examples/test_fab41.result/sample.a2m "
475                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
476                 + "--structureimage=" + testfiles
477                 + "/structureimage1-1.png "
478                 + "--open=./examples/test_fab41.result/sample.a2m "
479                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
480                 + "--structureimage=" + testfiles
481                 + "/structureimage1-2.png --scale=1.5 "
482                 + "--open=./examples/test_fab41.result/sample.a2m "
483                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
484                 + "--structureimage=" + testfiles
485                 + "/structureimage1-3.png --scale=2.0 ",
486             new String[]
487             { testfiles + "/structureimage1-1.png",
488                 testfiles + "/structureimage1-2.png",
489                 testfiles + "/structureimage1-3.png" } },
490         { "--gui --nonews --nosplash --open examples/1gaq.txt --append ./examples/3W5V.pdb "
491                 + "--structure examples/1gaq.txt --seqid \"1GAQ|A\" "
492                 + "--structureimage " + testfiles
493                 + "/structureimage2-1gaq.png --structure examples/3W5V.pdb "
494                 + "--seqid \"3W5V|A\" --structureimage " + testfiles
495                 + "/structureimage2-3w5v.png --overwrite",
496
497             new String[]
498             { testfiles + "/structureimage2-3w5v.png",
499                 testfiles + "/structureimage2-1gaq.png", } },
500         { "--headless --noquit --open ./examples/1gaq.txt --append ./examples/3W5V.pdb "
501                 + "--structure examples/1gaq.txt --seqid \"1GAQ|A\" "
502                 + "--structureimage " + testfiles
503                 + "/structureimage3-1gaq.png --structure examples/3W5V.pdb "
504                 + "--seqid \"3W5V|A\" --structureimage " + testfiles
505                 + "/structureimage3-3w5v.png --overwrite",
506
507             new String[]
508             { testfiles + "/structureimage3-3w5v.png",
509                 testfiles + "/structureimage3-1gaq.png", } }
510         /*
511                 */
512         //
513     };
514
515   }
516
517   @DataProvider(name = "argfileOutputFiles")
518   public Object[][] argfileOutputFiles()
519   {
520     return new Object[][] {
521         //
522         { "--gui --argfile=" + testfiles + "/**/*.txt", new String[]
523         { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png",
524             testfiles + "/dir3/subdir/test0.png" } },
525         { "--gui --argfile=" + testfiles + "/**/argfile.txt", new String[]
526         { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } },
527         { "--gui --argfile=" + testfiles + "/dir*/argfile.txt", new String[]
528         { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } },
529         { "--gui --initsubstitutions --append examples/uniref50.fa --image "
530                 + testfiles + "/{basename}.png",
531             new String[]
532             { testfiles + "/uniref50.png" } },
533         { "--gui --append examples/uniref50.fa --nosubstitutions --image "
534                 + testfiles + "/{basename}.png",
535             new String[]
536             { testfiles + "/{basename}.png" } }
537         //
538     };
539
540   }
541
542   @DataProvider(name = "cmdLines")
543   public Object[][] cmdLines()
544   {
545     String[] someUniref50Seqs = new String[] { "FER_CAPAA", "FER_CAPAN",
546         "FER1_MAIZE", "FER1_SPIOL", "O80429_MAIZE" };
547     String[] t1 = new String[] { "TEST1" };
548     String[] t2 = new String[] { "TEST2" };
549     String[] t3 = new String[] { "TEST3" };
550     return new Object[][] {
551         /*
552         */
553         { "--append=examples/uniref50.fa", true, 1, someUniref50Seqs },
554         { "--append examples/uniref50.fa", true, 1, someUniref50Seqs },
555         { "--append=examples/uniref50*.fa", true, 1, someUniref50Seqs },
556         // NOTE we cannot use shell expansion in tests, so list all files!
557         { "--append examples/uniref50.fa examples/uniref50_mz.fa", true, 1,
558             someUniref50Seqs },
559         { "--append=[new]examples/uniref50*.fa", true, 2,
560             someUniref50Seqs },
561         { "--open=examples/uniref50*.fa", true, 2, someUniref50Seqs },
562         { "examples/uniref50.fa", true, 1, someUniref50Seqs },
563         { "examples/uniref50.fa " + testfiles + "/test1.fa", true, 2,
564             ArrayUtils.concatArrays(someUniref50Seqs, t1) },
565         { "examples/uniref50.fa " + testfiles + "/test1.fa", true, 2, t1 },
566         { "--gui --argfile=" + testfiles + "/argfile0.txt", true, 1,
567             ArrayUtils.concatArrays(t1, t3) },
568         { "--gui --argfile=" + testfiles + "/argfile*.txt", true, 5,
569             ArrayUtils.concatArrays(t1, t2, t3) },
570         { "--gui --argfile=" + testfiles + "/argfile.autocounter", true, 3,
571             ArrayUtils.concatArrays(t1, t2) } };
572
573   }
574
575   public static boolean lookForSequenceName(String sequenceName)
576   {
577     AlignFrame[] afs = Desktop.getDesktopAlignFrames();
578     for (AlignFrame af : afs)
579     {
580       for (String name : af.getViewport().getAlignment().getSequenceNames())
581       {
582         if (sequenceName.equals(name))
583         {
584           return true;
585         }
586       }
587     }
588     return false;
589   }
590
591   public static void cleanupFiles(String[] filenames)
592   {
593     for (String filename : filenames)
594     {
595       File file = new File(filename);
596       if (file.exists())
597       {
598         file.delete();
599       }
600     }
601   }
602
603   private final String deleteDir = "test/deleteAfter";
604
605   @Test(
606     groups = "Functional",
607     dataProvider = "allLinkedIdsData",
608     singleThreaded = true)
609   public void allLinkedIdsTest(String cmdLine, String[] filenames,
610           String[] nonfilenames)
611   {
612     String[] args = (cmdLine + " --gui").split("\\s+");
613     callJalviewMain(args);
614     Commands cmds = Jalview.getInstance().getCommands();
615     Assert.assertNotNull(cmds);
616     for (String filename : filenames)
617     {
618       Assert.assertTrue(new File(filename).exists(),
619               "File '" + filename + "' was not created");
620     }
621     cleanupFiles(filenames);
622     if (nonfilenames != null)
623     {
624       for (String nonfilename : nonfilenames)
625       {
626         File nonfile = new File(nonfilename);
627         Assert.assertFalse(nonfile.exists(),
628                 "File " + nonfilename + " exists when it shouldn't!");
629       }
630     }
631
632     File deleteDirF = new File(deleteDir);
633     if (deleteDirF.exists())
634     {
635       deleteDirF.delete();
636     }
637   }
638
639   @DataProvider(name = "allLinkedIdsData")
640   public Object[][] allLinkedIdsData()
641   {
642     return new Object[][] {
643         //
644         { "--gui --open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --output={dirname}/{basename}.stk --close",
645             new String[]
646             { "test/jalview/bin/argparser/testfiles/test1.stk",
647                 "test/jalview/bin/argparser/testfiles/test2.stk",
648                 "test/jalview/bin/argparser/testfiles/test3.stk", },
649             null },
650         { "--gui --open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --image={dirname}/{basename}.png --close",
651             new String[]
652             { "test/jalview/bin/argparser/testfiles/test1.png",
653                 "test/jalview/bin/argparser/testfiles/test2.png",
654                 "test/jalview/bin/argparser/testfiles/test3.png", },
655             null },
656         { "--gui --open=test/jalview/bin/argparser/testfiles/*.fa --all --output={dirname}/{basename}.stk --close",
657             new String[]
658             { "test/jalview/bin/argparser/testfiles/test1.stk",
659                 "test/jalview/bin/argparser/testfiles/test2.stk",
660                 "test/jalview/bin/argparser/testfiles/test3.stk", },
661             new String[]
662             { "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
663                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
664                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
665                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
666                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
667                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
668                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
669                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
670                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, },
671         { "--gui --open=test/jalview/bin/argparser/**/*.fa --all --output={dirname}/{basename}.stk --close",
672             new String[]
673             { "test/jalview/bin/argparser/testfiles/test1.stk",
674                 "test/jalview/bin/argparser/testfiles/test2.stk",
675                 "test/jalview/bin/argparser/testfiles/test3.stk",
676                 "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
677                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
678                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
679                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
680                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
681                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
682                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
683                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
684                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", },
685             null },
686         { "--gui --open=test/jalview/bin/argparser/**/*.fa --output=*/*.stk --close",
687             new String[]
688             { "test/jalview/bin/argparser/testfiles/test1.stk",
689                 "test/jalview/bin/argparser/testfiles/test2.stk",
690                 "test/jalview/bin/argparser/testfiles/test3.stk",
691                 "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
692                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
693                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
694                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
695                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
696                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
697                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
698                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
699                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", },
700             null },
701         { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --all --output=*/*.stk --close",
702             new String[]
703             { "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
704                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
705                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
706                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
707                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk", },
708             new String[]
709             { "test/jalview/bin/argparser/testfiles/test1.stk",
710                 "test/jalview/bin/argparser/testfiles/test2.stk",
711                 "test/jalview/bin/argparser/testfiles/test3.stk",
712                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
713                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
714                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
715                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, },
716         { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output=*/*.stk --close",
717             new String[]
718             { "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
719                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
720                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk", },
721             new String[]
722             { "test/jalview/bin/argparser/testfiles/test1.stk",
723                 "test/jalview/bin/argparser/testfiles/test2.stk",
724                 "test/jalview/bin/argparser/testfiles/test3.stk",
725                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
726                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
727                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
728                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, },
729         { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output={dirname}/{basename}.stk --close",
730             new String[]
731             { "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
732                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
733                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk", },
734             new String[]
735             { "test/jalview/bin/argparser/testfiles/test1.stk",
736                 "test/jalview/bin/argparser/testfiles/test2.stk",
737                 "test/jalview/bin/argparser/testfiles/test3.stk",
738                 "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
739                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
740                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
741                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
742                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
743                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, },
744         { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output={dirname}/{basename}.stk --close",
745             new String[]
746             { "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
747                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
748                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk", },
749             new String[]
750             { "test/jalview/bin/argparser/testfiles/test1.stk",
751                 "test/jalview/bin/argparser/testfiles/test2.stk",
752                 "test/jalview/bin/argparser/testfiles/test3.stk",
753                 "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
754                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
755                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
756                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
757                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
758                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, },
759         { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --output {dirname}/{basename}.stk --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output={dirname}/{basename}.aln --close",
760             new String[]
761             { "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
762                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
763                 "test/jalview/bin/argparser/testfiles/dir2/test1.aln",
764                 "test/jalview/bin/argparser/testfiles/dir2/test2.aln",
765                 "test/jalview/bin/argparser/testfiles/dir2/test3.aln", },
766             new String[]
767             { "test/jalview/bin/argparser/testfiles/test1.stk",
768                 "test/jalview/bin/argparser/testfiles/test2.stk",
769                 "test/jalview/bin/argparser/testfiles/test3.stk",
770                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
771                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
772                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
773                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
774                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
775                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
776                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk",
777                 "test/jalview/bin/argparser/testfiles/test1.aln",
778                 "test/jalview/bin/argparser/testfiles/test2.aln",
779                 "test/jalview/bin/argparser/testfiles/test3.aln",
780                 "test/jalview/bin/argparser/testfiles/dir1/test1.aln",
781                 "test/jalview/bin/argparser/testfiles/dir1/test2.aln",
782                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.aln",
783                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.aln",
784                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.aln",
785                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.aln", }, },
786         // --mkdirs
787         { "--headless --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --output "
788                 + deleteDir
789                 + "/{dirname}/{basename}.stk --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output="
790                 + deleteDir
791                 + "/{dirname}/{basename}.aln --close --all --mkdirs",
792             new String[]
793             { deleteDir
794                     + "/test/jalview/bin/argparser/testfiles/dir1/test1.stk",
795                 deleteDir
796                         + "/test/jalview/bin/argparser/testfiles/dir1/test2.stk",
797                 deleteDir
798                         + "/test/jalview/bin/argparser/testfiles/dir2/test1.aln",
799                 deleteDir
800                         + "/test/jalview/bin/argparser/testfiles/dir2/test2.aln",
801                 deleteDir
802                         + "/test/jalview/bin/argparser/testfiles/dir2/test3.aln", },
803             new String[]
804             { "test/jalview/bin/argparser/testfiles/test1.stk",
805                 "test/jalview/bin/argparser/testfiles/test2.stk",
806                 "test/jalview/bin/argparser/testfiles/test3.stk",
807                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
808                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
809                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
810                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
811                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
812                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
813                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk",
814                 "test/jalview/bin/argparser/testfiles/test1.aln",
815                 "test/jalview/bin/argparser/testfiles/test2.aln",
816                 "test/jalview/bin/argparser/testfiles/test3.aln",
817                 "test/jalview/bin/argparser/testfiles/dir1/test1.aln",
818                 "test/jalview/bin/argparser/testfiles/dir1/test2.aln",
819                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.aln",
820                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.aln",
821                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.aln",
822                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.aln",
823                 deleteDir
824                         + "test/jalview/bin/argparser/testfiles/test1.stk",
825                 deleteDir
826                         + "test/jalview/bin/argparser/testfiles/test2.stk",
827                 deleteDir
828                         + "test/jalview/bin/argparser/testfiles/test3.stk",
829                 deleteDir
830                         + "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
831                 deleteDir
832                         + "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
833                 deleteDir
834                         + "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
835                 deleteDir
836                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
837                 deleteDir
838                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
839                 deleteDir
840                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
841                 deleteDir
842                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk",
843                 deleteDir
844                         + "test/jalview/bin/argparser/testfiles/test1.aln",
845                 deleteDir
846                         + "test/jalview/bin/argparser/testfiles/test2.aln",
847                 deleteDir
848                         + "test/jalview/bin/argparser/testfiles/test3.aln",
849                 deleteDir
850                         + "test/jalview/bin/argparser/testfiles/dir1/test1.aln",
851                 deleteDir
852                         + "test/jalview/bin/argparser/testfiles/dir1/test2.aln",
853                 deleteDir
854                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.aln",
855                 deleteDir
856                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.aln",
857                 deleteDir
858                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.aln",
859                 deleteDir
860                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.aln", }, },
861         //
862     };
863   }
864
865   @Test(
866     groups =
867     { "Functional", "testTask3" },
868     dataProvider = "structureImageAnnotationsOutputFiles",
869     singleThreaded = true)
870   public void structureImageAnnotationsOutputTest(String cmdLine,
871           String filename, int height) throws IOException
872   {
873     cleanupFiles(new String[] { filename });
874     String[] args = (cmdLine).split("\\s+");
875     callJalviewMain(args, true); // Create new instance of Jalview each time for
876                                  // linkedIds
877     BufferedImage img = ImageIO.read(new File(filename));
878     Assert.assertEquals(height, img.getHeight(), "Output image '" + filename
879             + "' is not in the expected height range, possibly because of the wrong number of annotations");
880
881     cleanupFiles(new String[] { filename });
882     tearDown();
883   }
884
885   @DataProvider(name = "structureImageAnnotationsOutputFiles")
886   public Object[][] structureImageAnnotationsOutputFiles()
887   {
888     String filename = "test/jalview/bin/argparser/testfiles/test_annotations.png";
889     return new Object[][] {
890         // MUST use --noquit with --headless to avoid a System.exit()
891         { "--noquit --headless --nonews --nosplash --open=./examples/uniref50.fa "
892                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
893                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
894                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
895                 + "--image=" + filename + " " + "--tempfac=plddt "
896                 + "--overwrite " //
897                 + "--noshowssannotations " + "--noshowannotations", //
898             filename, //
899             252 }, //
900         { "--noquit --headless --nonews --nosplash --open=./examples/uniref50.fa "
901                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
902                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
903                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
904                 + "--image=" + filename + " " + "--tempfac=plddt "
905                 + "--overwrite " //
906                 + "--showssannotations " + "--noshowannotations", //
907             filename, //
908             368 }, //
909         { "--noquit --headless --nonews --nosplash --open=./examples/uniref50.fa "
910                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
911                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
912                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
913                 + "--image=" + filename + " " + "--tempfac=plddt "
914                 + "--overwrite " //
915                 + "--noshowssannotations " + "--showannotations", //
916             filename, //
917             524 }, //
918         { "--noquit --headless --nonews --nosplash --open=./examples/uniref50.fa "
919                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
920                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
921                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
922                 + "--image=" + filename + " " + "--tempfac=plddt "
923                 + "--overwrite " //
924                 + "--showssannotations " + "--showannotations", //
925             filename, //
926             660 }, //
927         { "--gui --nonews --nosplash --open=./examples/uniref50.fa "
928                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
929                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
930                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
931                 + "--image=" + filename + " " + "--tempfac=plddt "
932                 + "--overwrite " //
933                 + "--noshowssannotations " + "--noshowannotations", //
934             filename, //
935             252 }, //
936         { "--gui --nonews --nosplash --open=./examples/uniref50.fa "
937                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
938                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
939                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
940                 + "--image=" + filename + " " + "--tempfac=plddt "
941                 + "--overwrite " //
942                 + "--showssannotations " + "--noshowannotations", //
943             filename, //
944             368 }, //
945         { "--gui --nonews --nosplash --open=./examples/uniref50.fa "
946                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
947                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
948                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
949                 + "--image=" + filename + " " + "--tempfac=plddt "
950                 + "--overwrite " //
951                 + "--noshowssannotations " + "--showannotations", //
952             filename, //
953             524 }, //
954         { "--gui --nonews --nosplash --open=./examples/uniref50.fa "
955                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
956                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
957                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
958                 + "--image=" + filename + " " + "--tempfac=plddt "
959                 + "--overwrite " //
960                 + "--showssannotations " + "--showannotations", //
961             filename, //
962             660 }, //
963     };
964   }
965
966 }