1 package jalview.ws.slivkaws;
3 import jalview.ws.params.ArgumentI;
4 import jalview.ws.params.WsParamSetI;
5 import jalview.ws.params.simple.BooleanOption;
6 import jalview.ws.params.simple.DoubleParameter;
7 import jalview.ws.params.simple.IntegerParameter;
8 import jalview.ws.params.simple.StringParameter;
10 import java.io.IOException;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.List;
15 import uk.ac.dundee.compbio.slivkaclient.Parameter;
16 import uk.ac.dundee.compbio.slivkaclient.SlivkaService;
18 public class SlivkaParamSet implements WsParamSetI
20 private SlivkaService service;
22 private List<ArgumentI> args = new ArrayList<>();
24 SlivkaParamSet(SlivkaService service) throws IOException
26 this.service = service;
27 for (Parameter param : service.getParameters())
29 Object defaultValue = param.getDefault() instanceof List ? ((List<?>) param.getDefault()).get(0)
31 if (param instanceof Parameter.FlagParameter)
33 args.add(new BooleanOption(param.getId(), param.getDescription(),
34 param.getName(), param.isRequired(), (Boolean) defaultValue, null));
36 else if (param instanceof Parameter.TextParameter)
38 args.add(new StringParameter(param.getId(), param.getDescription(),
39 param.isRequired(), (String) defaultValue, (String) defaultValue));
41 else if (param instanceof Parameter.IntegerParameter)
43 Integer min = ((Parameter.IntegerParameter) param).getMin();
44 Integer max = ((Parameter.IntegerParameter) param).getMax();
45 Integer defVal = defaultValue != null ? ((Number) defaultValue).intValue() : null;
46 args.add(new IntegerParameter(param.getId(), param.getDescription(),
47 param.isRequired(), defVal, (min == null) ? Integer.MIN_VALUE : min,
48 (max == null) ? Integer.MAX_VALUE : max));
50 else if (param instanceof Parameter.DecimalParameter)
52 Double min = ((Parameter.DecimalParameter) param).getMin();
53 Double max = ((Parameter.DecimalParameter) param).getMax();
54 Double defVal = defaultValue != null ? ((Number) defaultValue).doubleValue() : null;
55 args.add(new DoubleParameter(param.getId(), param.getDescription(),
56 param.isRequired(), defVal, (min == null) ? -Double.MAX_VALUE : min,
57 (max == null) ? Double.MAX_VALUE : max));
59 else if (param instanceof Parameter.ChoiceParameter)
61 List<String> choices = ((Parameter.ChoiceParameter) param)
66 List<?> selected = param.getDefault() != null
67 ? (List<?>) param.getDefault()
68 : Collections.EMPTY_LIST;
69 for (String choice : choices)
71 args.add(new BooleanOption(
72 String.format("%s$%d", param.getId(), i++),
73 param.getDescription(), choice, param.isRequired(),
74 selected.contains(choice), choice, null));
79 args.add(new StringParameter(
80 param.getId(), param.getDescription(),
81 param.isRequired(), (String) param.getDefault(),
82 (String) defaultValue, choices, choices));
85 else if (param instanceof Parameter.FileParameter)
87 // skip: files are provided from sequences
91 String defaultVal = param.getDefault() != null
92 ? param.getDefault().toString()
94 args.add(new StringParameter(param.getId(), param.getDescription(),
95 param.isRequired(), defaultVal, defaultVal));
101 public String getName()
107 public String getDescription()
113 public String[] getApplicableUrls()
115 return new String[] { service.getUrl().toString() };
119 public String getSourceFile()
125 public void setSourceFile(String newfile)
130 public boolean isModifiable()
136 public List<ArgumentI> getArguments()
142 public void setArguments(List<ArgumentI> args)
144 throw new RuntimeException();