3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
5 import static org.junit.Assert.fail;
6 import jalview.datamodel.AlignmentI;
10 import org.junit.Test;
12 public class AnnotationFileIOTest
15 static String TestFiles[][] = {{ "Test example annotation import/export","examples/uniref50.fa", "examples/testdata/example_annot_file.jva" }
16 ,{"Test multiple combine annotation statements import/export","examples/uniref50.fa", "examples/testdata/test_combine_annot.jva"}};
19 public void exampleAnnotationFileIO() throws Exception
21 for (String[] testPair:TestFiles)
23 testAnnotationFileIO(testPair[0], new File(testPair[1]), new File(testPair[2]));
27 public static AlignmentI readAlignmentFile(File f)
29 System.out.println("Reading file: " + f);
30 String ff = f.getPath();
33 FormatAdapter rf = new FormatAdapter();
35 AlignmentI al = rf.readFile(ff, AppletFormatAdapter.FILE,
36 new IdentifyFile().Identify(ff, AppletFormatAdapter.FILE));
38 // make sure dataset is initialised ? not sure about this
39 for (int i = 0; i < al.getSequencesArray().length; ++i)
41 al.getSequenceAt(i).setDatasetSequence(al.getSequenceAt(i).createDatasetSequence());
43 assertNotNull("Couldn't read supplied alignment data.", al);
49 fail("Couln't read the alignment in file '"+f.toString()+"'");
53 * test alignment data in given file can be imported, exported and reimported
57 * - source datafile (IdentifyFile.identify() should work with it)
59 * - label for IO class used to write and read back in the data from
62 public static void testAnnotationFileIO(String testname, File f, File annotFile)
64 System.out.println("Test: "+testname+"\nReading annotation file '"+annotFile+"' onto : " + f);
65 String af = annotFile.getPath();
68 AlignmentI al = readAlignmentFile(f);
70 assertTrue("Test "+testname+"\nAlignment was not annotated - annotation file not imported.",new AnnotationFile().readAnnotationFile(al, af, FormatAdapter.FILE));
72 String anfileout = new AnnotationFile().printAnnotations(al.getAlignmentAnnotation(), al.getGroups(), al.getProperties());
73 assertTrue("Test "+testname+"\nAlignment annotation file was not regenerated. Null string",anfileout!=null);
74 assertTrue("Test "+testname+"\nAlignment annotation file was not regenerated. Empty string",anfileout.length()>"JALVIEW_ANNOTATION".length());
76 System.out.println("Output annotation file:\n"+anfileout+"\n<<EOF\n");
78 AlignmentI al_new = readAlignmentFile(f);
79 assertTrue("Test "+testname+"\nregenerated annotation file did not annotate alignment.",new AnnotationFile().readAnnotationFile(al_new, anfileout, FormatAdapter.PASTE));
81 // test for consistency in io
82 StockholmFileTest.testAlignmentEquivalence(al, al_new);
88 fail("Test "+testname+"\nCouldn't complete Annotation file roundtrip input/output/input test for '"+annotFile+"'.");