Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep: (βœ“ Sandbox Passed) #116

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/Snps/ReferenceSequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class ReferenceSequence
{

public function __construct(
private readonly string $ID = "",
private readonly string $url = "",
private readonly string $path = "",
private readonly string $assembly = "",
private readonly string $species = "",
private readonly string $taxonomy = ""
private string $ID = "",
private string $url = "",
private string $path = "",
private string $assembly = "",
private string $species = "",
private string $taxonomy = ""
) {
$this->sequence = [];
$this->md5 = "";
Expand All @@ -37,7 +37,7 @@ public function __toString()
*/
public function getID(): string
{
return $this->_ID;
return $this->ID;
}

/**
Expand All @@ -47,7 +47,7 @@ public function getID(): string
*/
public function getChrom(): string
{
return $this->_ID;
return $this->ID;
}

/**
Expand All @@ -57,7 +57,7 @@ public function getChrom(): string
*/
public function getUrl(): string
{
return $this->_url;
return $this->url;
}

/**
Expand All @@ -67,7 +67,7 @@ public function getUrl(): string
*/
public function getPath(): string
{
return $this->_path;
return $this->path;
}

/**
Expand All @@ -77,7 +77,7 @@ public function getPath(): string
*/
public function getAssembly(): string
{
return $this->_assembly;
return $this->assembly;
}

/**
Expand All @@ -87,7 +87,7 @@ public function getAssembly(): string
*/
public function getBuild(): string
{
return "B" . substr($this->_assembly, -2);
return "B" . substr($this->assembly, -2);
}
/**
* Returns the species of the reference sequence.
Expand All @@ -96,7 +96,7 @@ public function getBuild(): string
*/
public function getSpecies(): string
{
return $this->_species;
return $this->species;
}

/**
Expand All @@ -106,7 +106,7 @@ public function getSpecies(): string
*/
public function getTaxonomy(): string
{
return $this->_taxonomy;
return $this->taxonomy;
}

/**
Expand Down Expand Up @@ -167,7 +167,7 @@ private function loadSequence(): void
{
if (!count($this->sequence)) {
// Decompress and read file
$data = file_get_contents($this->_path);
$data = file_get_contents($this->path);

// check if file is gzipped
if (str_starts_with($data, "\x1f\x8b")) {
Expand Down
52 changes: 52 additions & 0 deletions src/Snps/Resources.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Dna\Snps;

use GuzzleHttp\Client;

class Resources
{
private string $baseUrl;
private string $localResourceDir;
private Client $httpClient;

public function __construct(string $baseUrl, string $localResourceDir)
{
$this->baseUrl = $baseUrl;
$this->localResourceDir = $localResourceDir;
$this->httpClient = new Client();
}

public function downloadResource(string $url, string $destinationPath): void
{
$response = $this->httpClient->get($url);
file_put_contents($destinationPath, $response->getBody());
}

public function loadDataFromFile(string $filePath)
{
return file_get_contents($filePath);
}

public function getReferenceSequence(string $id): ReferenceSequence
{
$filePath = $this->getLocalPathForResource($id);
$sequenceData = $this->loadDataFromFile($filePath);
return new ReferenceSequence($id, $sequenceData);
}

public function getAssemblyMappingData(string $id)
{
// Implementation for fetching assembly mapping data
}

public function getExampleDataset(string $id)
{
// Implementation for fetching example datasets
}

private function getLocalPathForResource(string $resourceId): string
{
return $this->localResourceDir . DIRECTORY_SEPARATOR . $resourceId;
}
}