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 void validateJobParams(String toolName)
123 CiJob validateJob = cipresClient
124 .validateJob(toolName, vParams, inputParams, metadata);
125 validateJob.show(true); // currently outputs just to console, should be
127 paramsValidated = true;
129 } catch (CiCipresException ce)
131 paramsValidated = false; // parameters gave an error.
132 ErrorData ed = ce.getErrorData();
134 "Cipres error while trying to validate parameters, code="
135 + ed.code + ", message="
138 if (ed.code == ErrorData.FORM_VALIDATION)
140 for (ParamError pe : ed.paramError)
142 System.out.println(pe.param + ": " + pe.error);
149 public void submitJob(String toolName)
151 if (!paramsValidated)
153 validateJobParams(toolName); // validate before running some expensive job