Skip to content

Commit

Permalink
Rack to object with positions
Browse files Browse the repository at this point in the history
  • Loading branch information
simbig authored Aug 6, 2024
1 parent 6eb961f commit 3b6a13a
Show file tree
Hide file tree
Showing 31 changed files with 525 additions and 344 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ See [GitHub releases](https://github.com/mll-lab/php-utils/releases).

## Unreleased

## v4.0.0

### Added

- Add specific class for each `MLLLabWareRack`-type that includes a `positions`-Collection

### Changed

- Breaking Change: Delete class `MLLLabWareRack`
- Breaking Change: Delete class `CustomRack`
- Breaking Change: Add method `positionCount` to interface `Rack`
- Breaking Change: Limit the usage of `BarcodeLocation` to objects implementing `ScannedRack`

## v3.2.0

### Added
Expand Down
13 changes: 5 additions & 8 deletions src/Tecan/BasicCommands/AspirateAndDispenseParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ public function __construct(Rack $rack, int $startPosition, int $endPosition)
/** Serializes the aspirate and dispense parameters as part of a reagent distribution according the gwl file format. */
public function toString(): string
{
return implode(
';',
[
$this->rack->toString(),
$this->startPosition,
$this->endPosition,
]
);
return implode(';', [
$this->rack->toString(),
$this->startPosition,
$this->endPosition,
]);
}
}
19 changes: 8 additions & 11 deletions src/Tecan/BasicCommands/BasicPipettingActionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ abstract public static function commandLetter(): string;

public function toString(): string
{
return implode(
';',
[
static::commandLetter(),
$this->location->toString(),
$this->volume,
$this->liquidClass->name(),
null, // tipType
$this->getTipMask(),
]
);
return implode(';', [
static::commandLetter(),
$this->location->toString(),
$this->volume,
$this->liquidClass->name(),
null, // tipType
$this->getTipMask(),
]);
}

protected function getTipMask(): string
Expand Down
25 changes: 11 additions & 14 deletions src/Tecan/BasicCommands/ReagentDistribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,17 @@ public function __construct(

public function toString(): string
{
return implode(
';',
[
'R',
$this->source->toString(),
$this->target->toString(),
$this->volume,
$this->liquidClass->name(),
$this->numberOfDitiReuses,
$this->numberOfMultiDisp,
$this->direction->value,
$this->excludedWells(),
]
);
return implode(';', [
'R',
$this->source->toString(),
$this->target->toString(),
$this->volume,
$this->liquidClass->name(),
$this->numberOfDitiReuses,
$this->numberOfMultiDisp,
$this->direction->value,
$this->excludedWells(),
]);
}

private function excludedWells(): string
Expand Down
23 changes: 10 additions & 13 deletions src/Tecan/Location/BarcodeLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace MLL\Utils\Tecan\Location;

use MLL\Utils\Tecan\Rack\Rack;
use MLL\Utils\Tecan\Rack\ScannedRack;

class BarcodeLocation implements Location
{
private string $barcode;

private Rack $rack;
private ScannedRack $rack;

public function __construct(string $barcode, Rack $rack)
public function __construct(string $barcode, ScannedRack $rack)
{
$this->barcode = $barcode;
$this->rack = $rack;
Expand Down Expand Up @@ -43,15 +43,12 @@ public function rackID(): ?string

public function toString(): string
{
return implode(
';',
[
$this->rackName(),
$this->rackID(),
$this->rackType(),
$this->position(),
$this->tubeID(),
]
);
return implode(';', [
$this->rackName(),
$this->rackID(),
$this->rackType(),
$this->position(),
$this->tubeID(),
]);
}
}
17 changes: 7 additions & 10 deletions src/Tecan/Location/PositionLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,12 @@ public function rackID(): ?string

public function toString(): string
{
return implode(
';',
[
$this->rackName(),
$this->rackID(),
$this->rackType(),
$this->position(),
$this->tubeID(),
]
);
return implode(';', [
$this->rackName(),
$this->rackID(),
$this->rackType(),
$this->position(),
$this->tubeID(),
]);
}
}
21 changes: 21 additions & 0 deletions src/Tecan/Rack/AlublockA.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types=1);

namespace MLL\Utils\Tecan\Rack;

class AlublockA extends BaseRack
{
public function type(): string
{
return 'Eppis 24x0.5 ml Cooled';
}

public function name(): string
{
return 'A';
}

public function positionCount(): int
{
return 24;
}
}
85 changes: 85 additions & 0 deletions src/Tecan/Rack/BaseRack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php declare(strict_types=1);

namespace MLL\Utils\Tecan\Rack;

use Illuminate\Support\Collection;

abstract class BaseRack implements Rack
{
public const EMPTY_POSITION = null;

/** @var Collection<int, mixed> */
public Collection $positions;

public function __construct()
{
$this->positions = Collection::times($this->positionCount(), fn () => self::EMPTY_POSITION)
->mapWithKeys(fn ($content, int $position): array => [$position + 1 => $content]);
}

public function id(): ?string
{
return null;
}

public function toString(): string
{
return implode(';', [
$this->name(),
$this->id(),
$this->type(),
]);
}

/** @param mixed $content Anything goes, null is considered empty */
public function assignFirstEmptyPosition($content): int
{
return $this->assignPosition($content, $this->findFirstEmptyPosition());
}

/** @param mixed $content Anything goes, null is considered empty */
public function assignLastEmptyPosition($content): int
{
return $this->assignPosition($content, $this->findLastEmptyPosition());
}

public function findFirstEmptyPosition(): int
{
$firstEmpty = $this->positions
->filter(fn ($content): bool => $content === self::EMPTY_POSITION)
->keys()
->first();

if ($firstEmpty === null) {
throw new NoEmptyPositionOnRack();
}

return $firstEmpty;
}

public function findLastEmptyPosition(): int
{
$lastEmpty = $this->positions
->filter(fn ($content): bool => $content === self::EMPTY_POSITION)
->keys()
->last();

if ($lastEmpty === null) {
throw new NoEmptyPositionOnRack();
}

return $lastEmpty;
}

/** @param mixed $content Anything goes, null is considered empty */
public function assignPosition($content, int $position): int
{
if (! $this->positions->has($position)) {
throw new InvalidPositionOnRack($position, $this);
}

$this->positions[$position] = $content;

return $position;
}
}
46 changes: 0 additions & 46 deletions src/Tecan/Rack/CustomRack.php

This file was deleted.

21 changes: 21 additions & 0 deletions src/Tecan/Rack/DestLC.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types=1);

namespace MLL\Utils\Tecan\Rack;

class DestLC extends BaseRack
{
public function type(): string
{
return '96 Well MP LightCycler480';
}

public function name(): string
{
return 'DestLC';
}

public function positionCount(): int
{
return 96;
}
}
21 changes: 21 additions & 0 deletions src/Tecan/Rack/DestPCR.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types=1);

namespace MLL\Utils\Tecan\Rack;

class DestPCR extends BaseRack
{
public function type(): string
{
return '96 Well PCR ABI semi-skirted';
}

public function name(): string
{
return 'DestPCR';
}

public function positionCount(): int
{
return 96;
}
}
21 changes: 21 additions & 0 deletions src/Tecan/Rack/DestTaqMan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types=1);

namespace MLL\Utils\Tecan\Rack;

class DestTaqMan extends BaseRack
{
public function type(): string
{
return '96 Well PCR TaqMan';
}

public function name(): string
{
return 'DestTaqMan';
}

public function positionCount(): int
{
return 96;
}
}
Loading

0 comments on commit 3b6a13a

Please sign in to comment.