export async function submitBatchAnalysis()

in client/src/components/special/cellprofiler/model/analysis/batch.js [116:250]


export async function submitBatchAnalysis (specification) {
  const {
    dockerImage,
    settings,
    specs,
    results,
    mounts,
    rawImagesPath,
    tempFilesPath
  } = await getBatchAnalysisSettings(true);
  const uuid = generateUUID();
  const specFullPath = specs.storage.joinPaths(specs.folder, uuid, 'spec.json');
  const {
    measurementUUID,
    inputs,
    modules,
    pipeline
  } = specification;
  const spec = {
    measurementUUID: (measurementUUID || '').split('/').pop(),
    inputs,
    modules,
    pipeline
  };
  try {
    await specs.storage.writeFile(specFullPath, JSON.stringify(spec, undefined, ' '));
  } catch (e) {
    const storageName = specs.storage.path ||
      specs.storage.pathMask ||
      (specs.storage.id ? `storage #${specs.storage.id}` : 'storage');
    throw new Error(`Error writing analysis specification to ${storageName}: ${e.message}`);
  }
  const resultsDirFullPath = results.storage.joinPaths(results.folder, uuid);
  const localSpecPath = specs.storage.getLocalPath(specFullPath);
  const localResultsPath = results.storage.getLocalPath(resultsDirFullPath);
  const storagesToMount = [
    ...new Set([...mounts, specs.storage, results.storage].map(o => o.id))
  ];
  const {
    parameters: toolParameters = {},
    cmd_template: cmdTemplate,
    instance_disk: hddSize,
    instance_size: instanceType,
    is_spot: isSpot,
    nonPause
  } = settings || {};
  const parameters = {
    ...toolParameters
  };
  const getParameterValue = (parameter) => {
    if (parameters[parameter]) {
      return parameters[parameter].value;
    }
    return undefined;
  };
  const setParameterValue = (parameter, value, skipIfExists = false) => {
    if (value === undefined) {
      return;
    }
    if (
      !skipIfExists ||
      !parameters[parameter] ||
      parameters[parameter].value === undefined
    ) {
      parameters[parameter] = {value, type: 'string'};
    }
  };
  const limitMountsParameter = [...new Set(
    (getParameterValue(CP_CAP_LIMIT_MOUNTS) || '')
      .split(',')
      .concat(storagesToMount)
  )].join(',');
  setParameterValue(CP_CAP_LIMIT_MOUNTS, limitMountsParameter);
  if (rawImagesPath) {
    setParameterValue(CELLPROFILER_API_RAW_DATA_ROOT_DIR, rawImagesPath, true);
  }
  if (tempFilesPath) {
    setParameterValue(CELLPROFILER_API_COMMON_RESULTS_DIR, tempFilesPath);
  }
  setParameterValue(CELLPROFILER_API_BATCH_RESULTS_DIR, localResultsPath);
  setParameterValue(CELLPROFILER_API_BATCH_RESULTS_STORAGE, results.storage.id);
  setParameterValue(CELLPROFILER_API_BATCH_RESULTS_STORAGE_PATH, resultsDirFullPath);
  setParameterValue(CELLPROFILER_API_BATCH_SPEC_FILE, localSpecPath);
  setParameterValue(CELLPROFILER_API_BATCH_SPEC_STORAGE, specs.storage.id);
  setParameterValue(CELLPROFILER_API_BATCH_SPEC_STORAGE_PATH, specFullPath);
  setParameterValue(CELLPROFILER_API_BATCH_UUID, specification.measurementUUID);
  setParameterValue(CELLPROFILER_API_BATCH_FILE_STORAGE, specification.storage);
  setParameterValue(CELLPROFILER_API_BATCH_FILE_PATH, specification.path);
  setParameterValue(
    CELLPROFILER_API_BATCH_FILE_NAME,
    (specification.path || '').split(/[\\/]/).pop()
  );
  setParameterValue(
    CELLPROFILER_API_BATCH_PIPELINE,
    pipeline ? (pipeline.uuid || pipeline.path) : undefined
  );
  setParameterValue(
    CELLPROFILER_API_BATCH_PIPELINE_NAME,
    pipeline ? pipeline.name : undefined
  );
  setParameterValue(
    CELLPROFILER_API_BATCH_SPEC_INPUTS,
    getInputFilesPresentation(inputs)
  );
  setParameterValue(
    CELLPROFILER_API_BATCH_SPEC_MODULES,
    getModulesPresentation(modules)
  );
  setParameterValue(CELLPROFILER_API_BATCH, true);
  const tags = {
    analysisFileName: (specification.path || '')
      .split(/[\\/]/).pop()
      .split('.').slice(0, -1).join('.'),
    analysisPipeline: pipeline ? pipeline.name : undefined,
    [HCS_ANALISYS_TAG]: true
  };
  if (specification.alias) {
    tags.analysisAlias = specification.alias;
  }
  const pipelineRunnerRequest = new PipelineRunner();
  await pipelineRunnerRequest.send({
    dockerImage,
    cmdTemplate,
    instanceType,
    hddSize,
    isSpot,
    nonPause,
    params: parameters,
    tags
  });
  if (pipelineRunnerRequest.error) {
    throw new Error(`Error submitting batch analysis: ${pipelineRunnerRequest.error}`);
  }
  return pipelineRunnerRequest.value;
}