-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQueryDecipher.php
More file actions
100 lines (77 loc) · 2 KB
/
QueryDecipher.php
File metadata and controls
100 lines (77 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Decipher;
use App\Gene;
class QueryDecipher extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'decipher:query';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
echo "Updating HI Predictions from Decipher ...";
try {
// $results = file_get_contents("https://decipher.sanger.ac.uk/files/downloads/HI_Predictions_Version3.bed.gz");
$results = file_get_contents("https://www.deciphergenomics.org/files/downloads/HI_Predictions_Version3.bed.gz");
} catch (\Exception $e) {
echo "\n(E001) Error retreiving decipher data\n";
exit;
}
// unzip the data
$data = gzdecode($results);
// discard the header
$line = strtok($data, "\n");
// parse the remaining file
while (($line = strtok("\n")) !== false)
{
$parts = explode("\t", $line, 5);
// what we want is in the fourth section...
if (isset($parts[3]))
{
//... and is itself delimited by pipes
$subparts = explode('|', $parts[3]);
if (isset($subparts['2']) && strpos($subparts['2'], '%') !== false)
{
$gene = Gene::where('name', $subparts[0])->first();
if (empty($gene))
{
// check previous sympols
$gene = Gene::whereJsonContains('prev_symbol', $subparts[0])->first();
}
if (empty($gene))
continue;
// remove the percent sign
$k = strpos($subparts['2'], '%');
$gene->hi = substr($subparts['2'], 0, $k);
$gene->save();
// echo $subparts['0'] . " has a HI of " . $subparts['2'] . "\n";
}
}
}
echo "DONE\n";
}
}