|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace MLL\Utils\LightcyclerSampleSheet; |
| 4 | + |
| 5 | +use MLL\Utils\Microplate\Coordinates; |
| 6 | +use MLL\Utils\Microplate\CoordinateSystem12x8; |
| 7 | + |
| 8 | +class AbsoluteQuantificationSample |
| 9 | +{ |
| 10 | + public string $sampleName; |
| 11 | + |
| 12 | + public string $filterCombination; |
| 13 | + |
| 14 | + public string $hexColor; |
| 15 | + |
| 16 | + public string $sampleType; |
| 17 | + |
| 18 | + /** Key used to determine replication grouping - samples with the same key will replicate to the first occurrence */ |
| 19 | + public string $replicationOfKey; |
| 20 | + |
| 21 | + public ?int $concentration; |
| 22 | + |
| 23 | + public function __construct( |
| 24 | + string $sampleName, |
| 25 | + string $filterCombination, |
| 26 | + string $hexColor, |
| 27 | + string $sampleType, |
| 28 | + string $replicationOfKey, |
| 29 | + ?int $concentration |
| 30 | + ) { |
| 31 | + $this->sampleName = $sampleName; |
| 32 | + $this->filterCombination = $filterCombination; |
| 33 | + $this->hexColor = $hexColor; |
| 34 | + $this->sampleType = $sampleType; |
| 35 | + $this->replicationOfKey = $replicationOfKey; |
| 36 | + $this->concentration = $concentration; |
| 37 | + } |
| 38 | + |
| 39 | + public static function formatConcentration(?int $concentration): ?string |
| 40 | + { |
| 41 | + if ($concentration === null) { |
| 42 | + return null; |
| 43 | + } |
| 44 | + |
| 45 | + $exponent = (int) floor(log10(abs($concentration))); |
| 46 | + $mantissa = $concentration / (10 ** $exponent); |
| 47 | + |
| 48 | + return number_format($mantissa, 2) . 'E' . $exponent; |
| 49 | + } |
| 50 | + |
| 51 | + /** @return array<string, string|null> */ |
| 52 | + public function toSerializableArray(string $coordinatesString, string $replicationOfCoordinate): array |
| 53 | + { |
| 54 | + return [ |
| 55 | + 'General:Pos' => Coordinates::fromString($coordinatesString, new CoordinateSystem12x8())->toString(), |
| 56 | + 'General:Sample Name' => $this->sampleName, |
| 57 | + 'General:Repl. Of' => $replicationOfCoordinate, |
| 58 | + 'General:Filt. Comb.' => $this->filterCombination, |
| 59 | + 'Sample Preferences:Color' => RandomHexGenerator::LIGHTCYCLER_COLOR_PREFIX . $this->hexColor, |
| 60 | + 'Abs Quant:Sample Type' => $this->sampleType, |
| 61 | + 'Abs Quant:Concentration' => self::formatConcentration($this->concentration), |
| 62 | + ]; |
| 63 | + } |
| 64 | +} |
0 commit comments