From c55368ae1a94b7205c6e3745f4b6e45c6d542bc8 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Mon, 22 Apr 2024 10:07:50 +0200 Subject: [PATCH 01/29] feature: Add Support Illumina NovaSeq Sample Sheets --- .gitignore | 1 + CHANGELOG.md | 6 ++ composer.json | 2 +- rector.php | 4 + src/IlluminaSampleSheet/BclConvertDataRow.php | 52 ++++++++++ .../BclConvertDataSection.php | 43 ++++++++ .../BclConvertSettingsSection.php | 35 +++++++ src/IlluminaSampleSheet/CloudDataSample.php | 42 ++++++++ src/IlluminaSampleSheet/CloudDataSection.php | 35 +++++++ .../CloudSettingsSection.php | 30 ++++++ src/IlluminaSampleSheet/DataSection.php | 26 +++++ .../IlluminaSampleSheetException.php | 5 + src/IlluminaSampleSheet/MiSeqDataSection.php | 11 +++ .../MiSeqHeaderSection.php | 59 +++++++++++ src/IlluminaSampleSheet/MiSeqSample.php | 61 ++++++++++++ src/IlluminaSampleSheet/MiSeqSampleSheet.php | 17 ++++ .../NovaSeqDataSection.php | 11 +++ .../NovaSeqHeaderSection.php | 64 ++++++++++++ src/IlluminaSampleSheet/NovaSeqSample.php | 66 +++++++++++++ .../NovaSeqSampleSheet.php | 18 ++++ .../NovaSeqXCloudHeaderSection.php | 40 ++++++++ .../NovaSeqXCloudReadsSection.php | 40 ++++++++ .../NovaSeqXCloudSampleSheet.php | 27 +++++ ...NovaSeqXCloudSequencingSettingsSection.php | 25 +++++ .../NovaSeqXpDataSection.php | 11 +++ src/IlluminaSampleSheet/NovaSeqXpSample.php | 71 ++++++++++++++ .../NovaSeqXpSampleSheet.php | 18 ++++ src/IlluminaSampleSheet/ReadsSection.php | 21 ++++ src/IlluminaSampleSheet/Sample.php | 40 ++++++++ src/IlluminaSampleSheet/SampleSheet.php | 25 +++++ src/IlluminaSampleSheet/SectionInterface.php | 8 ++ src/IlluminaSampleSheet/SettingsSection.php | 31 ++++++ .../CloudDataSampleTest.php | 47 +++++++++ .../CloudDataSectionTest.php | 20 ++++ .../CloudSettingsSectionTest.php | 18 ++++ .../MiSeqSampleSheetTest.php | 72 ++++++++++++++ .../NovaSeqHeaderSectionTest.php | 28 ++++++ .../NovaSeqSampleSheetTest.php | 80 +++++++++++++++ .../NovaSeqXCloudSampleSheetTest.php | 98 +++++++++++++++++++ .../NovaSeqXpSampleSheetTest.php | 81 +++++++++++++++ .../IlluminaSampleSheet/ReadsSectionTest.php | 16 +++ tests/IlluminaSampleSheet/SampleSheetTest.php | 25 +++++ .../SettingsSectionTest.php | 16 +++ 43 files changed, 1445 insertions(+), 1 deletion(-) create mode 100644 src/IlluminaSampleSheet/BclConvertDataRow.php create mode 100644 src/IlluminaSampleSheet/BclConvertDataSection.php create mode 100644 src/IlluminaSampleSheet/BclConvertSettingsSection.php create mode 100644 src/IlluminaSampleSheet/CloudDataSample.php create mode 100644 src/IlluminaSampleSheet/CloudDataSection.php create mode 100644 src/IlluminaSampleSheet/CloudSettingsSection.php create mode 100644 src/IlluminaSampleSheet/DataSection.php create mode 100644 src/IlluminaSampleSheet/IlluminaSampleSheetException.php create mode 100644 src/IlluminaSampleSheet/MiSeqDataSection.php create mode 100644 src/IlluminaSampleSheet/MiSeqHeaderSection.php create mode 100644 src/IlluminaSampleSheet/MiSeqSample.php create mode 100644 src/IlluminaSampleSheet/MiSeqSampleSheet.php create mode 100644 src/IlluminaSampleSheet/NovaSeqDataSection.php create mode 100644 src/IlluminaSampleSheet/NovaSeqHeaderSection.php create mode 100644 src/IlluminaSampleSheet/NovaSeqSample.php create mode 100644 src/IlluminaSampleSheet/NovaSeqSampleSheet.php create mode 100644 src/IlluminaSampleSheet/NovaSeqXCloudHeaderSection.php create mode 100644 src/IlluminaSampleSheet/NovaSeqXCloudReadsSection.php create mode 100644 src/IlluminaSampleSheet/NovaSeqXCloudSampleSheet.php create mode 100644 src/IlluminaSampleSheet/NovaSeqXCloudSequencingSettingsSection.php create mode 100644 src/IlluminaSampleSheet/NovaSeqXpDataSection.php create mode 100644 src/IlluminaSampleSheet/NovaSeqXpSample.php create mode 100644 src/IlluminaSampleSheet/NovaSeqXpSampleSheet.php create mode 100644 src/IlluminaSampleSheet/ReadsSection.php create mode 100644 src/IlluminaSampleSheet/Sample.php create mode 100644 src/IlluminaSampleSheet/SampleSheet.php create mode 100644 src/IlluminaSampleSheet/SectionInterface.php create mode 100644 src/IlluminaSampleSheet/SettingsSection.php create mode 100644 tests/IlluminaSampleSheet/CloudDataSampleTest.php create mode 100644 tests/IlluminaSampleSheet/CloudDataSectionTest.php create mode 100644 tests/IlluminaSampleSheet/CloudSettingsSectionTest.php create mode 100644 tests/IlluminaSampleSheet/MiSeqSampleSheetTest.php create mode 100644 tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php create mode 100644 tests/IlluminaSampleSheet/NovaSeqSampleSheetTest.php create mode 100644 tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php create mode 100644 tests/IlluminaSampleSheet/NovaSeqXpSampleSheetTest.php create mode 100644 tests/IlluminaSampleSheet/ReadsSectionTest.php create mode 100644 tests/IlluminaSampleSheet/SampleSheetTest.php create mode 100644 tests/IlluminaSampleSheet/SettingsSectionTest.php diff --git a/.gitignore b/.gitignore index 468ff9e..4c8de23 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /.idea /vendor /composer.lock +/.phpunit.result.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index 59043ac..0ffe66e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ See [GitHub releases](https://github.com/mll-lab/php-utils/releases). ## Unreleased +## v1.13.0 + +### Added + +- Add support for creating different Illumina NovaSeq Sample Sheets, including specific sections (Header, Reads, Data, Settings etc.). + ## v1.12.0 ### Added diff --git a/composer.json b/composer.json index b6055e5..a500a2f 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "phpstan/phpstan-phpunit": "^1", "phpstan/phpstan-strict-rules": "^1", "phpunit/phpunit": "^9 || ^10", - "rector/rector": "^0.17", + "rector/rector": "^1", "thecodingmachine/phpstan-safe-rule": "^1.2" }, "autoload": { diff --git a/rector.php b/rector.php index 9e93ade..5444e6d 100644 --- a/rector.php +++ b/rector.php @@ -2,6 +2,7 @@ use Rector\CodeQuality\Rector\Concat\JoinStringConcatRector; use Rector\Config\RectorConfig; +use Rector\PHPUnit\Rector\Class_\PreferPHPUnitSelfCallRector; use Rector\Set\ValueObject\SetList; return static function (RectorConfig $rectorConfig): void { @@ -17,6 +18,9 @@ __DIR__ . '/tests/CSVArrayTest.php', // keep `\r\n` for readability ], ]); + + $rectorConfig->rule(PreferPHPUnitSelfCallRector::class); + $rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/tests']); $rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon'); }; diff --git a/src/IlluminaSampleSheet/BclConvertDataRow.php b/src/IlluminaSampleSheet/BclConvertDataRow.php new file mode 100644 index 0000000..1c0a60c --- /dev/null +++ b/src/IlluminaSampleSheet/BclConvertDataRow.php @@ -0,0 +1,52 @@ +lane = $lane; + $this->sampleId = $sampleId; + $this->index = $index; + $this->index2 = $index2; + $this->overrideCycles = $overrideCycles; + $this->adapterRead1 = $adapterRead1; + $this->adapterRead2 = $adapterRead2; + } + + /** @return array */ + public function toArray(): array + { + return [ + $this->lane, + $this->sampleId, + $this->index, + $this->index2, + $this->overrideCycles, + $this->adapterRead1, + $this->adapterRead2, + ]; + } +} diff --git a/src/IlluminaSampleSheet/BclConvertDataSection.php b/src/IlluminaSampleSheet/BclConvertDataSection.php new file mode 100644 index 0000000..c0a75e9 --- /dev/null +++ b/src/IlluminaSampleSheet/BclConvertDataSection.php @@ -0,0 +1,43 @@ + */ + private array $dataRows = []; + + public function addSample( + int $lane, + string $sampleId, + string $index, + string $index2, + string $overrideCycles, + string $adapterRead1, + string $adapterRead2 + ): void { + $this->dataRows[] = new BclConvertDataRow( + $lane, + $sampleId, + $index, + $index2, + $overrideCycles, + $adapterRead1, + $adapterRead2 + ); + } + + public function toString(): string + { + $bclConvertDataLines = [ + '[BCLConvert_Data]', + 'Lane,Sample_ID,Index,Index2,OverrideCycles,AdapterRead1,AdapterRead2', + ]; + + foreach ($this->dataRows as $dataRow) { + $bclConvertDataLines[] = implode(',', $dataRow->toArray()); + } + + return implode("\n", $bclConvertDataLines) . "\n"; + } +} diff --git a/src/IlluminaSampleSheet/BclConvertSettingsSection.php b/src/IlluminaSampleSheet/BclConvertSettingsSection.php new file mode 100644 index 0000000..e6ef745 --- /dev/null +++ b/src/IlluminaSampleSheet/BclConvertSettingsSection.php @@ -0,0 +1,35 @@ +softwareVersion = $softwareVersion; + $this->trimUMI = $trimUMI; + $this->fastqCompressionFormat = $fastqCompressionFormat; + } + + public function toString(): string + { + $bclConvertSettingsLines = [ + '[BCLConvert_Settings]', + "SoftwareVersion,{$this->softwareVersion}", + "TrimUMI,{$this->trimUMI}", + "FastqCompressionFormat,{$this->fastqCompressionFormat}", + '', + ]; + + return implode("\n", $bclConvertSettingsLines); + } +} diff --git a/src/IlluminaSampleSheet/CloudDataSample.php b/src/IlluminaSampleSheet/CloudDataSample.php new file mode 100644 index 0000000..b6f19f9 --- /dev/null +++ b/src/IlluminaSampleSheet/CloudDataSample.php @@ -0,0 +1,42 @@ +sampleId = $sampleId; + $this->projectName = $projectName; + $this->libraryName = $libraryName; + $this->libraryPrepKitName = $libraryPrepKitName; + $this->indexAdapterKitName = $indexAdapterKitName; + } + + /** @return array */ + public function toArray(): array + { + return [ + 'Sample_ID' => $this->sampleId, + 'ProjectName' => $this->projectName, + 'LibraryName' => $this->libraryName, + 'LibraryPrepKitName' => $this->libraryPrepKitName, + 'IndexAdapterKitName' => $this->indexAdapterKitName, + ]; + } +} diff --git a/src/IlluminaSampleSheet/CloudDataSection.php b/src/IlluminaSampleSheet/CloudDataSection.php new file mode 100644 index 0000000..f3b1fb3 --- /dev/null +++ b/src/IlluminaSampleSheet/CloudDataSection.php @@ -0,0 +1,35 @@ + */ + private array $samples = []; + + public function addSample( + string $sampleId, + string $projectName, + string $libraryName, + string $libraryPrepKitName, + string $indexAdapterKitName + ): void { + $this->samples[] = new CloudDataSample( + $sampleId, + $projectName, + $libraryName, + $libraryPrepKitName, + $indexAdapterKitName + ); + } + + public function toString(): string + { + $dataLines = ["[Cloud_Data]\nSample_ID,ProjectName,LibraryName,LibraryPrepKitName,IndexAdapterKitName"]; + foreach ($this->samples as $sample) { + $dataLines[] = implode(',', $sample->toArray()); + } + + return implode("\n", $dataLines) . "\n"; + } +} diff --git a/src/IlluminaSampleSheet/CloudSettingsSection.php b/src/IlluminaSampleSheet/CloudSettingsSection.php new file mode 100644 index 0000000..f9dce3e --- /dev/null +++ b/src/IlluminaSampleSheet/CloudSettingsSection.php @@ -0,0 +1,30 @@ +generatedVersion = $generatedVersion; + $this->cloudWorkflow = $cloudWorkflow; + $this->bclConvertPipeline = $bclConvertPipeline; + } + + public function toString(): string + { + return '[Cloud_Settings] +GeneratedVersion,' . $this->generatedVersion . "\n" + . 'Cloud_Workflow,' . $this->cloudWorkflow . "\n" + . 'BCLConvert_Pipeline,' . $this->bclConvertPipeline . "\n"; + } +} diff --git a/src/IlluminaSampleSheet/DataSection.php b/src/IlluminaSampleSheet/DataSection.php new file mode 100644 index 0000000..193cabf --- /dev/null +++ b/src/IlluminaSampleSheet/DataSection.php @@ -0,0 +1,26 @@ + */ + private array $samples = []; + + public function addSample(Sample $sample): void + { + $this->samples[] = $sample; + } + + public function toString(): string + { + $dataLines = ["[Data]\n{$this->dataSectionHeader()}"]; + foreach ($this->samples as $sample) { + $dataLines[] = $sample->toString(); + } + + return implode("\n", $dataLines) . "\n"; + } + + abstract public function dataSectionHeader(): string; +} diff --git a/src/IlluminaSampleSheet/IlluminaSampleSheetException.php b/src/IlluminaSampleSheet/IlluminaSampleSheetException.php new file mode 100644 index 0000000..37a71c5 --- /dev/null +++ b/src/IlluminaSampleSheet/IlluminaSampleSheetException.php @@ -0,0 +1,5 @@ +experimentName = $experimentName; + $this->date = $date; + $this->module = $module; + $this->workflow = $workflow; + $this->libraryPrepKit = $libraryPrepKit; + $this->indexKit = $indexKit; + $this->description = $description; + $this->chemistry = $chemistry; + } + + public function toString(): string + { + $headerLines = [ + '[Header]', + "Experiment Name,{$this->experimentName}", + "Date,{$this->date}", + "Module,{$this->module}", + "Workflow,{$this->workflow}", + "Library Prep Kit,{$this->libraryPrepKit}", + "Index Kit,{$this->indexKit}", + "Description,{$this->description}", + "Chemistry,{$this->chemistry}", + ]; + + return implode("\n", $headerLines); + } +} diff --git a/src/IlluminaSampleSheet/MiSeqSample.php b/src/IlluminaSampleSheet/MiSeqSample.php new file mode 100644 index 0000000..97cdc18 --- /dev/null +++ b/src/IlluminaSampleSheet/MiSeqSample.php @@ -0,0 +1,61 @@ +sampleId = $this->validateSampleId($sampleId); + $this->sampleName = $this->validateSampleName($sampleName); + $this->samplePlate = $samplePlate; + $this->sampleWell = $sampleWell; + $this->sampleProject = $sampleProject; + $this->i7IndexId = $i7IndexId; + $this->index = $this->validateIndex($index); + $this->i5IndexId = $i5IndexId; + $this->index2 = $this->validateIndex($index2); + } + + public function toString(): string + { + return implode(',', [ + $this->sampleId, + $this->sampleName, + $this->samplePlate, + $this->sampleWell, + $this->sampleProject, + $this->i7IndexId, + $this->index, + $this->i5IndexId, + $this->index2, + ]); + } +} diff --git a/src/IlluminaSampleSheet/MiSeqSampleSheet.php b/src/IlluminaSampleSheet/MiSeqSampleSheet.php new file mode 100644 index 0000000..119904d --- /dev/null +++ b/src/IlluminaSampleSheet/MiSeqSampleSheet.php @@ -0,0 +1,17 @@ +addSection($header); + $this->addSection($reads); + $this->addSection(new SettingsSection()); + $this->addSection($data); + } +} diff --git a/src/IlluminaSampleSheet/NovaSeqDataSection.php b/src/IlluminaSampleSheet/NovaSeqDataSection.php new file mode 100644 index 0000000..8a6c342 --- /dev/null +++ b/src/IlluminaSampleSheet/NovaSeqDataSection.php @@ -0,0 +1,11 @@ +chemistry = $chemistry; + $this->description = $description; + $this->assay = $assay; + $this->application = $application; + $this->workflow = $workflow; + $this->date = $date; + $this->investigatorName = $investigatorName; + $this->experimentName = $experimentName; + $this->iemFileVersion = $iemFileVersion; + } + + public function toString(): string + { + $headerLines = [ + '[Header]', + "IEMFileVersion,{$this->iemFileVersion}", + "Investigator Name,{$this->investigatorName}", + "Experiment Name,{$this->experimentName}", + "Date,{$this->date}", + "Workflow,{$this->workflow}", + "Application,{$this->application}", + "Assay,{$this->assay}", + "Description,{$this->description}", + "Chemistry,{$this->chemistry}", + ]; + + return implode("\n", $headerLines); + } +} diff --git a/src/IlluminaSampleSheet/NovaSeqSample.php b/src/IlluminaSampleSheet/NovaSeqSample.php new file mode 100644 index 0000000..a6817f8 --- /dev/null +++ b/src/IlluminaSampleSheet/NovaSeqSample.php @@ -0,0 +1,66 @@ +sampleId = $this->validateSampleId($sampleId); + $this->sampleName = $this->validateSampleName($sampleName); + $this->samplePlate = $samplePlate; + $this->sampleWell = $sampleWell; + $this->i7IndexId = $i7IndexId; + $this->index = $this->validateIndex($index); + $this->i5IndexId = $i5IndexId; + $this->index2 = $this->validateIndex($index2); + $this->sampleProject = $sampleProject; + $this->description = $description; + } + + public function toString(): string + { + return implode(',', [ + $this->sampleId, + $this->sampleName, + $this->samplePlate, + $this->sampleWell, + $this->i7IndexId, + $this->index, + $this->i5IndexId, + $this->index2, + $this->sampleProject, + $this->description, + ]); + } +} diff --git a/src/IlluminaSampleSheet/NovaSeqSampleSheet.php b/src/IlluminaSampleSheet/NovaSeqSampleSheet.php new file mode 100644 index 0000000..e807c63 --- /dev/null +++ b/src/IlluminaSampleSheet/NovaSeqSampleSheet.php @@ -0,0 +1,18 @@ +addSection($header); + $this->addSection($reads); + $this->addSection($settings); + $this->addSection($data); + } +} diff --git a/src/IlluminaSampleSheet/NovaSeqXCloudHeaderSection.php b/src/IlluminaSampleSheet/NovaSeqXCloudHeaderSection.php new file mode 100644 index 0000000..008dd21 --- /dev/null +++ b/src/IlluminaSampleSheet/NovaSeqXCloudHeaderSection.php @@ -0,0 +1,40 @@ +fileFormatVersion = $fileFormatVersion; + $this->runName = $runName; + $this->instrumentPlatform = $instrumentPlatform; + $this->indexOrientation = $indexOrientation; + } + + public function toString(): string + { + $headerLines = [ + '[Header]', + "FileFormatVersion,{$this->fileFormatVersion}", + "RunName,{$this->runName}", + "InstrumentPlatform,{$this->instrumentPlatform}", + "IndexOrientation,{$this->indexOrientation}", + '', + ]; + + return implode("\n", $headerLines); + } +} diff --git a/src/IlluminaSampleSheet/NovaSeqXCloudReadsSection.php b/src/IlluminaSampleSheet/NovaSeqXCloudReadsSection.php new file mode 100644 index 0000000..06ea4ab --- /dev/null +++ b/src/IlluminaSampleSheet/NovaSeqXCloudReadsSection.php @@ -0,0 +1,40 @@ +read1Cycles = $read1Cycles; + $this->read2Cycles = $read2Cycles; + $this->index1Cycles = $index1Cycles; + $this->index2Cycles = $index2Cycles; + } + + public function toString(): string + { + $readsLines = [ + '[Reads]', + "Read1Cycles,{$this->read1Cycles}", + "Read2Cycles,{$this->read2Cycles}", + "Index1Cycles,{$this->index1Cycles}", + "Index2Cycles,{$this->index2Cycles}", + '', + ]; + + return implode("\n", $readsLines); + } +} diff --git a/src/IlluminaSampleSheet/NovaSeqXCloudSampleSheet.php b/src/IlluminaSampleSheet/NovaSeqXCloudSampleSheet.php new file mode 100644 index 0000000..e9729a9 --- /dev/null +++ b/src/IlluminaSampleSheet/NovaSeqXCloudSampleSheet.php @@ -0,0 +1,27 @@ +addSection($header); + $this->addSection($reads); + $this->addSection($sequencingSettingsSection); + $this->addSection($bclConvertSettingsSection); + $this->addSection($bclConvertDataSection); + $this->addSection($cloudSettings); + $this->addSection($cloudData); + $this->bclConvertSettingsSection = $bclConvertSettingsSection; + } +} diff --git a/src/IlluminaSampleSheet/NovaSeqXCloudSequencingSettingsSection.php b/src/IlluminaSampleSheet/NovaSeqXCloudSequencingSettingsSection.php new file mode 100644 index 0000000..d93edad --- /dev/null +++ b/src/IlluminaSampleSheet/NovaSeqXCloudSequencingSettingsSection.php @@ -0,0 +1,25 @@ +libraryPrepKits = $libraryPrepKits; + } + + public function toString(): string + { + $sequencingSettingsLines = [ + '[Sequencing_Settings]', + "LibraryPrepKits,{$this->libraryPrepKits}", + '', + ]; + + return implode("\n", $sequencingSettingsLines); + } +} diff --git a/src/IlluminaSampleSheet/NovaSeqXpDataSection.php b/src/IlluminaSampleSheet/NovaSeqXpDataSection.php new file mode 100644 index 0000000..bf631b4 --- /dev/null +++ b/src/IlluminaSampleSheet/NovaSeqXpDataSection.php @@ -0,0 +1,11 @@ +lane = $lane; + $this->sampleId = $this->validateSampleId($sampleId); + $this->sampleName = $this->validateSampleName($sampleName); + $this->samplePlate = $samplePlate; + $this->sampleWell = $sampleWell; + $this->i7IndexId = $i7IndexId; + $this->index = $this->validateIndex($index); + $this->i5IndexId = $i5IndexId; + $this->index2 = $this->validateIndex($index2); + $this->sampleProject = $sampleProject; + $this->description = $description; + } + + public function toString(): string + { + return implode(',', [ + $this->lane, + $this->sampleId, + $this->sampleName, + $this->samplePlate, + $this->sampleWell, + $this->i7IndexId, + $this->index, + $this->i5IndexId, + $this->index2, + $this->sampleProject, + $this->description, + ]); + } +} diff --git a/src/IlluminaSampleSheet/NovaSeqXpSampleSheet.php b/src/IlluminaSampleSheet/NovaSeqXpSampleSheet.php new file mode 100644 index 0000000..f27eea7 --- /dev/null +++ b/src/IlluminaSampleSheet/NovaSeqXpSampleSheet.php @@ -0,0 +1,18 @@ +addSection($header); + $this->addSection($reads); + $this->addSection($settings); + $this->addSection($data); + } +} diff --git a/src/IlluminaSampleSheet/ReadsSection.php b/src/IlluminaSampleSheet/ReadsSection.php new file mode 100644 index 0000000..ce0c861 --- /dev/null +++ b/src/IlluminaSampleSheet/ReadsSection.php @@ -0,0 +1,21 @@ +read1Cycles = $read1Cycles; + $this->read2Cycles = $read2Cycles; + } + + public function toString(): string + { + return "[Reads]\n" . $this->read1Cycles . "\n" . $this->read2Cycles; + } +} diff --git a/src/IlluminaSampleSheet/Sample.php b/src/IlluminaSampleSheet/Sample.php new file mode 100644 index 0000000..f2e438d --- /dev/null +++ b/src/IlluminaSampleSheet/Sample.php @@ -0,0 +1,40 @@ +isValidNucleotidSequence($index)) { + throw new IlluminaSampleSheetException('Index contains invalid characters. Only A, T, C, G, N are allowed.'); + } + + return $index; + } + + protected function validateSampleId(string $sampleId): string + { + if ($sampleId === '') { + throw new IlluminaSampleSheetException('Sample ID cannot be empty.'); + } + + return $sampleId; + } + + protected function validateSampleName(string $sampleName): string + { + if ($sampleName === '') { + throw new IlluminaSampleSheetException('Sample Name cannot be empty.'); + } + + return $sampleName; + } + + protected function isValidNucleotidSequence(string $index): bool + { + return (bool) \Safe\preg_match('/^[ATCGN]+$/', $index); + } +} diff --git a/src/IlluminaSampleSheet/SampleSheet.php b/src/IlluminaSampleSheet/SampleSheet.php new file mode 100644 index 0000000..547193f --- /dev/null +++ b/src/IlluminaSampleSheet/SampleSheet.php @@ -0,0 +1,25 @@ + */ + protected array $sections = []; + + public function addSection(SectionInterface $section): void + { + $this->sections[] = $section; + } + + public function toString(): string + { + return implode("\n", array_map(fn (SectionInterface $section) => $section->toString(), $this->sections)); + } + + /** @return array */ + public function getSections(): array + { + return $this->sections; + } +} diff --git a/src/IlluminaSampleSheet/SectionInterface.php b/src/IlluminaSampleSheet/SectionInterface.php new file mode 100644 index 0000000..8adec77 --- /dev/null +++ b/src/IlluminaSampleSheet/SectionInterface.php @@ -0,0 +1,8 @@ +adapter = $adapter; + $this->adapterRead2 = $adapterRead2; + } + + public function toString(): string + { + $settingsLines = ['[Settings]']; + + if ($this->adapter !== null) { + $settingsLines[] = 'Adapter,' . $this->adapter; + } + + if ($this->adapterRead2 !== null) { + $settingsLines[] = 'AdapterRead2,' . $this->adapterRead2; + } + + return implode("\n", $settingsLines); + } +} diff --git a/tests/IlluminaSampleSheet/CloudDataSampleTest.php b/tests/IlluminaSampleSheet/CloudDataSampleTest.php new file mode 100644 index 0000000..0c53c66 --- /dev/null +++ b/tests/IlluminaSampleSheet/CloudDataSampleTest.php @@ -0,0 +1,47 @@ +sampleId); + self::assertSame('projectName2', $cloudDataSample->projectName); + self::assertSame('libraryName2', $cloudDataSample->libraryName); + self::assertSame('libraryPrepKitName2', $cloudDataSample->libraryPrepKitName); + self::assertSame('indexAdapterKitName2', $cloudDataSample->indexAdapterKitName); + } + + public function testToArrayReturnsCorrectStructure(): void + { + $cloudDataSample = new CloudDataSample( + 'sampleId1', + 'projectName1', + 'libraryName1', + 'libraryPrepKitName1', + 'indexAdapterKitName1' + ); + + $expectedArray = [ + 'Sample_ID' => 'sampleId1', + 'ProjectName' => 'projectName1', + 'LibraryName' => 'libraryName1', + 'LibraryPrepKitName' => 'libraryPrepKitName1', + 'IndexAdapterKitName' => 'indexAdapterKitName1', + ]; + + self::assertSame($expectedArray, $cloudDataSample->toArray()); + } +} diff --git a/tests/IlluminaSampleSheet/CloudDataSectionTest.php b/tests/IlluminaSampleSheet/CloudDataSectionTest.php new file mode 100644 index 0000000..c36ffe2 --- /dev/null +++ b/tests/IlluminaSampleSheet/CloudDataSectionTest.php @@ -0,0 +1,20 @@ +addSample('sampleId1', 'projectName1', 'libraryName1', 'libraryPrepKitName1', 'indexAdapterKitName1'); + $cloudDataSection->addSample('sampleId2', 'projectName2', 'libraryName2', 'libraryPrepKitName2', 'indexAdapterKitName2'); + + $expectedString = "[Cloud_Data]\nSample_ID,ProjectName,LibraryName,LibraryPrepKitName,IndexAdapterKitName\nsampleId1,projectName1,libraryName1,libraryPrepKitName1,indexAdapterKitName1\nsampleId2,projectName2,libraryName2,libraryPrepKitName2,indexAdapterKitName2\n"; + + self::assertSame($expectedString, $cloudDataSection->toString()); + } +} diff --git a/tests/IlluminaSampleSheet/CloudSettingsSectionTest.php b/tests/IlluminaSampleSheet/CloudSettingsSectionTest.php new file mode 100644 index 0000000..f3f3d4b --- /dev/null +++ b/tests/IlluminaSampleSheet/CloudSettingsSectionTest.php @@ -0,0 +1,18 @@ +toString()); + } +} diff --git a/tests/IlluminaSampleSheet/MiSeqSampleSheetTest.php b/tests/IlluminaSampleSheet/MiSeqSampleSheetTest.php new file mode 100644 index 0000000..33aa330 --- /dev/null +++ b/tests/IlluminaSampleSheet/MiSeqSampleSheetTest.php @@ -0,0 +1,72 @@ +createMock(MiSeqHeaderSection::class); + $readsSection = $this->createMock(ReadsSection::class); + $dataSection = $this->createMock(DataSection::class); + + $miSeqSampleSheet = new MiSeqSampleSheet($headerSection, $readsSection, $dataSection); + + self::assertContains($headerSection, $miSeqSampleSheet->getSections()); + self::assertContains($readsSection, $miSeqSampleSheet->getSections()); + self::assertContains($dataSection, $miSeqSampleSheet->getSections()); + } + + public function testMiSeqSampleSheetToStringReturnsExpectedResult(): void + { + $headerSection = new MiSeqHeaderSection( + 'Run7906-ROUTINE', + '03.04.2024', + 'GenerateFASTQ - 3.0.1', + 'GenerateFASTQ', + 'Illumina DNA Prep', + 'Custom', + 'NA-ISP', + 'Amplicon' + ); + + $readsSection = new ReadsSection(150, 150); + + $dataSection = new MiSeqDataSection(); + + $dataSection->addSample(new MiSeqSample('1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A501', 'TGAACCTT')); + $dataSection->addSample(new MiSeqSample('2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A502', 'TGCTAAGT')); + $dataSection->addSample(new MiSeqSample('3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A503', 'TGTTCTCT')); + + $miSeqSampleSheet = new MiSeqSampleSheet($headerSection, $readsSection, $dataSection); + + $expected = '[Header] +Experiment Name,Run7906-ROUTINE +Date,03.04.2024 +Module,GenerateFASTQ - 3.0.1 +Workflow,GenerateFASTQ +Library Prep Kit,Illumina DNA Prep +Index Kit,Custom +Description,NA-ISP +Chemistry,Amplicon +[Reads] +150 +150 +[Settings] +[Data] +Sample_ID,Sample_Name,Sample_Plate,Sample_Well,Sample_Project,I7_Index_ID,Index,I5_Index_ID,Index2 +1,Sample-001-M001,RunXXXX-PLATE,,RunXXXX-PROJECT,R701,ATCACG,A501,TGAACCTT +2,Sample-002-M002,RunXXXX-PLATE,,RunXXXX-PROJECT,R701,ATCACG,A502,TGCTAAGT +3,Sample-003-M003,RunXXXX-PLATE,,RunXXXX-PROJECT,R701,ATCACG,A503,TGTTCTCT +'; + self::assertSame($expected, $miSeqSampleSheet->toString()); + } +} diff --git a/tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php b/tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php new file mode 100644 index 0000000..a5ec2cb --- /dev/null +++ b/tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php @@ -0,0 +1,28 @@ +toString()); + } +} diff --git a/tests/IlluminaSampleSheet/NovaSeqSampleSheetTest.php b/tests/IlluminaSampleSheet/NovaSeqSampleSheetTest.php new file mode 100644 index 0000000..aae6bb8 --- /dev/null +++ b/tests/IlluminaSampleSheet/NovaSeqSampleSheetTest.php @@ -0,0 +1,80 @@ +createMock(NovaSeqHeaderSection::class); + $readsSection = $this->createMock(ReadsSection::class); + $settingsSection = $this->createMock(SettingsSection::class); + $dataSection = $this->createMock(DataSection::class); + + $novaSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settingsSection, $dataSection); + + self::assertContains($headerSection, $novaSeqSampleSheet->getSections()); + self::assertContains($readsSection, $novaSeqSampleSheet->getSections()); + self::assertContains($settingsSection, $novaSeqSampleSheet->getSections()); + self::assertContains($dataSection, $novaSeqSampleSheet->getSections()); + } + + public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): void + { + $headerSection = new NovaSeqHeaderSection( + '4', + 'DonalDuck', + 'MyExperiment', + '19.04.2024', + 'MyWorkflow', + 'MyApplication', + 'MyAssay', + 'MyDescription', + 'MyChemistry', + ); + + $readsSection = new ReadsSection(101, 101); + + $dataSection = new NovaSeqDataSection(); + + $dataSection->addSample(new NovaSeqSample('1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description')); + $dataSection->addSample(new NovaSeqSample('2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description')); + $dataSection->addSample(new NovaSeqSample('3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description')); + + $settings = new SettingsSection('AGATCGGAAGAGCACACGTCTGAACTCCAGTCA', 'AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT'); + $miSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); + + $expected = '[Header] +IEMFileVersion,4 +Investigator Name,DonalDuck +Experiment Name,MyExperiment +Date,19.04.2024 +Workflow,MyWorkflow +Application,MyApplication +Assay,MyAssay +Description,MyDescription +Chemistry,MyChemistry +[Reads] +101 +101 +[Settings] +Adapter,AGATCGGAAGAGCACACGTCTGAACTCCAGTCA +AdapterRead2,AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT +[Data] +Sample_ID,Sample_Name,Sample_Plate,Sample_Well,I7_Index_ID,Index,I5_Index_ID,Index2,Sample_Project,Description +1,Sample-001-M001,RunXXXX-PLATE,,UDP0090,TCAGGCTT,UDP0090,ATCATGCG,RunXXXX-PROJECT,description +2,Sample-002-M002,RunXXXX-PLATE,,UDP0091,CCTTGTAG,UDP0091,CCTTGGAA,RunXXXX-PROJECT,description +3,Sample-003-M003,RunXXXX-PLATE,,UDP0092,GAACATCG,UDP0092,TCGACAAG,RunXXXX-PROJECT,description +'; + self::assertSame($expected, $miSeqSampleSheet->toString()); + } +} diff --git a/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php b/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php new file mode 100644 index 0000000..ef09816 --- /dev/null +++ b/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php @@ -0,0 +1,98 @@ +addSample(1, 'Sample1', 'Index1', 'Index2', 'Cycles1', 'Adapter1', 'Adapter2'); + $bclConvertDataSection->addSample(2, 'Sample2', 'Index3', 'Index4', 'Cycles2', 'Adapter3', 'Adapter4'); + $bclConvertDataSection->addSample(3, 'Sample3', 'Index5', 'Index6', 'Cycles3', 'Adapter5', 'Adapter6'); + + $cloudSettingsSection = new CloudSettingsSection('1.0.0', 'Workflow1', 'Pipeline1'); + + $cloudDataSection = new CloudDataSection(); + $cloudDataSection->addSample('Sample4', 'Project1', 'Library1', 'Kit1', 'AdapterKit1'); + $cloudDataSection->addSample('Sample5', 'Project2', 'Library2', 'Kit2', 'AdapterKit2'); + $cloudDataSection->addSample('Sample6', 'Project3', 'Library3', 'Kit3', 'AdapterKit3'); + + $novaSeqXCloudSampleSheet = new NovaSeqXCloudSampleSheet( + $headerSection, + $readsSection, + $sequenceSettingsSection, + $bclConvertSettingsSection, + $bclConvertDataSection, + $cloudSettingsSection, + $cloudDataSection + ); + + $expected = '[Header] +FileFormatVersion,1 +RunName,Run1 +InstrumentPlatform,Platform1 +IndexOrientation,Orientation1 + +[Reads] +Read1Cycles,100 +Read2Cycles,101 +Index1Cycles,10 +Index2Cycles,11 + +[Sequencing_Settings] +LibraryPrepKits,Settings1 + +[BCLConvert_Settings] +SoftwareVersion,1.0.0 +TrimUMI,0 +FastqCompressionFormat,gzip + +[BCLConvert_Data] +Lane,Sample_ID,Index,Index2,OverrideCycles,AdapterRead1,AdapterRead2 +1,Sample1,Index1,Index2,Cycles1,Adapter1,Adapter2 +2,Sample2,Index3,Index4,Cycles2,Adapter3,Adapter4 +3,Sample3,Index5,Index6,Cycles3,Adapter5,Adapter6 + +[Cloud_Settings] +GeneratedVersion,1.0.0 +Cloud_Workflow,Workflow1 +BCLConvert_Pipeline,Pipeline1 + +[Cloud_Data] +Sample_ID,ProjectName,LibraryName,LibraryPrepKitName,IndexAdapterKitName +Sample4,Project1,Library1,Kit1,AdapterKit1 +Sample5,Project2,Library2,Kit2,AdapterKit2 +Sample6,Project3,Library3,Kit3,AdapterKit3 +'; + + self::assertEquals($expected, $novaSeqXCloudSampleSheet->toString()); + } +} diff --git a/tests/IlluminaSampleSheet/NovaSeqXpSampleSheetTest.php b/tests/IlluminaSampleSheet/NovaSeqXpSampleSheetTest.php new file mode 100644 index 0000000..08eaf32 --- /dev/null +++ b/tests/IlluminaSampleSheet/NovaSeqXpSampleSheetTest.php @@ -0,0 +1,81 @@ +createMock(NovaSeqHeaderSection::class); + $readsSection = $this->createMock(ReadsSection::class); + $settingsSection = $this->createMock(SettingsSection::class); + $dataSection = $this->createMock(DataSection::class); + + $novaSeqSampleSheet = new NovaSeqXpSampleSheet($headerSection, $readsSection, $settingsSection, $dataSection); + + self::assertContains($headerSection, $novaSeqSampleSheet->getSections()); + self::assertContains($readsSection, $novaSeqSampleSheet->getSections()); + self::assertContains($settingsSection, $novaSeqSampleSheet->getSections()); + self::assertContains($dataSection, $novaSeqSampleSheet->getSections()); + } + + public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): void + { + $headerSection = new NovaSeqHeaderSection( + '4', + 'DonalDuck', + 'MyExperiment', + '19.04.2024', + 'MyWorkflow', + 'MyApplication', + 'MyAssay', + 'MyDescription', + 'MyChemistry', + ); + + $readsSection = new ReadsSection(101, 101); + + $dataSection = new NovaSeqXpDataSection(); + + $dataSection->addSample(new NovaSeqXpSample('2', '1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description')); + $dataSection->addSample(new NovaSeqXpSample('1', '2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description')); + $dataSection->addSample(new NovaSeqXpSample('4', '3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description')); + + $settings = new SettingsSection('AGATCGGAAGAGCACACGTCTGAACTCCAGTCA', 'AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT'); + $miSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); + + $expected = '[Header] +IEMFileVersion,4 +Investigator Name,DonalDuck +Experiment Name,MyExperiment +Date,19.04.2024 +Workflow,MyWorkflow +Application,MyApplication +Assay,MyAssay +Description,MyDescription +Chemistry,MyChemistry +[Reads] +101 +101 +[Settings] +Adapter,AGATCGGAAGAGCACACGTCTGAACTCCAGTCA +AdapterRead2,AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT +[Data] +Lane,Sample_ID,Sample_Name,Sample_Plate,Sample_Well,I7_Index_ID,Index,I5_Index_ID,Index2,Sample_Project,Description +2,1,Sample-001-M001,RunXXXX-PLATE,,UDP0090,TCAGGCTT,UDP0090,ATCATGCG,RunXXXX-PROJECT,description +1,2,Sample-002-M002,RunXXXX-PLATE,,UDP0091,CCTTGTAG,UDP0091,CCTTGGAA,RunXXXX-PROJECT,description +4,3,Sample-003-M003,RunXXXX-PLATE,,UDP0092,GAACATCG,UDP0092,TCGACAAG,RunXXXX-PROJECT,description +'; + self::assertSame($expected, $miSeqSampleSheet->toString()); + } +} diff --git a/tests/IlluminaSampleSheet/ReadsSectionTest.php b/tests/IlluminaSampleSheet/ReadsSectionTest.php new file mode 100644 index 0000000..0176b89 --- /dev/null +++ b/tests/IlluminaSampleSheet/ReadsSectionTest.php @@ -0,0 +1,16 @@ +toString()); + } +} diff --git a/tests/IlluminaSampleSheet/SampleSheetTest.php b/tests/IlluminaSampleSheet/SampleSheetTest.php new file mode 100644 index 0000000..3a4e51e --- /dev/null +++ b/tests/IlluminaSampleSheet/SampleSheetTest.php @@ -0,0 +1,25 @@ +createMock(SectionInterface::class); + $sectionMock1->method('toString')->willReturn('section1'); + + $sectionMock2 = $this->createMock(SectionInterface::class); + $sectionMock2->method('toString')->willReturn('section2'); + + $sampleSheet = $this->createPartialMock(SampleSheet::class, []); + $sampleSheet->addSection($sectionMock1); + $sampleSheet->addSection($sectionMock2); + + self::assertSame("section1\nsection2", $sampleSheet->toString()); + } +} diff --git a/tests/IlluminaSampleSheet/SettingsSectionTest.php b/tests/IlluminaSampleSheet/SettingsSectionTest.php new file mode 100644 index 0000000..797b75f --- /dev/null +++ b/tests/IlluminaSampleSheet/SettingsSectionTest.php @@ -0,0 +1,16 @@ +toString()); + } +} From b8fdb076175f31fa721be76a45faeb66035d81c7 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Wed, 24 Apr 2024 08:46:25 +0200 Subject: [PATCH 02/29] move to v1 and v2 --- .../{ => V1}/DataSection.php | 4 ++- .../{ => V1}/MiSeqDataSection.php | 2 +- .../{ => V1}/MiSeqHeaderSection.php | 4 ++- .../{ => V1}/MiSeqSample.php | 2 +- .../{ => V1}/MiSeqSampleSheet.php | 4 ++- .../{ => V1}/NovaSeqDataSection.php | 2 +- .../{ => V1}/NovaSeqHeaderSection.php | 4 ++- .../{ => V1}/NovaSeqSample.php | 2 +- .../{ => V1}/NovaSeqSampleSheet.php | 4 ++- .../{ => V1}/NovaSeqXpDataSection.php | 2 +- .../{ => V1}/NovaSeqXpSample.php | 2 +- .../{ => V1}/NovaSeqXpSampleSheet.php | 4 ++- .../{ => V1}/ReadsSection.php | 4 ++- src/IlluminaSampleSheet/{ => V1}/Sample.php | 4 ++- .../{ => V1}/SettingsSection.php | 4 ++- .../{ => V2}/BclConvertDataRow.php | 2 +- .../{ => V2}/BclConvertDataSection.php | 4 ++- .../{ => V2}/BclConvertSettingsSection.php | 4 ++- .../{ => V2}/CloudDataSample.php | 2 +- .../{ => V2}/CloudDataSection.php | 4 ++- .../{ => V2}/CloudSettingsSection.php | 4 ++- .../{ => V2}/NovaSeqXCloudHeaderSection.php | 4 ++- .../{ => V2}/NovaSeqXCloudReadsSection.php | 4 ++- .../{ => V2}/NovaSeqXCloudSampleSheet.php | 4 ++- ...NovaSeqXCloudSequencingSettingsSection.php | 4 ++- .../CloudDataSampleTest.php | 2 +- .../CloudDataSectionTest.php | 2 +- .../CloudSettingsSectionTest.php | 2 +- .../MiSeqSampleSheetTest.php | 19 ++++++-------- .../NovaSeqHeaderSectionTest.php | 3 +-- .../NovaSeqSampleSheetTest.php | 26 ++++++++----------- .../NovaSeqXCloudSampleSheetTest.php | 20 ++++++-------- .../NovaSeqXpSampleSheetTest.php | 22 +++++++--------- .../IlluminaSampleSheet/ReadsSectionTest.php | 3 +-- .../SettingsSectionTest.php | 3 +-- 35 files changed, 101 insertions(+), 85 deletions(-) rename src/IlluminaSampleSheet/{ => V1}/DataSection.php (85%) rename src/IlluminaSampleSheet/{ => V1}/MiSeqDataSection.php (85%) rename src/IlluminaSampleSheet/{ => V1}/MiSeqHeaderSection.php (93%) rename src/IlluminaSampleSheet/{ => V1}/MiSeqSample.php (97%) rename src/IlluminaSampleSheet/{ => V1}/MiSeqSampleSheet.php (80%) rename src/IlluminaSampleSheet/{ => V1}/NovaSeqDataSection.php (86%) rename src/IlluminaSampleSheet/{ => V1}/NovaSeqHeaderSection.php (94%) rename src/IlluminaSampleSheet/{ => V1}/NovaSeqSample.php (97%) rename src/IlluminaSampleSheet/{ => V1}/NovaSeqSampleSheet.php (81%) rename src/IlluminaSampleSheet/{ => V1}/NovaSeqXpDataSection.php (86%) rename src/IlluminaSampleSheet/{ => V1}/NovaSeqXpSample.php (97%) rename src/IlluminaSampleSheet/{ => V1}/NovaSeqXpSampleSheet.php (81%) rename src/IlluminaSampleSheet/{ => V1}/ReadsSection.php (81%) rename src/IlluminaSampleSheet/{ => V1}/Sample.php (90%) rename src/IlluminaSampleSheet/{ => V1}/SettingsSection.php (87%) rename src/IlluminaSampleSheet/{ => V2}/BclConvertDataRow.php (96%) rename src/IlluminaSampleSheet/{ => V2}/BclConvertDataSection.php (91%) rename src/IlluminaSampleSheet/{ => V2}/BclConvertSettingsSection.php (90%) rename src/IlluminaSampleSheet/{ => V2}/CloudDataSample.php (96%) rename src/IlluminaSampleSheet/{ => V2}/CloudDataSection.php (90%) rename src/IlluminaSampleSheet/{ => V2}/CloudSettingsSection.php (88%) rename src/IlluminaSampleSheet/{ => V2}/NovaSeqXCloudHeaderSection.php (91%) rename src/IlluminaSampleSheet/{ => V2}/NovaSeqXCloudReadsSection.php (90%) rename src/IlluminaSampleSheet/{ => V2}/NovaSeqXCloudSampleSheet.php (91%) rename src/IlluminaSampleSheet/{ => V2}/NovaSeqXCloudSequencingSettingsSection.php (84%) diff --git a/src/IlluminaSampleSheet/DataSection.php b/src/IlluminaSampleSheet/V1/DataSection.php similarity index 85% rename from src/IlluminaSampleSheet/DataSection.php rename to src/IlluminaSampleSheet/V1/DataSection.php index 193cabf..6deca56 100644 --- a/src/IlluminaSampleSheet/DataSection.php +++ b/src/IlluminaSampleSheet/V1/DataSection.php @@ -1,6 +1,8 @@ createMock(MiSeqHeaderSection::class); + $headerSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\MiSeqHeaderSection::class); $readsSection = $this->createMock(ReadsSection::class); - $dataSection = $this->createMock(DataSection::class); + $dataSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\DataSection::class); $miSeqSampleSheet = new MiSeqSampleSheet($headerSection, $readsSection, $dataSection); @@ -27,7 +24,7 @@ public function testMiSeqSampleSheetToStringReturnsCorrectFormat(): void public function testMiSeqSampleSheetToStringReturnsExpectedResult(): void { - $headerSection = new MiSeqHeaderSection( + $headerSection = new \MLL\Utils\IlluminaSampleSheet\V1\MiSeqHeaderSection( 'Run7906-ROUTINE', '03.04.2024', 'GenerateFASTQ - 3.0.1', @@ -40,11 +37,11 @@ public function testMiSeqSampleSheetToStringReturnsExpectedResult(): void $readsSection = new ReadsSection(150, 150); - $dataSection = new MiSeqDataSection(); + $dataSection = new \MLL\Utils\IlluminaSampleSheet\V1\MiSeqDataSection(); $dataSection->addSample(new MiSeqSample('1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A501', 'TGAACCTT')); $dataSection->addSample(new MiSeqSample('2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A502', 'TGCTAAGT')); - $dataSection->addSample(new MiSeqSample('3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A503', 'TGTTCTCT')); + $dataSection->addSample(new \MLL\Utils\IlluminaSampleSheet\V1\MiSeqSample('3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A503', 'TGTTCTCT')); $miSeqSampleSheet = new MiSeqSampleSheet($headerSection, $readsSection, $dataSection); diff --git a/tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php b/tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php index a5ec2cb..7073d2a 100644 --- a/tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php +++ b/tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php @@ -2,14 +2,13 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet; -use MLL\Utils\IlluminaSampleSheet\NovaSeqHeaderSection; use PHPUnit\Framework\TestCase; class NovaSeqHeaderSectionTest extends TestCase { public function testHeaderSectionToStringReturnsCorrectFormat(): void { - $headerSection = new NovaSeqHeaderSection( + $headerSection = new \MLL\Utils\IlluminaSampleSheet\V1\NovaSeqHeaderSection( '4', 'Investigator1', 'Experiment1', diff --git a/tests/IlluminaSampleSheet/NovaSeqSampleSheetTest.php b/tests/IlluminaSampleSheet/NovaSeqSampleSheetTest.php index aae6bb8..b0be066 100644 --- a/tests/IlluminaSampleSheet/NovaSeqSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/NovaSeqSampleSheetTest.php @@ -2,23 +2,19 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet; -use MLL\Utils\IlluminaSampleSheet\DataSection; -use MLL\Utils\IlluminaSampleSheet\NovaSeqDataSection; -use MLL\Utils\IlluminaSampleSheet\NovaSeqHeaderSection; -use MLL\Utils\IlluminaSampleSheet\NovaSeqSample; -use MLL\Utils\IlluminaSampleSheet\NovaSeqSampleSheet; -use MLL\Utils\IlluminaSampleSheet\ReadsSection; -use MLL\Utils\IlluminaSampleSheet\SettingsSection; +use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqSample; +use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqSampleSheet; +use MLL\Utils\IlluminaSampleSheet\V1\SettingsSection; use PHPUnit\Framework\TestCase; class NovaSeqSampleSheetTest extends TestCase { public function testNovaSeqSampleSheetAddsSectionsOnConstruction(): void { - $headerSection = $this->createMock(NovaSeqHeaderSection::class); - $readsSection = $this->createMock(ReadsSection::class); - $settingsSection = $this->createMock(SettingsSection::class); - $dataSection = $this->createMock(DataSection::class); + $headerSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\NovaSeqHeaderSection::class); + $readsSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\ReadsSection::class); + $settingsSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\SettingsSection::class); + $dataSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\DataSection::class); $novaSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settingsSection, $dataSection); @@ -30,7 +26,7 @@ public function testNovaSeqSampleSheetAddsSectionsOnConstruction(): void public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): void { - $headerSection = new NovaSeqHeaderSection( + $headerSection = new \MLL\Utils\IlluminaSampleSheet\V1\NovaSeqHeaderSection( '4', 'DonalDuck', 'MyExperiment', @@ -42,16 +38,16 @@ public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): v 'MyChemistry', ); - $readsSection = new ReadsSection(101, 101); + $readsSection = new \MLL\Utils\IlluminaSampleSheet\V1\ReadsSection(101, 101); - $dataSection = new NovaSeqDataSection(); + $dataSection = new \MLL\Utils\IlluminaSampleSheet\V1\NovaSeqDataSection(); $dataSection->addSample(new NovaSeqSample('1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description')); $dataSection->addSample(new NovaSeqSample('2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description')); $dataSection->addSample(new NovaSeqSample('3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description')); $settings = new SettingsSection('AGATCGGAAGAGCACACGTCTGAACTCCAGTCA', 'AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT'); - $miSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); + $miSeqSampleSheet = new \MLL\Utils\IlluminaSampleSheet\V1\NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); $expected = '[Header] IEMFileVersion,4 diff --git a/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php b/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php index ef09816..0254694 100644 --- a/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php @@ -2,14 +2,10 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet; -use MLL\Utils\IlluminaSampleSheet\BclConvertDataSection; -use MLL\Utils\IlluminaSampleSheet\BclConvertSettingsSection; -use MLL\Utils\IlluminaSampleSheet\CloudDataSection; -use MLL\Utils\IlluminaSampleSheet\CloudSettingsSection; -use MLL\Utils\IlluminaSampleSheet\NovaSeqXCloudHeaderSection; -use MLL\Utils\IlluminaSampleSheet\NovaSeqXCloudReadsSection; -use MLL\Utils\IlluminaSampleSheet\NovaSeqXCloudSampleSheet; -use MLL\Utils\IlluminaSampleSheet\NovaSeqXCloudSequencingSettingsSection; +use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudHeaderSection; +use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudReadsSection; +use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudSampleSheet; +use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudSequencingSettingsSection; use PHPUnit\Framework\TestCase; class NovaSeqXCloudSampleSheetTest extends TestCase @@ -31,16 +27,16 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi ); $sequenceSettingsSection = new NovaSeqXCloudSequencingSettingsSection('Settings1'); - $bclConvertSettingsSection = new BclConvertSettingsSection('1.0.0', '0', 'gzip'); + $bclConvertSettingsSection = new \MLL\Utils\IlluminaSampleSheet\V2\BclConvertSettingsSection('1.0.0', '0', 'gzip'); - $bclConvertDataSection = new BclConvertDataSection(); + $bclConvertDataSection = new \MLL\Utils\IlluminaSampleSheet\V2\BclConvertDataSection(); $bclConvertDataSection->addSample(1, 'Sample1', 'Index1', 'Index2', 'Cycles1', 'Adapter1', 'Adapter2'); $bclConvertDataSection->addSample(2, 'Sample2', 'Index3', 'Index4', 'Cycles2', 'Adapter3', 'Adapter4'); $bclConvertDataSection->addSample(3, 'Sample3', 'Index5', 'Index6', 'Cycles3', 'Adapter5', 'Adapter6'); - $cloudSettingsSection = new CloudSettingsSection('1.0.0', 'Workflow1', 'Pipeline1'); + $cloudSettingsSection = new \MLL\Utils\IlluminaSampleSheet\V2\CloudSettingsSection('1.0.0', 'Workflow1', 'Pipeline1'); - $cloudDataSection = new CloudDataSection(); + $cloudDataSection = new \MLL\Utils\IlluminaSampleSheet\V2\CloudDataSection(); $cloudDataSection->addSample('Sample4', 'Project1', 'Library1', 'Kit1', 'AdapterKit1'); $cloudDataSection->addSample('Sample5', 'Project2', 'Library2', 'Kit2', 'AdapterKit2'); $cloudDataSection->addSample('Sample6', 'Project3', 'Library3', 'Kit3', 'AdapterKit3'); diff --git a/tests/IlluminaSampleSheet/NovaSeqXpSampleSheetTest.php b/tests/IlluminaSampleSheet/NovaSeqXpSampleSheetTest.php index 08eaf32..9322188 100644 --- a/tests/IlluminaSampleSheet/NovaSeqXpSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/NovaSeqXpSampleSheetTest.php @@ -2,14 +2,10 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet; -use MLL\Utils\IlluminaSampleSheet\DataSection; -use MLL\Utils\IlluminaSampleSheet\NovaSeqHeaderSection; -use MLL\Utils\IlluminaSampleSheet\NovaSeqSampleSheet; -use MLL\Utils\IlluminaSampleSheet\NovaSeqXpDataSection; -use MLL\Utils\IlluminaSampleSheet\NovaSeqXpSample; -use MLL\Utils\IlluminaSampleSheet\NovaSeqXpSampleSheet; -use MLL\Utils\IlluminaSampleSheet\ReadsSection; -use MLL\Utils\IlluminaSampleSheet\SettingsSection; +use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqHeaderSection; +use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqXpDataSection; +use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqXpSample; +use MLL\Utils\IlluminaSampleSheet\V1\SettingsSection; use PHPUnit\Framework\TestCase; class NovaSeqXpSampleSheetTest extends TestCase @@ -17,11 +13,11 @@ class NovaSeqXpSampleSheetTest extends TestCase public function testNovaSeqSampleSheetAddsSectionsOnConstruction(): void { $headerSection = $this->createMock(NovaSeqHeaderSection::class); - $readsSection = $this->createMock(ReadsSection::class); + $readsSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\ReadsSection::class); $settingsSection = $this->createMock(SettingsSection::class); - $dataSection = $this->createMock(DataSection::class); + $dataSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\DataSection::class); - $novaSeqSampleSheet = new NovaSeqXpSampleSheet($headerSection, $readsSection, $settingsSection, $dataSection); + $novaSeqSampleSheet = new \MLL\Utils\IlluminaSampleSheet\V1\NovaSeqXpSampleSheet($headerSection, $readsSection, $settingsSection, $dataSection); self::assertContains($headerSection, $novaSeqSampleSheet->getSections()); self::assertContains($readsSection, $novaSeqSampleSheet->getSections()); @@ -43,7 +39,7 @@ public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): v 'MyChemistry', ); - $readsSection = new ReadsSection(101, 101); + $readsSection = new \MLL\Utils\IlluminaSampleSheet\V1\ReadsSection(101, 101); $dataSection = new NovaSeqXpDataSection(); @@ -52,7 +48,7 @@ public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): v $dataSection->addSample(new NovaSeqXpSample('4', '3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description')); $settings = new SettingsSection('AGATCGGAAGAGCACACGTCTGAACTCCAGTCA', 'AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT'); - $miSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); + $miSeqSampleSheet = new \MLL\Utils\IlluminaSampleSheet\V1\NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); $expected = '[Header] IEMFileVersion,4 diff --git a/tests/IlluminaSampleSheet/ReadsSectionTest.php b/tests/IlluminaSampleSheet/ReadsSectionTest.php index 0176b89..75d9610 100644 --- a/tests/IlluminaSampleSheet/ReadsSectionTest.php +++ b/tests/IlluminaSampleSheet/ReadsSectionTest.php @@ -2,14 +2,13 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet; -use MLL\Utils\IlluminaSampleSheet\ReadsSection; use PHPUnit\Framework\TestCase; class ReadsSectionTest extends TestCase { public function testReadsSectionToStringReturnsCorrectFormat(): void { - $readsSection = new ReadsSection(150, 50); + $readsSection = new \MLL\Utils\IlluminaSampleSheet\V1\ReadsSection(150, 50); self::assertSame("[Reads]\n150\n50", $readsSection->toString()); } diff --git a/tests/IlluminaSampleSheet/SettingsSectionTest.php b/tests/IlluminaSampleSheet/SettingsSectionTest.php index 797b75f..536ed70 100644 --- a/tests/IlluminaSampleSheet/SettingsSectionTest.php +++ b/tests/IlluminaSampleSheet/SettingsSectionTest.php @@ -2,14 +2,13 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet; -use MLL\Utils\IlluminaSampleSheet\SettingsSection; use PHPUnit\Framework\TestCase; class SettingsSectionTest extends TestCase { public function testSettingsSectionToStringReturnsCorrectFormat(): void { - $settingsSection = new SettingsSection('AGATCG', 'TCG'); + $settingsSection = new \MLL\Utils\IlluminaSampleSheet\V1\SettingsSection('AGATCG', 'TCG'); self::assertSame("[Settings]\nAdapter,AGATCG\nAdapterRead2,TCG", $settingsSection->toString()); } From 3a95c00598d279f7d4e60579fd9686168f01935c Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Wed, 24 Apr 2024 09:14:08 +0200 Subject: [PATCH 03/29] header and convertSectionToString --- src/IlluminaSampleSheet/SampleSheet.php | 2 +- src/IlluminaSampleSheet/SectionInterface.php | 2 +- src/IlluminaSampleSheet/V1/DataSection.php | 2 +- .../V1/MiSeqHeaderSection.php | 2 +- .../V1/NovaSeqHeaderSection.php | 2 +- src/IlluminaSampleSheet/V1/ReadsSection.php | 2 +- .../V1/SettingsSection.php | 2 +- .../V2/BclConvertDataSection.php | 2 +- .../V2/BclConvertSettingsSection.php | 2 +- .../V2/CloudDataSection.php | 2 +- .../V2/CloudSettingsSection.php | 2 +- src/IlluminaSampleSheet/V2/HeaderSection.php | 68 +++++++++++++++++++ .../V2/NovaSeqXCloudHeaderSection.php | 42 ------------ .../V2/NovaSeqXCloudReadsSection.php | 2 +- .../V2/NovaSeqXCloudSampleSheet.php | 2 +- ...NovaSeqXCloudSequencingSettingsSection.php | 2 +- .../CloudDataSectionTest.php | 2 +- .../CloudSettingsSectionTest.php | 2 +- .../NovaSeqHeaderSectionTest.php | 2 +- .../NovaSeqXCloudSampleSheetTest.php | 13 ++-- .../IlluminaSampleSheet/ReadsSectionTest.php | 2 +- tests/IlluminaSampleSheet/SampleSheetTest.php | 4 +- .../SettingsSectionTest.php | 2 +- 23 files changed, 95 insertions(+), 70 deletions(-) create mode 100644 src/IlluminaSampleSheet/V2/HeaderSection.php delete mode 100644 src/IlluminaSampleSheet/V2/NovaSeqXCloudHeaderSection.php diff --git a/src/IlluminaSampleSheet/SampleSheet.php b/src/IlluminaSampleSheet/SampleSheet.php index 547193f..d4142fe 100644 --- a/src/IlluminaSampleSheet/SampleSheet.php +++ b/src/IlluminaSampleSheet/SampleSheet.php @@ -14,7 +14,7 @@ public function addSection(SectionInterface $section): void public function toString(): string { - return implode("\n", array_map(fn (SectionInterface $section) => $section->toString(), $this->sections)); + return implode("\n", array_map(fn (SectionInterface $section) => $section->convertSectionToString(), $this->sections)); } /** @return array */ diff --git a/src/IlluminaSampleSheet/SectionInterface.php b/src/IlluminaSampleSheet/SectionInterface.php index 8adec77..87982cd 100644 --- a/src/IlluminaSampleSheet/SectionInterface.php +++ b/src/IlluminaSampleSheet/SectionInterface.php @@ -4,5 +4,5 @@ interface SectionInterface { - public function toString(): string; + public function convertSectionToString(): string; } diff --git a/src/IlluminaSampleSheet/V1/DataSection.php b/src/IlluminaSampleSheet/V1/DataSection.php index 6deca56..b0c7626 100644 --- a/src/IlluminaSampleSheet/V1/DataSection.php +++ b/src/IlluminaSampleSheet/V1/DataSection.php @@ -14,7 +14,7 @@ public function addSample(Sample $sample): void $this->samples[] = $sample; } - public function toString(): string + public function convertSectionToString(): string { $dataLines = ["[Data]\n{$this->dataSectionHeader()}"]; foreach ($this->samples as $sample) { diff --git a/src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php b/src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php index 172ca57..b46aced 100644 --- a/src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php +++ b/src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php @@ -42,7 +42,7 @@ public function __construct( $this->chemistry = $chemistry; } - public function toString(): string + public function convertSectionToString(): string { $headerLines = [ '[Header]', diff --git a/src/IlluminaSampleSheet/V1/NovaSeqHeaderSection.php b/src/IlluminaSampleSheet/V1/NovaSeqHeaderSection.php index b815dab..5dfb9b6 100644 --- a/src/IlluminaSampleSheet/V1/NovaSeqHeaderSection.php +++ b/src/IlluminaSampleSheet/V1/NovaSeqHeaderSection.php @@ -46,7 +46,7 @@ public function __construct( $this->iemFileVersion = $iemFileVersion; } - public function toString(): string + public function convertSectionToString(): string { $headerLines = [ '[Header]', diff --git a/src/IlluminaSampleSheet/V1/ReadsSection.php b/src/IlluminaSampleSheet/V1/ReadsSection.php index 29c746e..7d45ad2 100644 --- a/src/IlluminaSampleSheet/V1/ReadsSection.php +++ b/src/IlluminaSampleSheet/V1/ReadsSection.php @@ -16,7 +16,7 @@ public function __construct(int $read1Cycles, int $read2Cycles) $this->read2Cycles = $read2Cycles; } - public function toString(): string + public function convertSectionToString(): string { return "[Reads]\n" . $this->read1Cycles . "\n" . $this->read2Cycles; } diff --git a/src/IlluminaSampleSheet/V1/SettingsSection.php b/src/IlluminaSampleSheet/V1/SettingsSection.php index c3e3638..8b2bac8 100644 --- a/src/IlluminaSampleSheet/V1/SettingsSection.php +++ b/src/IlluminaSampleSheet/V1/SettingsSection.php @@ -16,7 +16,7 @@ public function __construct(?string $adapter = null, ?string $adapterRead2 = nul $this->adapterRead2 = $adapterRead2; } - public function toString(): string + public function convertSectionToString(): string { $settingsLines = ['[Settings]']; diff --git a/src/IlluminaSampleSheet/V2/BclConvertDataSection.php b/src/IlluminaSampleSheet/V2/BclConvertDataSection.php index ff021ce..7d3b8c0 100644 --- a/src/IlluminaSampleSheet/V2/BclConvertDataSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvertDataSection.php @@ -29,7 +29,7 @@ public function addSample( ); } - public function toString(): string + public function convertSectionToString(): string { $bclConvertDataLines = [ '[BCLConvert_Data]', diff --git a/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php b/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php index 3e598aa..79aa1c1 100644 --- a/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php @@ -22,7 +22,7 @@ public function __construct( $this->fastqCompressionFormat = $fastqCompressionFormat; } - public function toString(): string + public function convertSectionToString(): string { $bclConvertSettingsLines = [ '[BCLConvert_Settings]', diff --git a/src/IlluminaSampleSheet/V2/CloudDataSection.php b/src/IlluminaSampleSheet/V2/CloudDataSection.php index 4273176..160bbeb 100644 --- a/src/IlluminaSampleSheet/V2/CloudDataSection.php +++ b/src/IlluminaSampleSheet/V2/CloudDataSection.php @@ -25,7 +25,7 @@ public function addSample( ); } - public function toString(): string + public function convertSectionToString(): string { $dataLines = ["[Cloud_Data]\nSample_ID,ProjectName,LibraryName,LibraryPrepKitName,IndexAdapterKitName"]; foreach ($this->samples as $sample) { diff --git a/src/IlluminaSampleSheet/V2/CloudSettingsSection.php b/src/IlluminaSampleSheet/V2/CloudSettingsSection.php index 6fe562d..42c87df 100644 --- a/src/IlluminaSampleSheet/V2/CloudSettingsSection.php +++ b/src/IlluminaSampleSheet/V2/CloudSettingsSection.php @@ -22,7 +22,7 @@ public function __construct( $this->bclConvertPipeline = $bclConvertPipeline; } - public function toString(): string + public function convertSectionToString(): string { return '[Cloud_Settings] GeneratedVersion,' . $this->generatedVersion . "\n" diff --git a/src/IlluminaSampleSheet/V2/HeaderSection.php b/src/IlluminaSampleSheet/V2/HeaderSection.php new file mode 100644 index 0000000..5a9b5a5 --- /dev/null +++ b/src/IlluminaSampleSheet/V2/HeaderSection.php @@ -0,0 +1,68 @@ + */ + private array $customParams = []; + + /** + * @param string $runName - Required. Name of the run. + * @param string|null $instrumentPlatform - Optional. Platform of the instrument. + * @param string|null $runDescription - Optional. Description of the run. + * @param string|null $instrumentType - Optional. Type of the instrument. + */ + public function __construct(string $runName, ?string $instrumentPlatform = null, ?string $runDescription = null, ?string $instrumentType = null) + { + $this->runName = $runName; + $this->runDescription = $runDescription; + $this->instrumentType = $instrumentType; + $this->instrumentPlatform = $instrumentPlatform; + } + + /** + * @param string $paramName - Name of the parameter + * @param string $paramValue - Value of the parameter + */ + public function addCustomParam(string $paramName, string $paramValue): void + { + $this->customParams[$paramName] = $paramValue; + } + + public function convertSectionToString(): string + { + $headerLines = [ + '[Header]', + "FileFormatVersion,{$this->fileFormatVersion}", + "RunName,{$this->runName}", + ]; + if ($this->runDescription !== null) { + $headerLines[] = "RunDescription,{$this->runDescription}"; + } + if ($this->instrumentType !== null) { + $headerLines[] = "InstrumentType,{$this->instrumentType}"; + } + if ($this->instrumentPlatform !== null) { + $headerLines[] = "InstrumentPlatform,{$this->instrumentPlatform}"; + } + foreach ($this->customParams as $paramName => $paramValue) { + $headerLines[] = "{$paramName},{$paramValue}"; + } + $headerLines[] = ''; // blank line at the end + + return implode("\n", $headerLines); + } +} diff --git a/src/IlluminaSampleSheet/V2/NovaSeqXCloudHeaderSection.php b/src/IlluminaSampleSheet/V2/NovaSeqXCloudHeaderSection.php deleted file mode 100644 index 27fb867..0000000 --- a/src/IlluminaSampleSheet/V2/NovaSeqXCloudHeaderSection.php +++ /dev/null @@ -1,42 +0,0 @@ -fileFormatVersion = $fileFormatVersion; - $this->runName = $runName; - $this->instrumentPlatform = $instrumentPlatform; - $this->indexOrientation = $indexOrientation; - } - - public function toString(): string - { - $headerLines = [ - '[Header]', - "FileFormatVersion,{$this->fileFormatVersion}", - "RunName,{$this->runName}", - "InstrumentPlatform,{$this->instrumentPlatform}", - "IndexOrientation,{$this->indexOrientation}", - '', - ]; - - return implode("\n", $headerLines); - } -} diff --git a/src/IlluminaSampleSheet/V2/NovaSeqXCloudReadsSection.php b/src/IlluminaSampleSheet/V2/NovaSeqXCloudReadsSection.php index 058f262..ad5c551 100644 --- a/src/IlluminaSampleSheet/V2/NovaSeqXCloudReadsSection.php +++ b/src/IlluminaSampleSheet/V2/NovaSeqXCloudReadsSection.php @@ -26,7 +26,7 @@ public function __construct( $this->index2Cycles = $index2Cycles; } - public function toString(): string + public function convertSectionToString(): string { $readsLines = [ '[Reads]', diff --git a/src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php b/src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php index e95b16e..db73688 100644 --- a/src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php +++ b/src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php @@ -9,7 +9,7 @@ class NovaSeqXCloudSampleSheet extends SampleSheet public BclConvertSettingsSection $bclConvertSettingsSection; public function __construct( - NovaSeqXCloudHeaderSection $header, + HeaderSection $header, NovaSeqXCloudReadsSection $reads, NovaSeqXCloudSequencingSettingsSection $sequencingSettingsSection, BclConvertSettingsSection $bclConvertSettingsSection, diff --git a/src/IlluminaSampleSheet/V2/NovaSeqXCloudSequencingSettingsSection.php b/src/IlluminaSampleSheet/V2/NovaSeqXCloudSequencingSettingsSection.php index f461dd3..2c73bae 100644 --- a/src/IlluminaSampleSheet/V2/NovaSeqXCloudSequencingSettingsSection.php +++ b/src/IlluminaSampleSheet/V2/NovaSeqXCloudSequencingSettingsSection.php @@ -14,7 +14,7 @@ public function __construct( $this->libraryPrepKits = $libraryPrepKits; } - public function toString(): string + public function convertSectionToString(): string { $sequencingSettingsLines = [ '[Sequencing_Settings]', diff --git a/tests/IlluminaSampleSheet/CloudDataSectionTest.php b/tests/IlluminaSampleSheet/CloudDataSectionTest.php index 988efe4..f7e8934 100644 --- a/tests/IlluminaSampleSheet/CloudDataSectionTest.php +++ b/tests/IlluminaSampleSheet/CloudDataSectionTest.php @@ -15,6 +15,6 @@ public function testCloudDataSectionToStringReturnsCorrectFormat(): void $expectedString = "[Cloud_Data]\nSample_ID,ProjectName,LibraryName,LibraryPrepKitName,IndexAdapterKitName\nsampleId1,projectName1,libraryName1,libraryPrepKitName1,indexAdapterKitName1\nsampleId2,projectName2,libraryName2,libraryPrepKitName2,indexAdapterKitName2\n"; - self::assertSame($expectedString, $cloudDataSection->toString()); + self::assertSame($expectedString, $cloudDataSection->convertSectionToString()); } } diff --git a/tests/IlluminaSampleSheet/CloudSettingsSectionTest.php b/tests/IlluminaSampleSheet/CloudSettingsSectionTest.php index c713de7..9902696 100644 --- a/tests/IlluminaSampleSheet/CloudSettingsSectionTest.php +++ b/tests/IlluminaSampleSheet/CloudSettingsSectionTest.php @@ -13,6 +13,6 @@ public function testCloudSettingsSectionToStringReturnsCorrectFormat(): void $expectedString = "[Cloud_Settings]\nGeneratedVersion,1.0\nCloud_Workflow,Workflow1\nBCLConvert_Pipeline,Pipeline1\n"; - self::assertSame($expectedString, $cloudSettingsSection->toString()); + self::assertSame($expectedString, $cloudSettingsSection->convertSectionToString()); } } diff --git a/tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php b/tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php index 7073d2a..fd9bfe5 100644 --- a/tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php +++ b/tests/IlluminaSampleSheet/NovaSeqHeaderSectionTest.php @@ -22,6 +22,6 @@ public function testHeaderSectionToStringReturnsCorrectFormat(): void $expectedString = "[Header]\nIEMFileVersion,4\nInvestigator Name,Investigator1\nExperiment Name,Experiment1\nDate,2022-01-01\nWorkflow,Workflow1\nApplication,Application1\nAssay,Assay1\nDescription,Description1\nChemistry,Chemistry1"; - self::assertSame($expectedString, $headerSection->toString()); + self::assertSame($expectedString, $headerSection->convertSectionToString()); } } diff --git a/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php b/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php index 0254694..91eb0e4 100644 --- a/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php @@ -2,7 +2,7 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet; -use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudHeaderSection; +use MLL\Utils\IlluminaSampleSheet\V2\HeaderSection; use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudReadsSection; use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudSampleSheet; use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudSequencingSettingsSection; @@ -12,12 +12,11 @@ class NovaSeqXCloudSampleSheetTest extends TestCase { public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): void { - $headerSection = new NovaSeqXCloudHeaderSection( - '1', + $headerSection = new HeaderSection( 'Run1', - 'Platform1', - 'Orientation1' + 'NovaSeqXSeries', ); + $headerSection->addCustomParam('IndexOrientation', 'Orientation1'); $readsSection = new NovaSeqXCloudReadsSection( 100, @@ -52,9 +51,9 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi ); $expected = '[Header] -FileFormatVersion,1 +FileFormatVersion,2 RunName,Run1 -InstrumentPlatform,Platform1 +InstrumentPlatform,NovaSeqXSeries IndexOrientation,Orientation1 [Reads] diff --git a/tests/IlluminaSampleSheet/ReadsSectionTest.php b/tests/IlluminaSampleSheet/ReadsSectionTest.php index 75d9610..999d32b 100644 --- a/tests/IlluminaSampleSheet/ReadsSectionTest.php +++ b/tests/IlluminaSampleSheet/ReadsSectionTest.php @@ -10,6 +10,6 @@ public function testReadsSectionToStringReturnsCorrectFormat(): void { $readsSection = new \MLL\Utils\IlluminaSampleSheet\V1\ReadsSection(150, 50); - self::assertSame("[Reads]\n150\n50", $readsSection->toString()); + self::assertSame("[Reads]\n150\n50", $readsSection->convertSectionToString()); } } diff --git a/tests/IlluminaSampleSheet/SampleSheetTest.php b/tests/IlluminaSampleSheet/SampleSheetTest.php index 3a4e51e..695e8cc 100644 --- a/tests/IlluminaSampleSheet/SampleSheetTest.php +++ b/tests/IlluminaSampleSheet/SampleSheetTest.php @@ -11,10 +11,10 @@ class SampleSheetTest extends TestCase public function testSampleSheetToStringReturnsCorrectFormat(): void { $sectionMock1 = $this->createMock(SectionInterface::class); - $sectionMock1->method('toString')->willReturn('section1'); + $sectionMock1->method('convertSectionToString')->willReturn('section1'); $sectionMock2 = $this->createMock(SectionInterface::class); - $sectionMock2->method('toString')->willReturn('section2'); + $sectionMock2->method('convertSectionToString')->willReturn('section2'); $sampleSheet = $this->createPartialMock(SampleSheet::class, []); $sampleSheet->addSection($sectionMock1); diff --git a/tests/IlluminaSampleSheet/SettingsSectionTest.php b/tests/IlluminaSampleSheet/SettingsSectionTest.php index 536ed70..1b5ff41 100644 --- a/tests/IlluminaSampleSheet/SettingsSectionTest.php +++ b/tests/IlluminaSampleSheet/SettingsSectionTest.php @@ -10,6 +10,6 @@ public function testSettingsSectionToStringReturnsCorrectFormat(): void { $settingsSection = new \MLL\Utils\IlluminaSampleSheet\V1\SettingsSection('AGATCG', 'TCG'); - self::assertSame("[Settings]\nAdapter,AGATCG\nAdapterRead2,TCG", $settingsSection->toString()); + self::assertSame("[Settings]\nAdapter,AGATCG\nAdapterRead2,TCG", $settingsSection->convertSectionToString()); } } From b7965e30a3dabbaf4ddef1ad1a1282fb3bfe8eae Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Wed, 24 Apr 2024 09:46:19 +0200 Subject: [PATCH 04/29] ReadsSection --- src/IlluminaSampleSheet/V2/HeaderSection.php | 9 ++- .../V2/NovaSeqXCloudReadsSection.php | 42 -------------- .../V2/NovaSeqXCloudSampleSheet.php | 2 +- src/IlluminaSampleSheet/V2/ReadsSection.php | 57 +++++++++++++++++++ .../NovaSeqXCloudSampleSheetTest.php | 4 +- 5 files changed, 64 insertions(+), 50 deletions(-) delete mode 100644 src/IlluminaSampleSheet/V2/NovaSeqXCloudReadsSection.php create mode 100644 src/IlluminaSampleSheet/V2/ReadsSection.php diff --git a/src/IlluminaSampleSheet/V2/HeaderSection.php b/src/IlluminaSampleSheet/V2/HeaderSection.php index 5a9b5a5..4ff1a43 100644 --- a/src/IlluminaSampleSheet/V2/HeaderSection.php +++ b/src/IlluminaSampleSheet/V2/HeaderSection.php @@ -6,9 +6,9 @@ class HeaderSection implements SectionInterface { - private string $runName; + private const FILE_FORMAT_VERSION = '2'; - private string $fileFormatVersion = '2'; + private string $runName; private ?string $runDescription; @@ -46,7 +46,7 @@ public function convertSectionToString(): string { $headerLines = [ '[Header]', - "FileFormatVersion,{$this->fileFormatVersion}", + 'FileFormatVersion,' . self::FILE_FORMAT_VERSION . '', "RunName,{$this->runName}", ]; if ($this->runDescription !== null) { @@ -61,8 +61,7 @@ public function convertSectionToString(): string foreach ($this->customParams as $paramName => $paramValue) { $headerLines[] = "{$paramName},{$paramValue}"; } - $headerLines[] = ''; // blank line at the end - return implode("\n", $headerLines); + return implode("\n", $headerLines) . "\n"; } } diff --git a/src/IlluminaSampleSheet/V2/NovaSeqXCloudReadsSection.php b/src/IlluminaSampleSheet/V2/NovaSeqXCloudReadsSection.php deleted file mode 100644 index ad5c551..0000000 --- a/src/IlluminaSampleSheet/V2/NovaSeqXCloudReadsSection.php +++ /dev/null @@ -1,42 +0,0 @@ -read1Cycles = $read1Cycles; - $this->read2Cycles = $read2Cycles; - $this->index1Cycles = $index1Cycles; - $this->index2Cycles = $index2Cycles; - } - - public function convertSectionToString(): string - { - $readsLines = [ - '[Reads]', - "Read1Cycles,{$this->read1Cycles}", - "Read2Cycles,{$this->read2Cycles}", - "Index1Cycles,{$this->index1Cycles}", - "Index2Cycles,{$this->index2Cycles}", - '', - ]; - - return implode("\n", $readsLines); - } -} diff --git a/src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php b/src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php index db73688..5ef0026 100644 --- a/src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php +++ b/src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php @@ -10,7 +10,7 @@ class NovaSeqXCloudSampleSheet extends SampleSheet public function __construct( HeaderSection $header, - NovaSeqXCloudReadsSection $reads, + ReadsSection $reads, NovaSeqXCloudSequencingSettingsSection $sequencingSettingsSection, BclConvertSettingsSection $bclConvertSettingsSection, BclConvertDataSection $bclConvertDataSection, diff --git a/src/IlluminaSampleSheet/V2/ReadsSection.php b/src/IlluminaSampleSheet/V2/ReadsSection.php new file mode 100644 index 0000000..72aa534 --- /dev/null +++ b/src/IlluminaSampleSheet/V2/ReadsSection.php @@ -0,0 +1,57 @@ + 12)) { + throw new IlluminaSampleSheetException('Index1Cycles must be between 6 and 12 or null.'); + } + if ($index2Cycles !== null && ($index2Cycles < 6 || $index2Cycles > 12)) { + throw new IlluminaSampleSheetException('Index2Cycles must be between 6 and 12 or null.'); + } + $this->read1Cycles = $read1Cycles; + $this->read2Cycles = $read2Cycles; + $this->index1Cycles = $index1Cycles; + $this->index2Cycles = $index2Cycles; + } + + public function convertSectionToString(): string + { + $readsLines = ['[Reads]']; + + if (isset($this->read1Cycles)) { + $readsLines[] = "Read1Cycles,{$this->read1Cycles}"; + } + if (isset($this->read2Cycles)) { + $readsLines[] = "Read2Cycles,{$this->read2Cycles}"; + } + if (isset($this->index1Cycles)) { + $readsLines[] = "Index1Cycles,{$this->index1Cycles}"; + } + if (isset($this->index2Cycles)) { + $readsLines[] = "Index2Cycles,{$this->index2Cycles}"; + } + + return implode("\n", $readsLines) . "\n"; + } +} diff --git a/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php b/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php index 91eb0e4..2332e4a 100644 --- a/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/NovaSeqXCloudSampleSheetTest.php @@ -3,9 +3,9 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet; use MLL\Utils\IlluminaSampleSheet\V2\HeaderSection; -use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudReadsSection; use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudSampleSheet; use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudSequencingSettingsSection; +use MLL\Utils\IlluminaSampleSheet\V2\ReadsSection; use PHPUnit\Framework\TestCase; class NovaSeqXCloudSampleSheetTest extends TestCase @@ -18,7 +18,7 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi ); $headerSection->addCustomParam('IndexOrientation', 'Orientation1'); - $readsSection = new NovaSeqXCloudReadsSection( + $readsSection = new ReadsSection( 100, 101, 10, From 752cfce159a66bbefe8b864bfba22ce1a609bbf8 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Wed, 24 Apr 2024 09:56:13 +0200 Subject: [PATCH 05/29] move tests --- tests/IlluminaSampleSheet/{ => V1}/MiSeqSampleSheetTest.php | 2 +- tests/IlluminaSampleSheet/{ => V1}/NovaSeqHeaderSectionTest.php | 2 +- tests/IlluminaSampleSheet/{ => V1}/NovaSeqSampleSheetTest.php | 2 +- tests/IlluminaSampleSheet/{ => V1}/NovaSeqXpSampleSheetTest.php | 2 +- tests/IlluminaSampleSheet/{ => V1}/ReadsSectionTest.php | 2 +- tests/IlluminaSampleSheet/{ => V1}/SettingsSectionTest.php | 2 +- tests/IlluminaSampleSheet/{ => V2}/CloudDataSampleTest.php | 2 +- tests/IlluminaSampleSheet/{ => V2}/CloudDataSectionTest.php | 2 +- tests/IlluminaSampleSheet/{ => V2}/CloudSettingsSectionTest.php | 2 +- .../{ => V2}/NovaSeqXCloudSampleSheetTest.php | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) rename tests/IlluminaSampleSheet/{ => V1}/MiSeqSampleSheetTest.php (98%) rename tests/IlluminaSampleSheet/{ => V1}/NovaSeqHeaderSectionTest.php (94%) rename tests/IlluminaSampleSheet/{ => V1}/NovaSeqSampleSheetTest.php (98%) rename tests/IlluminaSampleSheet/{ => V1}/NovaSeqXpSampleSheetTest.php (98%) rename tests/IlluminaSampleSheet/{ => V1}/ReadsSectionTest.php (88%) rename tests/IlluminaSampleSheet/{ => V1}/SettingsSectionTest.php (89%) rename tests/IlluminaSampleSheet/{ => V2}/CloudDataSampleTest.php (96%) rename tests/IlluminaSampleSheet/{ => V2}/CloudDataSectionTest.php (94%) rename tests/IlluminaSampleSheet/{ => V2}/CloudSettingsSectionTest.php (92%) rename tests/IlluminaSampleSheet/{ => V2}/NovaSeqXCloudSampleSheetTest.php (98%) diff --git a/tests/IlluminaSampleSheet/MiSeqSampleSheetTest.php b/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php similarity index 98% rename from tests/IlluminaSampleSheet/MiSeqSampleSheetTest.php rename to tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php index 6b413b5..f08df32 100644 --- a/tests/IlluminaSampleSheet/MiSeqSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php @@ -1,6 +1,6 @@ Date: Wed, 24 Apr 2024 10:22:41 +0200 Subject: [PATCH 06/29] simplify --- src/IlluminaSampleSheet/V1/DataSection.php | 28 ------- .../V1/MiSeqDataSection.php | 23 +++++- .../V1/MiSeqSampleSheet.php | 2 +- .../V1/NovaSeqDataSection.php | 37 ++++++++- src/IlluminaSampleSheet/V1/NovaSeqSample.php | 66 ---------------- .../V1/NovaSeqSampleSheet.php | 2 +- .../V1/NovaSeqXpDataSection.php | 11 --- .../V1/NovaSeqXpSample.php | 20 ++++- .../V1/NovaSeqXpSampleSheet.php | 20 ----- .../V1/MiSeqSampleSheetTest.php | 12 +-- .../V1/NovaSeqHeaderSectionTest.php | 27 ------- .../V1/NovaSeqSampleSheetTest.php | 77 ++++++++++++++++--- .../V1/NovaSeqXpSampleSheetTest.php | 77 ------------------- .../V1/ReadsSectionTest.php | 15 ---- .../V1/SettingsSectionTest.php | 15 ---- .../V2/NovaSeqXCloudSampleSheetTest.php | 12 ++- 16 files changed, 156 insertions(+), 288 deletions(-) delete mode 100644 src/IlluminaSampleSheet/V1/DataSection.php delete mode 100644 src/IlluminaSampleSheet/V1/NovaSeqSample.php delete mode 100644 src/IlluminaSampleSheet/V1/NovaSeqXpDataSection.php delete mode 100644 src/IlluminaSampleSheet/V1/NovaSeqXpSampleSheet.php delete mode 100644 tests/IlluminaSampleSheet/V1/NovaSeqHeaderSectionTest.php delete mode 100644 tests/IlluminaSampleSheet/V1/NovaSeqXpSampleSheetTest.php delete mode 100644 tests/IlluminaSampleSheet/V1/ReadsSectionTest.php delete mode 100644 tests/IlluminaSampleSheet/V1/SettingsSectionTest.php diff --git a/src/IlluminaSampleSheet/V1/DataSection.php b/src/IlluminaSampleSheet/V1/DataSection.php deleted file mode 100644 index b0c7626..0000000 --- a/src/IlluminaSampleSheet/V1/DataSection.php +++ /dev/null @@ -1,28 +0,0 @@ - */ - private array $samples = []; - - public function addSample(Sample $sample): void - { - $this->samples[] = $sample; - } - - public function convertSectionToString(): string - { - $dataLines = ["[Data]\n{$this->dataSectionHeader()}"]; - foreach ($this->samples as $sample) { - $dataLines[] = $sample->toString(); - } - - return implode("\n", $dataLines) . "\n"; - } - - abstract public function dataSectionHeader(): string; -} diff --git a/src/IlluminaSampleSheet/V1/MiSeqDataSection.php b/src/IlluminaSampleSheet/V1/MiSeqDataSection.php index a7d8b5a..4327354 100644 --- a/src/IlluminaSampleSheet/V1/MiSeqDataSection.php +++ b/src/IlluminaSampleSheet/V1/MiSeqDataSection.php @@ -2,8 +2,29 @@ namespace MLL\Utils\IlluminaSampleSheet\V1; -class MiSeqDataSection extends DataSection +use MLL\Utils\IlluminaSampleSheet\SectionInterface; + +class MiSeqDataSection implements SectionInterface { + /** @var array */ + private array $samples = []; + + public function addSample(MiSeqSample $sample): void + { + $this->samples[] = $sample; + } + + public function convertSectionToString(): string + { + $dataLines = ["[Data]\n{$this->dataSectionHeader()}"]; + + foreach ($this->samples as $sample) { + $dataLines[] = $sample->toString(); + } + + return implode("\n", $dataLines) . "\n"; + } + public function dataSectionHeader(): string { return 'Sample_ID,Sample_Name,Sample_Plate,Sample_Well,Sample_Project,I7_Index_ID,Index,I5_Index_ID,Index2'; diff --git a/src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php b/src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php index 3dd8530..03ad602 100644 --- a/src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php +++ b/src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php @@ -9,7 +9,7 @@ class MiSeqSampleSheet extends SampleSheet public function __construct( MiSeqHeaderSection $header, ReadsSection $reads, - DataSection $data + MiSeqDataSection $data ) { $this->addSection($header); $this->addSection($reads); diff --git a/src/IlluminaSampleSheet/V1/NovaSeqDataSection.php b/src/IlluminaSampleSheet/V1/NovaSeqDataSection.php index 5772a24..5b1ae7d 100644 --- a/src/IlluminaSampleSheet/V1/NovaSeqDataSection.php +++ b/src/IlluminaSampleSheet/V1/NovaSeqDataSection.php @@ -2,10 +2,41 @@ namespace MLL\Utils\IlluminaSampleSheet\V1; -class NovaSeqDataSection extends DataSection +use MLL\Utils\IlluminaSampleSheet\SectionInterface; + +class NovaSeqDataSection implements SectionInterface { - public function dataSectionHeader(): string + /** @var array */ + private array $samples = []; + + public function addSample(NovaSeqXpSample $sample): void + { + $this->samples[] = $sample; + } + + public function convertSectionToString(): string + { + $dataLines = ["[Data]\n{$this->dataSectionHeader()}"]; + $requiresLanesColumn = $this->requiresLanesColumn(); + + foreach ($this->samples as $sample) { + $dataLines[] = $requiresLanesColumn ? $sample->toStringWithoutLane() : $sample->toString(); + } + + return implode("\n", $dataLines) . "\n"; + } + + private function dataSectionHeader(): string + { + if ($this->requiresLanesColumn()) { + return 'Sample_ID,Sample_Name,Sample_Plate,Sample_Well,I7_Index_ID,Index,I5_Index_ID,Index2,Sample_Project,Description'; + } + + return 'Lane,Sample_ID,Sample_Name,Sample_Plate,Sample_Well,I7_Index_ID,Index,I5_Index_ID,Index2,Sample_Project,Description'; + } + + private function requiresLanesColumn(): bool { - return 'Sample_ID,Sample_Name,Sample_Plate,Sample_Well,I7_Index_ID,Index,I5_Index_ID,Index2,Sample_Project,Description'; + return count(array_unique(array_map(fn (NovaSeqXpSample $sample) => $sample->lane, $this->samples))) === 1; } } diff --git a/src/IlluminaSampleSheet/V1/NovaSeqSample.php b/src/IlluminaSampleSheet/V1/NovaSeqSample.php deleted file mode 100644 index c5f67a1..0000000 --- a/src/IlluminaSampleSheet/V1/NovaSeqSample.php +++ /dev/null @@ -1,66 +0,0 @@ -sampleId = $this->validateSampleId($sampleId); - $this->sampleName = $this->validateSampleName($sampleName); - $this->samplePlate = $samplePlate; - $this->sampleWell = $sampleWell; - $this->i7IndexId = $i7IndexId; - $this->index = $this->validateIndex($index); - $this->i5IndexId = $i5IndexId; - $this->index2 = $this->validateIndex($index2); - $this->sampleProject = $sampleProject; - $this->description = $description; - } - - public function toString(): string - { - return implode(',', [ - $this->sampleId, - $this->sampleName, - $this->samplePlate, - $this->sampleWell, - $this->i7IndexId, - $this->index, - $this->i5IndexId, - $this->index2, - $this->sampleProject, - $this->description, - ]); - } -} diff --git a/src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php b/src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php index 66ad37f..142b162 100644 --- a/src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php +++ b/src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php @@ -10,7 +10,7 @@ public function __construct( NovaSeqHeaderSection $header, ReadsSection $reads, SettingsSection $settings, - DataSection $data + NovaSeqDataSection $data ) { $this->addSection($header); $this->addSection($reads); diff --git a/src/IlluminaSampleSheet/V1/NovaSeqXpDataSection.php b/src/IlluminaSampleSheet/V1/NovaSeqXpDataSection.php deleted file mode 100644 index 7537d05..0000000 --- a/src/IlluminaSampleSheet/V1/NovaSeqXpDataSection.php +++ /dev/null @@ -1,11 +0,0 @@ -description, ]); } + + public function toStringWithoutLane(): string + { + return implode(',', [ + $this->sampleId, + $this->sampleName, + $this->samplePlate, + $this->sampleWell, + $this->i7IndexId, + $this->index, + $this->i5IndexId, + $this->index2, + $this->sampleProject, + $this->description, + ]); + } } diff --git a/src/IlluminaSampleSheet/V1/NovaSeqXpSampleSheet.php b/src/IlluminaSampleSheet/V1/NovaSeqXpSampleSheet.php deleted file mode 100644 index d5bb252..0000000 --- a/src/IlluminaSampleSheet/V1/NovaSeqXpSampleSheet.php +++ /dev/null @@ -1,20 +0,0 @@ -addSection($header); - $this->addSection($reads); - $this->addSection($settings); - $this->addSection($data); - } -} diff --git a/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php b/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php index f08df32..cdc135c 100644 --- a/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php @@ -2,6 +2,8 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet\V1; +use MLL\Utils\IlluminaSampleSheet\V1\MiSeqDataSection; +use MLL\Utils\IlluminaSampleSheet\V1\MiSeqHeaderSection; use MLL\Utils\IlluminaSampleSheet\V1\MiSeqSample; use MLL\Utils\IlluminaSampleSheet\V1\MiSeqSampleSheet; use MLL\Utils\IlluminaSampleSheet\V1\ReadsSection; @@ -11,9 +13,9 @@ class MiSeqSampleSheetTest extends TestCase { public function testMiSeqSampleSheetToStringReturnsCorrectFormat(): void { - $headerSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\MiSeqHeaderSection::class); + $headerSection = $this->createMock(MiSeqHeaderSection::class); $readsSection = $this->createMock(ReadsSection::class); - $dataSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\DataSection::class); + $dataSection = $this->createMock(MiSeqDataSection::class); $miSeqSampleSheet = new MiSeqSampleSheet($headerSection, $readsSection, $dataSection); @@ -24,7 +26,7 @@ public function testMiSeqSampleSheetToStringReturnsCorrectFormat(): void public function testMiSeqSampleSheetToStringReturnsExpectedResult(): void { - $headerSection = new \MLL\Utils\IlluminaSampleSheet\V1\MiSeqHeaderSection( + $headerSection = new MiSeqHeaderSection( 'Run7906-ROUTINE', '03.04.2024', 'GenerateFASTQ - 3.0.1', @@ -37,11 +39,11 @@ public function testMiSeqSampleSheetToStringReturnsExpectedResult(): void $readsSection = new ReadsSection(150, 150); - $dataSection = new \MLL\Utils\IlluminaSampleSheet\V1\MiSeqDataSection(); + $dataSection = new MiSeqDataSection(); $dataSection->addSample(new MiSeqSample('1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A501', 'TGAACCTT')); $dataSection->addSample(new MiSeqSample('2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A502', 'TGCTAAGT')); - $dataSection->addSample(new \MLL\Utils\IlluminaSampleSheet\V1\MiSeqSample('3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A503', 'TGTTCTCT')); + $dataSection->addSample(new MiSeqSample('3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A503', 'TGTTCTCT')); $miSeqSampleSheet = new MiSeqSampleSheet($headerSection, $readsSection, $dataSection); diff --git a/tests/IlluminaSampleSheet/V1/NovaSeqHeaderSectionTest.php b/tests/IlluminaSampleSheet/V1/NovaSeqHeaderSectionTest.php deleted file mode 100644 index b3286fb..0000000 --- a/tests/IlluminaSampleSheet/V1/NovaSeqHeaderSectionTest.php +++ /dev/null @@ -1,27 +0,0 @@ -convertSectionToString()); - } -} diff --git a/tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php b/tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php index 61935cf..9ae1f9a 100644 --- a/tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php @@ -2,8 +2,11 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet\V1; -use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqSample; +use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqDataSection; +use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqHeaderSection; use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqSampleSheet; +use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqXpSample; +use MLL\Utils\IlluminaSampleSheet\V1\ReadsSection; use MLL\Utils\IlluminaSampleSheet\V1\SettingsSection; use PHPUnit\Framework\TestCase; @@ -11,10 +14,10 @@ class NovaSeqSampleSheetTest extends TestCase { public function testNovaSeqSampleSheetAddsSectionsOnConstruction(): void { - $headerSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\NovaSeqHeaderSection::class); - $readsSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\ReadsSection::class); - $settingsSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\SettingsSection::class); - $dataSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\DataSection::class); + $headerSection = $this->createMock(NovaSeqHeaderSection::class); + $readsSection = $this->createMock(ReadsSection::class); + $settingsSection = $this->createMock(SettingsSection::class); + $dataSection = $this->createMock(NovaSeqDataSection::class); $novaSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settingsSection, $dataSection); @@ -26,7 +29,7 @@ public function testNovaSeqSampleSheetAddsSectionsOnConstruction(): void public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): void { - $headerSection = new \MLL\Utils\IlluminaSampleSheet\V1\NovaSeqHeaderSection( + $headerSection = new NovaSeqHeaderSection( '4', 'DonalDuck', 'MyExperiment', @@ -38,16 +41,16 @@ public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): v 'MyChemistry', ); - $readsSection = new \MLL\Utils\IlluminaSampleSheet\V1\ReadsSection(101, 101); + $readsSection = new ReadsSection(101, 101); - $dataSection = new \MLL\Utils\IlluminaSampleSheet\V1\NovaSeqDataSection(); + $dataSection = new NovaSeqDataSection(); - $dataSection->addSample(new NovaSeqSample('1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description')); - $dataSection->addSample(new NovaSeqSample('2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description')); - $dataSection->addSample(new NovaSeqSample('3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description')); + $dataSection->addSample(new NovaSeqXpSample(1, '1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description')); + $dataSection->addSample(new NovaSeqXpSample(1, '2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description')); + $dataSection->addSample(new NovaSeqXpSample(1, '3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description')); $settings = new SettingsSection('AGATCGGAAGAGCACACGTCTGAACTCCAGTCA', 'AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT'); - $miSeqSampleSheet = new \MLL\Utils\IlluminaSampleSheet\V1\NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); + $miSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); $expected = '[Header] IEMFileVersion,4 @@ -70,6 +73,56 @@ public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): v 1,Sample-001-M001,RunXXXX-PLATE,,UDP0090,TCAGGCTT,UDP0090,ATCATGCG,RunXXXX-PROJECT,description 2,Sample-002-M002,RunXXXX-PLATE,,UDP0091,CCTTGTAG,UDP0091,CCTTGGAA,RunXXXX-PROJECT,description 3,Sample-003-M003,RunXXXX-PLATE,,UDP0092,GAACATCG,UDP0092,TCGACAAG,RunXXXX-PROJECT,description +'; + self::assertSame($expected, $miSeqSampleSheet->toString()); + } + + public function testNovaSeqXpSampleSheetWithLanesToStringReturnsExpectedResult(): void + { + $headerSection = new NovaSeqHeaderSection( + '4', + 'DonalDuck', + 'MyExperiment', + '19.04.2024', + 'MyWorkflow', + 'MyApplication', + 'MyAssay', + 'MyDescription', + 'MyChemistry', + ); + + $readsSection = new ReadsSection(101, 101); + + $dataSection = new NovaSeqDataSection(); + + $dataSection->addSample(new NovaSeqXpSample(2, '1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description')); + $dataSection->addSample(new NovaSeqXpSample(1, '2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description')); + $dataSection->addSample(new NovaSeqXpSample(4, '3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description')); + + $settings = new SettingsSection('AGATCGGAAGAGCACACGTCTGAACTCCAGTCA', 'AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT'); + $miSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); + + $expected = '[Header] +IEMFileVersion,4 +Investigator Name,DonalDuck +Experiment Name,MyExperiment +Date,19.04.2024 +Workflow,MyWorkflow +Application,MyApplication +Assay,MyAssay +Description,MyDescription +Chemistry,MyChemistry +[Reads] +101 +101 +[Settings] +Adapter,AGATCGGAAGAGCACACGTCTGAACTCCAGTCA +AdapterRead2,AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT +[Data] +Lane,Sample_ID,Sample_Name,Sample_Plate,Sample_Well,I7_Index_ID,Index,I5_Index_ID,Index2,Sample_Project,Description +2,1,Sample-001-M001,RunXXXX-PLATE,,UDP0090,TCAGGCTT,UDP0090,ATCATGCG,RunXXXX-PROJECT,description +1,2,Sample-002-M002,RunXXXX-PLATE,,UDP0091,CCTTGTAG,UDP0091,CCTTGGAA,RunXXXX-PROJECT,description +4,3,Sample-003-M003,RunXXXX-PLATE,,UDP0092,GAACATCG,UDP0092,TCGACAAG,RunXXXX-PROJECT,description '; self::assertSame($expected, $miSeqSampleSheet->toString()); } diff --git a/tests/IlluminaSampleSheet/V1/NovaSeqXpSampleSheetTest.php b/tests/IlluminaSampleSheet/V1/NovaSeqXpSampleSheetTest.php deleted file mode 100644 index e40e0c6..0000000 --- a/tests/IlluminaSampleSheet/V1/NovaSeqXpSampleSheetTest.php +++ /dev/null @@ -1,77 +0,0 @@ -createMock(NovaSeqHeaderSection::class); - $readsSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\ReadsSection::class); - $settingsSection = $this->createMock(SettingsSection::class); - $dataSection = $this->createMock(\MLL\Utils\IlluminaSampleSheet\V1\DataSection::class); - - $novaSeqSampleSheet = new \MLL\Utils\IlluminaSampleSheet\V1\NovaSeqXpSampleSheet($headerSection, $readsSection, $settingsSection, $dataSection); - - self::assertContains($headerSection, $novaSeqSampleSheet->getSections()); - self::assertContains($readsSection, $novaSeqSampleSheet->getSections()); - self::assertContains($settingsSection, $novaSeqSampleSheet->getSections()); - self::assertContains($dataSection, $novaSeqSampleSheet->getSections()); - } - - public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): void - { - $headerSection = new NovaSeqHeaderSection( - '4', - 'DonalDuck', - 'MyExperiment', - '19.04.2024', - 'MyWorkflow', - 'MyApplication', - 'MyAssay', - 'MyDescription', - 'MyChemistry', - ); - - $readsSection = new \MLL\Utils\IlluminaSampleSheet\V1\ReadsSection(101, 101); - - $dataSection = new NovaSeqXpDataSection(); - - $dataSection->addSample(new NovaSeqXpSample('2', '1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description')); - $dataSection->addSample(new NovaSeqXpSample('1', '2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description')); - $dataSection->addSample(new NovaSeqXpSample('4', '3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description')); - - $settings = new SettingsSection('AGATCGGAAGAGCACACGTCTGAACTCCAGTCA', 'AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT'); - $miSeqSampleSheet = new \MLL\Utils\IlluminaSampleSheet\V1\NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); - - $expected = '[Header] -IEMFileVersion,4 -Investigator Name,DonalDuck -Experiment Name,MyExperiment -Date,19.04.2024 -Workflow,MyWorkflow -Application,MyApplication -Assay,MyAssay -Description,MyDescription -Chemistry,MyChemistry -[Reads] -101 -101 -[Settings] -Adapter,AGATCGGAAGAGCACACGTCTGAACTCCAGTCA -AdapterRead2,AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT -[Data] -Lane,Sample_ID,Sample_Name,Sample_Plate,Sample_Well,I7_Index_ID,Index,I5_Index_ID,Index2,Sample_Project,Description -2,1,Sample-001-M001,RunXXXX-PLATE,,UDP0090,TCAGGCTT,UDP0090,ATCATGCG,RunXXXX-PROJECT,description -1,2,Sample-002-M002,RunXXXX-PLATE,,UDP0091,CCTTGTAG,UDP0091,CCTTGGAA,RunXXXX-PROJECT,description -4,3,Sample-003-M003,RunXXXX-PLATE,,UDP0092,GAACATCG,UDP0092,TCGACAAG,RunXXXX-PROJECT,description -'; - self::assertSame($expected, $miSeqSampleSheet->toString()); - } -} diff --git a/tests/IlluminaSampleSheet/V1/ReadsSectionTest.php b/tests/IlluminaSampleSheet/V1/ReadsSectionTest.php deleted file mode 100644 index 43c329d..0000000 --- a/tests/IlluminaSampleSheet/V1/ReadsSectionTest.php +++ /dev/null @@ -1,15 +0,0 @@ -convertSectionToString()); - } -} diff --git a/tests/IlluminaSampleSheet/V1/SettingsSectionTest.php b/tests/IlluminaSampleSheet/V1/SettingsSectionTest.php deleted file mode 100644 index 357451f..0000000 --- a/tests/IlluminaSampleSheet/V1/SettingsSectionTest.php +++ /dev/null @@ -1,15 +0,0 @@ -convertSectionToString()); - } -} diff --git a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php index da8c73c..336b5e8 100644 --- a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php @@ -2,6 +2,10 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet\V2; +use MLL\Utils\IlluminaSampleSheet\V2\BclConvertDataSection; +use MLL\Utils\IlluminaSampleSheet\V2\BclConvertSettingsSection; +use MLL\Utils\IlluminaSampleSheet\V2\CloudDataSection; +use MLL\Utils\IlluminaSampleSheet\V2\CloudSettingsSection; use MLL\Utils\IlluminaSampleSheet\V2\HeaderSection; use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudSampleSheet; use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudSequencingSettingsSection; @@ -26,16 +30,16 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi ); $sequenceSettingsSection = new NovaSeqXCloudSequencingSettingsSection('Settings1'); - $bclConvertSettingsSection = new \MLL\Utils\IlluminaSampleSheet\V2\BclConvertSettingsSection('1.0.0', '0', 'gzip'); + $bclConvertSettingsSection = new BclConvertSettingsSection('1.0.0', '0', 'gzip'); - $bclConvertDataSection = new \MLL\Utils\IlluminaSampleSheet\V2\BclConvertDataSection(); + $bclConvertDataSection = new BclConvertDataSection(); $bclConvertDataSection->addSample(1, 'Sample1', 'Index1', 'Index2', 'Cycles1', 'Adapter1', 'Adapter2'); $bclConvertDataSection->addSample(2, 'Sample2', 'Index3', 'Index4', 'Cycles2', 'Adapter3', 'Adapter4'); $bclConvertDataSection->addSample(3, 'Sample3', 'Index5', 'Index6', 'Cycles3', 'Adapter5', 'Adapter6'); - $cloudSettingsSection = new \MLL\Utils\IlluminaSampleSheet\V2\CloudSettingsSection('1.0.0', 'Workflow1', 'Pipeline1'); + $cloudSettingsSection = new CloudSettingsSection('1.0.0', 'Workflow1', 'Pipeline1'); - $cloudDataSection = new \MLL\Utils\IlluminaSampleSheet\V2\CloudDataSection(); + $cloudDataSection = new CloudDataSection(); $cloudDataSection->addSample('Sample4', 'Project1', 'Library1', 'Kit1', 'AdapterKit1'); $cloudDataSection->addSample('Sample5', 'Project2', 'Library2', 'Kit2', 'AdapterKit2'); $cloudDataSection->addSample('Sample6', 'Project3', 'Library3', 'Kit3', 'AdapterKit3'); From 465f5d1a29f6e7fce6dbf6e347f0428c050555d4 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Wed, 24 Apr 2024 10:46:38 +0200 Subject: [PATCH 07/29] MiSeq header --- .../V1/MiSeqHeaderSection.php | 105 ++++++++++++------ .../V1/MiSeqSampleSheetTest.php | 3 +- 2 files changed, 73 insertions(+), 35 deletions(-) diff --git a/src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php b/src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php index b46aced..707c070 100644 --- a/src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php +++ b/src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php @@ -2,59 +2,96 @@ namespace MLL\Utils\IlluminaSampleSheet\V1; +use Carbon\Carbon; use MLL\Utils\IlluminaSampleSheet\SectionInterface; class MiSeqHeaderSection implements SectionInterface { - public string $experimentName; + public ?string $experimentName; - public string $date; + public ?Carbon $date; - public string $module; + public ?string $module; - public string $workflow; + public ?string $workflow; - public string $libraryPrepKit; + public ?string $libraryPrepKit; - public string $indexKit; + public ?string $indexKit; - public string $description; + public ?string $description; - public string $chemistry; + public ?string $chemistry; public function __construct( - string $experimentName, - string $date, - string $module, - string $workflow, - string $libraryPrepKit, - string $indexKit, - string $description, - string $chemistry + ?string $experimentName, + ?Carbon $date, + ?string $module, + ?string $workflow, + ?string $libraryPrepKit, + ?string $indexKit, + ?string $description, + ?string $chemistry ) { - $this->experimentName = $experimentName; + $this->experimentName = $this->validateString($experimentName, 'Experiment Name'); $this->date = $date; - $this->module = $module; - $this->workflow = $workflow; - $this->libraryPrepKit = $libraryPrepKit; - $this->indexKit = $indexKit; - $this->description = $description; - $this->chemistry = $chemistry; + $this->module = $this->validateString($module, 'Module'); + $this->workflow = $this->validateString($workflow, 'Workflow'); + $this->libraryPrepKit = $this->validateString($libraryPrepKit, 'Library Prep Kit'); + $this->indexKit = $this->validateString($indexKit, 'Index Kit'); + $this->description = $this->validateString($description, 'Description'); + $this->chemistry = $this->validateString($chemistry, 'Chemistry'); + } + + private function validateString(?string $value, string $fieldName): ?string + { + if ($value === null) { + return null; + } + + $trimmedValue = trim($value); + if ($trimmedValue === '') { + throw new \InvalidArgumentException("{$fieldName} cannot be empty."); + } + + return $trimmedValue; } public function convertSectionToString(): string { - $headerLines = [ - '[Header]', - "Experiment Name,{$this->experimentName}", - "Date,{$this->date}", - "Module,{$this->module}", - "Workflow,{$this->workflow}", - "Library Prep Kit,{$this->libraryPrepKit}", - "Index Kit,{$this->indexKit}", - "Description,{$this->description}", - "Chemistry,{$this->chemistry}", - ]; + $headerLines = ['[Header]']; + + if ($this->experimentName !== null) { + $headerLines[] = "Experiment Name,{$this->experimentName}"; + } + + if ($this->date instanceof Carbon) { + $headerLines[] = "Date,{$this->date->format('d.m.Y')}"; + } + + if ($this->module !== null) { + $headerLines[] = "Module,{$this->module}"; + } + + if ($this->workflow !== null) { + $headerLines[] = "Workflow,{$this->workflow}"; + } + + if ($this->libraryPrepKit !== null) { + $headerLines[] = "Library Prep Kit,{$this->libraryPrepKit}"; + } + + if ($this->indexKit !== null) { + $headerLines[] = "Index Kit,{$this->indexKit}"; + } + + if ($this->description !== null) { + $headerLines[] = "Description,{$this->description}"; + } + + if ($this->chemistry !== null) { + $headerLines[] = "Chemistry,{$this->chemistry}"; + } return implode("\n", $headerLines); } diff --git a/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php b/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php index cdc135c..1f2702e 100644 --- a/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php @@ -2,6 +2,7 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet\V1; +use Carbon\Carbon; use MLL\Utils\IlluminaSampleSheet\V1\MiSeqDataSection; use MLL\Utils\IlluminaSampleSheet\V1\MiSeqHeaderSection; use MLL\Utils\IlluminaSampleSheet\V1\MiSeqSample; @@ -28,7 +29,7 @@ public function testMiSeqSampleSheetToStringReturnsExpectedResult(): void { $headerSection = new MiSeqHeaderSection( 'Run7906-ROUTINE', - '03.04.2024', + Carbon::createStrict(2024, 4, 3, 12, 1, 1), 'GenerateFASTQ - 3.0.1', 'GenerateFASTQ', 'Illumina DNA Prep', From 57c6d87054a576379c7f956630fdc80a4154df31 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Wed, 24 Apr 2024 12:21:41 +0200 Subject: [PATCH 08/29] flexible data section --- src/IlluminaSampleSheet/V1/DataInterface.php | 12 +++ src/IlluminaSampleSheet/V1/DataSection.php | 62 +++++++++++++ .../V1/MiSeqDataSection.php | 32 ------- src/IlluminaSampleSheet/V1/MiSeqSample.php | 61 ------------- .../V1/MiSeqSampleSheet.php | 2 +- .../V1/NovaSeqDataSection.php | 42 --------- .../V1/NovaSeqSampleSheet.php | 2 +- .../V1/NovaSeqXpSample.php | 87 ------------------- src/IlluminaSampleSheet/V1/Sample.php | 12 +-- .../V1/SampleSheetData.php | 34 ++++++++ .../V1/MiSeqSampleSheetTest.php | 19 ++-- .../V1/NovaSeqSampleSheetTest.php | 30 ++++--- 12 files changed, 142 insertions(+), 253 deletions(-) create mode 100644 src/IlluminaSampleSheet/V1/DataInterface.php create mode 100644 src/IlluminaSampleSheet/V1/DataSection.php delete mode 100644 src/IlluminaSampleSheet/V1/MiSeqDataSection.php delete mode 100644 src/IlluminaSampleSheet/V1/MiSeqSample.php delete mode 100644 src/IlluminaSampleSheet/V1/NovaSeqDataSection.php delete mode 100644 src/IlluminaSampleSheet/V1/NovaSeqXpSample.php create mode 100644 src/IlluminaSampleSheet/V1/SampleSheetData.php diff --git a/src/IlluminaSampleSheet/V1/DataInterface.php b/src/IlluminaSampleSheet/V1/DataInterface.php new file mode 100644 index 0000000..eeac13e --- /dev/null +++ b/src/IlluminaSampleSheet/V1/DataInterface.php @@ -0,0 +1,12 @@ + */ + public function getColumns(): array; + + /** @return array> */ + public function getRows(): array; +} diff --git a/src/IlluminaSampleSheet/V1/DataSection.php b/src/IlluminaSampleSheet/V1/DataSection.php new file mode 100644 index 0000000..943dc67 --- /dev/null +++ b/src/IlluminaSampleSheet/V1/DataSection.php @@ -0,0 +1,62 @@ +data = $data; + } + + public function convertSectionToString(): string + { + $this->validateData(); + + $header = implode(',', $this->data->getColumns()); + $rows = []; + foreach ($this->data->getRows() as $rowData) { + $rows[] = implode(',', $rowData); + } + + return "[Data]\n{$header}\n" . implode("\n", $rows) . "\n"; + } + + private function validateData(): void + { + $columns = $this->data->getColumns(); + $rows = $this->data->getRows(); + + if (! in_array('Sample_ID', $columns, true)) { + throw new \InvalidArgumentException('Sample_ID column is required.'); + } + + $this->uniqueSampleIDs($columns, $rows); + } + + private function uniqueSampleIDs(array $columns, array $rows): void + { + $columnKey = array_search('Sample_ID', $columns, true); + assert($columnKey !== false); + + $sampleIDs = array_column($rows, $columnKey); + if (count($sampleIDs) !== count(array_unique($sampleIDs))) { + throw new \InvalidArgumentException('Sample_ID values must be distinct.'); + } + } + + protected function validateIndex(string $index): string + { + if (! (bool) preg_match('/^[ATCGN]+$/', $index)) { + throw new IlluminaSampleSheetException('Index contains invalid characters. Only A, T, C, G, N are allowed.'); + } + + return $index; + } +} diff --git a/src/IlluminaSampleSheet/V1/MiSeqDataSection.php b/src/IlluminaSampleSheet/V1/MiSeqDataSection.php deleted file mode 100644 index 4327354..0000000 --- a/src/IlluminaSampleSheet/V1/MiSeqDataSection.php +++ /dev/null @@ -1,32 +0,0 @@ - */ - private array $samples = []; - - public function addSample(MiSeqSample $sample): void - { - $this->samples[] = $sample; - } - - public function convertSectionToString(): string - { - $dataLines = ["[Data]\n{$this->dataSectionHeader()}"]; - - foreach ($this->samples as $sample) { - $dataLines[] = $sample->toString(); - } - - return implode("\n", $dataLines) . "\n"; - } - - public function dataSectionHeader(): string - { - return 'Sample_ID,Sample_Name,Sample_Plate,Sample_Well,Sample_Project,I7_Index_ID,Index,I5_Index_ID,Index2'; - } -} diff --git a/src/IlluminaSampleSheet/V1/MiSeqSample.php b/src/IlluminaSampleSheet/V1/MiSeqSample.php deleted file mode 100644 index d3f4119..0000000 --- a/src/IlluminaSampleSheet/V1/MiSeqSample.php +++ /dev/null @@ -1,61 +0,0 @@ -sampleId = $this->validateSampleId($sampleId); - $this->sampleName = $this->validateSampleName($sampleName); - $this->samplePlate = $samplePlate; - $this->sampleWell = $sampleWell; - $this->sampleProject = $sampleProject; - $this->i7IndexId = $i7IndexId; - $this->index = $this->validateIndex($index); - $this->i5IndexId = $i5IndexId; - $this->index2 = $this->validateIndex($index2); - } - - public function toString(): string - { - return implode(',', [ - $this->sampleId, - $this->sampleName, - $this->samplePlate, - $this->sampleWell, - $this->sampleProject, - $this->i7IndexId, - $this->index, - $this->i5IndexId, - $this->index2, - ]); - } -} diff --git a/src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php b/src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php index 03ad602..3dd8530 100644 --- a/src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php +++ b/src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php @@ -9,7 +9,7 @@ class MiSeqSampleSheet extends SampleSheet public function __construct( MiSeqHeaderSection $header, ReadsSection $reads, - MiSeqDataSection $data + DataSection $data ) { $this->addSection($header); $this->addSection($reads); diff --git a/src/IlluminaSampleSheet/V1/NovaSeqDataSection.php b/src/IlluminaSampleSheet/V1/NovaSeqDataSection.php deleted file mode 100644 index 5b1ae7d..0000000 --- a/src/IlluminaSampleSheet/V1/NovaSeqDataSection.php +++ /dev/null @@ -1,42 +0,0 @@ - */ - private array $samples = []; - - public function addSample(NovaSeqXpSample $sample): void - { - $this->samples[] = $sample; - } - - public function convertSectionToString(): string - { - $dataLines = ["[Data]\n{$this->dataSectionHeader()}"]; - $requiresLanesColumn = $this->requiresLanesColumn(); - - foreach ($this->samples as $sample) { - $dataLines[] = $requiresLanesColumn ? $sample->toStringWithoutLane() : $sample->toString(); - } - - return implode("\n", $dataLines) . "\n"; - } - - private function dataSectionHeader(): string - { - if ($this->requiresLanesColumn()) { - return 'Sample_ID,Sample_Name,Sample_Plate,Sample_Well,I7_Index_ID,Index,I5_Index_ID,Index2,Sample_Project,Description'; - } - - return 'Lane,Sample_ID,Sample_Name,Sample_Plate,Sample_Well,I7_Index_ID,Index,I5_Index_ID,Index2,Sample_Project,Description'; - } - - private function requiresLanesColumn(): bool - { - return count(array_unique(array_map(fn (NovaSeqXpSample $sample) => $sample->lane, $this->samples))) === 1; - } -} diff --git a/src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php b/src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php index 142b162..66ad37f 100644 --- a/src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php +++ b/src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php @@ -10,7 +10,7 @@ public function __construct( NovaSeqHeaderSection $header, ReadsSection $reads, SettingsSection $settings, - NovaSeqDataSection $data + DataSection $data ) { $this->addSection($header); $this->addSection($reads); diff --git a/src/IlluminaSampleSheet/V1/NovaSeqXpSample.php b/src/IlluminaSampleSheet/V1/NovaSeqXpSample.php deleted file mode 100644 index 8e10593..0000000 --- a/src/IlluminaSampleSheet/V1/NovaSeqXpSample.php +++ /dev/null @@ -1,87 +0,0 @@ -lane = $lane; - $this->sampleId = $this->validateSampleId($sampleId); - $this->sampleName = $this->validateSampleName($sampleName); - $this->samplePlate = $samplePlate; - $this->sampleWell = $sampleWell; - $this->i7IndexId = $i7IndexId; - $this->index = $this->validateIndex($index); - $this->i5IndexId = $i5IndexId; - $this->index2 = $this->validateIndex($index2); - $this->sampleProject = $sampleProject; - $this->description = $description; - } - - public function toString(): string - { - return implode(',', [ - $this->lane, - $this->sampleId, - $this->sampleName, - $this->samplePlate, - $this->sampleWell, - $this->i7IndexId, - $this->index, - $this->i5IndexId, - $this->index2, - $this->sampleProject, - $this->description, - ]); - } - - public function toStringWithoutLane(): string - { - return implode(',', [ - $this->sampleId, - $this->sampleName, - $this->samplePlate, - $this->sampleWell, - $this->i7IndexId, - $this->index, - $this->i5IndexId, - $this->index2, - $this->sampleProject, - $this->description, - ]); - } -} diff --git a/src/IlluminaSampleSheet/V1/Sample.php b/src/IlluminaSampleSheet/V1/Sample.php index 2ad7a2b..2c3059a 100644 --- a/src/IlluminaSampleSheet/V1/Sample.php +++ b/src/IlluminaSampleSheet/V1/Sample.php @@ -3,19 +3,13 @@ namespace MLL\Utils\IlluminaSampleSheet\V1; use MLL\Utils\IlluminaSampleSheet\IlluminaSampleSheetException; +use function Safe\preg_match; abstract class Sample { abstract public function toString(): string; - protected function validateIndex(string $index): string - { - if (! $this->isValidNucleotidSequence($index)) { - throw new IlluminaSampleSheetException('Index contains invalid characters. Only A, T, C, G, N are allowed.'); - } - return $index; - } protected function validateSampleId(string $sampleId): string { @@ -35,8 +29,4 @@ protected function validateSampleName(string $sampleName): string return $sampleName; } - protected function isValidNucleotidSequence(string $index): bool - { - return (bool) \Safe\preg_match('/^[ATCGN]+$/', $index); - } } diff --git a/src/IlluminaSampleSheet/V1/SampleSheetData.php b/src/IlluminaSampleSheet/V1/SampleSheetData.php new file mode 100644 index 0000000..877b107 --- /dev/null +++ b/src/IlluminaSampleSheet/V1/SampleSheetData.php @@ -0,0 +1,34 @@ + */ + private array $columns; + + /** @var array> */ + private array $rows; + + /** + * @param array $columns + * @param array> $rows + */ + public function __construct(array $columns, array $rows) + { + $this->columns = $columns; + $this->rows = $rows; + } + + /** {@inheritDoc} */ + public function getColumns(): array + { + return $this->columns; + } + + /** {@inheritDoc} */ + public function getRows(): array + { + return $this->rows; + } +} diff --git a/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php b/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php index 1f2702e..d1f41e1 100644 --- a/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php @@ -3,11 +3,11 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet\V1; use Carbon\Carbon; -use MLL\Utils\IlluminaSampleSheet\V1\MiSeqDataSection; +use MLL\Utils\IlluminaSampleSheet\V1\DataSection; use MLL\Utils\IlluminaSampleSheet\V1\MiSeqHeaderSection; -use MLL\Utils\IlluminaSampleSheet\V1\MiSeqSample; use MLL\Utils\IlluminaSampleSheet\V1\MiSeqSampleSheet; use MLL\Utils\IlluminaSampleSheet\V1\ReadsSection; +use MLL\Utils\IlluminaSampleSheet\V1\SampleSheetData; use PHPUnit\Framework\TestCase; class MiSeqSampleSheetTest extends TestCase @@ -16,7 +16,7 @@ public function testMiSeqSampleSheetToStringReturnsCorrectFormat(): void { $headerSection = $this->createMock(MiSeqHeaderSection::class); $readsSection = $this->createMock(ReadsSection::class); - $dataSection = $this->createMock(MiSeqDataSection::class); + $dataSection = $this->createMock(DataSection::class); $miSeqSampleSheet = new MiSeqSampleSheet($headerSection, $readsSection, $dataSection); @@ -40,11 +40,16 @@ public function testMiSeqSampleSheetToStringReturnsExpectedResult(): void $readsSection = new ReadsSection(150, 150); - $dataSection = new MiSeqDataSection(); + $columns = ['Sample_ID', 'Sample_Name', 'Sample_Plate', 'Sample_Well', 'Sample_Project', 'I7_Index_ID', 'Index', 'I5_Index_ID', 'Index2']; + $rows = [ + ['1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A501', 'TGAACCTT'], + ['2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A502', 'TGCTAAGT'], + ['3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A503', 'TGTTCTCT'], + ]; - $dataSection->addSample(new MiSeqSample('1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A501', 'TGAACCTT')); - $dataSection->addSample(new MiSeqSample('2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A502', 'TGCTAAGT')); - $dataSection->addSample(new MiSeqSample('3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A503', 'TGTTCTCT')); + $sampleSheetData = new SampleSheetData($columns, $rows); + + $dataSection = new DataSection($sampleSheetData); $miSeqSampleSheet = new MiSeqSampleSheet($headerSection, $readsSection, $dataSection); diff --git a/tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php b/tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php index 9ae1f9a..95ec3b8 100644 --- a/tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php @@ -2,11 +2,11 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet\V1; -use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqDataSection; +use MLL\Utils\IlluminaSampleSheet\V1\DataSection; use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqHeaderSection; use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqSampleSheet; -use MLL\Utils\IlluminaSampleSheet\V1\NovaSeqXpSample; use MLL\Utils\IlluminaSampleSheet\V1\ReadsSection; +use MLL\Utils\IlluminaSampleSheet\V1\SampleSheetData; use MLL\Utils\IlluminaSampleSheet\V1\SettingsSection; use PHPUnit\Framework\TestCase; @@ -17,7 +17,7 @@ public function testNovaSeqSampleSheetAddsSectionsOnConstruction(): void $headerSection = $this->createMock(NovaSeqHeaderSection::class); $readsSection = $this->createMock(ReadsSection::class); $settingsSection = $this->createMock(SettingsSection::class); - $dataSection = $this->createMock(NovaSeqDataSection::class); + $dataSection = $this->createMock(DataSection::class); $novaSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settingsSection, $dataSection); @@ -43,11 +43,15 @@ public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): v $readsSection = new ReadsSection(101, 101); - $dataSection = new NovaSeqDataSection(); + $columns = ['Sample_ID', 'Sample_Name', 'Sample_Plate', 'Sample_Well', 'I7_Index_ID', 'Index', 'I5_Index_ID', 'Index2', 'Sample_Project', 'Description']; + $rows = [ + ['1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description'], + ['2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description'], + ['3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description'], + ]; - $dataSection->addSample(new NovaSeqXpSample(1, '1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description')); - $dataSection->addSample(new NovaSeqXpSample(1, '2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description')); - $dataSection->addSample(new NovaSeqXpSample(1, '3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description')); + $sampleSheetData = new SampleSheetData($columns, $rows); + $dataSection = new DataSection($sampleSheetData); $settings = new SettingsSection('AGATCGGAAGAGCACACGTCTGAACTCCAGTCA', 'AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT'); $miSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); @@ -93,11 +97,15 @@ public function testNovaSeqXpSampleSheetWithLanesToStringReturnsExpectedResult() $readsSection = new ReadsSection(101, 101); - $dataSection = new NovaSeqDataSection(); + $columns = ['Lane', 'Sample_ID', 'Sample_Name', 'Sample_Plate', 'Sample_Well', 'I7_Index_ID', 'Index', 'I5_Index_ID', 'Index2', 'Sample_Project', 'Description']; + $rows = [ + [2, '1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description'], + [1, '2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description'], + [4, '3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description'], + ]; - $dataSection->addSample(new NovaSeqXpSample(2, '1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description')); - $dataSection->addSample(new NovaSeqXpSample(1, '2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description')); - $dataSection->addSample(new NovaSeqXpSample(4, '3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description')); + $sampleSheetData = new SampleSheetData($columns, $rows); + $dataSection = new DataSection($sampleSheetData); $settings = new SettingsSection('AGATCGGAAGAGCACACGTCTGAACTCCAGTCA', 'AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT'); $miSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); From 44277ca879e51e6168f135fd5c4b40812e1ec230 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Wed, 24 Apr 2024 12:45:15 +0200 Subject: [PATCH 09/29] validate index --- src/IlluminaSampleSheet/V1/DataInterface.php | 7 ++++- src/IlluminaSampleSheet/V1/DataSection.php | 31 ++++++++++++++----- src/IlluminaSampleSheet/V1/Sample.php | 32 -------------------- 3 files changed, 29 insertions(+), 41 deletions(-) delete mode 100644 src/IlluminaSampleSheet/V1/Sample.php diff --git a/src/IlluminaSampleSheet/V1/DataInterface.php b/src/IlluminaSampleSheet/V1/DataInterface.php index eeac13e..466fa9f 100644 --- a/src/IlluminaSampleSheet/V1/DataInterface.php +++ b/src/IlluminaSampleSheet/V1/DataInterface.php @@ -2,11 +2,16 @@ namespace MLL\Utils\IlluminaSampleSheet\V1; +use MLL\Utils\CSVArray; + +/** + * @phpstan-import-type CSVPrimitive from CSVArray + */ interface DataInterface { /** @return array */ public function getColumns(): array; - /** @return array> */ + /** @return array> */ public function getRows(): array; } diff --git a/src/IlluminaSampleSheet/V1/DataSection.php b/src/IlluminaSampleSheet/V1/DataSection.php index 943dc67..7f69af3 100644 --- a/src/IlluminaSampleSheet/V1/DataSection.php +++ b/src/IlluminaSampleSheet/V1/DataSection.php @@ -2,10 +2,15 @@ namespace MLL\Utils\IlluminaSampleSheet\V1; +use MLL\Utils\CSVArray; use MLL\Utils\IlluminaSampleSheet\IlluminaSampleSheetException; use MLL\Utils\IlluminaSampleSheet\SectionInterface; + use function Safe\preg_match; +/** + * @phpstan-import-type CSVPrimitive from CSVArray + */ class DataSection implements SectionInterface { private DataInterface $data; @@ -37,24 +42,34 @@ private function validateData(): void throw new \InvalidArgumentException('Sample_ID column is required.'); } - $this->uniqueSampleIDs($columns, $rows); - } - - private function uniqueSampleIDs(array $columns, array $rows): void - { $columnKey = array_search('Sample_ID', $columns, true); assert($columnKey !== false); $sampleIDs = array_column($rows, $columnKey); if (count($sampleIDs) !== count(array_unique($sampleIDs))) { - throw new \InvalidArgumentException('Sample_ID values must be distinct.'); + throw new IlluminaSampleSheetException('Sample_ID values must be distinct.'); + } + + // validate Index-Column to be a valid index + if (in_array('Index', $columns, true)) { + $indexKey = array_search('Index', $columns, true); + assert($indexKey !== false); + $indexes = array_column($rows, $indexKey); + foreach ($indexes as $index) { + $this->validateIndex($index); + } } } - protected function validateIndex(string $index): string + /** @param CSVPrimitive $index */ + protected function validateIndex($index): string { + if (! is_string($index)) { + throw new IlluminaSampleSheetException('Index must be a string.'); + } + if (! (bool) preg_match('/^[ATCGN]+$/', $index)) { - throw new IlluminaSampleSheetException('Index contains invalid characters. Only A, T, C, G, N are allowed.'); + throw new IlluminaSampleSheetException("Index '{$index}' contains invalid characters. Only A, T, C, G, N are allowed."); } return $index; diff --git a/src/IlluminaSampleSheet/V1/Sample.php b/src/IlluminaSampleSheet/V1/Sample.php deleted file mode 100644 index 2c3059a..0000000 --- a/src/IlluminaSampleSheet/V1/Sample.php +++ /dev/null @@ -1,32 +0,0 @@ - Date: Wed, 24 Apr 2024 14:16:55 +0200 Subject: [PATCH 10/29] Update phpunit cli --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 50f420f..a25e4ec 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ stan: vendor ## Runs a static analysis with phpstan .PHONY: test test: vendor ## Runs auto-review, unit, and integration tests with phpunit mkdir --parents .build/phpunit - vendor/bin/phpunit --cache-result-file=.build/phpunit/result.cache + vendor/bin/phpunit --cache-directory=.build/phpunit vendor: composer.json composer validate --strict From 5afda9f3644b612435e904203e4e835b043ff67e Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Wed, 24 Apr 2024 14:38:16 +0200 Subject: [PATCH 11/29] DataProvider-Attribute --- .gitignore | 1 - tests/BavarianHolidaysTest.php | 6 +++--- tests/CSVArrayTest.php | 7 ++----- tests/Microplate/CoordinateSystemTest.php | 2 +- tests/Microplate/CoordinatesTest.php | 18 +++++++++--------- .../MicroplateSet/MicroplateSetABCDTest.php | 4 ++-- .../MicroplateSet/MicroplateSetABTest.php | 4 ++-- tests/NumberTest.php | 3 +-- tests/StringUtilTest.php | 16 +++++----------- 9 files changed, 25 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 4c8de23..468ff9e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ /.idea /vendor /composer.lock -/.phpunit.result.cache diff --git a/tests/BavarianHolidaysTest.php b/tests/BavarianHolidaysTest.php index 77d55a4..b68421e 100644 --- a/tests/BavarianHolidaysTest.php +++ b/tests/BavarianHolidaysTest.php @@ -15,21 +15,21 @@ public function testNameHoliday(): void self::assertSame(BavarianHolidays::OSTERSONNTAG, BavarianHolidays::nameHoliday(self::easterSunday2019())); } - /** @dataProvider businessDays */ + #[\PHPUnit\Framework\Attributes\DataProvider('businessDays')] public function testBusinessDays(Carbon $businessDay): void { self::assertTrue(BavarianHolidays::isBusinessDay($businessDay)); self::assertFalse(BavarianHolidays::isHoliday($businessDay)); } - /** @dataProvider holidays */ + #[\PHPUnit\Framework\Attributes\DataProvider('holidays')] public function testHolidays(Carbon $holiday): void { self::assertFalse(BavarianHolidays::isBusinessDay($holiday)); self::assertTrue(BavarianHolidays::isHoliday($holiday)); } - /** @dataProvider weekend */ + #[\PHPUnit\Framework\Attributes\DataProvider('weekend')] public function testWeekend(Carbon $weekend): void { self::assertFalse(BavarianHolidays::isBusinessDay($weekend)); diff --git a/tests/CSVArrayTest.php b/tests/CSVArrayTest.php index 6ce0500..8827d68 100644 --- a/tests/CSVArrayTest.php +++ b/tests/CSVArrayTest.php @@ -41,11 +41,8 @@ public static function csvAndArrayStringValues(): iterable ]; } - /** - * @dataProvider csvAndArrayStringValues - * - * @param array> $array - */ + /** @param array> $array */ + #[\PHPUnit\Framework\Attributes\DataProvider('csvAndArrayStringValues')] public function testStringValues(string $csv, array $array): void { self::assertSame($array, CSVArray::toArray($csv)); diff --git a/tests/Microplate/CoordinateSystemTest.php b/tests/Microplate/CoordinateSystemTest.php index 923b61a..457daaf 100644 --- a/tests/Microplate/CoordinateSystemTest.php +++ b/tests/Microplate/CoordinateSystemTest.php @@ -10,7 +10,7 @@ final class CoordinateSystemTest extends TestCase { - /** @dataProvider firstLast */ + #[\PHPUnit\Framework\Attributes\DataProvider('firstLast')] public function testFirstLast(CoordinateSystem $coordinateSystem, string $expectedFirst, string $expectedLast): void { $actualFirst = $coordinateSystem->first(); diff --git a/tests/Microplate/CoordinatesTest.php b/tests/Microplate/CoordinatesTest.php index 8609c70..330adba 100644 --- a/tests/Microplate/CoordinatesTest.php +++ b/tests/Microplate/CoordinatesTest.php @@ -10,7 +10,7 @@ final class CoordinatesTest extends TestCase { - /** @dataProvider dataProvider96Well */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] public function testCanConstructFromRowAndColumn(string $row, int $column, int $rowFlowPosition, int $columnFlowPosition): void { $coordinates96Well = new Coordinates($row, $column, new CoordinateSystem96Well()); @@ -18,7 +18,7 @@ public function testCanConstructFromRowAndColumn(string $row, int $column, int $ self::assertSame($row . $column, $coordinates96Well->toString()); } - /** @dataProvider dataProvider96Well */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] public function testCanConstructFromPosition(string $row, int $column, int $rowFlowPosition, int $columnFlowPosition): void { // test for Column-FlowDirection @@ -40,7 +40,7 @@ public function testCanConstructFromPosition(string $row, int $column, int $rowF self::assertSame($column, $coordinates->column); } - /** @dataProvider dataProvider96Well */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] public function testFromCoordinatesString(string $row, int $column, int $rowFlowPosition, int $columnFlowPosition): void { $coordinates = Coordinates::fromString($row . $column, new CoordinateSystem96Well()); @@ -48,7 +48,7 @@ public function testFromCoordinatesString(string $row, int $column, int $rowFlow self::assertSame($column, $coordinates->column); } - /** @dataProvider dataProviderPadded96Well */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderPadded96Well')] public function testFromPaddedCoordinatesString(string $paddedCoordinates, string $row, int $column): void { $coordinatesFromPadded = Coordinates::fromString($paddedCoordinates, new CoordinateSystem96Well()); @@ -88,7 +88,7 @@ public static function dataProviderPadded96Well(): iterable ]; } - /** @dataProvider dataProvider96Well */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] public function testPosition96Well(string $row, int $column, int $rowFlowPosition, int $columnFlowPosition): void { $coordinates = new Coordinates($row, $column, new CoordinateSystem96Well()); @@ -684,7 +684,7 @@ public static function dataProvider96Well(): iterable ]; } - /** @dataProvider dataProvider12Well */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider12Well')] public function testPosition12Well(string $row, int $column, int $rowFlowPosition, int $columnFlowPosition): void { $coordinates = new Coordinates($row, $column, new CoordinateSystem12Well()); @@ -771,7 +771,7 @@ public static function dataProvider12Well(): array ]; } - /** @dataProvider invalidRowsOrColumns */ + #[\PHPUnit\Framework\Attributes\DataProvider('invalidRowsOrColumns')] public function testThrowsOnInvalidRowsOrColumns(string $row, int $column): void { $this->expectException(\InvalidArgumentException::class); @@ -789,7 +789,7 @@ public static function invalidRowsOrColumns(): iterable yield ['rolf', 2]; } - /** @dataProvider invalidPositions */ + #[\PHPUnit\Framework\Attributes\DataProvider('invalidPositions')] public function testThrowsOnInvalidPositions(int $position): void { $this->expectException(\InvalidArgumentException::class); @@ -805,7 +805,7 @@ public static function invalidPositions(): iterable yield [10000]; } - /** @dataProvider invalidCoordinates */ + #[\PHPUnit\Framework\Attributes\DataProvider('invalidCoordinates')] public function testThrowsOnInvalidCoordinates(string $coordinatesString): void { $this->expectException(\InvalidArgumentException::class); diff --git a/tests/Microplate/MicroplateSet/MicroplateSetABCDTest.php b/tests/Microplate/MicroplateSet/MicroplateSetABCDTest.php index 81fc89b..613d605 100644 --- a/tests/Microplate/MicroplateSet/MicroplateSetABCDTest.php +++ b/tests/Microplate/MicroplateSet/MicroplateSetABCDTest.php @@ -46,7 +46,7 @@ public function testSetLocationFromSetPositionFor12WellPlatesOutOfRangeTooLow(): $microplateSet->locationFromPosition($setPositionLowerThanMin, FlowDirection::COLUMN()); } - /** @dataProvider dataProvider12Well */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider12Well')] public function testSetLocationFromSetPositionFor12Wells(int $position, string $coordinatesString, string $plateID): void { $microplateSet = new MicroplateSetABCD(new CoordinateSystem12Well()); @@ -91,7 +91,7 @@ public static function dataProvider12Well(): iterable ]; } - /** @dataProvider dataProvider96Well */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] public function testSetLocationFromSetPositionFor96Wells(int $position, string $coordinatesString, string $plateID): void { $microplateSet = new MicroplateSetABCD(new CoordinateSystem96Well()); diff --git a/tests/Microplate/MicroplateSet/MicroplateSetABTest.php b/tests/Microplate/MicroplateSet/MicroplateSetABTest.php index 6976d1a..01c6392 100644 --- a/tests/Microplate/MicroplateSet/MicroplateSetABTest.php +++ b/tests/Microplate/MicroplateSet/MicroplateSetABTest.php @@ -46,7 +46,7 @@ public function testSetLocationFromSetPositionFor12WellPlatesOutOfRangeTooLow(): $microplateSet->locationFromPosition($setPositionLowerThanMin, FlowDirection::COLUMN()); } - /** @dataProvider dataProvider12Well */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider12Well')] public function testSetLocationFromSetPositionFor12Wells(int $position, string $coordinatesString, string $plateID): void { $microplateSet = new MicroplateSetAB(new CoordinateSystem12Well()); @@ -91,7 +91,7 @@ public static function dataProvider12Well(): iterable ]; } - /** @dataProvider dataProvider96Well */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] public function testSetLocationFromSetPositionFor96Wells(int $position, string $coordinatesString, string $plateID): void { $microplateSet = new MicroplateSetAB(new CoordinateSystem96Well()); diff --git a/tests/NumberTest.php b/tests/NumberTest.php index d7e836d..964c2fd 100644 --- a/tests/NumberTest.php +++ b/tests/NumberTest.php @@ -8,13 +8,12 @@ final class NumberTest extends TestCase { /** - * @dataProvider clampProvider - * * @param float|int $min * @param float|int $max * @param float|int $current * @param float|int $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('clampProvider')] public function testClamp($min, $max, $current, $expected): void { self::assertSame($expected, Number::clamp($min, $max, $current)); diff --git a/tests/StringUtilTest.php b/tests/StringUtilTest.php index 9a1bd9c..a549b56 100644 --- a/tests/StringUtilTest.php +++ b/tests/StringUtilTest.php @@ -8,11 +8,8 @@ final class StringUtilTest extends TestCase { - /** - * @dataProvider joinNonEmpty - * - * @param iterable $parts - */ + /** @param iterable $parts */ + #[\PHPUnit\Framework\Attributes\DataProvider('joinNonEmpty')] public function testJoinNonEmpty(string $expectedJoined, string $glue, iterable $parts): void { self::assertSame( @@ -29,7 +26,7 @@ public static function joinNonEmpty(): iterable yield ['a,b', ',', new Collection(['a', null, '', 'b'])]; } - /** @dataProvider shortenFirstname */ + #[\PHPUnit\Framework\Attributes\DataProvider('shortenFirstname')] public function testShortenFirstname(string $expectedShortened, string $input): void { self::assertSame( @@ -48,11 +45,8 @@ public static function shortenFirstname(): iterable yield ['', '']; } - /** - * @dataProvider splitLines - * - * @param array $expectedLines - */ + /** @param array $expectedLines */ + #[\PHPUnit\Framework\Attributes\DataProvider('splitLines')] public function testSplitLines(array $expectedLines, string $input): void { self::assertSame($expectedLines, StringUtil::splitLines($input)); From f5144a63ef09aa836247199f5ef6114a1c5056c7 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Mon, 29 Apr 2024 11:21:21 +0200 Subject: [PATCH 12/29] ignore v1 sample sheet --- src/IlluminaSampleSheet/V1/DataInterface.php | 17 --- src/IlluminaSampleSheet/V1/DataSection.php | 77 ---------- .../V1/MiSeqHeaderSection.php | 98 ------------- .../V1/MiSeqSampleSheet.php | 19 --- .../V1/NovaSeqHeaderSection.php | 66 --------- .../V1/NovaSeqSampleSheet.php | 20 --- src/IlluminaSampleSheet/V1/ReadsSection.php | 23 --- .../V1/SampleSheetData.php | 34 ----- .../V1/SettingsSection.php | 33 ----- .../V1/MiSeqSampleSheetTest.php | 77 ---------- .../V1/NovaSeqSampleSheetTest.php | 137 ------------------ 11 files changed, 601 deletions(-) delete mode 100644 src/IlluminaSampleSheet/V1/DataInterface.php delete mode 100644 src/IlluminaSampleSheet/V1/DataSection.php delete mode 100644 src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php delete mode 100644 src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php delete mode 100644 src/IlluminaSampleSheet/V1/NovaSeqHeaderSection.php delete mode 100644 src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php delete mode 100644 src/IlluminaSampleSheet/V1/ReadsSection.php delete mode 100644 src/IlluminaSampleSheet/V1/SampleSheetData.php delete mode 100644 src/IlluminaSampleSheet/V1/SettingsSection.php delete mode 100644 tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php delete mode 100644 tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php diff --git a/src/IlluminaSampleSheet/V1/DataInterface.php b/src/IlluminaSampleSheet/V1/DataInterface.php deleted file mode 100644 index 466fa9f..0000000 --- a/src/IlluminaSampleSheet/V1/DataInterface.php +++ /dev/null @@ -1,17 +0,0 @@ - */ - public function getColumns(): array; - - /** @return array> */ - public function getRows(): array; -} diff --git a/src/IlluminaSampleSheet/V1/DataSection.php b/src/IlluminaSampleSheet/V1/DataSection.php deleted file mode 100644 index 7f69af3..0000000 --- a/src/IlluminaSampleSheet/V1/DataSection.php +++ /dev/null @@ -1,77 +0,0 @@ -data = $data; - } - - public function convertSectionToString(): string - { - $this->validateData(); - - $header = implode(',', $this->data->getColumns()); - $rows = []; - foreach ($this->data->getRows() as $rowData) { - $rows[] = implode(',', $rowData); - } - - return "[Data]\n{$header}\n" . implode("\n", $rows) . "\n"; - } - - private function validateData(): void - { - $columns = $this->data->getColumns(); - $rows = $this->data->getRows(); - - if (! in_array('Sample_ID', $columns, true)) { - throw new \InvalidArgumentException('Sample_ID column is required.'); - } - - $columnKey = array_search('Sample_ID', $columns, true); - assert($columnKey !== false); - - $sampleIDs = array_column($rows, $columnKey); - if (count($sampleIDs) !== count(array_unique($sampleIDs))) { - throw new IlluminaSampleSheetException('Sample_ID values must be distinct.'); - } - - // validate Index-Column to be a valid index - if (in_array('Index', $columns, true)) { - $indexKey = array_search('Index', $columns, true); - assert($indexKey !== false); - $indexes = array_column($rows, $indexKey); - foreach ($indexes as $index) { - $this->validateIndex($index); - } - } - } - - /** @param CSVPrimitive $index */ - protected function validateIndex($index): string - { - if (! is_string($index)) { - throw new IlluminaSampleSheetException('Index must be a string.'); - } - - if (! (bool) preg_match('/^[ATCGN]+$/', $index)) { - throw new IlluminaSampleSheetException("Index '{$index}' contains invalid characters. Only A, T, C, G, N are allowed."); - } - - return $index; - } -} diff --git a/src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php b/src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php deleted file mode 100644 index 707c070..0000000 --- a/src/IlluminaSampleSheet/V1/MiSeqHeaderSection.php +++ /dev/null @@ -1,98 +0,0 @@ -experimentName = $this->validateString($experimentName, 'Experiment Name'); - $this->date = $date; - $this->module = $this->validateString($module, 'Module'); - $this->workflow = $this->validateString($workflow, 'Workflow'); - $this->libraryPrepKit = $this->validateString($libraryPrepKit, 'Library Prep Kit'); - $this->indexKit = $this->validateString($indexKit, 'Index Kit'); - $this->description = $this->validateString($description, 'Description'); - $this->chemistry = $this->validateString($chemistry, 'Chemistry'); - } - - private function validateString(?string $value, string $fieldName): ?string - { - if ($value === null) { - return null; - } - - $trimmedValue = trim($value); - if ($trimmedValue === '') { - throw new \InvalidArgumentException("{$fieldName} cannot be empty."); - } - - return $trimmedValue; - } - - public function convertSectionToString(): string - { - $headerLines = ['[Header]']; - - if ($this->experimentName !== null) { - $headerLines[] = "Experiment Name,{$this->experimentName}"; - } - - if ($this->date instanceof Carbon) { - $headerLines[] = "Date,{$this->date->format('d.m.Y')}"; - } - - if ($this->module !== null) { - $headerLines[] = "Module,{$this->module}"; - } - - if ($this->workflow !== null) { - $headerLines[] = "Workflow,{$this->workflow}"; - } - - if ($this->libraryPrepKit !== null) { - $headerLines[] = "Library Prep Kit,{$this->libraryPrepKit}"; - } - - if ($this->indexKit !== null) { - $headerLines[] = "Index Kit,{$this->indexKit}"; - } - - if ($this->description !== null) { - $headerLines[] = "Description,{$this->description}"; - } - - if ($this->chemistry !== null) { - $headerLines[] = "Chemistry,{$this->chemistry}"; - } - - return implode("\n", $headerLines); - } -} diff --git a/src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php b/src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php deleted file mode 100644 index 3dd8530..0000000 --- a/src/IlluminaSampleSheet/V1/MiSeqSampleSheet.php +++ /dev/null @@ -1,19 +0,0 @@ -addSection($header); - $this->addSection($reads); - $this->addSection(new SettingsSection()); - $this->addSection($data); - } -} diff --git a/src/IlluminaSampleSheet/V1/NovaSeqHeaderSection.php b/src/IlluminaSampleSheet/V1/NovaSeqHeaderSection.php deleted file mode 100644 index 5dfb9b6..0000000 --- a/src/IlluminaSampleSheet/V1/NovaSeqHeaderSection.php +++ /dev/null @@ -1,66 +0,0 @@ -chemistry = $chemistry; - $this->description = $description; - $this->assay = $assay; - $this->application = $application; - $this->workflow = $workflow; - $this->date = $date; - $this->investigatorName = $investigatorName; - $this->experimentName = $experimentName; - $this->iemFileVersion = $iemFileVersion; - } - - public function convertSectionToString(): string - { - $headerLines = [ - '[Header]', - "IEMFileVersion,{$this->iemFileVersion}", - "Investigator Name,{$this->investigatorName}", - "Experiment Name,{$this->experimentName}", - "Date,{$this->date}", - "Workflow,{$this->workflow}", - "Application,{$this->application}", - "Assay,{$this->assay}", - "Description,{$this->description}", - "Chemistry,{$this->chemistry}", - ]; - - return implode("\n", $headerLines); - } -} diff --git a/src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php b/src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php deleted file mode 100644 index 66ad37f..0000000 --- a/src/IlluminaSampleSheet/V1/NovaSeqSampleSheet.php +++ /dev/null @@ -1,20 +0,0 @@ -addSection($header); - $this->addSection($reads); - $this->addSection($settings); - $this->addSection($data); - } -} diff --git a/src/IlluminaSampleSheet/V1/ReadsSection.php b/src/IlluminaSampleSheet/V1/ReadsSection.php deleted file mode 100644 index 7d45ad2..0000000 --- a/src/IlluminaSampleSheet/V1/ReadsSection.php +++ /dev/null @@ -1,23 +0,0 @@ -read1Cycles = $read1Cycles; - $this->read2Cycles = $read2Cycles; - } - - public function convertSectionToString(): string - { - return "[Reads]\n" . $this->read1Cycles . "\n" . $this->read2Cycles; - } -} diff --git a/src/IlluminaSampleSheet/V1/SampleSheetData.php b/src/IlluminaSampleSheet/V1/SampleSheetData.php deleted file mode 100644 index 877b107..0000000 --- a/src/IlluminaSampleSheet/V1/SampleSheetData.php +++ /dev/null @@ -1,34 +0,0 @@ - */ - private array $columns; - - /** @var array> */ - private array $rows; - - /** - * @param array $columns - * @param array> $rows - */ - public function __construct(array $columns, array $rows) - { - $this->columns = $columns; - $this->rows = $rows; - } - - /** {@inheritDoc} */ - public function getColumns(): array - { - return $this->columns; - } - - /** {@inheritDoc} */ - public function getRows(): array - { - return $this->rows; - } -} diff --git a/src/IlluminaSampleSheet/V1/SettingsSection.php b/src/IlluminaSampleSheet/V1/SettingsSection.php deleted file mode 100644 index 8b2bac8..0000000 --- a/src/IlluminaSampleSheet/V1/SettingsSection.php +++ /dev/null @@ -1,33 +0,0 @@ -adapter = $adapter; - $this->adapterRead2 = $adapterRead2; - } - - public function convertSectionToString(): string - { - $settingsLines = ['[Settings]']; - - if ($this->adapter !== null) { - $settingsLines[] = 'Adapter,' . $this->adapter; - } - - if ($this->adapterRead2 !== null) { - $settingsLines[] = 'AdapterRead2,' . $this->adapterRead2; - } - - return implode("\n", $settingsLines); - } -} diff --git a/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php b/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php deleted file mode 100644 index d1f41e1..0000000 --- a/tests/IlluminaSampleSheet/V1/MiSeqSampleSheetTest.php +++ /dev/null @@ -1,77 +0,0 @@ -createMock(MiSeqHeaderSection::class); - $readsSection = $this->createMock(ReadsSection::class); - $dataSection = $this->createMock(DataSection::class); - - $miSeqSampleSheet = new MiSeqSampleSheet($headerSection, $readsSection, $dataSection); - - self::assertContains($headerSection, $miSeqSampleSheet->getSections()); - self::assertContains($readsSection, $miSeqSampleSheet->getSections()); - self::assertContains($dataSection, $miSeqSampleSheet->getSections()); - } - - public function testMiSeqSampleSheetToStringReturnsExpectedResult(): void - { - $headerSection = new MiSeqHeaderSection( - 'Run7906-ROUTINE', - Carbon::createStrict(2024, 4, 3, 12, 1, 1), - 'GenerateFASTQ - 3.0.1', - 'GenerateFASTQ', - 'Illumina DNA Prep', - 'Custom', - 'NA-ISP', - 'Amplicon' - ); - - $readsSection = new ReadsSection(150, 150); - - $columns = ['Sample_ID', 'Sample_Name', 'Sample_Plate', 'Sample_Well', 'Sample_Project', 'I7_Index_ID', 'Index', 'I5_Index_ID', 'Index2']; - $rows = [ - ['1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A501', 'TGAACCTT'], - ['2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A502', 'TGCTAAGT'], - ['3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'RunXXXX-PROJECT', 'R701', 'ATCACG', 'A503', 'TGTTCTCT'], - ]; - - $sampleSheetData = new SampleSheetData($columns, $rows); - - $dataSection = new DataSection($sampleSheetData); - - $miSeqSampleSheet = new MiSeqSampleSheet($headerSection, $readsSection, $dataSection); - - $expected = '[Header] -Experiment Name,Run7906-ROUTINE -Date,03.04.2024 -Module,GenerateFASTQ - 3.0.1 -Workflow,GenerateFASTQ -Library Prep Kit,Illumina DNA Prep -Index Kit,Custom -Description,NA-ISP -Chemistry,Amplicon -[Reads] -150 -150 -[Settings] -[Data] -Sample_ID,Sample_Name,Sample_Plate,Sample_Well,Sample_Project,I7_Index_ID,Index,I5_Index_ID,Index2 -1,Sample-001-M001,RunXXXX-PLATE,,RunXXXX-PROJECT,R701,ATCACG,A501,TGAACCTT -2,Sample-002-M002,RunXXXX-PLATE,,RunXXXX-PROJECT,R701,ATCACG,A502,TGCTAAGT -3,Sample-003-M003,RunXXXX-PLATE,,RunXXXX-PROJECT,R701,ATCACG,A503,TGTTCTCT -'; - self::assertSame($expected, $miSeqSampleSheet->toString()); - } -} diff --git a/tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php b/tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php deleted file mode 100644 index 95ec3b8..0000000 --- a/tests/IlluminaSampleSheet/V1/NovaSeqSampleSheetTest.php +++ /dev/null @@ -1,137 +0,0 @@ -createMock(NovaSeqHeaderSection::class); - $readsSection = $this->createMock(ReadsSection::class); - $settingsSection = $this->createMock(SettingsSection::class); - $dataSection = $this->createMock(DataSection::class); - - $novaSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settingsSection, $dataSection); - - self::assertContains($headerSection, $novaSeqSampleSheet->getSections()); - self::assertContains($readsSection, $novaSeqSampleSheet->getSections()); - self::assertContains($settingsSection, $novaSeqSampleSheet->getSections()); - self::assertContains($dataSection, $novaSeqSampleSheet->getSections()); - } - - public function testNovaSeqStandardSampleSheetToStringReturnsExpectedResult(): void - { - $headerSection = new NovaSeqHeaderSection( - '4', - 'DonalDuck', - 'MyExperiment', - '19.04.2024', - 'MyWorkflow', - 'MyApplication', - 'MyAssay', - 'MyDescription', - 'MyChemistry', - ); - - $readsSection = new ReadsSection(101, 101); - - $columns = ['Sample_ID', 'Sample_Name', 'Sample_Plate', 'Sample_Well', 'I7_Index_ID', 'Index', 'I5_Index_ID', 'Index2', 'Sample_Project', 'Description']; - $rows = [ - ['1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description'], - ['2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description'], - ['3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description'], - ]; - - $sampleSheetData = new SampleSheetData($columns, $rows); - $dataSection = new DataSection($sampleSheetData); - - $settings = new SettingsSection('AGATCGGAAGAGCACACGTCTGAACTCCAGTCA', 'AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT'); - $miSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); - - $expected = '[Header] -IEMFileVersion,4 -Investigator Name,DonalDuck -Experiment Name,MyExperiment -Date,19.04.2024 -Workflow,MyWorkflow -Application,MyApplication -Assay,MyAssay -Description,MyDescription -Chemistry,MyChemistry -[Reads] -101 -101 -[Settings] -Adapter,AGATCGGAAGAGCACACGTCTGAACTCCAGTCA -AdapterRead2,AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT -[Data] -Sample_ID,Sample_Name,Sample_Plate,Sample_Well,I7_Index_ID,Index,I5_Index_ID,Index2,Sample_Project,Description -1,Sample-001-M001,RunXXXX-PLATE,,UDP0090,TCAGGCTT,UDP0090,ATCATGCG,RunXXXX-PROJECT,description -2,Sample-002-M002,RunXXXX-PLATE,,UDP0091,CCTTGTAG,UDP0091,CCTTGGAA,RunXXXX-PROJECT,description -3,Sample-003-M003,RunXXXX-PLATE,,UDP0092,GAACATCG,UDP0092,TCGACAAG,RunXXXX-PROJECT,description -'; - self::assertSame($expected, $miSeqSampleSheet->toString()); - } - - public function testNovaSeqXpSampleSheetWithLanesToStringReturnsExpectedResult(): void - { - $headerSection = new NovaSeqHeaderSection( - '4', - 'DonalDuck', - 'MyExperiment', - '19.04.2024', - 'MyWorkflow', - 'MyApplication', - 'MyAssay', - 'MyDescription', - 'MyChemistry', - ); - - $readsSection = new ReadsSection(101, 101); - - $columns = ['Lane', 'Sample_ID', 'Sample_Name', 'Sample_Plate', 'Sample_Well', 'I7_Index_ID', 'Index', 'I5_Index_ID', 'Index2', 'Sample_Project', 'Description']; - $rows = [ - [2, '1', 'Sample-001-M001', 'RunXXXX-PLATE', '', 'UDP0090', 'TCAGGCTT', 'UDP0090', 'ATCATGCG', 'RunXXXX-PROJECT', 'description'], - [1, '2', 'Sample-002-M002', 'RunXXXX-PLATE', '', 'UDP0091', 'CCTTGTAG', 'UDP0091', 'CCTTGGAA', 'RunXXXX-PROJECT', 'description'], - [4, '3', 'Sample-003-M003', 'RunXXXX-PLATE', '', 'UDP0092', 'GAACATCG', 'UDP0092', 'TCGACAAG', 'RunXXXX-PROJECT', 'description'], - ]; - - $sampleSheetData = new SampleSheetData($columns, $rows); - $dataSection = new DataSection($sampleSheetData); - - $settings = new SettingsSection('AGATCGGAAGAGCACACGTCTGAACTCCAGTCA', 'AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT'); - $miSeqSampleSheet = new NovaSeqSampleSheet($headerSection, $readsSection, $settings, $dataSection); - - $expected = '[Header] -IEMFileVersion,4 -Investigator Name,DonalDuck -Experiment Name,MyExperiment -Date,19.04.2024 -Workflow,MyWorkflow -Application,MyApplication -Assay,MyAssay -Description,MyDescription -Chemistry,MyChemistry -[Reads] -101 -101 -[Settings] -Adapter,AGATCGGAAGAGCACACGTCTGAACTCCAGTCA -AdapterRead2,AGATCGGAAGAGCGTCGTGTAGGGAAAGAGTGT -[Data] -Lane,Sample_ID,Sample_Name,Sample_Plate,Sample_Well,I7_Index_ID,Index,I5_Index_ID,Index2,Sample_Project,Description -2,1,Sample-001-M001,RunXXXX-PLATE,,UDP0090,TCAGGCTT,UDP0090,ATCATGCG,RunXXXX-PROJECT,description -1,2,Sample-002-M002,RunXXXX-PLATE,,UDP0091,CCTTGTAG,UDP0091,CCTTGGAA,RunXXXX-PROJECT,description -4,3,Sample-003-M003,RunXXXX-PLATE,,UDP0092,GAACATCG,UDP0092,TCGACAAG,RunXXXX-PROJECT,description -'; - self::assertSame($expected, $miSeqSampleSheet->toString()); - } -} From 3896dfa920e17dfb2bc9719f99367e20b8140107 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Mon, 29 Apr 2024 11:52:50 +0200 Subject: [PATCH 13/29] fluent --- .../V2/BclConvertSettingsSection.php | 29 +++++++---- .../V2/FastQCompressionFormat.php | 26 ++++++++++ src/IlluminaSampleSheet/V2/HeaderSection.php | 50 +++++++++++-------- .../V2/NovaSeqXCloudSampleSheet.php | 29 ----------- .../V2/NovaSeqXSampleSheet.php | 20 ++++++++ .../V2/NovaSeqXCloudSampleSheetTest.php | 42 ++++------------ 6 files changed, 105 insertions(+), 91 deletions(-) create mode 100644 src/IlluminaSampleSheet/V2/FastQCompressionFormat.php delete mode 100644 src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php create mode 100644 src/IlluminaSampleSheet/V2/NovaSeqXSampleSheet.php diff --git a/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php b/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php index 79aa1c1..2b637b9 100644 --- a/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php @@ -8,17 +8,15 @@ class BclConvertSettingsSection implements SectionInterface { public string $softwareVersion; - public string $trimUMI; + public FastQCompressionFormat $fastqCompressionFormat; - public string $fastqCompressionFormat; + public ?bool $trimUMI = null; public function __construct( string $softwareVersion, - string $trimUMI, - string $fastqCompressionFormat + FastQCompressionFormat $fastqCompressionFormat ) { $this->softwareVersion = $softwareVersion; - $this->trimUMI = $trimUMI; $this->fastqCompressionFormat = $fastqCompressionFormat; } @@ -27,11 +25,24 @@ public function convertSectionToString(): string $bclConvertSettingsLines = [ '[BCLConvert_Settings]', "SoftwareVersion,{$this->softwareVersion}", - "TrimUMI,{$this->trimUMI}", - "FastqCompressionFormat,{$this->fastqCompressionFormat}", - '', + "FastqCompressionFormat,{$this->fastqCompressionFormat->value}", ]; - return implode("\n", $bclConvertSettingsLines); + if (! is_null($this->trimUMI)) { + $booleanToString = $this->trimUMI + ? '1' + : '0'; + + $bclConvertSettingsLines[] = "TrimUMI,{$booleanToString}"; + } + + return implode("\n", $bclConvertSettingsLines) . "\n"; + } + + public function setTrimUMI(bool $trimUMI): BclConvertSettingsSection + { + $this->trimUMI = $trimUMI; + + return $this; } } diff --git a/src/IlluminaSampleSheet/V2/FastQCompressionFormat.php b/src/IlluminaSampleSheet/V2/FastQCompressionFormat.php new file mode 100644 index 0000000..15154b1 --- /dev/null +++ b/src/IlluminaSampleSheet/V2/FastQCompressionFormat.php @@ -0,0 +1,26 @@ +value = $value; + } + + public static function GZIP(): self + { + return new self(self::GZIP); + } + + public static function DRAGEN(): self + { + return new self(self::DRAGEN); + } +} diff --git a/src/IlluminaSampleSheet/V2/HeaderSection.php b/src/IlluminaSampleSheet/V2/HeaderSection.php index 4ff1a43..de130a1 100644 --- a/src/IlluminaSampleSheet/V2/HeaderSection.php +++ b/src/IlluminaSampleSheet/V2/HeaderSection.php @@ -8,54 +8,64 @@ class HeaderSection implements SectionInterface { private const FILE_FORMAT_VERSION = '2'; + private string $fileFormatVersion = self::FILE_FORMAT_VERSION; + private string $runName; - private ?string $runDescription; + private ?string $runDescription = null; - private ?string $instrumentType; + private ?string $instrumentType = null; - private ?string $instrumentPlatform; + private ?string $instrumentPlatform = null; /** @var array */ private array $customParams = []; - /** - * @param string $runName - Required. Name of the run. - * @param string|null $instrumentPlatform - Optional. Platform of the instrument. - * @param string|null $runDescription - Optional. Description of the run. - * @param string|null $instrumentType - Optional. Type of the instrument. - */ - public function __construct(string $runName, ?string $instrumentPlatform = null, ?string $runDescription = null, ?string $instrumentType = null) + public function __construct(string $runName) { $this->runName = $runName; + } + + public function setRunDescription(string $runDescription): HeaderSection + { $this->runDescription = $runDescription; + + return $this; + } + + public function setInstrumentType(string $instrumentType): HeaderSection + { $this->instrumentType = $instrumentType; + + return $this; + } + + public function setInstrumentPlatform(string $instrumentPlatform): HeaderSection + { $this->instrumentPlatform = $instrumentPlatform; + + return $this; } - /** - * @param string $paramName - Name of the parameter - * @param string $paramValue - Value of the parameter - */ - public function addCustomParam(string $paramName, string $paramValue): void + public function setCustomParam(string $paramName, string $paramValue): void { - $this->customParams[$paramName] = $paramValue; + $this->customParams['Custom_' . $paramName] = $paramValue; } public function convertSectionToString(): string { $headerLines = [ '[Header]', - 'FileFormatVersion,' . self::FILE_FORMAT_VERSION . '', + 'FileFormatVersion,' . $this->fileFormatVersion, "RunName,{$this->runName}", ]; - if ($this->runDescription !== null) { + if (! is_null($this->runDescription)) { $headerLines[] = "RunDescription,{$this->runDescription}"; } - if ($this->instrumentType !== null) { + if (! is_null($this->instrumentType)) { $headerLines[] = "InstrumentType,{$this->instrumentType}"; } - if ($this->instrumentPlatform !== null) { + if (! is_null($this->instrumentPlatform)) { $headerLines[] = "InstrumentPlatform,{$this->instrumentPlatform}"; } foreach ($this->customParams as $paramName => $paramValue) { diff --git a/src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php b/src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php deleted file mode 100644 index 5ef0026..0000000 --- a/src/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheet.php +++ /dev/null @@ -1,29 +0,0 @@ -addSection($header); - $this->addSection($reads); - $this->addSection($sequencingSettingsSection); - $this->addSection($bclConvertSettingsSection); - $this->addSection($bclConvertDataSection); - $this->addSection($cloudSettings); - $this->addSection($cloudData); - $this->bclConvertSettingsSection = $bclConvertSettingsSection; - } -} diff --git a/src/IlluminaSampleSheet/V2/NovaSeqXSampleSheet.php b/src/IlluminaSampleSheet/V2/NovaSeqXSampleSheet.php new file mode 100644 index 0000000..e3c643f --- /dev/null +++ b/src/IlluminaSampleSheet/V2/NovaSeqXSampleSheet.php @@ -0,0 +1,20 @@ +addSection($header); + $this->addSection($reads); + $this->addSection($bclConvertSettingsSection); + $this->addSection($bclConvertDataSection); + } +} diff --git a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php index 336b5e8..c1c2620 100644 --- a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php @@ -4,11 +4,10 @@ use MLL\Utils\IlluminaSampleSheet\V2\BclConvertDataSection; use MLL\Utils\IlluminaSampleSheet\V2\BclConvertSettingsSection; -use MLL\Utils\IlluminaSampleSheet\V2\CloudDataSection; -use MLL\Utils\IlluminaSampleSheet\V2\CloudSettingsSection; +use MLL\Utils\IlluminaSampleSheet\V2\FastQCompressionFormat; use MLL\Utils\IlluminaSampleSheet\V2\HeaderSection; -use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudSampleSheet; use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudSequencingSettingsSection; +use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXSampleSheet; use MLL\Utils\IlluminaSampleSheet\V2\ReadsSection; use PHPUnit\Framework\TestCase; @@ -18,9 +17,9 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi { $headerSection = new HeaderSection( 'Run1', - 'NovaSeqXSeries', ); - $headerSection->addCustomParam('IndexOrientation', 'Orientation1'); + $headerSection->setInstrumentPlatform('NovaSeqXSeries'); + $headerSection->setCustomParam('IndexOrientation', 'Orientation1'); $readsSection = new ReadsSection( 100, @@ -30,35 +29,26 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi ); $sequenceSettingsSection = new NovaSeqXCloudSequencingSettingsSection('Settings1'); - $bclConvertSettingsSection = new BclConvertSettingsSection('1.0.0', '0', 'gzip'); + $bclConvertSettingsSection = new BclConvertSettingsSection('1.0.0', FastQCompressionFormat::GZIP()); + $bclConvertSettingsSection->setTrimUMI(false); $bclConvertDataSection = new BclConvertDataSection(); $bclConvertDataSection->addSample(1, 'Sample1', 'Index1', 'Index2', 'Cycles1', 'Adapter1', 'Adapter2'); $bclConvertDataSection->addSample(2, 'Sample2', 'Index3', 'Index4', 'Cycles2', 'Adapter3', 'Adapter4'); $bclConvertDataSection->addSample(3, 'Sample3', 'Index5', 'Index6', 'Cycles3', 'Adapter5', 'Adapter6'); - $cloudSettingsSection = new CloudSettingsSection('1.0.0', 'Workflow1', 'Pipeline1'); - - $cloudDataSection = new CloudDataSection(); - $cloudDataSection->addSample('Sample4', 'Project1', 'Library1', 'Kit1', 'AdapterKit1'); - $cloudDataSection->addSample('Sample5', 'Project2', 'Library2', 'Kit2', 'AdapterKit2'); - $cloudDataSection->addSample('Sample6', 'Project3', 'Library3', 'Kit3', 'AdapterKit3'); - - $novaSeqXCloudSampleSheet = new NovaSeqXCloudSampleSheet( + $novaSeqXCloudSampleSheet = new NovaSeqXSampleSheet( $headerSection, $readsSection, - $sequenceSettingsSection, $bclConvertSettingsSection, $bclConvertDataSection, - $cloudSettingsSection, - $cloudDataSection ); $expected = '[Header] FileFormatVersion,2 RunName,Run1 InstrumentPlatform,NovaSeqXSeries -IndexOrientation,Orientation1 +Custom_IndexOrientation,Orientation1 [Reads] Read1Cycles,100 @@ -66,30 +56,16 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi Index1Cycles,10 Index2Cycles,11 -[Sequencing_Settings] -LibraryPrepKits,Settings1 - [BCLConvert_Settings] SoftwareVersion,1.0.0 -TrimUMI,0 FastqCompressionFormat,gzip +TrimUMI,0 [BCLConvert_Data] Lane,Sample_ID,Index,Index2,OverrideCycles,AdapterRead1,AdapterRead2 1,Sample1,Index1,Index2,Cycles1,Adapter1,Adapter2 2,Sample2,Index3,Index4,Cycles2,Adapter3,Adapter4 3,Sample3,Index5,Index6,Cycles3,Adapter5,Adapter6 - -[Cloud_Settings] -GeneratedVersion,1.0.0 -Cloud_Workflow,Workflow1 -BCLConvert_Pipeline,Pipeline1 - -[Cloud_Data] -Sample_ID,ProjectName,LibraryName,LibraryPrepKitName,IndexAdapterKitName -Sample4,Project1,Library1,Kit1,AdapterKit1 -Sample5,Project2,Library2,Kit2,AdapterKit2 -Sample6,Project3,Library3,Kit3,AdapterKit3 '; self::assertEquals($expected, $novaSeqXCloudSampleSheet->toString()); From 04c7e9e80fbce468fc9653615e9c022dad52c1ff Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Mon, 29 Apr 2024 11:54:38 +0200 Subject: [PATCH 14/29] no cloud --- .../V2/BclConvertSettingsSection.php | 1 + .../V2/CloudDataSample.php | 42 ----------------- .../V2/CloudDataSection.php | 37 --------------- .../V2/CloudSettingsSection.php | 32 ------------- .../V2/{ => Enums}/FastQCompressionFormat.php | 2 +- ...NovaSeqXCloudSequencingSettingsSection.php | 27 ----------- .../V2/CloudDataSampleTest.php | 47 ------------------- .../V2/CloudDataSectionTest.php | 20 -------- .../V2/CloudSettingsSectionTest.php | 18 ------- .../V2/NovaSeqXCloudSampleSheetTest.php | 5 +- 10 files changed, 3 insertions(+), 228 deletions(-) delete mode 100644 src/IlluminaSampleSheet/V2/CloudDataSample.php delete mode 100644 src/IlluminaSampleSheet/V2/CloudDataSection.php delete mode 100644 src/IlluminaSampleSheet/V2/CloudSettingsSection.php rename src/IlluminaSampleSheet/V2/{ => Enums}/FastQCompressionFormat.php (89%) delete mode 100644 src/IlluminaSampleSheet/V2/NovaSeqXCloudSequencingSettingsSection.php delete mode 100644 tests/IlluminaSampleSheet/V2/CloudDataSampleTest.php delete mode 100644 tests/IlluminaSampleSheet/V2/CloudDataSectionTest.php delete mode 100644 tests/IlluminaSampleSheet/V2/CloudSettingsSectionTest.php diff --git a/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php b/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php index 2b637b9..a99dd4a 100644 --- a/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php @@ -3,6 +3,7 @@ namespace MLL\Utils\IlluminaSampleSheet\V2; use MLL\Utils\IlluminaSampleSheet\SectionInterface; +use MLL\Utils\IlluminaSampleSheet\V2\Enums\FastQCompressionFormat; class BclConvertSettingsSection implements SectionInterface { diff --git a/src/IlluminaSampleSheet/V2/CloudDataSample.php b/src/IlluminaSampleSheet/V2/CloudDataSample.php deleted file mode 100644 index 49beecb..0000000 --- a/src/IlluminaSampleSheet/V2/CloudDataSample.php +++ /dev/null @@ -1,42 +0,0 @@ -sampleId = $sampleId; - $this->projectName = $projectName; - $this->libraryName = $libraryName; - $this->libraryPrepKitName = $libraryPrepKitName; - $this->indexAdapterKitName = $indexAdapterKitName; - } - - /** @return array */ - public function toArray(): array - { - return [ - 'Sample_ID' => $this->sampleId, - 'ProjectName' => $this->projectName, - 'LibraryName' => $this->libraryName, - 'LibraryPrepKitName' => $this->libraryPrepKitName, - 'IndexAdapterKitName' => $this->indexAdapterKitName, - ]; - } -} diff --git a/src/IlluminaSampleSheet/V2/CloudDataSection.php b/src/IlluminaSampleSheet/V2/CloudDataSection.php deleted file mode 100644 index 160bbeb..0000000 --- a/src/IlluminaSampleSheet/V2/CloudDataSection.php +++ /dev/null @@ -1,37 +0,0 @@ - */ - private array $samples = []; - - public function addSample( - string $sampleId, - string $projectName, - string $libraryName, - string $libraryPrepKitName, - string $indexAdapterKitName - ): void { - $this->samples[] = new CloudDataSample( - $sampleId, - $projectName, - $libraryName, - $libraryPrepKitName, - $indexAdapterKitName - ); - } - - public function convertSectionToString(): string - { - $dataLines = ["[Cloud_Data]\nSample_ID,ProjectName,LibraryName,LibraryPrepKitName,IndexAdapterKitName"]; - foreach ($this->samples as $sample) { - $dataLines[] = implode(',', $sample->toArray()); - } - - return implode("\n", $dataLines) . "\n"; - } -} diff --git a/src/IlluminaSampleSheet/V2/CloudSettingsSection.php b/src/IlluminaSampleSheet/V2/CloudSettingsSection.php deleted file mode 100644 index 42c87df..0000000 --- a/src/IlluminaSampleSheet/V2/CloudSettingsSection.php +++ /dev/null @@ -1,32 +0,0 @@ -generatedVersion = $generatedVersion; - $this->cloudWorkflow = $cloudWorkflow; - $this->bclConvertPipeline = $bclConvertPipeline; - } - - public function convertSectionToString(): string - { - return '[Cloud_Settings] -GeneratedVersion,' . $this->generatedVersion . "\n" - . 'Cloud_Workflow,' . $this->cloudWorkflow . "\n" - . 'BCLConvert_Pipeline,' . $this->bclConvertPipeline . "\n"; - } -} diff --git a/src/IlluminaSampleSheet/V2/FastQCompressionFormat.php b/src/IlluminaSampleSheet/V2/Enums/FastQCompressionFormat.php similarity index 89% rename from src/IlluminaSampleSheet/V2/FastQCompressionFormat.php rename to src/IlluminaSampleSheet/V2/Enums/FastQCompressionFormat.php index 15154b1..cceb713 100644 --- a/src/IlluminaSampleSheet/V2/FastQCompressionFormat.php +++ b/src/IlluminaSampleSheet/V2/Enums/FastQCompressionFormat.php @@ -1,6 +1,6 @@ libraryPrepKits = $libraryPrepKits; - } - - public function convertSectionToString(): string - { - $sequencingSettingsLines = [ - '[Sequencing_Settings]', - "LibraryPrepKits,{$this->libraryPrepKits}", - '', - ]; - - return implode("\n", $sequencingSettingsLines); - } -} diff --git a/tests/IlluminaSampleSheet/V2/CloudDataSampleTest.php b/tests/IlluminaSampleSheet/V2/CloudDataSampleTest.php deleted file mode 100644 index 0b60706..0000000 --- a/tests/IlluminaSampleSheet/V2/CloudDataSampleTest.php +++ /dev/null @@ -1,47 +0,0 @@ -sampleId); - self::assertSame('projectName2', $cloudDataSample->projectName); - self::assertSame('libraryName2', $cloudDataSample->libraryName); - self::assertSame('libraryPrepKitName2', $cloudDataSample->libraryPrepKitName); - self::assertSame('indexAdapterKitName2', $cloudDataSample->indexAdapterKitName); - } - - public function testToArrayReturnsCorrectStructure(): void - { - $cloudDataSample = new CloudDataSample( - 'sampleId1', - 'projectName1', - 'libraryName1', - 'libraryPrepKitName1', - 'indexAdapterKitName1' - ); - - $expectedArray = [ - 'Sample_ID' => 'sampleId1', - 'ProjectName' => 'projectName1', - 'LibraryName' => 'libraryName1', - 'LibraryPrepKitName' => 'libraryPrepKitName1', - 'IndexAdapterKitName' => 'indexAdapterKitName1', - ]; - - self::assertSame($expectedArray, $cloudDataSample->toArray()); - } -} diff --git a/tests/IlluminaSampleSheet/V2/CloudDataSectionTest.php b/tests/IlluminaSampleSheet/V2/CloudDataSectionTest.php deleted file mode 100644 index b897666..0000000 --- a/tests/IlluminaSampleSheet/V2/CloudDataSectionTest.php +++ /dev/null @@ -1,20 +0,0 @@ -addSample('sampleId1', 'projectName1', 'libraryName1', 'libraryPrepKitName1', 'indexAdapterKitName1'); - $cloudDataSection->addSample('sampleId2', 'projectName2', 'libraryName2', 'libraryPrepKitName2', 'indexAdapterKitName2'); - - $expectedString = "[Cloud_Data]\nSample_ID,ProjectName,LibraryName,LibraryPrepKitName,IndexAdapterKitName\nsampleId1,projectName1,libraryName1,libraryPrepKitName1,indexAdapterKitName1\nsampleId2,projectName2,libraryName2,libraryPrepKitName2,indexAdapterKitName2\n"; - - self::assertSame($expectedString, $cloudDataSection->convertSectionToString()); - } -} diff --git a/tests/IlluminaSampleSheet/V2/CloudSettingsSectionTest.php b/tests/IlluminaSampleSheet/V2/CloudSettingsSectionTest.php deleted file mode 100644 index 6ad7047..0000000 --- a/tests/IlluminaSampleSheet/V2/CloudSettingsSectionTest.php +++ /dev/null @@ -1,18 +0,0 @@ -convertSectionToString()); - } -} diff --git a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php index c1c2620..fa45546 100644 --- a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php @@ -4,9 +4,7 @@ use MLL\Utils\IlluminaSampleSheet\V2\BclConvertDataSection; use MLL\Utils\IlluminaSampleSheet\V2\BclConvertSettingsSection; -use MLL\Utils\IlluminaSampleSheet\V2\FastQCompressionFormat; use MLL\Utils\IlluminaSampleSheet\V2\HeaderSection; -use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXCloudSequencingSettingsSection; use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXSampleSheet; use MLL\Utils\IlluminaSampleSheet\V2\ReadsSection; use PHPUnit\Framework\TestCase; @@ -27,9 +25,8 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi 10, 11 ); - $sequenceSettingsSection = new NovaSeqXCloudSequencingSettingsSection('Settings1'); - $bclConvertSettingsSection = new BclConvertSettingsSection('1.0.0', FastQCompressionFormat::GZIP()); + $bclConvertSettingsSection = new BclConvertSettingsSection('1.0.0', \MLL\Utils\IlluminaSampleSheet\V2\Enums\FastQCompressionFormat::GZIP()); $bclConvertSettingsSection->setTrimUMI(false); $bclConvertDataSection = new BclConvertDataSection(); From 4b9786fa399e3d0ae2fe7ef039ba7bf614f51cf6 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Mon, 29 Apr 2024 12:07:35 +0200 Subject: [PATCH 15/29] bcl convert --- .../V2/{ => BclConvert}/BclConvertDataRow.php | 2 +- .../V2/BclConvert/BclConvertSection.php | 28 +++++++++++++++++++ .../DataSection.php} | 4 +-- .../SettingsSection.php} | 6 ++-- .../V2/NovaSeqXSampleSheet.php | 9 +++--- .../V2/NovaSeqXCloudSampleSheetTest.php | 14 ++++++---- 6 files changed, 47 insertions(+), 16 deletions(-) rename src/IlluminaSampleSheet/V2/{ => BclConvert}/BclConvertDataRow.php (95%) create mode 100644 src/IlluminaSampleSheet/V2/BclConvert/BclConvertSection.php rename src/IlluminaSampleSheet/V2/{BclConvertDataSection.php => BclConvert/DataSection.php} (91%) rename src/IlluminaSampleSheet/V2/{BclConvertSettingsSection.php => BclConvert/SettingsSection.php} (86%) diff --git a/src/IlluminaSampleSheet/V2/BclConvertDataRow.php b/src/IlluminaSampleSheet/V2/BclConvert/BclConvertDataRow.php similarity index 95% rename from src/IlluminaSampleSheet/V2/BclConvertDataRow.php rename to src/IlluminaSampleSheet/V2/BclConvert/BclConvertDataRow.php index 88674a5..2f877bf 100644 --- a/src/IlluminaSampleSheet/V2/BclConvertDataRow.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/BclConvertDataRow.php @@ -1,6 +1,6 @@ settingsSection = $settingsSection; + $this->dataSection = $dataSection; + } + + public function convertSectionToString(): string + { + $bclConvertLines = [ + $this->settingsSection->convertSectionToString(), + $this->dataSection->convertSectionToString(), + ]; + + return implode("\n", $bclConvertLines); + } +} diff --git a/src/IlluminaSampleSheet/V2/BclConvertDataSection.php b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php similarity index 91% rename from src/IlluminaSampleSheet/V2/BclConvertDataSection.php rename to src/IlluminaSampleSheet/V2/BclConvert/DataSection.php index 7d3b8c0..577d6ad 100644 --- a/src/IlluminaSampleSheet/V2/BclConvertDataSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php @@ -1,10 +1,10 @@ */ private array $dataRows = []; diff --git a/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php b/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php similarity index 86% rename from src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php rename to src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php index a99dd4a..cb8a567 100644 --- a/src/IlluminaSampleSheet/V2/BclConvertSettingsSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php @@ -1,11 +1,11 @@ trimUMI = $trimUMI; diff --git a/src/IlluminaSampleSheet/V2/NovaSeqXSampleSheet.php b/src/IlluminaSampleSheet/V2/NovaSeqXSampleSheet.php index e3c643f..e1858dc 100644 --- a/src/IlluminaSampleSheet/V2/NovaSeqXSampleSheet.php +++ b/src/IlluminaSampleSheet/V2/NovaSeqXSampleSheet.php @@ -3,18 +3,19 @@ namespace MLL\Utils\IlluminaSampleSheet\V2; use MLL\Utils\IlluminaSampleSheet\SampleSheet; +use MLL\Utils\IlluminaSampleSheet\V2\BclConvert\BclConvertSection; class NovaSeqXSampleSheet extends SampleSheet { public function __construct( HeaderSection $header, ReadsSection $reads, - BclConvertSettingsSection $bclConvertSettingsSection, - BclConvertDataSection $bclConvertDataSection + ?BclConvertSection $bclConvertSection ) { $this->addSection($header); $this->addSection($reads); - $this->addSection($bclConvertSettingsSection); - $this->addSection($bclConvertDataSection); + if (! is_null($bclConvertSection)) { + $this->addSection($bclConvertSection); + } } } diff --git a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php index fa45546..05571ba 100644 --- a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php @@ -2,8 +2,9 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet\V2; -use MLL\Utils\IlluminaSampleSheet\V2\BclConvertDataSection; -use MLL\Utils\IlluminaSampleSheet\V2\BclConvertSettingsSection; +use MLL\Utils\IlluminaSampleSheet\V2\BclConvert\BclConvertSection; +use MLL\Utils\IlluminaSampleSheet\V2\BclConvert\SettingsSection; +use MLL\Utils\IlluminaSampleSheet\V2\Enums\FastQCompressionFormat; use MLL\Utils\IlluminaSampleSheet\V2\HeaderSection; use MLL\Utils\IlluminaSampleSheet\V2\NovaSeqXSampleSheet; use MLL\Utils\IlluminaSampleSheet\V2\ReadsSection; @@ -26,19 +27,20 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi 11 ); - $bclConvertSettingsSection = new BclConvertSettingsSection('1.0.0', \MLL\Utils\IlluminaSampleSheet\V2\Enums\FastQCompressionFormat::GZIP()); + $bclConvertSettingsSection = new SettingsSection('1.0.0', FastQCompressionFormat::GZIP()); $bclConvertSettingsSection->setTrimUMI(false); - $bclConvertDataSection = new BclConvertDataSection(); + $bclConvertDataSection = new \MLL\Utils\IlluminaSampleSheet\V2\BclConvert\DataSection(); $bclConvertDataSection->addSample(1, 'Sample1', 'Index1', 'Index2', 'Cycles1', 'Adapter1', 'Adapter2'); $bclConvertDataSection->addSample(2, 'Sample2', 'Index3', 'Index4', 'Cycles2', 'Adapter3', 'Adapter4'); $bclConvertDataSection->addSample(3, 'Sample3', 'Index5', 'Index6', 'Cycles3', 'Adapter5', 'Adapter6'); + $bclConvertSection = new BclConvertSection($bclConvertSettingsSection, $bclConvertDataSection); + $novaSeqXCloudSampleSheet = new NovaSeqXSampleSheet( $headerSection, $readsSection, - $bclConvertSettingsSection, - $bclConvertDataSection, + $bclConvertSection, ); $expected = '[Header] From 71f0da251fd2f5c361d53e2b243d62868fa95168 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Mon, 29 Apr 2024 12:57:03 +0200 Subject: [PATCH 16/29] Bcl Sample --- .../V2/BclConvert/BclConvertDataRow.php | 52 -------- .../V2/BclConvert/BclSample.php | 112 ++++++++++++++++++ .../V2/BclConvert/DataSection.php | 45 ++++--- .../V2/NovaSeqXCloudSampleSheetTest.php | 29 ++++- 4 files changed, 164 insertions(+), 74 deletions(-) delete mode 100644 src/IlluminaSampleSheet/V2/BclConvert/BclConvertDataRow.php create mode 100644 src/IlluminaSampleSheet/V2/BclConvert/BclSample.php diff --git a/src/IlluminaSampleSheet/V2/BclConvert/BclConvertDataRow.php b/src/IlluminaSampleSheet/V2/BclConvert/BclConvertDataRow.php deleted file mode 100644 index 2f877bf..0000000 --- a/src/IlluminaSampleSheet/V2/BclConvert/BclConvertDataRow.php +++ /dev/null @@ -1,52 +0,0 @@ -lane = $lane; - $this->sampleId = $sampleId; - $this->index = $index; - $this->index2 = $index2; - $this->overrideCycles = $overrideCycles; - $this->adapterRead1 = $adapterRead1; - $this->adapterRead2 = $adapterRead2; - } - - /** @return array */ - public function toArray(): array - { - return [ - $this->lane, - $this->sampleId, - $this->index, - $this->index2, - $this->overrideCycles, - $this->adapterRead1, - $this->adapterRead2, - ]; - } -} diff --git a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php new file mode 100644 index 0000000..b77b708 --- /dev/null +++ b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php @@ -0,0 +1,112 @@ +lane = $lane; + $this->sample_ID = $sampleId; + $this->index = $index; + } + + public function setIndex2(string $index2): BclSample + { + $this->index2 = $index2; + + return $this; + } + + public function setOverrideCycles(string $overrideCycles): BclSample + { + $this->overrideCycles = $overrideCycles; + + return $this; + } + + public function setAdapterRead1(string $adapterRead1): BclSample + { + $this->adapterRead1 = $adapterRead1; + + return $this; + } + + public function setAdapterRead2(string $adapterRead2): BclSample + { + $this->adapterRead2 = $adapterRead2; + + return $this; + } + + public function setBarcodeMismatchesIndex1(string $barcodeMismatchesIndex1): BclSample + { + $this->barcodeMismatchesIndex1 = $barcodeMismatchesIndex1; + + return $this; + } + + public function setBarcodeMismatchesIndex2(string $barcodeMismatchesIndex2): BclSample + { + $this->barcodeMismatchesIndex2 = $barcodeMismatchesIndex2; + + return $this; + } + + /** @return array */ + public function toArray(): array + { + $data = [ + $this->lane, + $this->sample_ID, + $this->index, + ]; + + if (! is_null($this->index2)) { + $data[] = $this->index2; + } + + if (! is_null($this->overrideCycles)) { + $data[] = $this->overrideCycles; + } + + if (! is_null($this->adapterRead1)) { + $data[] = $this->adapterRead1; + } + + if (! is_null($this->adapterRead2)) { + $data[] = $this->adapterRead2; + } + + if (! is_null($this->barcodeMismatchesIndex1)) { + $data[] = $this->barcodeMismatchesIndex1; + } + + if (! is_null($this->barcodeMismatchesIndex2)) { + $data[] = $this->barcodeMismatchesIndex2; + } + + return $data; + } +} diff --git a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php index 577d6ad..bc680b4 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php @@ -6,34 +6,30 @@ class DataSection implements SectionInterface { - /** @var array */ + /** @var array */ private array $dataRows = []; public function addSample( - int $lane, - string $sampleId, - string $index, - string $index2, - string $overrideCycles, - string $adapterRead1, - string $adapterRead2 + BclSample $bclSample ): void { - $this->dataRows[] = new BclConvertDataRow( - $lane, - $sampleId, - $index, - $index2, - $overrideCycles, - $adapterRead1, - $adapterRead2 - ); + $this->dataRows[] = $bclSample; } public function convertSectionToString(): string { + /** @var array $samplePropertiesOfFirstSample */ + $samplePropertiesOfFirstSample = array_keys(get_object_vars($this->dataRows[0])); + foreach ($this->dataRows as $sample) { + if ($samplePropertiesOfFirstSample !== array_keys(get_object_vars($sample))) { + throw new \Exception('All samples must have the same properties'); + } + } + + $bclConvertDataLines = $this->generateDataHeaderByProperites($samplePropertiesOfFirstSample); + $bclConvertDataLines = [ '[BCLConvert_Data]', - 'Lane,Sample_ID,Index,Index2,OverrideCycles,AdapterRead1,AdapterRead2', + $bclConvertDataLines, ]; foreach ($this->dataRows as $dataRow) { @@ -42,4 +38,17 @@ public function convertSectionToString(): string return implode("\n", $bclConvertDataLines) . "\n"; } + + /** + * @param array $samplePropertiesOfFirstSample + */ + private function generateDataHeaderByProperites(array $samplePropertiesOfFirstSample): string + { + $samplePropertiesOfFirstSample = array_filter($samplePropertiesOfFirstSample, fn ($value) // @phpstan-ignore-next-line Variable property access on a non-object required here + => $this->dataRows[0]->$value !== null); + + $samplePropertiesOfFirstSample = array_map(fn ($value) => ucfirst($value), $samplePropertiesOfFirstSample); + + return implode(',', $samplePropertiesOfFirstSample); + } } diff --git a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php index 05571ba..d4f895d 100644 --- a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php @@ -3,6 +3,8 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet\V2; use MLL\Utils\IlluminaSampleSheet\V2\BclConvert\BclConvertSection; +use MLL\Utils\IlluminaSampleSheet\V2\BclConvert\BclSample; +use MLL\Utils\IlluminaSampleSheet\V2\BclConvert\DataSection; use MLL\Utils\IlluminaSampleSheet\V2\BclConvert\SettingsSection; use MLL\Utils\IlluminaSampleSheet\V2\Enums\FastQCompressionFormat; use MLL\Utils\IlluminaSampleSheet\V2\HeaderSection; @@ -30,10 +32,29 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi $bclConvertSettingsSection = new SettingsSection('1.0.0', FastQCompressionFormat::GZIP()); $bclConvertSettingsSection->setTrimUMI(false); - $bclConvertDataSection = new \MLL\Utils\IlluminaSampleSheet\V2\BclConvert\DataSection(); - $bclConvertDataSection->addSample(1, 'Sample1', 'Index1', 'Index2', 'Cycles1', 'Adapter1', 'Adapter2'); - $bclConvertDataSection->addSample(2, 'Sample2', 'Index3', 'Index4', 'Cycles2', 'Adapter3', 'Adapter4'); - $bclConvertDataSection->addSample(3, 'Sample3', 'Index5', 'Index6', 'Cycles3', 'Adapter5', 'Adapter6'); + $bclConvertDataSection = new DataSection(); + + $bclConvertDataSection->addSample( + (new BclSample(1, 'Sample1', 'Index1')) + ->setIndex2('Index2') + ->setOverrideCycles('Cycles1') + ->setAdapterRead1('Adapter1') + ->setAdapterRead2('Adapter2') + ); + $bclConvertDataSection->addSample( + (new BclSample(2, 'Sample2', 'Index3')) + ->setIndex2('Index4') + ->setOverrideCycles('Cycles2') + ->setAdapterRead1('Adapter3') + ->setAdapterRead2('Adapter4') + ); + $bclConvertDataSection->addSample( + (new BclSample(3, 'Sample3', 'Index5')) + ->setIndex2('Index6') + ->setOverrideCycles('Cycles3') + ->setAdapterRead1('Adapter5') + ->setAdapterRead2('Adapter6') + ); $bclConvertSection = new BclConvertSection($bclConvertSettingsSection, $bclConvertDataSection); From e805d91c624e48e9777db1899f140715caece8c6 Mon Sep 17 00:00:00 2001 From: simbig Date: Mon, 29 Apr 2024 10:59:23 +0000 Subject: [PATCH 17/29] Apply php-cs-fixer changes --- src/IlluminaSampleSheet/V2/BclConvert/DataSection.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php index bc680b4..5991d60 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php @@ -39,9 +39,7 @@ public function convertSectionToString(): string return implode("\n", $bclConvertDataLines) . "\n"; } - /** - * @param array $samplePropertiesOfFirstSample - */ + /** @param array $samplePropertiesOfFirstSample */ private function generateDataHeaderByProperites(array $samplePropertiesOfFirstSample): string { $samplePropertiesOfFirstSample = array_filter($samplePropertiesOfFirstSample, fn ($value) // @phpstan-ignore-next-line Variable property access on a non-object required here From 79538dd740688b8094de90e22cd8204d4b63b5ce Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Thu, 2 May 2024 13:35:12 +0200 Subject: [PATCH 18/29] update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c88b80..ea2162c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ See [GitHub releases](https://github.com/mll-lab/php-utils/releases). ### Added -- Add support for creating different Illumina NovaSeq Sample Sheets (V1 & V2), including specific sections (Header, Reads, Data, Settings etc.). +- Add support for creating Illumina NovaSeq Sample Sheets (V2) for NovaSeqX. ## v1.13.0 From adc6dfe615e868f5da7ce10bf88d2eb0aef6d675 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Fri, 3 May 2024 09:04:29 +0200 Subject: [PATCH 19/29] keep dataProvider --- tests/Microplate/CoordinatesTest.php | 8 ++++++++ tests/Microplate/MicroplateSet/MicroplateSetABCDTest.php | 2 ++ tests/NumberTest.php | 2 ++ 3 files changed, 12 insertions(+) diff --git a/tests/Microplate/CoordinatesTest.php b/tests/Microplate/CoordinatesTest.php index 330adba..78b215d 100644 --- a/tests/Microplate/CoordinatesTest.php +++ b/tests/Microplate/CoordinatesTest.php @@ -11,6 +11,7 @@ final class CoordinatesTest extends TestCase { #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] + /** @dataProvider dataProvider96Well */ public function testCanConstructFromRowAndColumn(string $row, int $column, int $rowFlowPosition, int $columnFlowPosition): void { $coordinates96Well = new Coordinates($row, $column, new CoordinateSystem96Well()); @@ -19,6 +20,7 @@ public function testCanConstructFromRowAndColumn(string $row, int $column, int $ } #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] + /** @dataProvider dataProvider96Well */ public function testCanConstructFromPosition(string $row, int $column, int $rowFlowPosition, int $columnFlowPosition): void { // test for Column-FlowDirection @@ -41,6 +43,7 @@ public function testCanConstructFromPosition(string $row, int $column, int $rowF } #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] + /** @dataProvider dataProvider96Well */ public function testFromCoordinatesString(string $row, int $column, int $rowFlowPosition, int $columnFlowPosition): void { $coordinates = Coordinates::fromString($row . $column, new CoordinateSystem96Well()); @@ -49,6 +52,7 @@ public function testFromCoordinatesString(string $row, int $column, int $rowFlow } #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderPadded96Well')] + /** @dataProvider dataProviderPadded96Well */ public function testFromPaddedCoordinatesString(string $paddedCoordinates, string $row, int $column): void { $coordinatesFromPadded = Coordinates::fromString($paddedCoordinates, new CoordinateSystem96Well()); @@ -685,6 +689,7 @@ public static function dataProvider96Well(): iterable } #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider12Well')] + /** @dataProvider dataProvider12Well */ public function testPosition12Well(string $row, int $column, int $rowFlowPosition, int $columnFlowPosition): void { $coordinates = new Coordinates($row, $column, new CoordinateSystem12Well()); @@ -772,6 +777,7 @@ public static function dataProvider12Well(): array } #[\PHPUnit\Framework\Attributes\DataProvider('invalidRowsOrColumns')] + /** @dataProvider invalidRowsOrColumns */ public function testThrowsOnInvalidRowsOrColumns(string $row, int $column): void { $this->expectException(\InvalidArgumentException::class); @@ -790,6 +796,7 @@ public static function invalidRowsOrColumns(): iterable } #[\PHPUnit\Framework\Attributes\DataProvider('invalidPositions')] + /** @dataProvider invalidPositions */ public function testThrowsOnInvalidPositions(int $position): void { $this->expectException(\InvalidArgumentException::class); @@ -806,6 +813,7 @@ public static function invalidPositions(): iterable } #[\PHPUnit\Framework\Attributes\DataProvider('invalidCoordinates')] + /** @dataProvider invalidCoordinates */ public function testThrowsOnInvalidCoordinates(string $coordinatesString): void { $this->expectException(\InvalidArgumentException::class); diff --git a/tests/Microplate/MicroplateSet/MicroplateSetABCDTest.php b/tests/Microplate/MicroplateSet/MicroplateSetABCDTest.php index 613d605..d98f67d 100644 --- a/tests/Microplate/MicroplateSet/MicroplateSetABCDTest.php +++ b/tests/Microplate/MicroplateSet/MicroplateSetABCDTest.php @@ -47,6 +47,7 @@ public function testSetLocationFromSetPositionFor12WellPlatesOutOfRangeTooLow(): } #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider12Well')] + /** @dataProvider dataProvider12Well */ public function testSetLocationFromSetPositionFor12Wells(int $position, string $coordinatesString, string $plateID): void { $microplateSet = new MicroplateSetABCD(new CoordinateSystem12Well()); @@ -92,6 +93,7 @@ public static function dataProvider12Well(): iterable } #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] + /** @dataProvider dataProvider96Well */ public function testSetLocationFromSetPositionFor96Wells(int $position, string $coordinatesString, string $plateID): void { $microplateSet = new MicroplateSetABCD(new CoordinateSystem96Well()); diff --git a/tests/NumberTest.php b/tests/NumberTest.php index 964c2fd..1c9fbc4 100644 --- a/tests/NumberTest.php +++ b/tests/NumberTest.php @@ -8,6 +8,8 @@ final class NumberTest extends TestCase { /** + * @dataProvider clampProvider + * * @param float|int $min * @param float|int $max * @param float|int $current From dfa2636f970a361281293e4ede54a63a03812945 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Fri, 3 May 2024 09:13:24 +0200 Subject: [PATCH 20/29] keep dataProvider pt2 --- tests/BavarianHolidaysTest.php | 3 +++ tests/CSVArrayTest.php | 6 +++++- tests/Microplate/CoordinateSystemTest.php | 1 + tests/StringUtilTest.php | 13 +++++++++++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/BavarianHolidaysTest.php b/tests/BavarianHolidaysTest.php index b68421e..aad68a2 100644 --- a/tests/BavarianHolidaysTest.php +++ b/tests/BavarianHolidaysTest.php @@ -16,6 +16,7 @@ public function testNameHoliday(): void } #[\PHPUnit\Framework\Attributes\DataProvider('businessDays')] + /** @dataProvider businessDays */ public function testBusinessDays(Carbon $businessDay): void { self::assertTrue(BavarianHolidays::isBusinessDay($businessDay)); @@ -23,6 +24,7 @@ public function testBusinessDays(Carbon $businessDay): void } #[\PHPUnit\Framework\Attributes\DataProvider('holidays')] + /** @dataProvider holidays */ public function testHolidays(Carbon $holiday): void { self::assertFalse(BavarianHolidays::isBusinessDay($holiday)); @@ -30,6 +32,7 @@ public function testHolidays(Carbon $holiday): void } #[\PHPUnit\Framework\Attributes\DataProvider('weekend')] + /** @dataProvider weekend */ public function testWeekend(Carbon $weekend): void { self::assertFalse(BavarianHolidays::isBusinessDay($weekend)); diff --git a/tests/CSVArrayTest.php b/tests/CSVArrayTest.php index 8827d68..991593c 100644 --- a/tests/CSVArrayTest.php +++ b/tests/CSVArrayTest.php @@ -41,7 +41,11 @@ public static function csvAndArrayStringValues(): iterable ]; } - /** @param array> $array */ + /** + * @dataProvider csvAndArrayStringValues + * + * @param array> $array + */ #[\PHPUnit\Framework\Attributes\DataProvider('csvAndArrayStringValues')] public function testStringValues(string $csv, array $array): void { diff --git a/tests/Microplate/CoordinateSystemTest.php b/tests/Microplate/CoordinateSystemTest.php index 457daaf..287a501 100644 --- a/tests/Microplate/CoordinateSystemTest.php +++ b/tests/Microplate/CoordinateSystemTest.php @@ -11,6 +11,7 @@ final class CoordinateSystemTest extends TestCase { #[\PHPUnit\Framework\Attributes\DataProvider('firstLast')] + /** @dataProvider firstLast */ public function testFirstLast(CoordinateSystem $coordinateSystem, string $expectedFirst, string $expectedLast): void { $actualFirst = $coordinateSystem->first(); diff --git a/tests/StringUtilTest.php b/tests/StringUtilTest.php index a549b56..7e654f5 100644 --- a/tests/StringUtilTest.php +++ b/tests/StringUtilTest.php @@ -8,7 +8,11 @@ final class StringUtilTest extends TestCase { - /** @param iterable $parts */ + /** + * @dataProvider joinNonEmpty + * + * @param iterable $parts + */ #[\PHPUnit\Framework\Attributes\DataProvider('joinNonEmpty')] public function testJoinNonEmpty(string $expectedJoined, string $glue, iterable $parts): void { @@ -27,6 +31,7 @@ public static function joinNonEmpty(): iterable } #[\PHPUnit\Framework\Attributes\DataProvider('shortenFirstname')] + /** @dataProvider shortenFirstname */ public function testShortenFirstname(string $expectedShortened, string $input): void { self::assertSame( @@ -45,7 +50,11 @@ public static function shortenFirstname(): iterable yield ['', '']; } - /** @param array $expectedLines */ + /** + * @dataProvider splitLines + * + * @param array $expectedLines + */ #[\PHPUnit\Framework\Attributes\DataProvider('splitLines')] public function testSplitLines(array $expectedLines, string $input): void { From 7c974dc93cecd29aaf44119c7998492889be3a48 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Fri, 3 May 2024 09:16:38 +0200 Subject: [PATCH 21/29] keep dataProvider pt3 --- tests/Microplate/CoordinatesTest.php | 1 + tests/Microplate/MicroplateSet/MicroplateSetABTest.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/tests/Microplate/CoordinatesTest.php b/tests/Microplate/CoordinatesTest.php index 78b215d..ee902a9 100644 --- a/tests/Microplate/CoordinatesTest.php +++ b/tests/Microplate/CoordinatesTest.php @@ -93,6 +93,7 @@ public static function dataProviderPadded96Well(): iterable } #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] + /** @dataProvider dataProvider96Well */ public function testPosition96Well(string $row, int $column, int $rowFlowPosition, int $columnFlowPosition): void { $coordinates = new Coordinates($row, $column, new CoordinateSystem96Well()); diff --git a/tests/Microplate/MicroplateSet/MicroplateSetABTest.php b/tests/Microplate/MicroplateSet/MicroplateSetABTest.php index 01c6392..a8c2af9 100644 --- a/tests/Microplate/MicroplateSet/MicroplateSetABTest.php +++ b/tests/Microplate/MicroplateSet/MicroplateSetABTest.php @@ -47,6 +47,7 @@ public function testSetLocationFromSetPositionFor12WellPlatesOutOfRangeTooLow(): } #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider12Well')] + /** @dataProvider dataProvider12Well */ public function testSetLocationFromSetPositionFor12Wells(int $position, string $coordinatesString, string $plateID): void { $microplateSet = new MicroplateSetAB(new CoordinateSystem12Well()); @@ -92,6 +93,7 @@ public static function dataProvider12Well(): iterable } #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider96Well')] + /** @dataProvider dataProvider96Well */ public function testSetLocationFromSetPositionFor96Wells(int $position, string $coordinatesString, string $plateID): void { $microplateSet = new MicroplateSetAB(new CoordinateSystem96Well()); From 3852ff61adf1245855aafc22b8235826c0e41512 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Fri, 3 May 2024 12:05:09 +0200 Subject: [PATCH 22/29] Apply suggestions from code review Co-authored-by: Benedikt Franke --- CHANGELOG.md | 2 +- src/IlluminaSampleSheet/SampleSheet.php | 7 ++++++- src/IlluminaSampleSheet/SectionInterface.php | 2 +- src/IlluminaSampleSheet/V2/BclConvert/BclSample.php | 2 +- src/IlluminaSampleSheet/V2/BclConvert/DataSection.php | 5 ++--- src/IlluminaSampleSheet/V2/HeaderSection.php | 2 +- tests/IlluminaSampleSheet/SampleSheetTest.php | 2 +- .../V2/NovaSeqXCloudSampleSheetTest.php | 8 +++----- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea2162c..b1a8836 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ See [GitHub releases](https://github.com/mll-lab/php-utils/releases). ### Added -- Add support for creating Illumina NovaSeq Sample Sheets (V2) for NovaSeqX. +- Support creating Illumina NovaSeq Sample Sheets (V2) for NovaSeqX ## v1.13.0 diff --git a/src/IlluminaSampleSheet/SampleSheet.php b/src/IlluminaSampleSheet/SampleSheet.php index d4142fe..fccc360 100644 --- a/src/IlluminaSampleSheet/SampleSheet.php +++ b/src/IlluminaSampleSheet/SampleSheet.php @@ -14,7 +14,12 @@ public function addSection(SectionInterface $section): void public function toString(): string { - return implode("\n", array_map(fn (SectionInterface $section) => $section->convertSectionToString(), $this->sections)); + $sectionStrings = array_map( + fn (SectionInterface $section): string => $section->convertSectionToString(), + $this->sections + ); + + return implode("\n", $sectionStrings); } /** @return array */ diff --git a/src/IlluminaSampleSheet/SectionInterface.php b/src/IlluminaSampleSheet/SectionInterface.php index 87982cd..c571129 100644 --- a/src/IlluminaSampleSheet/SectionInterface.php +++ b/src/IlluminaSampleSheet/SectionInterface.php @@ -2,7 +2,7 @@ namespace MLL\Utils\IlluminaSampleSheet; -interface SectionInterface +interface Section { public function convertSectionToString(): string; } diff --git a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php index b77b708..bb56a3e 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php @@ -24,7 +24,7 @@ class BclSample public function __construct( int $lane, - string $sampleId, + string $sampleID, string $index ) { $this->lane = $lane; diff --git a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php index 5991d60..b0d57de 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php @@ -9,9 +9,8 @@ class DataSection implements SectionInterface /** @var array */ private array $dataRows = []; - public function addSample( - BclSample $bclSample - ): void { + public function addSample(BclSample $bclSample): void + { $this->dataRows[] = $bclSample; } diff --git a/src/IlluminaSampleSheet/V2/HeaderSection.php b/src/IlluminaSampleSheet/V2/HeaderSection.php index de130a1..9511e37 100644 --- a/src/IlluminaSampleSheet/V2/HeaderSection.php +++ b/src/IlluminaSampleSheet/V2/HeaderSection.php @@ -56,7 +56,7 @@ public function convertSectionToString(): string { $headerLines = [ '[Header]', - 'FileFormatVersion,' . $this->fileFormatVersion, + "FileFormatVersion,{$this->fileFormatVersion}", "RunName,{$this->runName}", ]; if (! is_null($this->runDescription)) { diff --git a/tests/IlluminaSampleSheet/SampleSheetTest.php b/tests/IlluminaSampleSheet/SampleSheetTest.php index 695e8cc..2c36202 100644 --- a/tests/IlluminaSampleSheet/SampleSheetTest.php +++ b/tests/IlluminaSampleSheet/SampleSheetTest.php @@ -6,7 +6,7 @@ use MLL\Utils\IlluminaSampleSheet\SectionInterface; use PHPUnit\Framework\TestCase; -class SampleSheetTest extends TestCase +final class SampleSheetTest extends TestCase { public function testSampleSheetToStringReturnsCorrectFormat(): void { diff --git a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php index d4f895d..632b364 100644 --- a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php @@ -12,13 +12,11 @@ use MLL\Utils\IlluminaSampleSheet\V2\ReadsSection; use PHPUnit\Framework\TestCase; -class NovaSeqXCloudSampleSheetTest extends TestCase +final class NovaSeqXCloudSampleSheetTest extends TestCase { public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): void { - $headerSection = new HeaderSection( - 'Run1', - ); + $headerSection = new HeaderSection('Run1'); $headerSection->setInstrumentPlatform('NovaSeqXSeries'); $headerSection->setCustomParam('IndexOrientation', 'Orientation1'); @@ -88,6 +86,6 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi 3,Sample3,Index5,Index6,Cycles3,Adapter5,Adapter6 '; - self::assertEquals($expected, $novaSeqXCloudSampleSheet->toString()); + self::assertSame($expected, $novaSeqXCloudSampleSheet->toString()); } } From bd5e48a9e0b9e1a69662a7bb5716774e2490ac8c Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Fri, 3 May 2024 13:34:32 +0200 Subject: [PATCH 23/29] fix code --- src/IlluminaSampleSheet/SampleSheet.php | 8 ++++---- .../{SectionInterface.php => Section.php} | 0 .../V2/BclConvert/BclConvertSection.php | 4 ++-- src/IlluminaSampleSheet/V2/BclConvert/BclSample.php | 2 +- src/IlluminaSampleSheet/V2/BclConvert/DataSection.php | 4 ++-- src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php | 4 ++-- src/IlluminaSampleSheet/V2/HeaderSection.php | 4 ++-- src/IlluminaSampleSheet/V2/ReadsSection.php | 4 ++-- tests/IlluminaSampleSheet/SampleSheetTest.php | 6 +++--- 9 files changed, 18 insertions(+), 18 deletions(-) rename src/IlluminaSampleSheet/{SectionInterface.php => Section.php} (100%) diff --git a/src/IlluminaSampleSheet/SampleSheet.php b/src/IlluminaSampleSheet/SampleSheet.php index fccc360..5e3c262 100644 --- a/src/IlluminaSampleSheet/SampleSheet.php +++ b/src/IlluminaSampleSheet/SampleSheet.php @@ -4,10 +4,10 @@ abstract class SampleSheet { - /** @var array */ + /** @var array
*/ protected array $sections = []; - public function addSection(SectionInterface $section): void + public function addSection(Section $section): void { $this->sections[] = $section; } @@ -15,14 +15,14 @@ public function addSection(SectionInterface $section): void public function toString(): string { $sectionStrings = array_map( - fn (SectionInterface $section): string => $section->convertSectionToString(), + fn (Section $section): string => $section->convertSectionToString(), $this->sections ); return implode("\n", $sectionStrings); } - /** @return array */ + /** @return array
*/ public function getSections(): array { return $this->sections; diff --git a/src/IlluminaSampleSheet/SectionInterface.php b/src/IlluminaSampleSheet/Section.php similarity index 100% rename from src/IlluminaSampleSheet/SectionInterface.php rename to src/IlluminaSampleSheet/Section.php diff --git a/src/IlluminaSampleSheet/V2/BclConvert/BclConvertSection.php b/src/IlluminaSampleSheet/V2/BclConvert/BclConvertSection.php index 9f7deac..e8e1829 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/BclConvertSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/BclConvertSection.php @@ -2,9 +2,9 @@ namespace MLL\Utils\IlluminaSampleSheet\V2\BclConvert; -use MLL\Utils\IlluminaSampleSheet\SectionInterface; +use MLL\Utils\IlluminaSampleSheet\Section; -class BclConvertSection implements SectionInterface +class BclConvertSection implements Section { private SettingsSection $settingsSection; diff --git a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php index bb56a3e..9186f52 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php @@ -28,7 +28,7 @@ public function __construct( string $index ) { $this->lane = $lane; - $this->sample_ID = $sampleId; + $this->sample_ID = $sampleID; $this->index = $index; } diff --git a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php index b0d57de..4c6a972 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php @@ -2,9 +2,9 @@ namespace MLL\Utils\IlluminaSampleSheet\V2\BclConvert; -use MLL\Utils\IlluminaSampleSheet\SectionInterface; +use MLL\Utils\IlluminaSampleSheet\Section; -class DataSection implements SectionInterface +class DataSection implements Section { /** @var array */ private array $dataRows = []; diff --git a/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php b/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php index cb8a567..d4848f0 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php @@ -2,10 +2,10 @@ namespace MLL\Utils\IlluminaSampleSheet\V2\BclConvert; -use MLL\Utils\IlluminaSampleSheet\SectionInterface; +use MLL\Utils\IlluminaSampleSheet\Section; use MLL\Utils\IlluminaSampleSheet\V2\Enums\FastQCompressionFormat; -class SettingsSection implements SectionInterface +class SettingsSection implements Section { public string $softwareVersion; diff --git a/src/IlluminaSampleSheet/V2/HeaderSection.php b/src/IlluminaSampleSheet/V2/HeaderSection.php index 9511e37..5c7b37e 100644 --- a/src/IlluminaSampleSheet/V2/HeaderSection.php +++ b/src/IlluminaSampleSheet/V2/HeaderSection.php @@ -2,9 +2,9 @@ namespace MLL\Utils\IlluminaSampleSheet\V2; -use MLL\Utils\IlluminaSampleSheet\SectionInterface; +use MLL\Utils\IlluminaSampleSheet\Section; -class HeaderSection implements SectionInterface +class HeaderSection implements Section { private const FILE_FORMAT_VERSION = '2'; diff --git a/src/IlluminaSampleSheet/V2/ReadsSection.php b/src/IlluminaSampleSheet/V2/ReadsSection.php index 72aa534..8e1b903 100644 --- a/src/IlluminaSampleSheet/V2/ReadsSection.php +++ b/src/IlluminaSampleSheet/V2/ReadsSection.php @@ -3,9 +3,9 @@ namespace MLL\Utils\IlluminaSampleSheet\V2; use MLL\Utils\IlluminaSampleSheet\IlluminaSampleSheetException; -use MLL\Utils\IlluminaSampleSheet\SectionInterface; +use MLL\Utils\IlluminaSampleSheet\Section; -class ReadsSection implements SectionInterface +class ReadsSection implements Section { private int $read1Cycles; diff --git a/tests/IlluminaSampleSheet/SampleSheetTest.php b/tests/IlluminaSampleSheet/SampleSheetTest.php index 2c36202..6f51dde 100644 --- a/tests/IlluminaSampleSheet/SampleSheetTest.php +++ b/tests/IlluminaSampleSheet/SampleSheetTest.php @@ -3,17 +3,17 @@ namespace MLL\Utils\Tests\IlluminaSampleSheet; use MLL\Utils\IlluminaSampleSheet\SampleSheet; -use MLL\Utils\IlluminaSampleSheet\SectionInterface; +use MLL\Utils\IlluminaSampleSheet\Section; use PHPUnit\Framework\TestCase; final class SampleSheetTest extends TestCase { public function testSampleSheetToStringReturnsCorrectFormat(): void { - $sectionMock1 = $this->createMock(SectionInterface::class); + $sectionMock1 = $this->createMock(Section::class); $sectionMock1->method('convertSectionToString')->willReturn('section1'); - $sectionMock2 = $this->createMock(SectionInterface::class); + $sectionMock2 = $this->createMock(Section::class); $sectionMock2->method('convertSectionToString')->willReturn('section2'); $sampleSheet = $this->createPartialMock(SampleSheet::class, []); From 6cb433159b335434a95f7ff1b8df474fe6d6695a Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Fri, 3 May 2024 13:45:13 +0200 Subject: [PATCH 24/29] fixes from review --- src/IlluminaSampleSheet/SampleSheet.php | 6 ---- .../V2/BclConvert/BclSample.php | 36 +++++-------------- .../V2/BclConvert/DataSection.php | 15 ++++---- .../V2/BclConvert/SettingsSection.php | 4 +-- 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/src/IlluminaSampleSheet/SampleSheet.php b/src/IlluminaSampleSheet/SampleSheet.php index 5e3c262..e4ac0f3 100644 --- a/src/IlluminaSampleSheet/SampleSheet.php +++ b/src/IlluminaSampleSheet/SampleSheet.php @@ -21,10 +21,4 @@ public function toString(): string return implode("\n", $sectionStrings); } - - /** @return array
*/ - public function getSections(): array - { - return $this->sections; - } } diff --git a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php index 9186f52..15ce580 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php @@ -77,36 +77,16 @@ public function setBarcodeMismatchesIndex2(string $barcodeMismatchesIndex2): Bcl /** @return array */ public function toArray(): array { - $data = [ + return array_filter([ $this->lane, $this->sample_ID, $this->index, - ]; - - if (! is_null($this->index2)) { - $data[] = $this->index2; - } - - if (! is_null($this->overrideCycles)) { - $data[] = $this->overrideCycles; - } - - if (! is_null($this->adapterRead1)) { - $data[] = $this->adapterRead1; - } - - if (! is_null($this->adapterRead2)) { - $data[] = $this->adapterRead2; - } - - if (! is_null($this->barcodeMismatchesIndex1)) { - $data[] = $this->barcodeMismatchesIndex1; - } - - if (! is_null($this->barcodeMismatchesIndex2)) { - $data[] = $this->barcodeMismatchesIndex2; - } - - return $data; + $this->index2, + $this->overrideCycles, + $this->adapterRead1, + $this->adapterRead2, + $this->barcodeMismatchesIndex1, + $this->barcodeMismatchesIndex2, + ]); } } diff --git a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php index 4c6a972..767a79b 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php @@ -19,16 +19,17 @@ public function convertSectionToString(): string /** @var array $samplePropertiesOfFirstSample */ $samplePropertiesOfFirstSample = array_keys(get_object_vars($this->dataRows[0])); foreach ($this->dataRows as $sample) { - if ($samplePropertiesOfFirstSample !== array_keys(get_object_vars($sample))) { - throw new \Exception('All samples must have the same properties'); + $actualProperties = array_keys(get_object_vars($sample)); + if ($samplePropertiesOfFirstSample !== $actualProperties) { + throw new \Exception('All samples must have the same properties. Expected: ' . \Safe\json_encode($samplePropertiesOfFirstSample) . ', Actual: ' . \Safe\json_encode($actualProperties)); } } - $bclConvertDataLines = $this->generateDataHeaderByProperites($samplePropertiesOfFirstSample); + $bclConvertDataHeaderLines = $this->generateDataHeaderByProperties($samplePropertiesOfFirstSample); $bclConvertDataLines = [ '[BCLConvert_Data]', - $bclConvertDataLines, + $bclConvertDataHeaderLines, ]; foreach ($this->dataRows as $dataRow) { @@ -39,12 +40,12 @@ public function convertSectionToString(): string } /** @param array $samplePropertiesOfFirstSample */ - private function generateDataHeaderByProperites(array $samplePropertiesOfFirstSample): string + private function generateDataHeaderByProperties(array $samplePropertiesOfFirstSample): string { - $samplePropertiesOfFirstSample = array_filter($samplePropertiesOfFirstSample, fn ($value) // @phpstan-ignore-next-line Variable property access on a non-object required here + $samplePropertiesOfFirstSample = array_filter($samplePropertiesOfFirstSample, fn (string $value) // @phpstan-ignore-next-line Variable property access on a non-object required here => $this->dataRows[0]->$value !== null); - $samplePropertiesOfFirstSample = array_map(fn ($value) => ucfirst($value), $samplePropertiesOfFirstSample); + $samplePropertiesOfFirstSample = array_map(fn (string $value) => ucfirst($value), $samplePropertiesOfFirstSample); return implode(',', $samplePropertiesOfFirstSample); } diff --git a/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php b/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php index d4848f0..f612792 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php @@ -30,11 +30,11 @@ public function convertSectionToString(): string ]; if (! is_null($this->trimUMI)) { - $booleanToString = $this->trimUMI + $trimUMIAsString = $this->trimUMI ? '1' : '0'; - $bclConvertSettingsLines[] = "TrimUMI,{$booleanToString}"; + $bclConvertSettingsLines[] = "TrimUMI,{$trimUMIAsString}"; } return implode("\n", $bclConvertSettingsLines) . "\n"; From 58672d7f5498c92e000464559f4f92e5d225beaf Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Mon, 6 May 2024 09:18:20 +0200 Subject: [PATCH 25/29] protected --- .../V2/BclConvert/BclConvertSection.php | 4 ++-- .../V2/BclConvert/DataSection.php | 4 ++-- src/IlluminaSampleSheet/V2/HeaderSection.php | 14 +++++++------- src/IlluminaSampleSheet/V2/ReadsSection.php | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/IlluminaSampleSheet/V2/BclConvert/BclConvertSection.php b/src/IlluminaSampleSheet/V2/BclConvert/BclConvertSection.php index e8e1829..a5042da 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/BclConvertSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/BclConvertSection.php @@ -6,9 +6,9 @@ class BclConvertSection implements Section { - private SettingsSection $settingsSection; + protected SettingsSection $settingsSection; - private DataSection $dataSection; + protected DataSection $dataSection; public function __construct(SettingsSection $settingsSection, DataSection $dataSection) { diff --git a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php index 767a79b..e26cc39 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/DataSection.php @@ -7,7 +7,7 @@ class DataSection implements Section { /** @var array */ - private array $dataRows = []; + protected array $dataRows = []; public function addSample(BclSample $bclSample): void { @@ -40,7 +40,7 @@ public function convertSectionToString(): string } /** @param array $samplePropertiesOfFirstSample */ - private function generateDataHeaderByProperties(array $samplePropertiesOfFirstSample): string + protected function generateDataHeaderByProperties(array $samplePropertiesOfFirstSample): string { $samplePropertiesOfFirstSample = array_filter($samplePropertiesOfFirstSample, fn (string $value) // @phpstan-ignore-next-line Variable property access on a non-object required here => $this->dataRows[0]->$value !== null); diff --git a/src/IlluminaSampleSheet/V2/HeaderSection.php b/src/IlluminaSampleSheet/V2/HeaderSection.php index 5c7b37e..0d1c3c8 100644 --- a/src/IlluminaSampleSheet/V2/HeaderSection.php +++ b/src/IlluminaSampleSheet/V2/HeaderSection.php @@ -6,20 +6,20 @@ class HeaderSection implements Section { - private const FILE_FORMAT_VERSION = '2'; + protected const FILE_FORMAT_VERSION = '2'; - private string $fileFormatVersion = self::FILE_FORMAT_VERSION; + protected string $fileFormatVersion = self::FILE_FORMAT_VERSION; - private string $runName; + protected string $runName; - private ?string $runDescription = null; + protected ?string $runDescription = null; - private ?string $instrumentType = null; + protected ?string $instrumentType = null; - private ?string $instrumentPlatform = null; + protected ?string $instrumentPlatform = null; /** @var array */ - private array $customParams = []; + protected array $customParams = []; public function __construct(string $runName) { diff --git a/src/IlluminaSampleSheet/V2/ReadsSection.php b/src/IlluminaSampleSheet/V2/ReadsSection.php index 8e1b903..b8d69fc 100644 --- a/src/IlluminaSampleSheet/V2/ReadsSection.php +++ b/src/IlluminaSampleSheet/V2/ReadsSection.php @@ -7,13 +7,13 @@ class ReadsSection implements Section { - private int $read1Cycles; + protected int $read1Cycles; - private ?int $read2Cycles; + protected ?int $read2Cycles; - private ?int $index1Cycles; + protected ?int $index1Cycles; - private ?int $index2Cycles; + protected ?int $index2Cycles; public function __construct(int $read1Cycles, ?int $read2Cycles = null, ?int $index1Cycles = null, ?int $index2Cycles = null) { From 56a580ce49f2eb2c86d728d189b223f6b34f2849 Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Mon, 6 May 2024 12:32:46 +0200 Subject: [PATCH 26/29] remove setter --- .../V2/BclConvert/BclSample.php | 42 ----------------- .../V2/BclConvert/SettingsSection.php | 7 --- src/IlluminaSampleSheet/V2/HeaderSection.php | 29 ++---------- src/IlluminaSampleSheet/V2/ReadsSection.php | 10 ++-- .../V2/NovaSeqXCloudSampleSheetTest.php | 46 +++++++++---------- 5 files changed, 31 insertions(+), 103 deletions(-) diff --git a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php index 15ce580..bcfced0 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php @@ -32,48 +32,6 @@ public function __construct( $this->index = $index; } - public function setIndex2(string $index2): BclSample - { - $this->index2 = $index2; - - return $this; - } - - public function setOverrideCycles(string $overrideCycles): BclSample - { - $this->overrideCycles = $overrideCycles; - - return $this; - } - - public function setAdapterRead1(string $adapterRead1): BclSample - { - $this->adapterRead1 = $adapterRead1; - - return $this; - } - - public function setAdapterRead2(string $adapterRead2): BclSample - { - $this->adapterRead2 = $adapterRead2; - - return $this; - } - - public function setBarcodeMismatchesIndex1(string $barcodeMismatchesIndex1): BclSample - { - $this->barcodeMismatchesIndex1 = $barcodeMismatchesIndex1; - - return $this; - } - - public function setBarcodeMismatchesIndex2(string $barcodeMismatchesIndex2): BclSample - { - $this->barcodeMismatchesIndex2 = $barcodeMismatchesIndex2; - - return $this; - } - /** @return array */ public function toArray(): array { diff --git a/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php b/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php index f612792..7279c24 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/SettingsSection.php @@ -39,11 +39,4 @@ public function convertSectionToString(): string return implode("\n", $bclConvertSettingsLines) . "\n"; } - - public function setTrimUMI(bool $trimUMI): SettingsSection - { - $this->trimUMI = $trimUMI; - - return $this; - } } diff --git a/src/IlluminaSampleSheet/V2/HeaderSection.php b/src/IlluminaSampleSheet/V2/HeaderSection.php index 0d1c3c8..04089f2 100644 --- a/src/IlluminaSampleSheet/V2/HeaderSection.php +++ b/src/IlluminaSampleSheet/V2/HeaderSection.php @@ -10,13 +10,13 @@ class HeaderSection implements Section protected string $fileFormatVersion = self::FILE_FORMAT_VERSION; - protected string $runName; + public string $runName; - protected ?string $runDescription = null; + public ?string $runDescription = null; - protected ?string $instrumentType = null; + public ?string $instrumentType = null; - protected ?string $instrumentPlatform = null; + public ?string $instrumentPlatform = null; /** @var array */ protected array $customParams = []; @@ -26,27 +26,6 @@ public function __construct(string $runName) $this->runName = $runName; } - public function setRunDescription(string $runDescription): HeaderSection - { - $this->runDescription = $runDescription; - - return $this; - } - - public function setInstrumentType(string $instrumentType): HeaderSection - { - $this->instrumentType = $instrumentType; - - return $this; - } - - public function setInstrumentPlatform(string $instrumentPlatform): HeaderSection - { - $this->instrumentPlatform = $instrumentPlatform; - - return $this; - } - public function setCustomParam(string $paramName, string $paramValue): void { $this->customParams['Custom_' . $paramName] = $paramValue; diff --git a/src/IlluminaSampleSheet/V2/ReadsSection.php b/src/IlluminaSampleSheet/V2/ReadsSection.php index b8d69fc..590fde1 100644 --- a/src/IlluminaSampleSheet/V2/ReadsSection.php +++ b/src/IlluminaSampleSheet/V2/ReadsSection.php @@ -38,17 +38,15 @@ public function __construct(int $read1Cycles, ?int $read2Cycles = null, ?int $in public function convertSectionToString(): string { $readsLines = ['[Reads]']; + $readsLines[] = "Read1Cycles,{$this->read1Cycles}"; - if (isset($this->read1Cycles)) { - $readsLines[] = "Read1Cycles,{$this->read1Cycles}"; - } - if (isset($this->read2Cycles)) { + if ($this->read2Cycles !== null) { $readsLines[] = "Read2Cycles,{$this->read2Cycles}"; } - if (isset($this->index1Cycles)) { + if ($this->index1Cycles !== null) { $readsLines[] = "Index1Cycles,{$this->index1Cycles}"; } - if (isset($this->index2Cycles)) { + if ($this->index2Cycles !== null) { $readsLines[] = "Index2Cycles,{$this->index2Cycles}"; } diff --git a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php index 632b364..af808be 100644 --- a/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php +++ b/tests/IlluminaSampleSheet/V2/NovaSeqXCloudSampleSheetTest.php @@ -17,7 +17,7 @@ final class NovaSeqXCloudSampleSheetTest extends TestCase public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): void { $headerSection = new HeaderSection('Run1'); - $headerSection->setInstrumentPlatform('NovaSeqXSeries'); + $headerSection->instrumentPlatform = 'NovaSeqXSeries'; $headerSection->setCustomParam('IndexOrientation', 'Orientation1'); $readsSection = new ReadsSection( @@ -28,31 +28,31 @@ public function testNovaSeqXCloudSampleSheetToStringReturnsExpectedResult(): voi ); $bclConvertSettingsSection = new SettingsSection('1.0.0', FastQCompressionFormat::GZIP()); - $bclConvertSettingsSection->setTrimUMI(false); + $bclConvertSettingsSection->trimUMI = false; $bclConvertDataSection = new DataSection(); - $bclConvertDataSection->addSample( - (new BclSample(1, 'Sample1', 'Index1')) - ->setIndex2('Index2') - ->setOverrideCycles('Cycles1') - ->setAdapterRead1('Adapter1') - ->setAdapterRead2('Adapter2') - ); - $bclConvertDataSection->addSample( - (new BclSample(2, 'Sample2', 'Index3')) - ->setIndex2('Index4') - ->setOverrideCycles('Cycles2') - ->setAdapterRead1('Adapter3') - ->setAdapterRead2('Adapter4') - ); - $bclConvertDataSection->addSample( - (new BclSample(3, 'Sample3', 'Index5')) - ->setIndex2('Index6') - ->setOverrideCycles('Cycles3') - ->setAdapterRead1('Adapter5') - ->setAdapterRead2('Adapter6') - ); + $bclSample = new BclSample(1, 'Sample1', 'Index1'); + $bclSample->index2 = 'Index2'; + $bclSample->overrideCycles = 'Cycles1'; + $bclSample->adapterRead1 = 'Adapter1'; + $bclSample->adapterRead2 = 'Adapter2'; + + $bclSample1 = new BclSample(2, 'Sample2', 'Index3'); + $bclSample1->index2 = 'Index4'; + $bclSample1->overrideCycles = 'Cycles2'; + $bclSample1->adapterRead1 = 'Adapter3'; + $bclSample1->adapterRead2 = 'Adapter4'; + + $bclSample2 = new BclSample(3, 'Sample3', 'Index5'); + $bclSample2->index2 = 'Index6'; + $bclSample2->overrideCycles = 'Cycles3'; + $bclSample2->adapterRead1 = 'Adapter5'; + $bclSample2->adapterRead2 = 'Adapter6'; + + $bclConvertDataSection->addSample($bclSample); + $bclConvertDataSection->addSample($bclSample1); + $bclConvertDataSection->addSample($bclSample2); $bclConvertSection = new BclConvertSection($bclConvertSettingsSection, $bclConvertDataSection); From 27b6b660ac0829a463c936ae457fcde4494ee3eb Mon Sep 17 00:00:00 2001 From: Simon Bigelmayr Date: Wed, 8 May 2024 09:28:40 +0200 Subject: [PATCH 27/29] add comment to sample_ID property --- src/IlluminaSampleSheet/V2/BclConvert/BclSample.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php index bcfced0..a02516f 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php @@ -6,6 +6,7 @@ class BclSample { public int $lane; + // Keep the name "$sample_ID" as it is, because the property-name is used to generate the csv header line for the BCL-Sample-Section public string $sample_ID; public string $index; @@ -23,12 +24,12 @@ class BclSample public ?string $barcodeMismatchesIndex2 = null; public function __construct( - int $lane, - string $sampleID, + int $lane, + string $sample_ID, string $index ) { $this->lane = $lane; - $this->sample_ID = $sampleID; + $this->sample_ID = $sample_ID; $this->index = $index; } From fbb9d6e0c65bf33d132f18c78b78e50ea365b3cc Mon Sep 17 00:00:00 2001 From: simbig Date: Wed, 8 May 2024 07:31:10 +0000 Subject: [PATCH 28/29] Apply php-cs-fixer changes --- src/IlluminaSampleSheet/V2/BclConvert/BclSample.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php index a02516f..492954a 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php @@ -24,7 +24,7 @@ class BclSample public ?string $barcodeMismatchesIndex2 = null; public function __construct( - int $lane, + int $lane, string $sample_ID, string $index ) { From 3c2c3b414f1478b1320865ec69132efa09669cbf Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 8 May 2024 09:51:27 +0200 Subject: [PATCH 29/29] PHPDoc --- src/IlluminaSampleSheet/V2/BclConvert/BclSample.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php index 492954a..23c9bf4 100644 --- a/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php +++ b/src/IlluminaSampleSheet/V2/BclConvert/BclSample.php @@ -6,7 +6,7 @@ class BclSample { public int $lane; - // Keep the name "$sample_ID" as it is, because the property-name is used to generate the csv header line for the BCL-Sample-Section + /** Not using camelCase because the property names of this class must match the CSV file. */ public string $sample_ID; public string $index;