package compbio.ws.client; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.fail; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import javax.xml.namespace.QName; import javax.xml.ws.Service; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import compbio.data.msa.Annotation; import compbio.data.sequence.FastaSequence; import compbio.data.sequence.Method; import compbio.data.sequence.Score; import compbio.data.sequence.SequenceUtil; import compbio.metadata.JobSubmissionException; import compbio.metadata.LimitExceededException; import compbio.metadata.PresetManager; import compbio.metadata.ResultNotAvailableException; import compbio.metadata.RunnerConfig; import compbio.metadata.UnsupportedRuntimeException; import compbio.metadata.WrongParameterException; import compbio.runner.conservation.AACon; import compbio.util.SysPrefs; public class TestAAConWS { Annotation msaws; @BeforeTest void initConnection() { URL url = null; try { url = new URL("http://localhost:8080/jabaws/AAConWS?wsdl"); } catch (MalformedURLException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } String namespace = "http://msa.data.compbio/01/12/2010/"; QName qname = new QName(namespace, "AAConWS"); Service serv = Service.create(url, qname); msaws = serv.getPort(new QName(namespace, "AAConWSPort"), Annotation.class); } @Test public void testAnalize() throws FileNotFoundException, IOException { /* * MsaWS msaws = serv.getPort(new QName( * "http://msa.data.compbio/01/01/2010/", "ClustalWSPort"), * MsaWS.class); */ // Annotation msaws = serv.getPort(new QName(namespace, // "ClustalWSPort"), Annotation.class); // List fsl = SequenceUtil.readFasta(new FileInputStream( // AAConTester.test_alignment_input)); String CURRENT_DIRECTORY = SysPrefs.getCurrentDirectory() + File.separator; List fsl = SequenceUtil.readFasta(new FileInputStream( CURRENT_DIRECTORY + "testsrc" + File.separator + "testdata" + File.separator + "TO1381.fasta.aln")); try { System.out.println("Pres: " + msaws.getPresets().getPresets()); String jobId = msaws.analize(fsl); System.out.println("J: " + jobId); HashSet result = msaws.getAnnotation(jobId); assertNotNull(result); assertEquals(result.size(), 1); assertEquals(result.iterator().next().getMethod(), Method.SHENKIN); List scores = result.iterator().next().getScores(); assertNotNull(scores); assertEquals(scores.size(), 568); // Using presets PresetManager presets = msaws.getPresets(); jobId = msaws.presetAnalize(fsl, presets.getPresetByName("Quick conservation")); result = msaws.getAnnotation(jobId); assertNotNull(result); assertEquals(result.size(), 13); jobId = msaws.presetAnalize(fsl, presets.getPresetByName("Slow conservation")); result = msaws.getAnnotation(jobId); assertNotNull(result); assertEquals(result.size(), 5); jobId = msaws.presetAnalize(fsl, presets.getPresetByName("Complete conservation")); result = msaws.getAnnotation(jobId); assertNotNull(result); assertEquals(result.size(), 18); } catch (UnsupportedRuntimeException e) { e.printStackTrace(); fail(e.getMessage()); } catch (LimitExceededException e) { e.printStackTrace(); fail(e.getMessage()); } catch (JobSubmissionException e) { e.printStackTrace(); fail(e.getMessage()); } catch (ResultNotAvailableException e) { e.printStackTrace(); fail(e.getMessage()); } catch (WrongParameterException e) { e.printStackTrace(); fail(e.getMessage()); } } @Test public void testPresetAnalize() throws FileNotFoundException, IOException { String CURRENT_DIRECTORY = SysPrefs.getCurrentDirectory() + File.separator; List fsl = SequenceUtil.readFasta(new FileInputStream( CURRENT_DIRECTORY + "testsrc" + File.separator + "testdata" + File.separator + "TO1381.fasta.aln")); try { System.out.println("Pres: " + msaws.getPresets().getPresets()); // Using presets PresetManager presets = msaws.getPresets(); String jobId = msaws.presetAnalize(fsl, presets.getPresetByName("Quick conservation")); HashSet result = msaws.getAnnotation(jobId); assertNotNull(result); assertEquals(result.size(), 13); jobId = msaws.presetAnalize(fsl, presets.getPresetByName("Slow conservation")); result = msaws.getAnnotation(jobId); assertNotNull(result); assertEquals(result.size(), 5); jobId = msaws.presetAnalize(fsl, presets.getPresetByName("Complete conservation")); result = msaws.getAnnotation(jobId); assertNotNull(result); assertEquals(result.size(), 18); } catch (UnsupportedRuntimeException e) { e.printStackTrace(); fail(e.getMessage()); } catch (LimitExceededException e) { e.printStackTrace(); fail(e.getMessage()); } catch (JobSubmissionException e) { e.printStackTrace(); fail(e.getMessage()); } catch (ResultNotAvailableException e) { e.printStackTrace(); fail(e.getMessage()); } catch (WrongParameterException e) { e.printStackTrace(); fail(e.getMessage()); } } @Test public void testCustomAnalize() throws FileNotFoundException, IOException { String CURRENT_DIRECTORY = SysPrefs.getCurrentDirectory() + File.separator; List fsl = SequenceUtil.readFasta(new FileInputStream( CURRENT_DIRECTORY + "testsrc" + File.separator + "testdata" + File.separator + "TO1381.fasta.aln")); // Using options RunnerConfig options = msaws.getRunnerOptions(); // System.out.println(options.getArguments()); try { options.getArgument("Calculation method").setDefaultValue("SMERFS"); String jobId = msaws.customAnalize(fsl, options.getArguments()); HashSet result = msaws.getAnnotation(jobId); assertNotNull(result); assertEquals(result.size(), 1); assertEquals( new ArrayList(result).get(0).getScores().get(0), 0.698f); options.getArgument("Calculation method").setDefaultValue("SMERFS"); options.removeArgument("Normalize"); System.out.println(options); jobId = msaws.customAnalize(fsl, options.getArguments()); result = msaws.getAnnotation(jobId); assertNotNull(result); assertEquals(result.size(), 1); assertEquals( new ArrayList(result).get(0).getScores().get(0), 0.401f); } catch (WrongParameterException e) { e.printStackTrace(); fail(e.getMessage()); } catch (UnsupportedRuntimeException e) { e.printStackTrace(); fail(e.getMessage()); } catch (LimitExceededException e) { e.printStackTrace(); fail(e.getMessage()); } catch (JobSubmissionException e) { e.printStackTrace(); fail(e.getMessage()); } catch (ResultNotAvailableException e) { e.printStackTrace(); fail(e.getMessage()); } } }