JAL-4290 not quite working 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 (!newJalview || Jalview.getInstance() != null)
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 + " --gui").split("\\s+");
189     try
190     {
191       callJalviewMain(args);
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       verifyOrderedFileSet(cmdLines[0] + " vs " + cmdLines[1], filenames,
233               false);
234     } catch (Exception x)
235     {
236       Assert.fail("Unexpected exception during structureImageOutputTest",
237               x);
238     } finally
239     {
240       cleanupFiles(filenames);
241       tearDown();
242     }
243   }
244
245   @DataProvider(name = "compareHeadlessAndGUIOps")
246   public Object[][] compareHeadlessAndGUIOps()
247   {
248     return new Object[][] {
249         new Object[]
250         { new String[] { "--open examples/uniref50.fa "
251                 + "--structure [seqid=FER1_SPIOL,tempfac=plddt,showssannotations,structureviewer=jmol]"
252                 + "examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
253                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json --image="
254                 + testfiles
255                 + "test-al-pae-ss-gui.png --overwrite --gui --quit",
256             "--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-nogui.png --overwrite --nogui"
262
263         }, new String[] { testfiles + "test-al-pae-ss-gui.png",
264             testfiles + "test-al-pae-ss-nogui.png", } } };
265   }
266
267   private static void verifyIncreasingSize(String cmdLine,
268           String[] filenames) throws Exception
269   {
270     verifyOrderedFileSet(cmdLine, filenames, true);
271   }
272
273   private static void verifyOrderedFileSet(String cmdLine,
274           String[] filenames, boolean increasingSize) throws Exception
275   {
276     File lastFile = null;
277     for (String filename : filenames)
278     {
279       File file = new File(filename);
280       Assert.assertTrue(file.exists(), "File '" + filename
281               + "' was not created by '" + cmdLine + "'");
282       Assert.assertTrue(file.isFile(), "File '" + filename
283               + "' is not a file from '" + cmdLine + "'");
284       Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename
285               + "' has no content from '" + cmdLine + "'");
286       // make sure the successive output files get bigger!
287       if (lastFile != null)
288       {
289         waitForLastWrite(file, 25);
290
291         if (increasingSize)
292         {
293           Assert.assertTrue(
294                   Files.size(file.toPath()) > Files.size(lastFile.toPath()),
295                   "Expected " + file.toPath() + " to be larger than "
296                           + lastFile.toPath());
297         }
298         else
299         {
300           Assert.assertEquals(Files.size(file.toPath()),
301                   Files.size(lastFile.toPath()),
302                   "New file " + file.toPath()
303                           + " (actual size) not same as last file's size "
304                           + lastFile.toString());
305         }
306       }
307       // remember it for next file
308       lastFile = file;
309     }
310
311   }
312
313   private static long waitForLastWrite(File file, int i) throws IOException
314   {
315     long lastSize, stableSize = Files.size(file.toPath());
316     // wait around until we are sure the file has been completely written.
317     do
318     {
319       lastSize = stableSize;
320       try
321       {
322         Thread.sleep(i);
323       } catch (Exception x)
324       {
325       }
326       stableSize = Files.size(file.toPath());
327     } while (stableSize != lastSize);
328     return stableSize;
329   }
330
331   @Test(
332     groups = "Functional",
333     dataProvider = "argfileOutputFiles",
334     singleThreaded = true)
335
336   public void argFilesGlobAndSubstitutionsTest(String cmdLine,
337           String[] filenames) throws IOException
338   {
339     cleanupFiles(filenames);
340     String[] args = (cmdLine + " --gui").split("\\s+");
341     try
342     {
343       callJalviewMain(args);
344       Commands cmds = Jalview.getInstance().getCommands();
345       Assert.assertNotNull(cmds);
346       File lastFile = null;
347       for (String filename : filenames)
348       {
349         File file = new File(filename);
350         Assert.assertTrue(file.exists(), "File '" + filename
351                 + "' was not created by '" + cmdLine + "'");
352         Assert.assertTrue(file.isFile(), "File '" + filename
353                 + "' is not a file from '" + cmdLine + "'");
354         Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename
355                 + "' has no content from '" + cmdLine + "'");
356         // make sure the successive output files get bigger!
357         if (lastFile != null)
358         {
359           Assert.assertTrue(Files.size(file.toPath()) > Files
360                   .size(lastFile.toPath()));
361           System.out.println("this file: " + file + " +"
362                   + Files.size(file.toPath()) + " greater than "
363                   + Files.size(lastFile.toPath()));
364         }
365         // remember it for next file
366         lastFile = file;
367       }
368     } catch (Exception x)
369     {
370       Assert.fail(
371               "Unexpected exception during argFilesGlobAndSubstitutions",
372               x);
373     } finally
374     {
375       cleanupFiles(filenames);
376       tearDown();
377     }
378   }
379
380   @DataProvider(name = "structureImageOutputFiles")
381   public Object[][] structureImageOutputFiles()
382   {
383     return new Object[][] {
384         //
385         { "--gui --nonews --nosplash --open=./examples/test_fab41.result/sample.a2m "
386                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
387                 + "--structureimage=" + testfiles + "/structureimage1.png "
388                 + "--open=./examples/test_fab41.result/sample.a2m "
389                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
390                 + "--structureimage=" + testfiles
391                 + "/structureimage2.png --scale=1.5 "
392                 + "--open=./examples/test_fab41.result/sample.a2m "
393                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
394                 + "--structureimage=" + testfiles
395                 + "/structureimage3.png --scale=2.0 ",
396             new String[]
397             { testfiles + "/structureimage1.png",
398                 testfiles + "/structureimage2.png",
399                 testfiles + "/structureimage3.png" } },
400         { "--headless --noquit --open=./examples/test_fab41.result/sample.a2m "
401                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
402                 + "--structureimage=" + testfiles + "/structureimage1.png "
403                 + "--open=./examples/test_fab41.result/sample.a2m "
404                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
405                 + "--structureimage=" + testfiles
406                 + "/structureimage2.png --scale=1.5 "
407                 + "--open=./examples/test_fab41.result/sample.a2m "
408                 + "--structure=./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb "
409                 + "--structureimage=" + testfiles
410                 + "/structureimage3.png --scale=2.0 ",
411             new String[]
412             { testfiles + "/structureimage1.png",
413                 testfiles + "/structureimage2.png",
414                 testfiles + "/structureimage3.png" } },
415         { "--gui --nonews --nosplash --open examples/1gaq.txt --append ./examples/3W5V.pdb "
416                 + "--structure examples/1gaq.txt --seqid \"1GAQ|A\" "
417                 + "--structureimage " + testfiles
418                 + "/1gaq.png --structure examples/3W5V.pdb "
419                 + "--seqid \"3W5V|A\" --structureimage " + testfiles
420                 + "/3w5v.png --overwrite",
421
422             new String[]
423             { testfiles + "/1gaq.png",
424                 testfiles + "/3w5v.png" } },
425         { "--headless --noquit --open ./examples/1gaq.txt --append ./examples/3W5V.pdb "
426                 + "--structure examples/1gaq.txt --seqid \"1GAQ|A\" "
427                 + "--structureimage " + testfiles
428                 + "/1gaq.png --structure examples/3W5V.pdb "
429                 + "--seqid \"3W5V|A\" --structureimage " + testfiles
430                 + "/3w5v.png --overwrite",
431
432             new String[]
433             { testfiles + "/1gaq.png", testfiles + "/3w5v.png" } }
434
435         /*
436                 */
437         //
438     };
439
440   }
441
442   @DataProvider(name = "argfileOutputFiles")
443   public Object[][] argfileOutputFiles()
444   {
445     return new Object[][] {
446         //
447         { "--gui --argfile=" + testfiles + "/**/*.txt", new String[]
448         { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png",
449             testfiles + "/dir3/subdir/test0.png" } },
450         { "--gui --argfile=" + testfiles + "/**/argfile.txt", new String[]
451         { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } },
452         { "--gui --argfile=" + testfiles + "/dir*/argfile.txt", new String[]
453         { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } },
454         { "--gui --initsubstitutions --append examples/uniref50.fa --image "
455                 + testfiles + "/{basename}.png",
456             new String[]
457             { testfiles + "/uniref50.png" } },
458         { "--gui --append examples/uniref50.fa --nosubstitutions --image "
459                 + testfiles + "/{basename}.png",
460             new String[]
461             { testfiles + "/{basename}.png" } }
462         //
463     };
464
465   }
466
467   @DataProvider(name = "cmdLines")
468   public Object[][] cmdLines()
469   {
470     String[] someUniref50Seqs = new String[] { "FER_CAPAA", "FER_CAPAN",
471         "FER1_MAIZE", "FER1_SPIOL", "O80429_MAIZE" };
472     String[] t1 = new String[] { "TEST1" };
473     String[] t2 = new String[] { "TEST2" };
474     String[] t3 = new String[] { "TEST3" };
475     return new Object[][] {
476         /*
477         */
478         { "--append=examples/uniref50.fa", true, 1, someUniref50Seqs },
479         { "--append examples/uniref50.fa", true, 1, someUniref50Seqs },
480         { "--append=examples/uniref50*.fa", true, 1, someUniref50Seqs },
481         // NOTE we cannot use shell expansion in tests, so list all files!
482         { "--append examples/uniref50.fa examples/uniref50_mz.fa", true, 1,
483             someUniref50Seqs },
484         { "--append=[new]examples/uniref50*.fa", true, 2,
485             someUniref50Seqs },
486         { "--open=examples/uniref50*.fa", true, 2, someUniref50Seqs },
487         { "examples/uniref50.fa", true, 1, someUniref50Seqs },
488         { "examples/uniref50.fa " + testfiles + "/test1.fa", true, 2,
489             ArrayUtils.concatArrays(someUniref50Seqs, t1) },
490         { "examples/uniref50.fa " + testfiles + "/test1.fa", true, 2, t1 },
491         { "--gui --argfile=" + testfiles + "/argfile0.txt", true, 1,
492             ArrayUtils.concatArrays(t1, t3) },
493         { "--gui --argfile=" + testfiles + "/argfile*.txt", true, 5,
494             ArrayUtils.concatArrays(t1, t2, t3) },
495         { "--gui --argfile=" + testfiles + "/argfile.autocounter", true, 3,
496             ArrayUtils.concatArrays(t1, t2) } };
497
498   }
499
500   public static boolean lookForSequenceName(String sequenceName)
501   {
502     AlignFrame[] afs = Desktop.getDesktopAlignFrames();
503     for (AlignFrame af : afs)
504     {
505       for (String name : af.getViewport().getAlignment().getSequenceNames())
506       {
507         if (sequenceName.equals(name))
508         {
509           return true;
510         }
511       }
512     }
513     return false;
514   }
515
516   public static void cleanupFiles(String[] filenames)
517   {
518     for (String filename : filenames)
519     {
520       File file = new File(filename);
521       if (file.exists())
522       {
523         file.delete();
524       }
525     }
526   }
527
528   private final String deleteDir = "test/deleteAfter";
529
530   @Test(
531     groups = "Functional",
532     dataProvider = "allLinkedIdsData",
533     singleThreaded = true)
534   public void allLinkedIdsTest(String cmdLine, String[] filenames,
535           String[] nonfilenames)
536   {
537     String[] args = (cmdLine + " --gui").split("\\s+");
538     callJalviewMain(args);
539     Commands cmds = Jalview.getInstance().getCommands();
540     Assert.assertNotNull(cmds);
541     for (String filename : filenames)
542     {
543       Assert.assertTrue(new File(filename).exists(),
544               "File '" + filename + "' was not created");
545     }
546     cleanupFiles(filenames);
547     if (nonfilenames != null)
548     {
549       for (String nonfilename : nonfilenames)
550       {
551         File nonfile = new File(nonfilename);
552         Assert.assertFalse(nonfile.exists(),
553                 "File " + nonfilename + " exists when it shouldn't!");
554       }
555     }
556
557     File deleteDirF = new File(deleteDir);
558     if (deleteDirF.exists())
559     {
560       deleteDirF.delete();
561     }
562   }
563
564   @DataProvider(name = "allLinkedIdsData")
565   public Object[][] allLinkedIdsData()
566   {
567     return new Object[][] {
568         //
569         { "--gui --open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --output={dirname}/{basename}.stk --close",
570             new String[]
571             { "test/jalview/bin/argparser/testfiles/test1.stk",
572                 "test/jalview/bin/argparser/testfiles/test2.stk",
573                 "test/jalview/bin/argparser/testfiles/test3.stk", },
574             null },
575         { "--gui --open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --image={dirname}/{basename}.png --close",
576             new String[]
577             { "test/jalview/bin/argparser/testfiles/test1.png",
578                 "test/jalview/bin/argparser/testfiles/test2.png",
579                 "test/jalview/bin/argparser/testfiles/test3.png", },
580             null },
581         { "--gui --open=test/jalview/bin/argparser/testfiles/*.fa --all --output={dirname}/{basename}.stk --close",
582             new String[]
583             { "test/jalview/bin/argparser/testfiles/test1.stk",
584                 "test/jalview/bin/argparser/testfiles/test2.stk",
585                 "test/jalview/bin/argparser/testfiles/test3.stk", },
586             new String[]
587             { "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
588                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
589                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
590                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
591                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
592                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
593                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
594                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
595                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, },
596         { "--gui --open=test/jalview/bin/argparser/**/*.fa --all --output={dirname}/{basename}.stk --close",
597             new String[]
598             { "test/jalview/bin/argparser/testfiles/test1.stk",
599                 "test/jalview/bin/argparser/testfiles/test2.stk",
600                 "test/jalview/bin/argparser/testfiles/test3.stk",
601                 "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
602                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
603                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
604                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
605                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
606                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
607                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
608                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
609                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", },
610             null },
611         { "--gui --open=test/jalview/bin/argparser/**/*.fa --output=*/*.stk --close",
612             new String[]
613             { "test/jalview/bin/argparser/testfiles/test1.stk",
614                 "test/jalview/bin/argparser/testfiles/test2.stk",
615                 "test/jalview/bin/argparser/testfiles/test3.stk",
616                 "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
617                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
618                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
619                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
620                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
621                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
622                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
623                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
624                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", },
625             null },
626         { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --all --output=*/*.stk --close",
627             new String[]
628             { "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
629                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
630                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
631                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
632                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk", },
633             new String[]
634             { "test/jalview/bin/argparser/testfiles/test1.stk",
635                 "test/jalview/bin/argparser/testfiles/test2.stk",
636                 "test/jalview/bin/argparser/testfiles/test3.stk",
637                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
638                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
639                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
640                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, },
641         { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output=*/*.stk --close",
642             new String[]
643             { "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
644                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
645                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk", },
646             new String[]
647             { "test/jalview/bin/argparser/testfiles/test1.stk",
648                 "test/jalview/bin/argparser/testfiles/test2.stk",
649                 "test/jalview/bin/argparser/testfiles/test3.stk",
650                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
651                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
652                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
653                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, },
654         { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output={dirname}/{basename}.stk --close",
655             new String[]
656             { "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
657                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
658                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk", },
659             new String[]
660             { "test/jalview/bin/argparser/testfiles/test1.stk",
661                 "test/jalview/bin/argparser/testfiles/test2.stk",
662                 "test/jalview/bin/argparser/testfiles/test3.stk",
663                 "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
664                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
665                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
666                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
667                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
668                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, },
669         { "--gui --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output={dirname}/{basename}.stk --close",
670             new String[]
671             { "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
672                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
673                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk", },
674             new String[]
675             { "test/jalview/bin/argparser/testfiles/test1.stk",
676                 "test/jalview/bin/argparser/testfiles/test2.stk",
677                 "test/jalview/bin/argparser/testfiles/test3.stk",
678                 "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
679                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
680                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
681                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
682                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
683                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk", }, },
684         { "--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",
685             new String[]
686             { "test/jalview/bin/argparser/testfiles/dir1/test1.stk",
687                 "test/jalview/bin/argparser/testfiles/dir1/test2.stk",
688                 "test/jalview/bin/argparser/testfiles/dir2/test1.aln",
689                 "test/jalview/bin/argparser/testfiles/dir2/test2.aln",
690                 "test/jalview/bin/argparser/testfiles/dir2/test3.aln", },
691             new String[]
692             { "test/jalview/bin/argparser/testfiles/test1.stk",
693                 "test/jalview/bin/argparser/testfiles/test2.stk",
694                 "test/jalview/bin/argparser/testfiles/test3.stk",
695                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
696                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
697                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
698                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
699                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
700                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
701                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk",
702                 "test/jalview/bin/argparser/testfiles/test1.aln",
703                 "test/jalview/bin/argparser/testfiles/test2.aln",
704                 "test/jalview/bin/argparser/testfiles/test3.aln",
705                 "test/jalview/bin/argparser/testfiles/dir1/test1.aln",
706                 "test/jalview/bin/argparser/testfiles/dir1/test2.aln",
707                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.aln",
708                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.aln",
709                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.aln",
710                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.aln", }, },
711         // --mkdirs
712         { "--headless --open=test/jalview/bin/argparser/testfiles/dir1/*.fa --output "
713                 + deleteDir
714                 + "/{dirname}/{basename}.stk --open=test/jalview/bin/argparser/testfiles/dir2/*.fa --output="
715                 + deleteDir
716                 + "/{dirname}/{basename}.aln --close --all --mkdirs",
717             new String[]
718             { deleteDir
719                     + "/test/jalview/bin/argparser/testfiles/dir1/test1.stk",
720                 deleteDir
721                         + "/test/jalview/bin/argparser/testfiles/dir1/test2.stk",
722                 deleteDir
723                         + "/test/jalview/bin/argparser/testfiles/dir2/test1.aln",
724                 deleteDir
725                         + "/test/jalview/bin/argparser/testfiles/dir2/test2.aln",
726                 deleteDir
727                         + "/test/jalview/bin/argparser/testfiles/dir2/test3.aln", },
728             new String[]
729             { "test/jalview/bin/argparser/testfiles/test1.stk",
730                 "test/jalview/bin/argparser/testfiles/test2.stk",
731                 "test/jalview/bin/argparser/testfiles/test3.stk",
732                 "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
733                 "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
734                 "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
735                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
736                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
737                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
738                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk",
739                 "test/jalview/bin/argparser/testfiles/test1.aln",
740                 "test/jalview/bin/argparser/testfiles/test2.aln",
741                 "test/jalview/bin/argparser/testfiles/test3.aln",
742                 "test/jalview/bin/argparser/testfiles/dir1/test1.aln",
743                 "test/jalview/bin/argparser/testfiles/dir1/test2.aln",
744                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.aln",
745                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.aln",
746                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.aln",
747                 "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.aln",
748                 deleteDir
749                         + "test/jalview/bin/argparser/testfiles/test1.stk",
750                 deleteDir
751                         + "test/jalview/bin/argparser/testfiles/test2.stk",
752                 deleteDir
753                         + "test/jalview/bin/argparser/testfiles/test3.stk",
754                 deleteDir
755                         + "test/jalview/bin/argparser/testfiles/dir2/test1.stk",
756                 deleteDir
757                         + "test/jalview/bin/argparser/testfiles/dir2/test2.stk",
758                 deleteDir
759                         + "test/jalview/bin/argparser/testfiles/dir2/test3.stk",
760                 deleteDir
761                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.stk",
762                 deleteDir
763                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.stk",
764                 deleteDir
765                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.stk",
766                 deleteDir
767                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.stk",
768                 deleteDir
769                         + "test/jalview/bin/argparser/testfiles/test1.aln",
770                 deleteDir
771                         + "test/jalview/bin/argparser/testfiles/test2.aln",
772                 deleteDir
773                         + "test/jalview/bin/argparser/testfiles/test3.aln",
774                 deleteDir
775                         + "test/jalview/bin/argparser/testfiles/dir1/test1.aln",
776                 deleteDir
777                         + "test/jalview/bin/argparser/testfiles/dir1/test2.aln",
778                 deleteDir
779                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test0.aln",
780                 deleteDir
781                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test1.aln",
782                 deleteDir
783                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test2.aln",
784                 deleteDir
785                         + "test/jalview/bin/argparser/testfiles/dir3/subdir/test3.aln", }, },
786         //
787     };
788   }
789
790   @Test(
791     groups =
792     { "Functional", "testTask3" },
793     dataProvider = "structureImageAnnotationsOutputFiles",
794     singleThreaded = true)
795   public void structureImageAnnotationsOutputTest(String cmdLine,
796           String filename, int height) throws IOException
797   {
798     cleanupFiles(new String[] { filename });
799     String[] args = (cmdLine).split("\\s+");
800     callJalviewMain(args, true); // Create new instance of Jalview each time for
801                                  // linkedIds
802
803     BufferedImage img = ImageIO.read(new File(filename));
804     Assert.assertEquals(height, img.getHeight(), "Output image '" + filename
805             + "' is not in the expected height range, possibly because of the wrong number of annotations");
806
807     cleanupFiles(new String[] { filename });
808     tearDown();
809   }
810
811   @DataProvider(name = "structureImageAnnotationsOutputFiles")
812   public Object[][] structureImageAnnotationsOutputFiles()
813   {
814     String filename = "test/jalview/bin/argparser/testfiles/test_annotations.png";
815     return new Object[][] {
816         //
817         { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
818                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
819                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
820                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
821                 + "--image=" + filename + " " + "--tempfac=plddt "
822                 + "--noshowssannotations " + "--noshowannotations", //
823             filename, //
824             252 }, //
825         { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
826                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
827                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
828                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
829                 + "--image=" + filename + " " + "--tempfac=plddt "
830                 + "--showssannotations " + "--noshowannotations", //
831             filename, //
832             368 }, //
833         { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
834                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
835                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
836                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
837                 + "--image=" + filename + " " + "--tempfac=plddt "
838                 + "--noshowssannotations " + "--showannotations", //
839             filename, //
840             524 }, //
841         { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
842                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
843                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
844                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
845                 + "--image=" + filename + " " + "--tempfac=plddt "
846                 + "--showssannotations " + "--showannotations", //
847             filename, //
848             660 }, //
849         { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
850                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
851                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
852                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
853                 + "--image=" + filename + " " + "--tempfac=plddt "
854                 + "--noshowssannotations " + "--noshowannotations", //
855             filename, //
856             252 }, //
857         { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
858                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
859                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
860                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
861                 + "--image=" + filename + " " + "--tempfac=plddt "
862                 + "--showssannotations " + "--noshowannotations", //
863             filename, //
864             368 }, //
865         { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
866                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
867                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
868                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
869                 + "--image=" + filename + " " + "--tempfac=plddt "
870                 + "--noshowssannotations " + "--showannotations", //
871             filename, //
872             524 }, //
873         { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
874                 + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
875                 + "--seqid=FER1_SPIOL --structureviewer=jmol "
876                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
877                 + "--image=" + filename + " " + "--tempfac=plddt "
878                 + "--showssannotations " + "--showannotations", //
879             filename, //
880             660 }, //
881     };
882   }
883
884 }