Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into tecan-mix-command
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisa Fischer committed Sep 26, 2024
2 parents 57fccb6 + e142060 commit 657ccc8
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 267 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ See [GitHub releases](https://github.com/mll-lab/php-utils/releases).

## Unreleased

## v5.5.1

### Fixed

- Fix generic inference for `MLL\Utils\Microplate\Coordinates::fromPosition()`

## v5.5.0

### Added

- Add scalar `Column6`

## v5.4.0

### Added

- Add command `SetDiTiType` to tecan worklist

## v5.3.0

### Added
Expand Down
6 changes: 4 additions & 2 deletions src/Microplate/Coordinates.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ public static function fromString(string $coordinatesString, CoordinateSystem $c
}

/**
* @param TCoordinateSystem $coordinateSystem
* @template TCoord of CoordinateSystem
*
* @param TCoord $coordinateSystem
*
* @return static<TCoordinateSystem>
* @return static<TCoord>
*/
public static function fromPosition(int $position, FlowDirection $direction, CoordinateSystem $coordinateSystem): self
{
Expand Down
1 change: 0 additions & 1 deletion src/Microplate/MicroplateSet/MicroplateSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function locationFromPosition(int $setPosition, FlowDirection $direction)
$plateIndex = (int) floor(($setPosition - 1) / $this->coordinateSystem->positionsCount());
$positionOnSinglePlate = $setPosition - ($plateIndex * $this->coordinateSystem->positionsCount());

/** @phpstan-ignore-next-line Generic inference is too weak to recognize this code is correct */
return new Location(
Coordinates::fromPosition($positionOnSinglePlate, $direction, $this->coordinateSystem),
$this->plateIDs()[$plateIndex]
Expand Down
20 changes: 20 additions & 0 deletions src/Microplate/Scalars/Column6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace MLL\Utils\Microplate\Scalars;

use MLL\GraphQLScalars\IntRange;

class Column6 extends IntRange
{
public ?string $description = 'Represents a column in a coordinate system with 6 columns. Allowed values range from 1-6.';

protected static function min(): int
{
return 1;
}

protected static function max(): int
{
return 6;
}
}
23 changes: 23 additions & 0 deletions src/Tecan/BasicCommands/SetDiTiType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);

namespace MLL\Utils\Tecan\BasicCommands;

/**
* Can only be used at the very beginning of the worklist or directly after a Break command.
*
* @see BreakCommand
*/
class SetDiTiType extends Command
{
private int $indexOfDiTi;

public function __construct(int $indexOfDiTi)
{
$this->indexOfDiTi = $indexOfDiTi;
}

public function toString(): string
{
return "S;{$this->indexOfDiTi}";
}
}
74 changes: 64 additions & 10 deletions src/Tecan/TecanProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use MLL\Utils\Tecan\BasicCommands\BreakCommand;
use MLL\Utils\Tecan\BasicCommands\Command;
use MLL\Utils\Tecan\BasicCommands\Comment;
use MLL\Utils\Tecan\BasicCommands\SetDiTiType;
use MLL\Utils\Tecan\BasicCommands\UsesTipMask;
use MLL\Utils\Tecan\TipMask\TipMask;

Expand All @@ -20,19 +21,28 @@ class TecanProtocol

public const GEMINI_WORKLIST_FILENAME_SUFFIX = '.gwl';

private TipMask $tipMask;

private string $protocolName;

/** @var Collection<int, Command> */
private Collection $commands;

private TipMask $tipMask;
public ?int $defaultDiTiTypeIndex;

private string $protocolName;
public ?int $currentDiTiTypeIndex;

public function __construct(TipMask $tipMask, ?string $protocolName = null, ?string $userName = null)
{
$this->protocolName = $protocolName ?? Str::uuid()->toString();
public function __construct(
TipMask $tipMask,
?string $protocolName = null,
?string $userName = null,
?int $defaultDiTiTypeIndex = null
) {
$this->tipMask = $tipMask;

$this->commands = $this->initHeader($userName, $protocolName);
$this->protocolName = $protocolName ?? Str::uuid()->toString();
$this->commands = $this->buildHeader($userName, $protocolName);
$this->defaultDiTiTypeIndex = $defaultDiTiTypeIndex;
$this->currentDiTiTypeIndex = $defaultDiTiTypeIndex;
}

public function addCommand(Command $command): void
Expand All @@ -43,7 +53,8 @@ public function addCommand(Command $command): void
/** @param Command&UsesTipMask $command */
public function addCommandCurrentTip(Command $command): void
{
$command->setTipMask($this->tipMask->currentTip ?? TipMask::firstTip());
$tip = $this->tipMask->currentTip ?? TipMask::firstTip();
$this->setTipMask($command, $tip);

$this->commands->add($command);
}
Expand All @@ -55,11 +66,37 @@ public function addCommandForNextTip(Command $command): void
$this->commands->add(new BreakCommand());
}

$command->setTipMask($this->tipMask->nextTip());
$this->setTipMask($command, $this->tipMask->nextTip());

$this->commands->add($command);
}

private function shouldUseDifferentTipTypeIndex(): bool
{
return $this->defaultDiTiTypeIndex !== null
&& $this->defaultDiTiTypeIndex !== $this->currentDiTiTypeIndex;
}

private function setTipMask(UsesTipMask $command, int $tip): void
{
$command->setTipMask($tip);

if (! $this->shouldUseDifferentTipTypeIndex()) {
return;
}

if ($this->currentDiTiTypeIndex === null) {
return;
}

if ($this->commands->isEmpty()
|| $this->commandsAreOnlyComments()
|| $this->commands->last() instanceof BreakCommand
) {
$this->commands->add(new SetDiTiType($this->currentDiTiTypeIndex));
}
}

public function buildProtocol(): string
{
return $this->commands
Expand All @@ -73,8 +110,24 @@ public function fileName(): string
return $this->protocolName . self::GEMINI_WORKLIST_FILENAME_SUFFIX;
}

public function setCurrentDiTiTypeIndex(int $currentDiTiTypeIndex): void
{
if (! $this->commandsAreOnlyComments()
&& ! $this->commands->last() instanceof BreakCommand
) {
throw new TecanException('Cannot change the DiTi type index if the last command is not a break command.');
}

$this->currentDiTiTypeIndex = $currentDiTiTypeIndex;
}

private function commandsAreOnlyComments(): bool
{
return $this->commands->every(fn (Command $command): bool => $command instanceof Comment);
}

/** @return Collection<int, Command> */
private function initHeader(?string $userName, ?string $protocolName): Collection
private function buildHeader(?string $userName, ?string $protocolName): Collection
{
$package = Meta::PACKAGE_NAME;
$version = InstalledVersions::getPrettyVersion($package);
Expand All @@ -90,6 +143,7 @@ private function initHeader(?string $userName, ?string $protocolName): Collectio
if ($userName !== null) {
$commentCommands->add(new Comment("User: {$userName}"));
}

if ($protocolName !== null) {
$commentCommands->add(new Comment("Protocol name: {$protocolName}"));
}
Expand Down
59 changes: 0 additions & 59 deletions tests/Microplate/Scalars/Column12Test.php

This file was deleted.

59 changes: 0 additions & 59 deletions tests/Microplate/Scalars/Column2Test.php

This file was deleted.

Loading

0 comments on commit 657ccc8

Please sign in to comment.