Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement PythonDependencyAdapter for Python
- Loading branch information
1 parent
87b5cd2
commit 56fda3c
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Dna\Snps; | ||
|
||
use MathPHP\LinearAlgebra\Matrix; | ||
use MathPHP\Statistics\Descriptive; | ||
use League\Csv\Reader; | ||
use League\Csv\Writer; | ||
|
||
class PythonDependencyAdapter | ||
{ | ||
public function readCsv(string $filePath): array | ||
{ | ||
$csv = Reader::createFromPath($filePath, 'r'); | ||
$csv->setHeaderOffset(0); | ||
return $csv->getRecords(); | ||
} | ||
|
||
public function writeCsv(string $filePath, array $data): void | ||
{ | ||
$csv = Writer::createFromPath($filePath, 'w+'); | ||
$csv->insertOne(array_keys(reset($data))); | ||
$csv->insertAll($data); | ||
} | ||
|
||
public function matrixMultiplication(array $matrix1, array $matrix2): Matrix | ||
{ | ||
$matrixA = new Matrix($matrix1); | ||
$matrixB = new Matrix($matrix2); | ||
return $matrixA->multiply($matrixB); | ||
} | ||
|
||
public function calculateMean(array $data): float | ||
{ | ||
return Descriptive::mean($data); | ||
} | ||
|
||
public function filterData(array $data, callable $callback): array | ||
{ | ||
return array_filter($data, $callback); | ||
} | ||
|
||
public function mergeData(array $data1, array $data2): array | ||
{ | ||
return array_merge($data1, $data2); | ||
} | ||
} |