Skip to content

Commit

Permalink
Merge pull request #112 from liberu-genealogy/sweep/_3b4fc
Browse files Browse the repository at this point in the history
Sweep:  (✓ Sandbox Passed)
  • Loading branch information
curtisdelicata committed Mar 12, 2024
2 parents b437c4a + e5ebcc9 commit 78a634f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
10 changes: 8 additions & 2 deletions src/Snps/IO/CsvReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public function setColumnNames($columnNames)
}

public function setColumnTypes($columnTypes)
private $enclosure;

public function setEnclosure($enclosure)
{
$this->enclosure = $enclosure;
}
{
$this->columnTypes = $columnTypes;
}
Expand All @@ -45,10 +51,10 @@ public function read()

if (($handle = fopen($this->filePath, "r")) !== false) {
if ($this->header) {
fgetcsv($handle, 0, $this->separator); // Skip the header row
fgetcsv($handle, 0, $this->separator, $this->enclosure); // Skip the header row
}

while (($row = fgetcsv($handle, 0, $this->separator)) !== false) {
while (($row = fgetcsv($handle, 0, $this->separator, $this->enclosure)) !== false) {
if (!empty($this->columnNames)) {
print_r($row);
$row = array_combine($this->columnNames, $row);
Expand Down
1 change: 1 addition & 0 deletions src/Snps/IO/ExtraTabsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ public function filter($in, $out, int &$consumed, bool $closing): int
return PSFS_PASS_ON;
}
}
stream_filter_register("extra_tabs_filter", "Dna\\Snps\\IO\\ExtraTabsFilter");
20 changes: 9 additions & 11 deletions src/Snps/IO/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,27 @@ public function __construct(
private ?SNPsResources $resources,
private array $rsids
) {}
}

/**
* Read and parse a raw data / genotype file.
*
* @return array
* An array with the following items:
* - snps (pandas.DataFrame): Dataframe of parsed SNPs.
* - source (string): Detected source of SNPs.
* - phased (bool): Flag indicating if SNPs are phased.
* @return array An array with the following items:
* - 'snps': Array of parsed SNPs.
* - 'source': Detected source of SNPs.
* - 'phased': Flag indicating if SNPs are phased.
* - 'build': Detected build of SNPs.
*/
public function read(): array
{
$file = $this->file;
$compression = "infer";
$read_data = [];
$d = array(
"snps" => IO::get_empty_snps_dataframe(),
$d = [
"snps" => [],
"source" => "",
"phased" => false,
"build" => 0,
);
// Peek into files to determine the data format
// var_dump($file);
];
if (is_string($file) && file_exists($file)) {
if (strpos($file, ".zip") !== false) {
$zip = new ZipArchive(ZipArchive::RDONLY);
Expand Down

0 comments on commit 78a634f

Please sign in to comment.