| 1 |
|
package jalview.ws2.client.slivka; |
| 2 |
|
|
| 3 |
|
import java.io.IOException; |
| 4 |
|
import java.net.MalformedURLException; |
| 5 |
|
import java.net.URI; |
| 6 |
|
import java.net.URISyntaxException; |
| 7 |
|
import java.net.URL; |
| 8 |
|
import java.util.ArrayList; |
| 9 |
|
import java.util.List; |
| 10 |
|
import java.util.function.Function; |
| 11 |
|
|
| 12 |
|
import jalview.bin.Cache; |
| 13 |
|
import jalview.bin.Console; |
| 14 |
|
import jalview.ws.params.ParamManager; |
| 15 |
|
import jalview.ws2.actions.alignment.AlignmentAction; |
| 16 |
|
import jalview.ws2.actions.annotation.AnnotationAction; |
| 17 |
|
import jalview.ws2.api.WebService; |
| 18 |
|
import jalview.ws2.client.api.AbstractWebServiceDiscoverer; |
| 19 |
|
import uk.ac.dundee.compbio.slivkaclient.SlivkaClient; |
| 20 |
|
import uk.ac.dundee.compbio.slivkaclient.SlivkaService; |
| 21 |
|
|
| |
|
| 0% |
Uncovered Elements: 149 (149) |
Complexity: 30 |
Complexity Density: 0.25 |
|
| 22 |
|
public class SlivkaWSDiscoverer extends AbstractWebServiceDiscoverer |
| 23 |
|
{ |
| 24 |
|
private static final String SLIVKA_HOST_URLS = "SLIVKAHOSTURLS"; |
| 25 |
|
|
| 26 |
|
private static final URL DEFAULT_URL; |
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 27 |
0 |
static... |
| 28 |
|
{ |
| 29 |
0 |
try |
| 30 |
|
{ |
| 31 |
0 |
DEFAULT_URL = new URL("https://www.compbio.dundee.ac.uk/slivka/"); |
| 32 |
|
} catch (MalformedURLException e) |
| 33 |
|
{ |
| 34 |
0 |
throw new AssertionError(e); |
| 35 |
|
} |
| 36 |
|
} |
| 37 |
|
|
| 38 |
|
private static SlivkaWSDiscoverer instance = null; |
| 39 |
|
|
| 40 |
|
private static ParamManager paramManager = null; |
| 41 |
|
|
| 42 |
|
private final Function<URI, SlivkaClient> clientFactory; |
| 43 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 44 |
0 |
SlivkaWSDiscoverer(Function<URI, SlivkaClient> clientFactory)... |
| 45 |
|
{ |
| 46 |
0 |
this.clientFactory = clientFactory; |
| 47 |
|
} |
| 48 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 49 |
0 |
public static SlivkaWSDiscoverer getInstance()... |
| 50 |
|
{ |
| 51 |
0 |
if (instance == null) |
| 52 |
0 |
instance = new SlivkaWSDiscoverer(SlivkaClient::newInstance); |
| 53 |
0 |
return instance; |
| 54 |
|
} |
| 55 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 56 |
0 |
public static void setParamManager(ParamManager manager)... |
| 57 |
|
{ |
| 58 |
0 |
paramManager = manager; |
| 59 |
|
} |
| 60 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 61 |
0 |
@Override... |
| 62 |
|
public int getStatusForUrl(URL url) |
| 63 |
|
{ |
| 64 |
0 |
try |
| 65 |
|
{ |
| 66 |
0 |
List<?> services = clientFactory.apply(url.toURI()).getServices(); |
| 67 |
0 |
return services.isEmpty() ? STATUS_NO_SERVICES : STATUS_OK; |
| 68 |
|
} catch (URISyntaxException e) |
| 69 |
|
{ |
| 70 |
0 |
Console.error("invalid URL " + url, e); |
| 71 |
0 |
return STATUS_INVALID; |
| 72 |
|
} catch (IOException e) |
| 73 |
|
{ |
| 74 |
0 |
Console.error("slivka could not retrieve services from " + url, e); |
| 75 |
0 |
return STATUS_INVALID; |
| 76 |
|
} |
| 77 |
|
} |
| 78 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 79 |
0 |
@Override... |
| 80 |
|
protected String getUrlsPropertyKey() |
| 81 |
|
{ |
| 82 |
0 |
return SLIVKA_HOST_URLS; |
| 83 |
|
} |
| 84 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 85 |
0 |
@Override... |
| 86 |
|
protected URL getDefaultUrl() |
| 87 |
|
{ |
| 88 |
0 |
return DEFAULT_URL; |
| 89 |
|
} |
| 90 |
|
|
| |
|
| 0% |
Uncovered Elements: 91 (91) |
Complexity: 8 |
Complexity Density: 0.1 |
|
| 91 |
0 |
@Override... |
| 92 |
|
protected List<WebService<?>> fetchServices(URL url) throws IOException |
| 93 |
|
{ |
| 94 |
0 |
ArrayList<WebService<?>> allServices = new ArrayList<>(); |
| 95 |
0 |
SlivkaClient slivkaClient; |
| 96 |
0 |
try |
| 97 |
|
{ |
| 98 |
0 |
slivkaClient = clientFactory.apply(url.toURI()); |
| 99 |
|
} catch (URISyntaxException e) |
| 100 |
|
{ |
| 101 |
0 |
throw new MalformedURLException(e.getMessage()); |
| 102 |
|
} |
| 103 |
0 |
for (var slivkaService : slivkaClient.getServices()) |
| 104 |
|
{ |
| 105 |
0 |
int serviceClass = getServiceClass(slivkaService); |
| 106 |
0 |
if (serviceClass == SERVICE_CLASS_MSA) |
| 107 |
|
{ |
| 108 |
0 |
var wsb = WebService.<AlignmentAction> newBuilder(); |
| 109 |
0 |
initServiceBuilder(slivkaClient, slivkaService, wsb); |
| 110 |
0 |
wsb.category("Alignment"); |
| 111 |
0 |
wsb.interactive(false); |
| 112 |
0 |
wsb.actionClass(AlignmentAction.class); |
| 113 |
0 |
var msaService = wsb.build(); |
| 114 |
|
|
| 115 |
0 |
boolean canRealign = msaService.getName().contains("lustal"); |
| 116 |
0 |
var client = new SlivkaAlignmentWSClient(slivkaClient, slivkaService); |
| 117 |
0 |
var actionBuilder = AlignmentAction.newBuilder(client); |
| 118 |
0 |
actionBuilder.name("Alignment"); |
| 119 |
0 |
actionBuilder.webService(msaService); |
| 120 |
0 |
if (canRealign) |
| 121 |
0 |
actionBuilder.subcategory("Align"); |
| 122 |
0 |
actionBuilder.minSequences(2); |
| 123 |
0 |
msaService.addAction(actionBuilder.build()); |
| 124 |
0 |
if (canRealign) |
| 125 |
|
{ |
| 126 |
0 |
actionBuilder.name("Re-alignment"); |
| 127 |
0 |
actionBuilder.subcategory("Realign"); |
| 128 |
0 |
actionBuilder.submitGaps(true); |
| 129 |
0 |
msaService.addAction(actionBuilder.build()); |
| 130 |
|
} |
| 131 |
0 |
allServices.add(msaService); |
| 132 |
|
} |
| 133 |
0 |
else if (serviceClass == SERVICE_CLASS_PROT_SEQ_ANALYSIS) |
| 134 |
|
{ |
| 135 |
0 |
var wsb = WebService.<AnnotationAction> newBuilder(); |
| 136 |
0 |
initServiceBuilder(slivkaClient, slivkaService, wsb); |
| 137 |
0 |
wsb.category("Protein Disorder"); |
| 138 |
0 |
wsb.interactive(false); |
| 139 |
0 |
wsb.actionClass(AnnotationAction.class); |
| 140 |
0 |
var psaService = wsb.build(); |
| 141 |
0 |
var client = new SlivkaAnnotationWSClient(slivkaClient, slivkaService); |
| 142 |
0 |
var actionBuilder = AnnotationAction.newBuilder(client); |
| 143 |
0 |
actionBuilder.webService(psaService); |
| 144 |
0 |
actionBuilder.name("Analysis"); |
| 145 |
0 |
psaService.addAction(actionBuilder.build()); |
| 146 |
0 |
allServices.add(psaService); |
| 147 |
|
} |
| 148 |
0 |
else if (serviceClass == SERVICE_CLASS_CONSERVATION) |
| 149 |
|
{ |
| 150 |
0 |
var wsb = WebService.<AnnotationAction> newBuilder(); |
| 151 |
0 |
initServiceBuilder(slivkaClient, slivkaService, wsb); |
| 152 |
0 |
wsb.category("Conservation"); |
| 153 |
0 |
wsb.interactive(true); |
| 154 |
0 |
wsb.actionClass(AnnotationAction.class); |
| 155 |
0 |
var conService = wsb.build(); |
| 156 |
0 |
var client = new SlivkaAnnotationWSClient(slivkaClient, slivkaService); |
| 157 |
0 |
var actionBuilder = AnnotationAction.newBuilder(client); |
| 158 |
0 |
actionBuilder.webService(conService); |
| 159 |
0 |
actionBuilder.name(""); |
| 160 |
0 |
actionBuilder.alignmentAnalysis(true); |
| 161 |
0 |
actionBuilder.requireAlignedSequences(true); |
| 162 |
0 |
actionBuilder.filterSymbols(true); |
| 163 |
0 |
conService.addAction(actionBuilder.build()); |
| 164 |
0 |
allServices.add(conService); |
| 165 |
|
} |
| 166 |
0 |
else if (serviceClass == SERVICE_CLASS_RNA_SEC_STR_PRED) |
| 167 |
|
{ |
| 168 |
0 |
var wsb = WebService.<AnnotationAction> newBuilder(); |
| 169 |
0 |
initServiceBuilder(slivkaClient, slivkaService, wsb); |
| 170 |
0 |
wsb.category("Secondary Structure Prediction"); |
| 171 |
0 |
wsb.interactive(true); |
| 172 |
0 |
wsb.actionClass(AnnotationAction.class); |
| 173 |
0 |
var predService = wsb.build(); |
| 174 |
0 |
var client = new SlivkaAnnotationWSClient(slivkaClient, slivkaService); |
| 175 |
0 |
var actionBuilder = AnnotationAction.newBuilder(client); |
| 176 |
0 |
actionBuilder.webService(predService); |
| 177 |
0 |
actionBuilder.name("Prediction"); |
| 178 |
0 |
actionBuilder.minSequences(2); |
| 179 |
0 |
actionBuilder.allowNucleotide(true); |
| 180 |
0 |
actionBuilder.allowProtein(false); |
| 181 |
0 |
actionBuilder.alignmentAnalysis(true); |
| 182 |
0 |
actionBuilder.requireAlignedSequences(true); |
| 183 |
0 |
actionBuilder.filterSymbols(false); |
| 184 |
0 |
predService.addAction(actionBuilder.build()); |
| 185 |
0 |
allServices.add(predService); |
| 186 |
|
} |
| 187 |
|
else |
| 188 |
|
{ |
| 189 |
0 |
continue; |
| 190 |
|
} |
| 191 |
|
} |
| 192 |
0 |
return allServices; |
| 193 |
|
} |
| 194 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 195 |
0 |
private void initServiceBuilder(SlivkaClient client, SlivkaService service, WebService.Builder<?> wsBuilder)... |
| 196 |
|
{ |
| 197 |
0 |
try |
| 198 |
|
{ |
| 199 |
0 |
wsBuilder.url(client.getUrl().toURL()); |
| 200 |
|
} catch (MalformedURLException e) |
| 201 |
|
{ |
| 202 |
0 |
e.printStackTrace(); |
| 203 |
|
} |
| 204 |
0 |
wsBuilder.clientName("slivka"); |
| 205 |
0 |
wsBuilder.name(service.getName()); |
| 206 |
0 |
wsBuilder.description(service.getDescription()); |
| 207 |
0 |
var storeBuilder = new SlivkaParamStoreFactory(service, paramManager); |
| 208 |
0 |
wsBuilder.paramDatastore(storeBuilder.createParamDatastore()); |
| 209 |
|
} |
| 210 |
|
|
| 211 |
|
static final int SERVICE_CLASS_UNSUPPORTED = -1; |
| 212 |
|
|
| 213 |
|
static final int SERVICE_CLASS_MSA = 1; |
| 214 |
|
|
| 215 |
|
static final int SERVICE_CLASS_RNA_SEC_STR_PRED = 2; |
| 216 |
|
|
| 217 |
|
static final int SERVICE_CLASS_CONSERVATION = 3; |
| 218 |
|
|
| 219 |
|
static final int SERVICE_CLASS_PROT_SEQ_ANALYSIS = 4; |
| 220 |
|
|
| 221 |
|
static final int SERVICE_CLASS_PROT_SEC_STR_PRED = 5; |
| 222 |
|
|
| 223 |
|
|
| 224 |
|
|
| 225 |
|
|
| 226 |
|
|
| 227 |
|
@return |
| 228 |
|
|
| |
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 8 |
Complexity Density: 0.47 |
|
| 229 |
0 |
private static int getServiceClass(SlivkaService service)... |
| 230 |
|
{ |
| 231 |
0 |
for (String classifier : service.getClassifiers()) |
| 232 |
|
{ |
| 233 |
0 |
String[] path = classifier.split("\\s*::\\s*"); |
| 234 |
0 |
if (path.length < 3 || !path[0].equalsIgnoreCase("operation")) |
| 235 |
0 |
continue; |
| 236 |
|
|
| 237 |
0 |
var tail = path[path.length - 1].toLowerCase(); |
| 238 |
0 |
switch (tail) |
| 239 |
|
{ |
| 240 |
0 |
case "multiple sequence alignment": |
| 241 |
0 |
return SERVICE_CLASS_MSA; |
| 242 |
0 |
case "rna secondary structure prediction": |
| 243 |
0 |
return SERVICE_CLASS_RNA_SEC_STR_PRED; |
| 244 |
0 |
case "sequence alignment analysis (conservation)": |
| 245 |
0 |
return SERVICE_CLASS_CONSERVATION; |
| 246 |
0 |
case "protein sequence analysis": |
| 247 |
0 |
return SERVICE_CLASS_PROT_SEQ_ANALYSIS; |
| 248 |
0 |
case "protein secondary structure prediction": |
| 249 |
0 |
return SERVICE_CLASS_PROT_SEC_STR_PRED; |
| 250 |
|
} |
| 251 |
|
} |
| 252 |
0 |
return SERVICE_CLASS_UNSUPPORTED; |
| 253 |
|
} |
| 254 |
|
} |