-
Notifications
You must be signed in to change notification settings - Fork 5
/
import_dbsnp.php
executable file
·108 lines (83 loc) · 2.54 KB
/
import_dbsnp.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/php
<?php
;
// Copyright: see COPYING
// Authors: see git-blame(1)
if ($_SERVER["argc"] < 2)
{
die ("Usage: ".$_SERVER["argv"][0]." b130.bcp.gz\n");
}
$rundir = getcwd();
$fifo = $rundir."/tmp/".$_SERVER["argv"][0].".fifo";
@unlink ($fifo);
system ("mkfifo ".escapeshellarg($fifo));
if (($child = pcntl_fork()) === 0) {
$filename = $_SERVER["argv"][1];
$ph = popen ("gzip -cdf ".escapeshellarg($filename), "r");
$fh = fopen ($fifo, "w");
$line_count = 0;
$bytes_read = 0;
while ($line = fgets ($ph)) {
fputs ($fh, $line);
if (++$line_count % 100000 == 0) {
if ($line_count > 100000)
print "\010\010\010\010\010\010\010\010\010\010\010\010\010";
printf ("%10d...", $line_count);
}
}
fclose ($fh);
pclose ($ph);
printf ("\010\010\010\010\010\010\010\010\010\010\010\010\010%10d input rows...", $line_count);
exit;
}
if (!($child > 0)) {
die ("fork failed, giving up.\n");
}
chdir ('public_html');
require_once 'lib/setup.php';
chdir ($rundir);
print "Creating/updating get-evidence tables...";
evidence_create_tables ();
print "\n";
print "Creating temporary table...";
theDb()->query ("CREATE TEMPORARY TABLE dbsnp_tmp (
id INT UNSIGNED NOT NULL PRIMARY KEY,
chr CHAR(7) NOT NULL,
chr_pos INT UNSIGNED NOT NULL,
orient TINYINT UNSIGNED NOT NULL
)");
print "\n";
print "Importing...";
$q = theDb()->query ("LOAD DATA LOCAL INFILE ?
INTO TABLE dbsnp_tmp
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'",
array ($fifo));
if (theDb()->isError($q)) die ($q->getMessage());
print theDb()->affectedRows();
print "\n";
print "Removing chr=\"Multi\" rows...";
theDb()->query ("DELETE FROM dbsnp_tmp WHERE chr=?", array("Multi"));
print theDb()->affectedRows();
print "\n";
print "Removing chr_pos=0 rows...";
theDb()->query ("DELETE FROM dbsnp_tmp WHERE chr_pos=0");
print theDb()->affectedRows();
print "\n";
print "Adding \"chr\" prefix to chr column...";
theDb()->query ("UPDATE dbsnp_tmp SET chr=CONCAT('chr',chr)");
print theDb()->affectedRows();
print "\n";
print "Adding 1 to chr_pos column to get 1-based coordinates...";
theDb()->query ("UPDATE dbsnp_tmp SET chr_pos=chr_pos+1");
print theDb()->affectedRows();
print "\n";
print "Copying data to real dbsnp table...";
theDb()->query ("LOCK TABLES dbsnp WRITE");
theDb()->query ("DELETE FROM dbsnp");
theDb()->query ("INSERT INTO dbsnp (id,chr,chr_pos,orient) SELECT * FROM dbsnp_tmp");
print theDb()->affectedRows();
theDb()->query ("UNLOCK TABLES");
print "\n";
theDb()->query ("DROP TEMPORARY TABLE dbsnp_tmp");
?>