Clover icon

Coverage Report

  1. Project Clover database Mon Sep 2 2024 17:57:51 BST
  2. Package jalview.bin

File CommandsTest.java

 

Code metrics

34
165
25
1
964
853
54
0.33
6.6
25
2.16

Classes

Class Line # Actions
CommandsTest 46 165 54
0.9330357393.3%
 

Contributing tests

This file is covered by 51 tests. .

Source view

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