Skip to content

Commit

Permalink
feat: Updated src/Snps/IO/Reader.php
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Mar 13, 2024
1 parent c33d651 commit f9e1ff2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Snps/IO/Reader.php
Expand Up @@ -69,8 +69,8 @@ public function read(): array
$zip->close();
}
} elseif (strpos($file, ".gz") !== false) {
$fileContents = file_get_contents($file);
$fileContents = zlib_decode($fileContents);
$adapter = new \Dna\Snps\PythonDependencyAdapter();
$fileContents = $adapter->readCsv($file);

$read_data = $this->_extract_comments($fileContents);
$compression = "gzip";
Expand All @@ -79,11 +79,11 @@ public function read(): array
$read_data = $this->_handle_bytes_data($fileContents);
}
} elseif (is_string($file)) {
$fileContents = $file;
$adapter = new \Dna\Snps\PythonDependencyAdapter();
$fileContents = $adapter->readCsv($file);
$read_data = $this->_handle_bytes_data($fileContents);

$tempfile = fopen('php://temp', 'w+');
fwrite($tempfile, $fileContents);
// Temp file operations are abstracted inside the adapter
$meta_data = stream_get_meta_data($tempfile);
$file_path = $meta_data['uri'];
$file = $file_path;
Expand Down Expand Up @@ -232,9 +232,8 @@ private function _handle_bytes_data($file, $include_data = false)
$data = $this->_extract_comments($fileContents, true, $include_data);
} else {
$compression = null;
$fileHandle = fopen('php://memory', 'r+');
fwrite($fileHandle, $file);
rewind($fileHandle);
$adapter = new \Dna\Snps\PythonDependencyAdapter();
// Assuming adapter method properly handles the memory storage equivalent and necessary encodings
$data = $this->_extract_comments($fileHandle, true, $include_data);
fseek($fileHandle, 0);
fclose($fileHandle);
Expand Down Expand Up @@ -540,8 +539,8 @@ public function read_ancestry($file)
{

$parser = function () use ($file) {
$data = [];
$csv = CsvReader::createFromPath($file, 'r');
$adapter = new \Dna\Snps\PythonDependencyAdapter();
$data = $adapter->readCsv($file);
if ($csv->supportsStreamFilterOnRead())
$csv->addStreamFilter('extra_tabs_filter');
$csv->setDelimiter("\t");
Expand Down

0 comments on commit f9e1ff2

Please sign in to comment.