import { idFromName } from './builderIdUtils' import { wellIdsForFormat } from '../components/WellPlate.geometry' import { normalizeQpcrSample, normalizeQpcrTarget, } from './runNormalizers' import { createTemplateEnvelope } from './templateEnvelopes' import { validateQpcrPlateData } from './templateValidators' import type { CreateQpcrPlateTemplateOptions, QpcrPlateTemplate, QpcrPlateTemplateData, QpcrReaction, QpcrSample, QpcrTarget, } from './types' /** @deprecated Scheduled for removal from the core SDK in MINT 1.4; the biology templates move to a dedicated package or the owning plugins. */ export function createQpcrPlateTemplate( options: CreateQpcrPlateTemplateOptions ): QpcrPlateTemplate { const format = options.format ?? 96 const replicates = options.replicates ?? 3 if (replicates < 1) { throw new Error('qPCR replicates must be at least 1.') } const samples = options.samples.map((sample, index): QpcrSample => { if (typeof sample !== 'string') return normalizeQpcrSample(sample) return { sampleId: idFromName(sample, `sample-${index + 1}`), name: sample, metadata: {}, } }) const targets = options.targets.map((target, index): QpcrTarget => { if (typeof target !== 'string') return normalizeQpcrTarget(target) return { id: idFromName(target, `target-${index + 1}`), name: target, metadata: {}, } }) const wells = wellIdsForFormat(format) let wellIndex = 0 const reactions: QpcrReaction[] = [] for (const sample of samples) { for (const target of targets) { for (let replicate = 1; replicate <= replicates; replicate += 1) { const wellId = wells[wellIndex] if (!wellId) throw new Error(`qPCR plate format ${format} does not have enough wells.`) reactions.push({ id: `${sample.sampleId}-${target.id}-r${replicate}`, wellId, sampleId: sample.sampleId, targetId: target.id, replicate, controlKind: 'sample', flags: [], metadata: {}, }) wellIndex += 1 } } } if (options.includeNoTemplateControls !== false) { for (const target of targets) { const wellId = wells[wellIndex] if (!wellId) throw new Error(`qPCR plate format ${format} does not have enough wells.`) reactions.push({ id: `ntc-${target.id}`, wellId, targetId: target.id, replicate: 1, controlKind: 'no-template', flags: [], metadata: {}, }) wellIndex += 1 } } const data: QpcrPlateTemplateData = { plateId: 'qpcr-plate-1', format, samples, targets, reactions, instrument: options.instrument, chemistry: options.chemistry ?? 'sybr', metadata: options.metadata ?? {}, } validateQpcrPlateData(data) return createTemplateEnvelope('qpcr-plate', data, options.metadata ?? {}) }