generated from spawnia/php-package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Support creating Lightcycler Sample Sheets for Absolute Quantification #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
spawnia
merged 19 commits into
master
from
lightcycler-sample-sheets-for-absolute-quantification
Aug 5, 2025
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9794479
feat: Support creating Lightcycler Sample Sheets for Absolute Quantif…
ee12c53
refactor: Update skipped Rector rules:
bf1b1a6
feat: Introduce LIGHTCYCLER_COLOR_PREFIX for consistent hex color for…
dfaae77
Apply php-cs-fixer changes
simbig d1e412c
feat: Update AbsoluteQuantificationSample to use nullable integer for…
881f591
Merge remote-tracking branch 'origin/lightcycler-sample-sheets-for-ab…
aec73d5
refactor: Refactor concentration formatting with no sprintf
d65525e
refactor: Refactor concentration formatting with number_format
7ac393f
test: Add attribute for data provider in AbsoluteQuantificationSample…
00eac05
composer update in make setup
spawnia 7e6259a
long form cli
spawnia 7264ab1
link PR
spawnia b09c588
Set php-cs-fixer cache in config file
spawnia adb94bf
feat: Add replication mapping in AbsoluteQuantificationSample
d6a507b
Merge remote-tracking branch 'origin/lightcycler-sample-sheets-for-ab…
ef233f9
Leverage CSVArray
spawnia da32d17
Simplify with iterable, fix test
spawnia 6a57c2e
Unify Windows newline
spawnia a0b083d
Fix PHPStan
spawnia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/LightcyclerSampleSheet/AbsoluteQuantificationSample.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MLL\Utils\LightcyclerSampleSheet; | ||
|
||
use MLL\Utils\Microplate\Coordinates; | ||
use MLL\Utils\Microplate\CoordinateSystem12x8; | ||
|
||
class AbsoluteQuantificationSample | ||
{ | ||
public string $sampleName; | ||
|
||
public string $filterCombination; | ||
|
||
public string $hexColor; | ||
|
||
public string $sampleType; | ||
|
||
/** Key used to determine replication grouping - samples with the same key will replicate to the first occurrence */ | ||
public string $replicationOfKey; | ||
|
||
public ?int $concentration; | ||
|
||
public function __construct( | ||
string $sampleName, | ||
string $filterCombination, | ||
string $hexColor, | ||
string $sampleType, | ||
string $replicationOfKey, | ||
?int $concentration | ||
) { | ||
$this->sampleName = $sampleName; | ||
$this->filterCombination = $filterCombination; | ||
$this->hexColor = $hexColor; | ||
$this->sampleType = $sampleType; | ||
$this->replicationOfKey = $replicationOfKey; | ||
$this->concentration = $concentration; | ||
} | ||
|
||
public static function formatConcentration(?int $concentration): ?string | ||
{ | ||
if ($concentration === null) { | ||
return null; | ||
} | ||
|
||
$exponent = (int) floor(log10(abs($concentration))); | ||
$mantissa = $concentration / (10 ** $exponent); | ||
|
||
return number_format($mantissa, 2) . 'E' . $exponent; | ||
} | ||
|
||
/** @return array<string, string|null> */ | ||
public function toSerializableArray(string $coordinatesString, string $replicationOfCoordinate): array | ||
{ | ||
return [ | ||
'General:Pos' => Coordinates::fromString($coordinatesString, new CoordinateSystem12x8())->toString(), | ||
'General:Sample Name' => $this->sampleName, | ||
'General:Repl. Of' => $replicationOfCoordinate, | ||
'General:Filt. Comb.' => $this->filterCombination, | ||
'Sample Preferences:Color' => RandomHexGenerator::LIGHTCYCLER_COLOR_PREFIX . $this->hexColor, | ||
'Abs Quant:Sample Type' => $this->sampleType, | ||
'Abs Quant:Concentration' => self::formatConcentration($this->concentration), | ||
]; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/LightcyclerSampleSheet/AbsoluteQuantificationSheet.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MLL\Utils\LightcyclerSampleSheet; | ||
|
||
use Illuminate\Support\Collection; | ||
use MLL\Utils\CSVArray; | ||
|
||
class AbsoluteQuantificationSheet | ||
{ | ||
/** @param Collection<string, AbsoluteQuantificationSample> $samples */ | ||
public function generate(Collection $samples): string | ||
{ | ||
$replicationMapping = $this->calculateReplicationMapping($samples); | ||
|
||
$data = $samples->map(fn (AbsoluteQuantificationSample $well, string $coordinateFromKey): array => $well->toSerializableArray( | ||
$coordinateFromKey, | ||
$replicationMapping[$coordinateFromKey] | ||
)); | ||
|
||
return CSVArray::toCSV($data, "\t"); | ||
} | ||
|
||
/** | ||
* Calculate replication mapping based on replicationOfKey. | ||
* | ||
* @param Collection<string, AbsoluteQuantificationSample> $samples | ||
* | ||
* @return array<string, string> a map of coordinate -> replicationOfCoordinate | ||
*/ | ||
private function calculateReplicationMapping(Collection $samples): array | ||
{ | ||
$replicationKeyMap = []; | ||
$mapping = []; | ||
|
||
foreach ($samples as $coordinate => $sample) { | ||
if (! isset($replicationKeyMap[$sample->replicationOfKey])) { | ||
// The First occurrence replicates to itself | ||
$replicationKeyMap[$sample->replicationOfKey] = $coordinate; | ||
$mapping[$coordinate] = $coordinate; | ||
} else { | ||
// Later occurrences replicate to the first occurrence | ||
$firstOccurrenceCoordinate = $replicationKeyMap[$sample->replicationOfKey]; | ||
$mapping[$coordinate] = $firstOccurrenceCoordinate; | ||
} | ||
} | ||
|
||
return $mapping; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
simbig marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/LightcyclerSampleSheet/AbsoluteQuantificationSampleTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MLL\Utils\Tests\LightcyclerSampleSheet; | ||
|
||
use MLL\Utils\LightcyclerSampleSheet\AbsoluteQuantificationSample; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AbsoluteQuantificationSampleTest extends TestCase | ||
{ | ||
/** @dataProvider concentrationFormattingProvider */ | ||
#[DataProvider('concentrationFormattingProvider')] | ||
public function testFormatConcentration(?int $input, ?string $expected): void | ||
{ | ||
$result = AbsoluteQuantificationSample::formatConcentration($input); | ||
|
||
self::assertSame($expected, $result); | ||
} | ||
|
||
/** @return iterable<array{?int, ?string}> */ | ||
public static function concentrationFormattingProvider(): iterable | ||
{ | ||
yield 'null concentration returns null' => [null, null]; | ||
yield 'zero concentration' => [0, '0.00E0']; | ||
yield 'small positive number' => [1, '1.00E0']; | ||
yield 'ten' => [10, '1.00E1']; | ||
yield 'hundred' => [100, '1.00E2']; | ||
yield 'four hundred (common lab value)' => [400, '4.00E2']; | ||
yield 'thousand' => [1000, '1.00E3']; | ||
yield 'ten thousand' => [10000, '1.00E4']; | ||
yield 'million' => [1000000, '1.00E6']; | ||
yield 'large number' => [12345678, '1.23E7']; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.