1 package jalview.ext.cipres;
3 import java.util.Collection;
4 import java.util.HashMap;
7 import org.ngbw.directclient.CiApplication;
8 import org.ngbw.directclient.CiCipresException;
9 import org.ngbw.directclient.CiClient;
10 import org.ngbw.directclient.CiJob;
11 import org.ngbw.restdatatypes.ErrorData;
12 import org.ngbw.restdatatypes.ParamError;
14 public class CipresJob
17 private final static CiApplication app = CiApplication.getInstance();
19 private final static CiClient cipresClient = new CiClient(
20 app.getAppKey(), app.getUsername(), app.getPassword(),
24 private CiJob submittedJob;
28 private Map<String, Collection<String>> vParams = new HashMap<>();
30 private Map<String, String> inputParams = new HashMap<>();
32 private Map<String, String> metadata = new HashMap<>();
34 private boolean paramsValidated = false;
36 // Clients for umbrella application, not currently in use.
37 private static CiClient adminClient;
39 private static CiClient userClient;
45 public CipresJob(String alignmentFilePath)
48 inputParams.put("infile_", alignmentFilePath);
51 public CipresJob(String alignmentFilePath, String toolName)
53 this(alignmentFilePath);
62 * Specifies a parameter about the input data for a CIPRES job with its value,
63 * for example the "infile_" parameter for the MSA file to calculate a tree
64 * from with file path as value. Note that different tools support different
70 public void addInputParameter(String parameter, String value)
72 inputParams.put(parameter, value);
73 paramsValidated = false;
78 * Adds a CIPRES tool parameter that specifies job behaviour, for example
79 * "runtime_" with the maximum runtime (in hours) as value.
84 public void addToolParameters(String parameter, Collection<String> values)
86 vParams.put(parameter, values);
87 paramsValidated = false;
91 * Adds a metadata tag to the job, for example "clientJobName" with the name
92 * that this job should be referred by as value. CIPRES highly recommends all
93 * jobs are given a clientJobId metadata header.
95 * @param metadataHeader
98 public void addMetadata(String metadataHeader, String value)
100 metadata.put(metadataHeader, value);
101 paramsValidated = false;
104 public void clearAllParameters()
111 public void clearInputParameters()
116 public void clearToolsParameters()
121 public void clearMetadata()
126 public String getTool()
131 public void setTool(String toolName)
134 if (!(this.tool.equals(toolName)))
136 this.tool = toolName;
137 paramsValidated = false;
143 * Sends this job with all given parameters to the given Cipres tool but
144 * doesn't actually run the job. This is a lightweight way to validate that
145 * the given parameters are correct for a specified tool.
147 public CiJob validateJobParams()
149 CiJob validateJob = null;
152 validateJob = cipresClient
153 .validateJob(tool, vParams, inputParams, metadata);
154 validateJob.show(true); // currently outputs just to console, should be
156 paramsValidated = true;
159 } catch (CiCipresException ce)
161 ErrorData ed = ce.getErrorData();
163 "Cipres error while trying to validate parameters, code="
164 + ed.code + ", message="
167 if (ed.code == ErrorData.FORM_VALIDATION)
169 for (ParamError pe : ed.paramError)
171 System.out.println(pe.param + ": " + pe.error);
179 * Sends the job to CIPRES. If the job hasn't been validated beforehand this
180 * method will do so before submitting.
184 public CiJob submitJob()
187 if (!paramsValidated)
189 // validate before running some expensive job first.
190 CiJob validateJob = validateJobParams();
192 // should be redundant but extra check here anyway.
193 if (!validateJob.isError())
195 submittedJob = submitJob();
202 submittedJob = cipresClient
203 .submitJob(tool, vParams, inputParams, metadata);
205 } catch (CiCipresException ce)
207 ErrorData ed = ce.getErrorData();
209 "Cipres error in submitted job, code="
210 + ed.code + ", message=" + ed.displayMessage);
212 // invalid parameters shouldn't be possible here but just in case.
213 if (ed.code == ErrorData.FORM_VALIDATION)
215 for (ParamError pe : ed.paramError)
218 System.out.println(pe.param + ": " + pe.error);
226 public CiJob getSubmittedJob()