Fix problem with test data for RNAalifold
[jabaws.git] / webservices / compbio / ws / client / ServicesUtil.java
1 package compbio.ws.client;\r
2 \r
3 import java.io.File;\r
4 \r
5 import compbio.engine.client.ConfExecutable;\r
6 import compbio.engine.client.Executable;\r
7 import compbio.runner.conservation.AACon;\r
8 import compbio.runner.disorder.Disembl;\r
9 import compbio.runner.disorder.GlobPlot;\r
10 import compbio.runner.disorder.IUPred;\r
11 import compbio.runner.disorder.Jronn;\r
12 import compbio.runner.msa.ClustalO;\r
13 import compbio.runner.msa.ClustalW;\r
14 import compbio.runner.msa.Mafft;\r
15 import compbio.runner.msa.Muscle;\r
16 import compbio.runner.msa.Probcons;\r
17 import compbio.runner.msa.Tcoffee;\r
18 import compbio.runner.structure.RNAalifold;\r
19 \r
20 public class ServicesUtil {\r
21 \r
22         public static Services getServiceByRunner(Class<? extends Executable> class1) {\r
23                 assert class1 != null;\r
24                 String sname = class1.getSimpleName().toLowerCase();\r
25                 for (Services service : Services.values()) {\r
26                         if (service.toString().toLowerCase().contains(sname)) {\r
27                                 return service;\r
28                         }\r
29                 }\r
30                 return null;\r
31         }\r
32 \r
33         public static Class<? extends Executable<?>> getServiceImpl(Services service) {\r
34                 switch (service) {\r
35                         case AAConWS :\r
36                                 return AACon.class;\r
37                         case ClustalOWS :\r
38                                 return ClustalO.class;\r
39                         case ClustalWS :\r
40                                 return ClustalW.class;\r
41                         case MafftWS :\r
42                                 return Mafft.class;\r
43                         case MuscleWS :\r
44                                 return Muscle.class;\r
45                         case TcoffeeWS :\r
46                                 return Tcoffee.class;\r
47                         case ProbconsWS :\r
48                                 return Probcons.class;\r
49                         case DisemblWS :\r
50                                 return Disembl.class;\r
51                         case GlobPlotWS :\r
52                                 return GlobPlot.class;\r
53                         case JronnWS :\r
54                                 return Jronn.class;\r
55                         case IUPredWS :\r
56                                 return IUPred.class;\r
57                         case RNAalifoldWS :\r
58                                 return RNAalifold.class;\r
59                         default :\r
60                                 throw new RuntimeException(\r
61                                                 "Unknown web service implementation class for service: "\r
62                                                                 + service);\r
63                 }\r
64         }\r
65 \r
66         public static Class<? extends Executable<?>> getRunnerByJobDirectory(\r
67                         File jobdir) {\r
68                 Services service = getServiceByRunnerName(getRunnerNameByJobDirectory(jobdir));\r
69                 return getServiceImpl(service);\r
70         }\r
71 \r
72         private static String getRunnerNameByJobDirectory(File jobdir) {\r
73                 String name = jobdir.getName().split("#")[0];\r
74 \r
75                 if (name.startsWith(ConfExecutable.CLUSTER_TASK_ID_PREFIX)) {\r
76                         assert ConfExecutable.CLUSTER_TASK_ID_PREFIX.length() == 1;\r
77                         name = name.substring(1);\r
78                 }\r
79                 return name;\r
80         }\r
81 \r
82         public static Services getServiceByJobDirectory(File jobdir) {\r
83                 return getServiceByRunnerName(getRunnerNameByJobDirectory(jobdir));\r
84         }\r
85 \r
86         private static Services getServiceByRunnerName(String name) {\r
87                 for (Services service : Services.values()) {\r
88                         String runnerName = getServiceImpl(service).getSimpleName()\r
89                                         .toLowerCase();\r
90                         name = name.trim().toLowerCase();\r
91                         if (name.startsWith(runnerName)) {\r
92                                 return service;\r
93                         }\r
94                 }\r
95                 return null;\r
96         }\r
97 \r
98 }\r