test for JAL-952
[jalview.git] / test / jalview / io / Jalview2xmlTests.java
1 package jalview.io;
2
3 import static org.junit.Assert.*;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.SequenceI;
6 import jalview.gui.AlignFrame;
7
8 import java.io.File;
9
10 import org.junit.AfterClass;
11 import org.junit.BeforeClass;
12 import org.junit.Test;
13
14 public class Jalview2xmlTests
15 {
16
17   /**
18    * @throws java.lang.Exception
19    */
20   @BeforeClass
21   public static void setUpBeforeClass() throws Exception
22   {
23     jalview.bin.Jalview.main(new String[] {"-props","test/src/jalview/io/testProps.jvprops"});
24   }
25
26   /**
27    * @throws java.lang.Exception
28    */
29   @AfterClass
30   public static void tearDownAfterClass() throws Exception
31   {
32     jalview.gui.Desktop.instance.quit();
33   }
34   public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
35   {
36     int numdsann=0;
37     for (SequenceI sq: avp.getAlignment().getDataset().getSequences()) {
38       if (sq.getAnnotation() != null)
39       {
40         for (AlignmentAnnotation dssa : sq.getAnnotation())
41         {
42           if (dssa.isValidStruc())
43           {
44             numdsann++;
45           }
46         }
47       }
48     }
49     return numdsann;
50   }
51   @Test
52   public void testRNAStructureRecovery() throws Exception
53   {
54     String inFile = "examples/RF00031_folded.stk";
55     String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
56     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
57     assertTrue("Didn't read input file "+inFile, af!=null);
58     int olddsann=countDsAnn(af.getViewport());
59     assertTrue("Didn't find any dataset annotations",olddsann>0);
60     af.rnahelicesColour_actionPerformed(null);
61     assertTrue("Couldn't apply RNA helices colourscheme",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
62     assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
63     af.closeMenuItem_actionPerformed(true);
64     af=null;
65     af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
66     assertTrue("Failed to import new project", af!=null);
67     int newdsann=countDsAnn(af.getViewport());
68     assertTrue("Differing numbers of dataset sequence annotation\nOriginally "+olddsann+" and now "+newdsann,olddsann==newdsann);
69     System.out.println("Read in same number of annotations as originally present ("+olddsann+")");
70     assertTrue("RNA helices colourscheme was not applied on import.",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
71   }
72   @Test
73   public void testTCoffeeScores() throws Exception
74   {
75     String inFile = "examples/uniref50.fa",inAnnot="examples/uniref50.score_ascii";
76     String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
77     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
78     assertTrue("Didn't read input file "+inFile, af!=null);
79     af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null,null);
80     assertTrue(
81             "Didn't set T-coffee colourscheme",
82             af.getViewport().getGlobalColourScheme().getClass()
83                     .equals(jalview.schemes.TCoffeeColourScheme.class));
84     assertTrue(
85             "Recognise T-Coffee score from string",
86             jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
87                     .getAlignment(),
88                     jalview.schemes.ColourSchemeProperty.getColourName(af
89                             .getViewport().getGlobalColourScheme())) != null);
90
91     assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
92     af.closeMenuItem_actionPerformed(true);
93     af=null;
94     af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
95     assertTrue("Failed to import new project", af!=null);
96     assertTrue("Didn't set T-coffee colourscheme for imported project.",af.getViewport().getGlobalColourScheme().getClass().equals(jalview.schemes.TCoffeeColourScheme.class));
97     System.out.println("T-Coffee score shading successfully recovered from project.");
98   }
99 }