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.schemes.AnnotationColourGradient;
9 import jalview.schemes.ColourSchemeI;
13 import org.junit.AfterClass;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
17 public class Jalview2xmlTests
21 * @throws java.lang.Exception
24 public static void setUpBeforeClass() throws Exception
26 jalview.bin.Jalview.main(new String[] {"-props","test/src/jalview/io/testProps.jvprops"});
30 * @throws java.lang.Exception
33 public static void tearDownAfterClass() throws Exception
35 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
38 public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
41 for (SequenceI sq: avp.getAlignment().getDataset().getSequences()) {
42 if (sq.getAnnotation() != null)
44 for (AlignmentAnnotation dssa : sq.getAnnotation())
46 if (dssa.isValidStruc())
56 public void testRNAStructureRecovery() throws Exception
58 String inFile = "examples/RF00031_folded.stk";
59 String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
60 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
61 assertTrue("Didn't read input file "+inFile, af!=null);
62 int olddsann=countDsAnn(af.getViewport());
63 assertTrue("Didn't find any dataset annotations",olddsann>0);
64 af.rnahelicesColour_actionPerformed(null);
65 assertTrue("Couldn't apply RNA helices colourscheme",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
66 assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
67 af.closeMenuItem_actionPerformed(true);
69 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
70 assertTrue("Failed to import new project", af!=null);
71 int newdsann=countDsAnn(af.getViewport());
72 assertTrue("Differing numbers of dataset sequence annotation\nOriginally "+olddsann+" and now "+newdsann,olddsann==newdsann);
73 System.out.println("Read in same number of annotations as originally present ("+olddsann+")");
74 assertTrue("RNA helices colourscheme was not applied on import.",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
77 public void testTCoffeeScores() throws Exception
79 String inFile = "examples/uniref50.fa",inAnnot="examples/uniref50.score_ascii";
80 String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
81 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
82 assertTrue("Didn't read input file "+inFile, af!=null);
83 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null,null);
85 "Didn't set T-coffee colourscheme",
86 af.getViewport().getGlobalColourScheme().getClass()
87 .equals(jalview.schemes.TCoffeeColourScheme.class));
89 "Recognise T-Coffee score from string",
90 jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
92 jalview.schemes.ColourSchemeProperty.getColourName(af
93 .getViewport().getGlobalColourScheme())) != null);
95 assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
96 af.closeMenuItem_actionPerformed(true);
98 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
99 assertTrue("Failed to import new project", af!=null);
100 assertTrue("Didn't set T-coffee colourscheme for imported project.",af.getViewport().getGlobalColourScheme().getClass().equals(jalview.schemes.TCoffeeColourScheme.class));
101 System.out.println("T-Coffee score shading successfully recovered from project.");
104 public void testColourByAnnotScores() throws Exception
106 String inFile = "examples/uniref50.fa",inAnnot="examples/testdata/uniref50_iupred.jva";
107 String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
108 AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
109 assertTrue("Didn't read input file "+inFile, af!=null);
110 af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null,null);
111 AlignmentAnnotation[] aa = af.getViewport().getAlignment().getSequenceAt(0).getAnnotation("IUPredWS (Short)");
112 assertTrue("Didn't find any IUPred annotation to use to shade alignment.",aa!=null && aa.length>0);
113 AnnotationColourGradient cs = new jalview.schemes.AnnotationColourGradient(aa[0], null, AnnotationColourGradient.ABOVE_THRESHOLD);
114 AnnotationColourGradient gcs = new jalview.schemes.AnnotationColourGradient(aa[0], null, AnnotationColourGradient.BELOW_THRESHOLD);
115 cs.setSeqAssociated(true);
116 gcs.setSeqAssociated(true);
118 SequenceGroup sg = new SequenceGroup();
122 af.getViewport().getAlignment().addGroup(sg);
123 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
124 sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
125 af.alignPanel.alignmentChanged();
126 assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
127 af.closeMenuItem_actionPerformed(true);
129 af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
130 assertTrue("Failed to import new project", af!=null);
132 // check for group and alignment colourschemes
134 ColourSchemeI _rcs=af.getViewport().getGlobalColourScheme();
135 ColourSchemeI _rgcs=af.getViewport().getAlignment().getGroups().get(0).cs;
136 assertTrue("Didn't recover global colourscheme",_rcs!=null);
137 assertTrue("Didn't recover annotation colour global scheme",_rcs instanceof AnnotationColourGradient);
138 AnnotationColourGradient __rcs = (AnnotationColourGradient) _rcs;
139 assertTrue("Annotation colourscheme wasn't sequence associated",__rcs.isSeqAssociated());
142 boolean diffseqcols=false,diffgseqcols=false;
143 SequenceI[] sqs=af.getViewport().getAlignment().getSequencesArray();
144 for (int p=0,pSize=af.getViewport().getAlignment().getWidth();p<pSize && (!diffseqcols || !diffgseqcols);p++)
146 if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0])!=_rcs.findColour(sqs[5].getCharAt(p), p, sqs[5]))
151 assertTrue("Got Different sequence colours", diffseqcols);
152 System.out.println("Per sequence colourscheme (Background) successfully applied and recovered.");
154 assertTrue("Didn't recover group colourscheme",_rgcs!=null);
155 assertTrue("Didn't recover annotation colour group colourscheme",_rgcs instanceof AnnotationColourGradient);
156 __rcs = (AnnotationColourGradient) _rgcs;
157 assertTrue("Group Annotation colourscheme wasn't sequence associated",__rcs.isSeqAssociated());
159 for (int p=0,pSize=af.getViewport().getAlignment().getWidth();p<pSize && (!diffseqcols || !diffgseqcols);p++)
161 if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1])!=_rgcs.findColour(sqs[2].getCharAt(p), p, sqs[2]))
166 assertTrue("Got Different group sequence colours", diffgseqcols);
167 System.out.println("Per sequence (Group) colourscheme successfully applied and recovered.");