From ec4bfe5b2259dc86b8baa0ae4d925bdcedbc98b9 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 23 May 2013 12:04:24 +0100 Subject: [PATCH] JAL-1295 test to demonstrate JAL-1294 (caused by JAL-1297) --- .../ws/jabaws/DisorderAnnotExportImport.java | 144 ++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 test/jalview/ws/jabaws/DisorderAnnotExportImport.java diff --git a/test/jalview/ws/jabaws/DisorderAnnotExportImport.java b/test/jalview/ws/jabaws/DisorderAnnotExportImport.java new file mode 100644 index 0000000..fa19d00 --- /dev/null +++ b/test/jalview/ws/jabaws/DisorderAnnotExportImport.java @@ -0,0 +1,144 @@ +package jalview.ws.jabaws; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; +import jalview.io.AnnotationFile; +import jalview.io.FormatAdapter; +import jalview.io.StockholmFileTest; +import jalview.ws.jws2.AADisorderClient; +import jalview.ws.jws2.Jws2Discoverer; +import jalview.ws.jws2.jabaws2.Jws2Instance; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class DisorderAnnotExportImport +{ + public static String testseqs = "examples/uniref50.fa"; + + public static Jws2Discoverer disc; + + public static List iupreds; + + jalview.ws.jws2.AADisorderClient disorderClient; + + public static jalview.gui.AlignFrame af = null; + + @BeforeClass + public static void setUpBeforeClass() throws Exception + { + + jalview.bin.Cache.initLogger(); + disc = JalviewJabawsTestUtils.getJabawsDiscoverer(); + iupreds = new ArrayList(); + for (Jws2Instance svc : disc.getServices()) + { + if (svc.getServiceTypeURI().toLowerCase().contains("iupredws")) + { + iupreds.add(svc); + } + } + assertTrue("Couldn't discover any IUPred services to use to test.", + iupreds.size() > 0); + jalview.io.FileLoader fl = new jalview.io.FileLoader(false); + af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.FormatAdapter.FILE); + assertNotNull("Couldn't load test data ('" + testseqs + "')", af); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception + { + if (af != null) + { + af.setVisible(false); + af.dispose(); + } + } + + /** + * test for patches to JAL-1294 + */ + @Test + public void testDisorderAnnotExport() + { + disorderClient = new AADisorderClient(iupreds.get(0), af, null, null); + af.getViewport().getCalcManager().startWorker(disorderClient); + do + { + try + { + Thread.sleep(50); + } catch (InterruptedException x) + { + } + ; + } while (af.getViewport().getCalcManager().isWorking()); + AlignmentI orig_alig = af.getViewport().getAlignment(); + // NOTE: Consensus annotation row cannot be exported and reimported faithfully - so we remove them + List toremove = new ArrayList(); + for (AlignmentAnnotation aa:orig_alig.getAlignmentAnnotation()) + { + if (aa.autoCalculated) + { + toremove.add(aa); + } + } + for (AlignmentAnnotation aa:toremove) + { + orig_alig.deleteAnnotation(aa); + } + testAnnotationFileIO("Testing IUPred Annotation IO", orig_alig); + + } + + public static void testAnnotationFileIO(String testname, AlignmentI al) + { + try + { + String aligfileout = new FormatAdapter().formatSequences("PFAM", + al.getSequencesArray()); + 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<