-
Notifications
You must be signed in to change notification settings - Fork 5
/
import_variant_frequency.php
executable file
·85 lines (69 loc) · 2.87 KB
/
import_variant_frequency.php
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
#!/usr/bin/php
<?php
;
// Copyright: see COPYING
// Authors: see git-blame(1)
if ($_SERVER["argc"] < 2 || $_SERVER["argc"] > 3)
{
die ("Usage: ".$_SERVER["argv"][0]." variantid-frequency.tsv [tag]\n");
}
$rundir = getcwd();
chdir ('public_html');
require_once 'lib/setup.php';
chdir ($rundir);
print "Creating/updating get-evidence tables...";
evidence_create_tables ();
print "\n";
theDb()->query ("CREATE TEMPORARY TABLE import_variant_f (
variant_id VARCHAR(32),
variant_name VARCHAR(64) NOT NULL,
chr VARCHAR(12),
start BIGINT UNSIGNED,
end BIGINT UNSIGNED,
variant_alleles VARCHAR(32),
variant_count VARCHAR(32),
covered_count BIGINT UNSIGNED NOT NULL
)");
print "Loading ".$_SERVER["argv"][1]."...";
$q = theDb()->query ("LOAD DATA LOCAL INFILE ?
INTO TABLE import_variant_f
FIELDS TERMINATED BY '\t'
OPTIONALLY ENCLOSED BY '\\\"'
LINES TERMINATED BY '\n'",
array ($_SERVER["argv"][1]));
if (theDb()->isError($q)) print $q->getMessage();
print theDb()->affectedRows();
print "\n";
print "Looking up missing variant ids...";
$q = theDb()->query ("UPDATE import_variant_f SET variant_id=NULL where variant_id in ('unknown', 'null', '')");
$q = theDb()->query ("ALTER TABLE import_variant_f CHANGE variant_id variant_id BIGINT UNSIGNED");
$q = theDb()->query ("ALTER TABLE import_variant_f ADD INDEX(variant_id)");
$q = theDb()->query ("ALTER TABLE import_variant_f ADD INDEX(variant_name)");
$q = theDb()->query ("UPDATE import_variant_f SET variant_name = UPPER(replace(variant_name,'*','X'))");
$q = theDb()->query ("CREATE TEMPORARY TABLE v_id_name AS SELECT variant_id, if(variant_gene is null,concat('RS',variant_rsid),upper(concat(variant_gene,'-',variant_aa_del,variant_aa_pos,variant_aa_ins))) variant_name FROM variants");
$q = theDb()->query ("ALTER TABLE v_id_name ADD INDEX(variant_name)");
$q = theDb()->query ("UPDATE import_variant_f i
LEFT JOIN v_id_name v ON v.variant_name = i.variant_name
SET i.variant_id = v.variant_id
WHERE i.variant_id IS NULL");
if (theDb()->isError($q)) die ($q->getMessage());
print theDb()->affectedRows();
print "\n";
$tag = $_SERVER["argc"] == 3 ? $_SERVER["argv"][2] : "GET-Evidence";
print "Copying data into real variant_population_frequency table...";
theDb()->query ("START TRANSACTION");
theDb()->query ("DELETE FROM variant_population_frequency WHERE dbtag=?", array($tag));
theDb()->query ("REPLACE INTO variant_population_frequency
(variant_id, dbtag, chr, start, end, genotype, num, denom)
SELECT variant_id, ?, chr, start, end, variant_alleles, variant_count, covered_count
FROM import_variant_f
WHERE variant_id>0",
array ($tag));
if (theDb()->isError($q)) die ($q->getMessage());
print theDb()->affectedRows();
print "\n";
theDb()->query ("COMMIT");
if (theDb()->isError($q)) die ($q->getMessage());
theDb()->query ("DROP TEMPORARY TABLE import_variant_f");
if (theDb()->isError($q)) die ($q->getMessage());
?>