From: Jim Procter Date: Wed, 22 May 2013 16:49:09 +0000 (+0100) Subject: JAL-1296 JAL-1291 JAL-1297 JAL-1295 JAL-1294 X-Git-Tag: Jalview_2_9~249^2~15 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=597f27e694edb7a0770bc51c902a444dcd4db82c;p=jalview.git JAL-1296 JAL-1291 JAL-1297 JAL-1295 JAL-1294 test alignment annotation file IO for example given in documentation and for multiple combine statement --- diff --git a/examples/testdata/example_annot_file.jva b/examples/testdata/example_annot_file.jva new file mode 100644 index 0000000..794f42b --- /dev/null +++ b/examples/testdata/example_annot_file.jva @@ -0,0 +1,22 @@ +#Comment lines follow the hash symbol +JALVIEW_ANNOTATION +SEQUENCE_REF FER1_MESCR 5 +BAR_GRAPH Bar Graph 1 an html tooltip for Bar graph 1. ||-100,-|-200,-|-300,-|-400,-|200,+|300,+|150,+ +LINE_GRAPH Green Values 1.1|2.2|1.3|3.4|0.7|1.4|3.3|2.2|2.1|-1.1|3.2 +LINE_GRAPH Red Values 2.1|3.2|1.3|-1.4|5.5|1.4|1.3|4.2|-1.1|1.1|3.2 +BAR_GRAPH Bar Graph 2 1,.|2,*|3,:|4,.|5,*|4,:|3,.|2|1|1|2|3|4|5|4 +NO_GRAPH Icons ||||E,Sheet1|E|E||||H,Sheet 2|H|H|H|||||| +NO_GRAPH Purple Letters m|y|p|r|o|t|e|i|n +COLOUR Bar Graph 2 blue +COLOUR Red Values 255,0,0 +COLOUR Green Values green +COLOUR Purple Letters 151,52,228 +COMBINE Green Values Red Values +GRAPHLINE Red Values 2.6 threshold black + +SEQUENCE_GROUP Group_A 30 50 * +SEQUENCE_GROUP Group_B 1 351 2-5 +SEQUENCE_GROUP Group_C 12 14 -1 seq1 seq2 seq3 +PROPERTIES Group_A description=This is the description colour=Helix Propensity pidThreshold=0 outlineColour=red displayBoxes=true displayText=false colourText=false textCol1=black textCol2=black textColThreshold=0 +PROPERTIES Group_B outlineColour=red +PROPERTIES Group_C colour=Clustal diff --git a/examples/testdata/test_combine_annot.jva b/examples/testdata/test_combine_annot.jva new file mode 100644 index 0000000..e1ee9e0 --- /dev/null +++ b/examples/testdata/test_combine_annot.jva @@ -0,0 +1,31 @@ +#Comment lines follow the hash symbol +JALVIEW_ANNOTATION +SEQUENCE_REF FER1_MESCR 5 +BAR_GRAPH Bar Graph 1 an html tooltip for Bar graph 1. ||-100,-|-200,-|-300,-|-400,-|200,+|300,+|150,+ +LINE_GRAPH Green Values 1.1|2.2|1.3|3.4|0.7|1.4|3.3|2.2|2.1|-1.1|3.2 +LINE_GRAPH Red Values 2.1|3.2|1.3|-1.4|5.5|1.4|1.3|4.2|-1.1|1.1|3.2 +LINE_GRAPH Blue Values 0|0|0|1.1|2.2|1.3|3.4|0.7|1.4|3.3|2.2 +LINE_GRAPH Yellow Values 3.0|3.0|3.0|2.1|3.2|1.3|-1.4|5.5|1.4|1.3|4.2 + +BAR_GRAPH Bar Graph 2 1,.|2,*|3,:|4,.|5,*|4,:|3,.|2|1|1|2|3|4|5|4 + +NO_GRAPH Icons ||||E,Sheet1|E|E||||H,Sheet 2|H|H|H|||||| +NO_GRAPH Purple Letters m|y|p|r|o|t|e|i|n +COLOUR Bar Graph 2 blue +COLOUR Red Values 255,0,0 +COLOUR Green Values green +COLOUR Blue Values blue +COLOUR Yellow Values yellow +COLOUR Purple Letters 151,52,228 + +COMBINE Green Values Red Values +COMBINE Blue Values Yellow Values + +GRAPHLINE Red Values 2.6 threshold black + +SEQUENCE_GROUP Group_A 30 50 * +SEQUENCE_GROUP Group_B 1 351 2-5 +SEQUENCE_GROUP Group_C 12 14 -1 seq1 seq2 seq3 +PROPERTIES Group_A description=This is the description colour=Helix Propensity pidThreshold=0 outlineColour=red displayBoxes=true displayText=false colourText=false textCol1=black textCol2=black textColThreshold=0 +PROPERTIES Group_B outlineColour=red +PROPERTIES Group_C colour=Clustal diff --git a/test/jalview/io/AnnotationFileIOTest.java b/test/jalview/io/AnnotationFileIOTest.java new file mode 100644 index 0000000..2aed08b --- /dev/null +++ b/test/jalview/io/AnnotationFileIOTest.java @@ -0,0 +1,90 @@ +package jalview.io; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import jalview.datamodel.AlignmentI; + +import java.io.File; + +import org.junit.Test; + +public class AnnotationFileIOTest +{ + + static String TestFiles[][] = {{ "Test example annotation import/export","examples/uniref50.fa", "examples/testdata/example_annot_file.jva" } + ,{"Test multiple combine annotation statements import/export","examples/uniref50.fa", "examples/testdata/test_combine_annot.jva"}}; + + @Test + public void exampleAnnotationFileIO() throws Exception + { + for (String[] testPair:TestFiles) + { + testAnnotationFileIO(testPair[0], new File(testPair[1]), new File(testPair[2])); + } + } + + public static AlignmentI readAlignmentFile(File f) + { + System.out.println("Reading file: " + f); + String ff = f.getPath(); + try + { + FormatAdapter rf = new FormatAdapter(); + + AlignmentI al = rf.readFile(ff, AppletFormatAdapter.FILE, + new IdentifyFile().Identify(ff, AppletFormatAdapter.FILE)); + + // make sure dataset is initialised ? not sure about this + for (int i = 0; i < al.getSequencesArray().length; ++i) + { + al.getSequenceAt(i).setDatasetSequence(al.getSequenceAt(i).createDatasetSequence()); + } + assertNotNull("Couldn't read supplied alignment data.", al); + return al; + } catch (Exception e) + { + e.printStackTrace(); + } + fail("Couln't read the alignment in file '"+f.toString()+"'"); + return null; + } + /** + * test alignment data in given file can be imported, exported and reimported + * with no dataloss + * + * @param f + * - source datafile (IdentifyFile.identify() should work with it) + * @param ioformat + * - label for IO class used to write and read back in the data from + * f + */ + public static void testAnnotationFileIO(String testname, File f, File annotFile) + { + System.out.println("Test: "+testname+"\nReading annotation file '"+annotFile+"' onto : " + f); + String af = annotFile.getPath(); + try + { + AlignmentI al = readAlignmentFile(f); + + assertTrue("Test "+testname+"\nAlignment was not annotated - annotation file not imported.",new AnnotationFile().readAnnotationFile(al, af, FormatAdapter.FILE)); + + String anfileout = new AnnotationFile().printAnnotations(al.getAlignmentAnnotation(), al.getGroups(), al.getProperties()); + assertTrue("Test "+testname+"\nAlignment annotation file was not regenerated. Null string",anfileout!=null); + assertTrue("Test "+testname+"\nAlignment annotation file was not regenerated. Empty string",anfileout.length()>"JALVIEW_ANNOTATION".length()); + + System.out.println("Output annotation file:\n"+anfileout+"\n<