Skip to content

Commit 3b6a13a

Browse files
authored
Rack to object with positions
1 parent 6eb961f commit 3b6a13a

31 files changed

+525
-344
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ See [GitHub releases](https://github.com/mll-lab/php-utils/releases).
99

1010
## Unreleased
1111

12+
## v4.0.0
13+
14+
### Added
15+
16+
- Add specific class for each `MLLLabWareRack`-type that includes a `positions`-Collection
17+
18+
### Changed
19+
20+
- Breaking Change: Delete class `MLLLabWareRack`
21+
- Breaking Change: Delete class `CustomRack`
22+
- Breaking Change: Add method `positionCount` to interface `Rack`
23+
- Breaking Change: Limit the usage of `BarcodeLocation` to objects implementing `ScannedRack`
24+
1225
## v3.2.0
1326

1427
### Added

src/Tecan/BasicCommands/AspirateAndDispenseParameters.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ public function __construct(Rack $rack, int $startPosition, int $endPosition)
2222
/** Serializes the aspirate and dispense parameters as part of a reagent distribution according the gwl file format. */
2323
public function toString(): string
2424
{
25-
return implode(
26-
';',
27-
[
28-
$this->rack->toString(),
29-
$this->startPosition,
30-
$this->endPosition,
31-
]
32-
);
25+
return implode(';', [
26+
$this->rack->toString(),
27+
$this->startPosition,
28+
$this->endPosition,
29+
]);
3330
}
3431
}

src/Tecan/BasicCommands/BasicPipettingActionCommand.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ abstract public static function commandLetter(): string;
1919

2020
public function toString(): string
2121
{
22-
return implode(
23-
';',
24-
[
25-
static::commandLetter(),
26-
$this->location->toString(),
27-
$this->volume,
28-
$this->liquidClass->name(),
29-
null, // tipType
30-
$this->getTipMask(),
31-
]
32-
);
22+
return implode(';', [
23+
static::commandLetter(),
24+
$this->location->toString(),
25+
$this->volume,
26+
$this->liquidClass->name(),
27+
null, // tipType
28+
$this->getTipMask(),
29+
]);
3330
}
3431

3532
protected function getTipMask(): string

src/Tecan/BasicCommands/ReagentDistribution.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,17 @@ public function __construct(
5252

5353
public function toString(): string
5454
{
55-
return implode(
56-
';',
57-
[
58-
'R',
59-
$this->source->toString(),
60-
$this->target->toString(),
61-
$this->volume,
62-
$this->liquidClass->name(),
63-
$this->numberOfDitiReuses,
64-
$this->numberOfMultiDisp,
65-
$this->direction->value,
66-
$this->excludedWells(),
67-
]
68-
);
55+
return implode(';', [
56+
'R',
57+
$this->source->toString(),
58+
$this->target->toString(),
59+
$this->volume,
60+
$this->liquidClass->name(),
61+
$this->numberOfDitiReuses,
62+
$this->numberOfMultiDisp,
63+
$this->direction->value,
64+
$this->excludedWells(),
65+
]);
6966
}
7067

7168
private function excludedWells(): string

src/Tecan/Location/BarcodeLocation.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace MLL\Utils\Tecan\Location;
44

5-
use MLL\Utils\Tecan\Rack\Rack;
5+
use MLL\Utils\Tecan\Rack\ScannedRack;
66

77
class BarcodeLocation implements Location
88
{
99
private string $barcode;
1010

11-
private Rack $rack;
11+
private ScannedRack $rack;
1212

13-
public function __construct(string $barcode, Rack $rack)
13+
public function __construct(string $barcode, ScannedRack $rack)
1414
{
1515
$this->barcode = $barcode;
1616
$this->rack = $rack;
@@ -43,15 +43,12 @@ public function rackID(): ?string
4343

4444
public function toString(): string
4545
{
46-
return implode(
47-
';',
48-
[
49-
$this->rackName(),
50-
$this->rackID(),
51-
$this->rackType(),
52-
$this->position(),
53-
$this->tubeID(),
54-
]
55-
);
46+
return implode(';', [
47+
$this->rackName(),
48+
$this->rackID(),
49+
$this->rackType(),
50+
$this->position(),
51+
$this->tubeID(),
52+
]);
5653
}
5754
}

src/Tecan/Location/PositionLocation.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@ public function rackID(): ?string
4343

4444
public function toString(): string
4545
{
46-
return implode(
47-
';',
48-
[
49-
$this->rackName(),
50-
$this->rackID(),
51-
$this->rackType(),
52-
$this->position(),
53-
$this->tubeID(),
54-
]
55-
);
46+
return implode(';', [
47+
$this->rackName(),
48+
$this->rackID(),
49+
$this->rackType(),
50+
$this->position(),
51+
$this->tubeID(),
52+
]);
5653
}
5754
}

src/Tecan/Rack/AlublockA.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace MLL\Utils\Tecan\Rack;
4+
5+
class AlublockA extends BaseRack
6+
{
7+
public function type(): string
8+
{
9+
return 'Eppis 24x0.5 ml Cooled';
10+
}
11+
12+
public function name(): string
13+
{
14+
return 'A';
15+
}
16+
17+
public function positionCount(): int
18+
{
19+
return 24;
20+
}
21+
}

src/Tecan/Rack/BaseRack.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace MLL\Utils\Tecan\Rack;
4+
5+
use Illuminate\Support\Collection;
6+
7+
abstract class BaseRack implements Rack
8+
{
9+
public const EMPTY_POSITION = null;
10+
11+
/** @var Collection<int, mixed> */
12+
public Collection $positions;
13+
14+
public function __construct()
15+
{
16+
$this->positions = Collection::times($this->positionCount(), fn () => self::EMPTY_POSITION)
17+
->mapWithKeys(fn ($content, int $position): array => [$position + 1 => $content]);
18+
}
19+
20+
public function id(): ?string
21+
{
22+
return null;
23+
}
24+
25+
public function toString(): string
26+
{
27+
return implode(';', [
28+
$this->name(),
29+
$this->id(),
30+
$this->type(),
31+
]);
32+
}
33+
34+
/** @param mixed $content Anything goes, null is considered empty */
35+
public function assignFirstEmptyPosition($content): int
36+
{
37+
return $this->assignPosition($content, $this->findFirstEmptyPosition());
38+
}
39+
40+
/** @param mixed $content Anything goes, null is considered empty */
41+
public function assignLastEmptyPosition($content): int
42+
{
43+
return $this->assignPosition($content, $this->findLastEmptyPosition());
44+
}
45+
46+
public function findFirstEmptyPosition(): int
47+
{
48+
$firstEmpty = $this->positions
49+
->filter(fn ($content): bool => $content === self::EMPTY_POSITION)
50+
->keys()
51+
->first();
52+
53+
if ($firstEmpty === null) {
54+
throw new NoEmptyPositionOnRack();
55+
}
56+
57+
return $firstEmpty;
58+
}
59+
60+
public function findLastEmptyPosition(): int
61+
{
62+
$lastEmpty = $this->positions
63+
->filter(fn ($content): bool => $content === self::EMPTY_POSITION)
64+
->keys()
65+
->last();
66+
67+
if ($lastEmpty === null) {
68+
throw new NoEmptyPositionOnRack();
69+
}
70+
71+
return $lastEmpty;
72+
}
73+
74+
/** @param mixed $content Anything goes, null is considered empty */
75+
public function assignPosition($content, int $position): int
76+
{
77+
if (! $this->positions->has($position)) {
78+
throw new InvalidPositionOnRack($position, $this);
79+
}
80+
81+
$this->positions[$position] = $content;
82+
83+
return $position;
84+
}
85+
}

src/Tecan/Rack/CustomRack.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/Tecan/Rack/DestLC.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace MLL\Utils\Tecan\Rack;
4+
5+
class DestLC extends BaseRack
6+
{
7+
public function type(): string
8+
{
9+
return '96 Well MP LightCycler480';
10+
}
11+
12+
public function name(): string
13+
{
14+
return 'DestLC';
15+
}
16+
17+
public function positionCount(): int
18+
{
19+
return 96;
20+
}
21+
}

0 commit comments

Comments
 (0)