Clustal Omega web service wrapper and tester
[jabaws.git] / webservices / compbio / ws / client / Services.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.ws.client;\r
20 \r
21 import java.io.File;\r
22 import java.net.URL;\r
23 import java.util.Set;\r
24 \r
25 import javax.xml.namespace.QName;\r
26 import javax.xml.ws.Service;\r
27 \r
28 import compbio.data.msa.JABAService;\r
29 import compbio.data.msa.MsaWS;\r
30 import compbio.data.msa.SequenceAnnotation;\r
31 import compbio.engine.client.ConfExecutable;\r
32 import compbio.engine.client.Executable;\r
33 import compbio.runner.conservation.AACon;\r
34 import compbio.runner.disorder.Disembl;\r
35 import compbio.runner.disorder.GlobPlot;\r
36 import compbio.runner.disorder.IUPred;\r
37 import compbio.runner.disorder.Jronn;\r
38 import compbio.runner.msa.ClustalO;\r
39 import compbio.runner.msa.ClustalW;\r
40 import compbio.runner.msa.Mafft;\r
41 import compbio.runner.msa.Muscle;\r
42 import compbio.runner.msa.Probcons;\r
43 import compbio.runner.msa.Tcoffee;\r
44 \r
45 /**\r
46  * List of web services currently supported by JABAWS version 2\r
47  * \r
48  */\r
49 public enum Services {\r
50         MafftWS, MuscleWS, ClustalWS, ClustalOWS, TcoffeeWS, ProbconsWS, AAConWS, JronnWS, DisemblWS, GlobPlotWS, IUPredWS;\r
51 \r
52         public static Services getService(String servName) {\r
53                 servName = servName.trim().toLowerCase();\r
54                 for (Services service : Services.values()) {\r
55                         if (service.toString().equalsIgnoreCase(servName)) {\r
56                                 return service;\r
57                         }\r
58                 }\r
59                 return null;\r
60         }\r
61 \r
62         public static Services getServiceByRunner(\r
63                         Class<Executable<?>> runnerClassName) {\r
64                 assert runnerClassName != null;\r
65                 String sname = runnerClassName.getSimpleName().toLowerCase();\r
66                 for (Services service : Services.values()) {\r
67                         if (service.toString().toLowerCase().contains(sname)) {\r
68                                 return service;\r
69                         }\r
70                 }\r
71                 return null;\r
72         }\r
73 \r
74         public Class<? extends Executable<?>> getServiceImpl() {\r
75                 switch (this) {\r
76                         case AAConWS :\r
77                                 return AACon.class;\r
78                         case ClustalOWS :\r
79                                 return ClustalO.class;\r
80                         case ClustalWS :\r
81                                 return ClustalW.class;\r
82                         case MafftWS :\r
83                                 return Mafft.class;\r
84                         case MuscleWS :\r
85                                 return Muscle.class;\r
86                         case TcoffeeWS :\r
87                                 return Tcoffee.class;\r
88                         case ProbconsWS :\r
89                                 return Probcons.class;\r
90                         case DisemblWS :\r
91                                 return Disembl.class;\r
92                         case GlobPlotWS :\r
93                                 return GlobPlot.class;\r
94                         case JronnWS :\r
95                                 return Jronn.class;\r
96                         case IUPredWS :\r
97                                 return IUPred.class;\r
98                         default :\r
99                                 throw new RuntimeException(\r
100                                                 "Unknown web service implementation class for service: "\r
101                                                                 + this);\r
102                 }\r
103         }\r
104 \r
105         public static Class<? extends Executable<?>> getRunnerByJobDirectory(\r
106                         File jobdir) {\r
107                 Services service = getServiceByRunnerName(getRunnerNameByJobDirectory(jobdir));\r
108                 return service.getServiceImpl();\r
109         }\r
110 \r
111         private static String getRunnerNameByJobDirectory(File jobdir) {\r
112                 String name = jobdir.getName().split("#")[0];\r
113 \r
114                 if (name.startsWith(ConfExecutable.CLUSTER_TASK_ID_PREFIX)) {\r
115                         assert ConfExecutable.CLUSTER_TASK_ID_PREFIX.length() == 1;\r
116                         name = name.substring(1);\r
117                 }\r
118                 return name;\r
119         }\r
120 \r
121         public static Services getServiceByJobDirectory(File jobdir) {\r
122                 return getServiceByRunnerName(getRunnerNameByJobDirectory(jobdir));\r
123         }\r
124 \r
125         private static Services getServiceByRunnerName(String name) {\r
126                 for (Services service : Services.values()) {\r
127                         String runnerName = service.getServiceImpl().getSimpleName()\r
128                                         .toLowerCase();\r
129                         name = name.trim().toLowerCase();\r
130                         if (name.startsWith(runnerName)) {\r
131                                 return service;\r
132                         }\r
133                 }\r
134                 return null;\r
135         }\r
136 \r
137         Service getService(URL url, String sqname) {\r
138                 QName qname = new QName(sqname, this.toString());\r
139                 return Service.create(url, qname);\r
140         }\r
141 \r
142         public static String toString(Set<Services> services) {\r
143                 if (services == null || services.isEmpty()) {\r
144                         return "";\r
145                 }\r
146                 String value = "";\r
147                 String delim = ", ";\r
148                 for (Services serv : services) {\r
149                         value += serv.toString() + delim;\r
150                 }\r
151                 value = value.substring(0, value.length() - delim.length());\r
152                 return value;\r
153         }\r
154 \r
155         Class<? extends JABAService> getServiceType() {\r
156                 switch (this) {\r
157                         // deliberate leaking\r
158                         case AAConWS :\r
159                         case JronnWS :\r
160                         case DisemblWS :\r
161                         case GlobPlotWS :\r
162                         case IUPredWS :\r
163                                 return SequenceAnnotation.class;\r
164 \r
165                                 // deliberate leaking\r
166                         case ClustalWS :\r
167                         case ClustalOWS :\r
168                         case MafftWS :\r
169                         case MuscleWS :\r
170                         case ProbconsWS :\r
171                         case TcoffeeWS :\r
172 \r
173                                 return MsaWS.class;\r
174                         default :\r
175                                 throw new RuntimeException("Unrecognised Web Service Type "\r
176                                                 + this + " - Should never happened!");\r
177                 }\r
178         }\r
179 \r
180         JABAService getInterface(Service service) {\r
181                 assert service != null;\r
182 \r
183                 QName portName = new QName(service.getServiceName().getNamespaceURI(),\r
184                                 this.toString() + "Port");\r
185                 return service.getPort(portName, this.getServiceType());\r
186         }\r
187 }