package jalview.ext.cipres; import java.util.Collection; import java.util.HashMap; import java.util.Map; import org.ngbw.directclient.CiApplication; import org.ngbw.directclient.CiCipresException; import org.ngbw.directclient.CiClient; import org.ngbw.directclient.CiJob; import org.ngbw.restdatatypes.ErrorData; import org.ngbw.restdatatypes.ParamError; public class TreeJob { private final CiClient cipresClient; private final CiApplication app = CiApplication.getInstance(); private Map> vParams = new HashMap<>(); private Map inputParams = new HashMap<>(); private Map metadata = new HashMap<>(); private boolean paramsValidated = false; public TreeJob() { cipresClient = new CiClient( app.getAppKey(), app.getUsername(), app.getPassword(), app.getRestUrl() ); } public TreeJob(String alignmentFilePath) { cipresClient = new CiClient( app.getAppKey(), app.getUsername(), app.getPassword(), app.getRestUrl() ); inputParams.put("infile_", alignmentFilePath); } /** * Specifies a parameter about the input data for a CIPRES job with its value, * for example the "infile_" parameter for the MSA file to calculate a tree * from with file path as value. Note that different tools support different * input parameters. * * @param parameter * @param value */ public void addInputParameter(String parameter, String value) { inputParams.put(parameter, value); paramsValidated = false; } /** * Adds a CIPRES tool parameter that specifies job behaviour, for example * "runtime_" with the maximum runtime (in hours) as value. * * @param parameter * @param values */ public void addToolParameters(String parameter, Collection values) { vParams.put(parameter, values); paramsValidated = false; } /** * Adds a metadata tag to the job, for example "clientJobName" with the name * that this job should be referred by as value. CIPRES highly recommends all * jobs are given a clientJobId metadata header. * * @param metadataHeader * @param value */ public void addMetadata(String metadataHeader, String value) { metadata.put(metadataHeader, value); paramsValidated = false; } public void clearAllParameters() { vParams.clear(); inputParams.clear(); metadata.clear(); } public void clearInputParameters() { inputParams.clear(); } public void clearToolsParameters() { vParams.clear(); } public void clearMetadata() { metadata.clear(); } /** * Sends this job with all given parameters to the given Cipres tool but * doesn't actually run the job. This is a lightweight way to validate that * the given parameters are correct for a specified tool. */ public void validateJobParams(String toolName) { try { CiJob validateJob = cipresClient .validateJob(toolName, vParams, inputParams, metadata); validateJob.show(true); // currently outputs just to console, should be // graphical paramsValidated = true; } catch (CiCipresException ce) { paramsValidated = false; // parameters gave an error. ErrorData ed = ce.getErrorData(); System.out.println( "Cipres error while trying to validate parameters, code=" + ed.code + ", message=" + ed.displayMessage ); if (ed.code == ErrorData.FORM_VALIDATION) { for (ParamError pe : ed.paramError) { System.out.println(pe.param + ": " + pe.error); } } } } public void submitJob(String toolName) { if (!paramsValidated) { validateJobParams(toolName); // validate before running some expensive job // first } } }