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);
59 * Specifies a parameter about the input data for a CIPRES job with its value,
60 * for example the "infile_" parameter for the MSA file to calculate a tree
61 * from with file path as value. Note that different tools support different
67 public void addInputParameter(String parameter, String value)
69 inputParams.put(parameter, value);
70 paramsValidated = false;
75 * Adds a CIPRES tool parameter that specifies job behaviour, for example
76 * "runtime_" with the maximum runtime (in hours) as value.
81 public void addToolParameters(String parameter, Collection<String> values)
83 vParams.put(parameter, values);
84 paramsValidated = false;
88 * Adds a metadata tag to the job, for example "clientJobName" with the name
89 * that this job should be referred by as value. CIPRES highly recommends all
90 * jobs are given a clientJobId metadata header.
92 * @param metadataHeader
95 public void addMetadata(String metadataHeader, String value)
97 metadata.put(metadataHeader, value);
98 paramsValidated = false;
101 public void clearAllParameters()
108 public void clearInputParameters()
113 public void clearToolsParameters()
118 public void clearMetadata()
123 public String getTool()
128 public void setTool(String toolName)
131 if (!(this.tool.equals(toolName)))
133 this.tool = toolName;
134 paramsValidated = false;
140 * Sends this job with all given parameters to the given Cipres tool but
141 * doesn't actually run the job. This is a lightweight way to validate that
142 * the given parameters are correct for a specified tool.
144 public CiJob validateJobParams()
146 CiJob validateJob = null;
149 validateJob = cipresClient
150 .validateJob(tool, vParams, inputParams, metadata);
151 validateJob.show(true); // currently outputs just to console, should be
153 paramsValidated = true;
156 } catch (CiCipresException ce)
158 ErrorData ed = ce.getErrorData();
160 "Cipres error while trying to validate parameters, code="
161 + ed.code + ", message="
164 if (ed.code == ErrorData.FORM_VALIDATION)
166 for (ParamError pe : ed.paramError)
168 System.out.println(pe.param + ": " + pe.error);
176 * Sends the job to CIPRES. If the job hasn't been validated beforehand this
177 * method will do so before submitting.
181 public CiJob submitJob()
184 if (!paramsValidated)
186 // validate before running some expensive job first.
187 CiJob validateJob = validateJobParams();
189 submittedJob = submitJob();
196 submittedJob = cipresClient
197 .submitJob(tool, vParams, inputParams, metadata);
199 } catch (CiCipresException ce)
201 ErrorData ed = ce.getErrorData();
203 "Cipres error in submitted job, code="
204 + ed.code + ", message=" + ed.displayMessage);
206 // invalid parameters shouldn't be possible here but just in case.
207 if (ed.code == ErrorData.FORM_VALIDATION)
209 for (ParamError pe : ed.paramError)
212 System.out.println(pe.param + ": " + pe.error);
220 public CiJob getSubmittedJob()
226 public boolean areParamsValidated()
228 return paramsValidated;
231 public Map<String, Collection<String>> getvParams()
236 public Map<String, String> getInputParams()
241 public Map<String, String> getMetadata()