145cddfb65141598205594004d7cc7e8e3567f0d
[jalview.git] / test / jalview / ws / jabaws / MinJabawsClientTests.java
1 package jalview.ws.jabaws;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.fail;
5
6 import java.util.ArrayList;
7 import java.util.List;
8
9 import org.junit.Test;
10
11 import compbio.data.msa.MsaWS;
12 import compbio.data.msa.RegistryWS;
13 import compbio.data.sequence.FastaSequence;
14 import compbio.metadata.JobStatus;
15 import compbio.ws.client.Jws2Client;
16 import compbio.ws.client.Services;
17
18 public class MinJabawsClientTests {
19
20   /**
21    * simple test for the benefit of JAL-1338
22    * @throws Exception
23    */
24   @SuppressWarnings("rawtypes")
25   @Test
26   public void msaTest() throws Exception {
27     String url;
28     RegistryWS registry = Jws2Client
29             .connectToRegistry(url = "http://www.compbio.dundee.ac.uk/jabaws");
30     if (registry != null)
31     {
32
33       MsaWS msaservice = null;
34       for (Services service : registry.getSupportedServices())
35       {
36         if (service.equals(Services.ClustalOWS))
37         {
38           msaservice = (MsaWS) Jws2Client.connect(url, service);
39           if (msaservice != null)
40           {
41             break;
42           }
43         }
44       }
45       if (msaservice == null)
46       {
47         fail("couldn't find a clustalO service on the public registry");
48       }
49       FastaSequence fsq = new FastaSequence("seqA",
50               "SESESESESESESESSESESSESESESESESESESESESEEEEEESSESESESESSSSESESESESESESE");
51       List<FastaSequence> iseqs = new ArrayList<FastaSequence>();
52       for (int i = 0; i < 9; i++)
53       {
54         iseqs.add(new FastaSequence(fsq.getId() + i, fsq.getSequence()
55                 + fsq.getSequence().substring(i + 3, i + 3 + i)));
56       }
57
58       String jobid = msaservice.align(iseqs);
59       if (jobid != null)
60       {
61         JobStatus js = null;
62         do
63         {
64           try
65           {
66             Thread.sleep(500);
67           } catch (InterruptedException q)
68           {
69           }
70           ;
71           js = msaservice.getJobStatus(jobid);
72         } while (!js.equals(JobStatus.FAILED)
73                 && !js.equals(JobStatus.CANCELLED)
74                 && !js.equals(JobStatus.FINISHED));
75         assertEquals("Trial alignment failed. State was " + js.name(), js,
76                 JobStatus.FINISHED);
77         assertEquals(
78                 "Mismatch in number of input and result sequences - assume alignment service wasn't interacted with correctly",
79                 msaservice.getResult(jobid).getSequences().size(),
80                 iseqs.size());
81
82         List<FastaSequence> fastaSequences = msaservice.getResult(jobid).getSequences();
83         for(FastaSequence fastaSequence : fastaSequences){
84           System.out.println(">" + fastaSequence.getId());
85           System.out.println(fastaSequence.getFormattedFasta());
86         }
87       }
88
89       //        msaservice.getResult(jobid).getSequences()
90       //        .forEach(new Consumer<FastaSequence>()
91       //                {
92       //                  @Override
93       //                  public void accept(FastaSequence t)
94       //                  {
95       //                    System.out.println(">" + t.getId());
96       //                    System.out.println(t.getFormattedFasta());
97       //                  }
98       //                });
99     }
100
101   }
102 }
103