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;
17 private final CiClient cipresClient;
19 private final CiApplication app = CiApplication.getInstance();
21 private Map<String, Collection<String>> vParams = new HashMap<>();
23 private Map<String, String> inputParams = new HashMap<>();
25 private Map<String, String> metadata = new HashMap<>();
27 private boolean paramsValidated = false;
31 cipresClient = new CiClient(
32 app.getAppKey(), app.getUsername(), app.getPassword(),
38 public TreeJob(String alignmentFilePath)
40 cipresClient = new CiClient(
41 app.getAppKey(), app.getUsername(), app.getPassword(),
44 inputParams.put("infile_", alignmentFilePath);
50 * Specifies a parameter about the input data for a CIPRES job with its value,
51 * for example the "infile_" parameter for the MSA file to calculate a tree
52 * from with file path as value. Note that different tools support different
58 public void addInputParameter(String parameter, String value)
60 inputParams.put(parameter, value);
61 paramsValidated = false;
66 * Adds a CIPRES tool parameter that specifies job behaviour, for example
67 * "runtime_" with the maximum runtime (in hours) as value.
72 public void addToolParameters(String parameter, Collection<String> values)
74 vParams.put(parameter, values);
75 paramsValidated = false;
79 * Adds a metadata tag to the job, for example "clientJobName" with the name
80 * that this job should be referred by as value. CIPRES highly recommends all
81 * jobs are given a clientJobId metadata header.
83 * @param metadataHeader
86 public void addMetadata(String metadataHeader, String value)
88 metadata.put(metadataHeader, value);
89 paramsValidated = false;
92 public void clearAllParameters()
99 public void clearInputParameters()
104 public void clearToolsParameters()
109 public void clearMetadata()
115 * Sends this job with all given parameters to the given Cipres tool but
116 * doesn't actually run the job. This is a lightweight way to validate that
117 * the given parameters are correct for a specified tool.
119 public CiJob validateJobParams(String toolName)
121 CiJob validateJob = null;
124 validateJob = cipresClient
125 .validateJob(toolName, vParams, inputParams, metadata);
126 validateJob.show(true); // currently outputs just to console, should be
128 paramsValidated = true;
131 } catch (CiCipresException ce)
133 ErrorData ed = ce.getErrorData();
135 "Cipres error while trying to validate parameters, code="
136 + ed.code + ", message="
139 if (ed.code == ErrorData.FORM_VALIDATION)
141 for (ParamError pe : ed.paramError)
143 System.out.println(pe.param + ": " + pe.error);
151 * Sends the job to CIPRES. If the job hasn't been validated beforehand this
152 * method will do so before submitting.
156 public CiJob submitJob(String toolName)
158 CiJob submittedJob = null;
159 if (!paramsValidated)
161 // validate before running some expensive job first.
162 CiJob validateJob = validateJobParams(toolName);
164 // should be redundant but extra check here anyway.
165 if (!validateJob.isError())
167 submittedJob = submitJob(toolName);
174 submittedJob = cipresClient
175 .submitJob(toolName, vParams, inputParams, metadata);
176 } catch (CiCipresException ce)
178 ErrorData ed = ce.getErrorData();
180 "Cipres error in submitted job, code="
181 + ed.code + ", message=" + ed.displayMessage);
183 if (ed.code == ErrorData.FORM_VALIDATION)
185 for (ParamError pe : ed.paramError)
186 // invalid parameters shouldn't be possible here but just in case.
188 System.out.println(pe.param + ": " + pe.error);