forked from tomclegg/get-evidence
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_flat_summary.php
executable file
·66 lines (58 loc) · 1.72 KB
/
update_flat_summary.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
#!/usr/bin/php
<?php
;
// Copyright: see COPYING
// Authors: see git-blame(1)
chdir ('public_html');
include "lib/setup.php";
evidence_create_tables();
function sqlflush (&$sql, &$sqlparam)
{
if (count ($sqlparam) == 0) {
$sql = "";
return;
}
$sql = ereg_replace (',$', '', $sql);
$q = theDb()->query ("REPLACE INTO flat_summary (variant_id, flat_summary, autoscore, webscore, n_genomes) VALUES $sql", $sqlparam);
if (theDb()->isError ($q)) die ($q->getMessage());
$sql = "";
$sqlparam = array();
}
print "Updating flat_summary...\n";
$snap = "latest";
// If any are missing, just generate those
$join = "LEFT JOIN flat_summary fs ON v.variant_id=fs.variant_id WHERE fs.variant_id IS NULL";
$tot = theDb()->getOne ("SELECT COUNT(*) FROM variants v $join");
if ($tot == 0) {
// If none are missing, refresh all
$join = "";
$tot = theDb()->getOne ("SELECT COUNT(*) FROM variants v");
}
$q = theDb()->query ("SELECT DISTINCT v.variant_id FROM variants v $join");
$n = 0;
$starttime = time();
$eta = "";
$sql = "";
while ($row =& $q->fetchRow()) {
++$n;
if ($n % 30 == 0) {
$remain = (time()-$starttime)*($tot-$n)/$n;
$eta = sprintf ("ETA %d:%02d:%02ds = %s ",
floor($remain/3600),
floor($remain/60)%60,
floor($remain)%60,
date("r", time()+$remain));
}
print "\r$n / $tot $eta";
$flat = evidence_get_assoc_flat_summary ($snap, $row["variant_id"]);
$sql .= "(?, ?, ?, ?, ?),";
$sqlparam[] = $row["variant_id"];
$sqlparam[] = json_encode ($flat);
$sqlparam[] = $flat["autoscore"];
$sqlparam[] = $flat["webscore"];
$sqlparam[] = $flat["n_genomes"];
if (count($sqlparam) > 100)
sqlflush (&$sql, &$sqlparam);
}
sqlflush (&$sql, &$sqlparam);
print "\n";