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"}
17 ,{"Test multiple combine annotation statements with sequence_ref import/export","examples/uniref50.fa", "examples/testdata/uniref50_iupred.jva"}};
20 public void exampleAnnotationFileIO() throws Exception
22 for (String[] testPair:TestFiles)
24 testAnnotationFileIO(testPair[0], new File(testPair[1]), new File(testPair[2]));
28 public static AlignmentI readAlignmentFile(File f)
30 System.out.println("Reading file: " + f);
31 String ff = f.getPath();
34 FormatAdapter rf = new FormatAdapter();
36 AlignmentI al = rf.readFile(ff, AppletFormatAdapter.FILE,
37 new IdentifyFile().Identify(ff, AppletFormatAdapter.FILE));
39 // make sure dataset is initialised ? not sure about this
40 for (int i = 0; i < al.getSequencesArray().length; ++i)
42 al.getSequenceAt(i).setDatasetSequence(al.getSequenceAt(i).createDatasetSequence());
44 assertNotNull("Couldn't read supplied alignment data.", al);
50 fail("Couln't read the alignment in file '"+f.toString()+"'");
54 * test alignment data in given file can be imported, exported and reimported
58 * - source datafile (IdentifyFile.identify() should work with it)
60 * - label for IO class used to write and read back in the data from
63 public static void testAnnotationFileIO(String testname, File f, File annotFile)
65 System.out.println("Test: "+testname+"\nReading annotation file '"+annotFile+"' onto : " + f);
66 String af = annotFile.getPath();
69 AlignmentI al = readAlignmentFile(f);
71 assertTrue("Test "+testname+"\nAlignment was not annotated - annotation file not imported.",new AnnotationFile().readAnnotationFile(al, af, FormatAdapter.FILE));
73 String anfileout = new AnnotationFile().printAnnotations(al.getAlignmentAnnotation(), al.getGroups(), al.getProperties());
74 assertTrue("Test "+testname+"\nAlignment annotation file was not regenerated. Null string",anfileout!=null);
75 assertTrue("Test "+testname+"\nAlignment annotation file was not regenerated. Empty string",anfileout.length()>"JALVIEW_ANNOTATION".length());
77 System.out.println("Output annotation file:\n"+anfileout+"\n<<EOF\n");
79 AlignmentI al_new = readAlignmentFile(f);
80 assertTrue("Test "+testname+"\nregenerated annotation file did not annotate alignment.",new AnnotationFile().readAnnotationFile(al_new, anfileout, FormatAdapter.PASTE));
82 // test for consistency in io
83 StockholmFileTest.testAlignmentEquivalence(al, al_new);
89 fail("Test "+testname+"\nCouldn't complete Annotation file roundtrip input/output/input test for '"+annotFile+"'.");