3 import static org.junit.Assert.*;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.SequenceGroup;
6 import jalview.datamodel.SequenceI;
7 import jalview.gui.AlignFrame;
8 import jalview.gui.Desktop;
9 import jalview.schemes.AnnotationColourGradient;
10 import jalview.schemes.ColourSchemeI;
14 import org.junit.AfterClass;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
18 public class Jalview2xmlTests
22 * @throws java.lang.Exception
25 public static void setUpBeforeClass() throws Exception
27 jalview.bin.Jalview.main(new String[] {"-props","test/src/jalview/io/testProps.jvprops"});
31 * @throws java.lang.Exception
34 public static void tearDownAfterClass() throws Exception
36 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
39 public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
42 for (SequenceI sq: avp.getAlignment().getDataset().getSequences()) {
43 if (sq.getAnnotation() != null)
45 for (AlignmentAnnotation dssa : sq.getAnnotation())
47 if (dssa.isValidStruc())
57 public void testRNAStructureRecovery() throws Exception
59 String inFile = "examples/RF00031_folded.stk";
60 String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
61 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
62 assertTrue("Didn't read input file "+inFile, af!=null);
63 int olddsann=countDsAnn(af.getViewport());
64 assertTrue("Didn't find any dataset annotations",olddsann>0);
65 af.rnahelicesColour_actionPerformed(null);
66 assertTrue("Couldn't apply RNA helices colourscheme",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
67 assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
68 af.closeMenuItem_actionPerformed(true);
70 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
71 assertTrue("Failed to import new project", af!=null);
72 int newdsann=countDsAnn(af.getViewport());
73 assertTrue("Differing numbers of dataset sequence annotation\nOriginally "+olddsann+" and now "+newdsann,olddsann==newdsann);
74 System.out.println("Read in same number of annotations as originally present ("+olddsann+")");
75 assertTrue("RNA helices colourscheme was not applied on import.",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
78 public void testTCoffeeScores() throws Exception
80 String inFile = "examples/uniref50.fa",inAnnot="examples/uniref50.score_ascii";
81 String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
82 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
83 assertTrue("Didn't read input file "+inFile, af!=null);
84 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null,null);
86 "Didn't set T-coffee colourscheme",
87 af.getViewport().getGlobalColourScheme().getClass()
88 .equals(jalview.schemes.TCoffeeColourScheme.class));
90 "Recognise T-Coffee score from string",
91 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
93 jalview.schemes.ColourSchemeProperty.getColourName(af
94 .getViewport().getGlobalColourScheme())) != null);
96 assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
97 af.closeMenuItem_actionPerformed(true);
99 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
100 assertTrue("Failed to import new project", af!=null);
101 assertTrue("Didn't set T-coffee colourscheme for imported project.",af.getViewport().getGlobalColourScheme().getClass().equals(jalview.schemes.TCoffeeColourScheme.class));
102 System.out.println("T-Coffee score shading successfully recovered from project.");
105 public void testColourByAnnotScores() throws Exception
107 String inFile = "examples/uniref50.fa",inAnnot="examples/testdata/uniref50_iupred.jva";
108 String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
109 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
110 assertTrue("Didn't read input file "+inFile, af!=null);
111 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null,null);
112 AlignmentAnnotation[] aa = af.getViewport().getAlignment().getSequenceAt(0).getAnnotation("IUPredWS (Short)");
113 assertTrue("Didn't find any IUPred annotation to use to shade alignment.",aa!=null && aa.length>0);
114 AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD);
115 AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD);
116 cs.setSeqAssociated(true);
117 gcs.setSeqAssociated(true);
119 SequenceGroup sg = new SequenceGroup();
123 af.getViewport().getAlignment().addGroup(sg);
124 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
125 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
126 af.alignPanel.alignmentChanged();
127 assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
128 af.closeMenuItem_actionPerformed(true);
130 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
131 assertTrue("Failed to import new project", af!=null);
133 // check for group and alignment colourschemes
135 ColourSchemeI _rcs=af.getViewport().getGlobalColourScheme();
136 ColourSchemeI _rgcs=af.getViewport().getAlignment().getGroups().get(0).cs;
137 assertTrue("Didn't recover global colourscheme",_rcs!=null);
138 assertTrue("Didn't recover annotation colour global scheme",_rcs instanceof AnnotationColourGradient);
139 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
140 assertTrue("Annotation colourscheme wasn't sequence associated",__rcs.isSeqAssociated());
143 boolean diffseqcols=false,diffgseqcols=false;
144 SequenceI[] sqs=af.getViewport().getAlignment().getSequencesArray();
145 for (int p=0,pSize=af.getViewport().getAlignment().getWidth();p<pSize && (!diffseqcols || !diffgseqcols);p++)
147 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0])!=_rcs.findColour(sqs[5].getCharAt(p), p, sqs[5]))
152 assertTrue("Got Different sequence colours", diffseqcols);
153 System.out.println("Per sequence colourscheme (Background) successfully applied and recovered.");
155 assertTrue("Didn't recover group colourscheme",_rgcs!=null);
156 assertTrue("Didn't recover annotation colour group colourscheme",_rgcs instanceof AnnotationColourGradient);
157 __rcs = (AnnotationColourGradient) _rgcs;
158 assertTrue("Group Annotation colourscheme wasn't sequence associated",__rcs.isSeqAssociated());
160 for (int p=0,pSize=af.getViewport().getAlignment().getWidth();p<pSize && (!diffseqcols || !diffgseqcols);p++)
162 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1])!=_rgcs.findColour(sqs[2].getCharAt(p), p, sqs[2]))
167 assertTrue("Got Different group sequence colours", diffgseqcols);
168 System.out.println("Per sequence (Group) colourscheme successfully applied and recovered.");
171 public void gatherViewsHere() throws Exception
173 int origCount = Desktop.getAlignframes().length;
174 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded("examples/exampleFile_2_7.jar", FormatAdapter.FILE);
175 assertTrue("Didn't read in the example file correctly.",af!=null);
176 assertTrue("Didn't gather the views in the example file.", Desktop.getAlignframes().length==1+origCount);